Class ReceiverSvc

java.lang.Object
com.patreonshout.rest.BaseSvc
com.patreonshout.rest.ReceiverSvc
All Implemented Interfaces:
ReceiverImpl

@RestController
public class ReceiverSvc
extends BaseSvc
implements ReceiverImpl
Patreon Webhook RESTful Endpoint Interface
  • Field Summary

    Fields
    Modifier and Type Field Description
    (package private) CreatorPageFunctions creatorPageFunctions
    An autowired Spring component that endpoints utilize to send or receive data from the database
    private com.patreon.PatreonOAuth oauthClient
    oauthClient is a communication layer to Patreon utilized for acquiring tokens when users link accounts via OAuth
    (package private) com.fasterxml.jackson.databind.ObjectMapper objectMapper
    Jackson object mapper that allows converting Java type Object to custom POJOs.
    (package private) PatreonCampaignsFunctions patreonCampaignsFunctions
    An autowired Spring component that endpoints utilize to send or receive data from the database
    private PatreonCredentials patreonCredentials
    patreonCredentials is a Spring bean that holds our Patreon client credentials
    (package private) PostsRepository postsRepository
    An autowired Spring component that endpoints utilize to send or receive data from the database
    private TwitterCredentials twitterCredentials
    twitterCredentials is a Spring bean that holds our Twitter app credentials
    (package private) WebAccountFunctions webAccountFunctions
    An autowired Spring component that endpoints utilize to send or receive data from the database
  • Constructor Summary

    Constructors
    Constructor Description
    ReceiverSvc()  
  • Method Summary

    Modifier and Type Method Description
    private void createWebhookForPatreon​(WebAccount webAccount, java.lang.String accessToken, int campaignId)
    Creates the Patreon webhook trigger needed to get post information when a post is published
    private java.lang.Object getCampaignData​(java.lang.String accessToken)
    Gets the campaign data for a content creator on patreon
    java.lang.String PatreonOAuth​(java.lang.String code, java.lang.String loginToken)
    Is called by Patreon in order to give us information for linking a user's account via OAuth
    org.springframework.http.ResponseEntity<?> PatreonWebhook​(java.lang.String patreonSignature, java.lang.String patreonEvent, java.lang.String userAgent, WebhookRequest webhookRequest, long webaccountId)
    Receives post information from Patreon after a post is either published, updated, or deleted, initiates cross posting
    void saveCampaignPosts​(java.lang.String accessToken, int campaignId)
    fetches posts from patreon and saves them in the database
    (package private) void sendDiscordMessage​(PatreonPostV2 patreonPost, java.lang.String webhookUrl)
    sends a message to Discord for a specific content creator
    (package private) void sendTwitterPost​(PatreonPostV2 patreonPost, WebAccount webAccount)
    sends a message to Twitter for a specific content creator
    java.lang.String TwitterOAuth​(java.lang.String code, java.lang.String state)
    Is called by Twitter in order to give us information for linking a user's account via OAuth

    Methods inherited from class com.patreonshout.rest.BaseSvc

    catchCustomException, catchSQLIntegrityConstraintViolationException

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • webAccountFunctions

      @Autowired WebAccountFunctions webAccountFunctions
      An autowired Spring component that endpoints utilize to send or receive data from the database
    • creatorPageFunctions

      @Autowired CreatorPageFunctions creatorPageFunctions
      An autowired Spring component that endpoints utilize to send or receive data from the database
    • patreonCampaignsFunctions

      @Autowired PatreonCampaignsFunctions patreonCampaignsFunctions
      An autowired Spring component that endpoints utilize to send or receive data from the database
    • postsRepository

      @Autowired PostsRepository postsRepository
      An autowired Spring component that endpoints utilize to send or receive data from the database
    • oauthClient

      @Autowired private com.patreon.PatreonOAuth oauthClient
      oauthClient is a communication layer to Patreon utilized for acquiring tokens when users link accounts via OAuth
    • twitterCredentials

      @Autowired private TwitterCredentials twitterCredentials
      twitterCredentials is a Spring bean that holds our Twitter app credentials
    • patreonCredentials

      @Autowired private PatreonCredentials patreonCredentials
      patreonCredentials is a Spring bean that holds our Patreon client credentials
    • objectMapper

      @Autowired com.fasterxml.jackson.databind.ObjectMapper objectMapper
      Jackson object mapper that allows converting Java type Object to custom POJOs.
  • Constructor Details

    • ReceiverSvc

      public ReceiverSvc()
  • Method Details

    • PatreonOAuth

      public java.lang.String PatreonOAuth​(@RequestParam(required=false,name="code") java.lang.String code, @RequestParam(required=false,name="state") java.lang.String loginToken) throws java.io.IOException, PSException
      Is called by Patreon in order to give us information for linking a user's account via OAuth
      Specified by:
      PatreonOAuth in interface ReceiverImpl
      Parameters:
      code - is used to fetch access tokens for the session that just signed in with Patreon
      loginToken - is transparently appended from the state param provided in PatreonShout Client from Dev Portal
      Returns:
      a json body telling the user that their Patreon was successfully OAuth'd
      Throws:
      java.io.IOException - when we cannot parse the input
      PSException - when there is an internal error with Patreon Shout
    • TwitterOAuth

      public java.lang.String TwitterOAuth​(java.lang.String code, java.lang.String state) throws org.json.simple.parser.ParseException, PSException
      Is called by Twitter in order to give us information for linking a user's account via OAuth
      Specified by:
      TwitterOAuth in interface ReceiverImpl
      Parameters:
      code - is used to fetch access tokens for the session that just signed in with Patreon
      state - is transparently appended from the state param provided in PatreonShout Client from Dev Portal
      Returns:
      a json body telling the user that their Twitter was successfully OAuth'd
      Throws:
      org.json.simple.parser.ParseException
      PSException
    • createWebhookForPatreon

      private void createWebhookForPatreon​(WebAccount webAccount, java.lang.String accessToken, int campaignId)
      Creates the Patreon webhook trigger needed to get post information when a post is published
      Parameters:
      webAccount - is the user's WebAccount object
      accessToken - is the access token of the user
      campaignId - is the Patreon campaign id of the user
    • getCampaignData

      private java.lang.Object getCampaignData​(java.lang.String accessToken) throws PSException
      Gets the campaign data for a content creator on patreon
      Parameters:
      accessToken - the content creator's access token, needed to gain information
      Returns:
      an PatreonDataV2 object
      Throws:
      PSException - in case there is a problem with the database or a user mismatch
    • saveCampaignPosts

      public void saveCampaignPosts​(java.lang.String accessToken, int campaignId) throws java.io.IOException
      fetches posts from patreon and saves them in the database
      Parameters:
      accessToken - Patreon access token for a creator
      campaignId - Patreon creator's campaign ID
      Throws:
      java.io.IOException
    • PatreonWebhook

      public org.springframework.http.ResponseEntity<?> PatreonWebhook​(@RequestHeader("x-patreon-signature") java.lang.String patreonSignature, @RequestHeader("x-patreon-event") java.lang.String patreonEvent, @RequestHeader("User-Agent") java.lang.String userAgent, @RequestBody WebhookRequest webhookRequest, @PathVariable long webaccountId) throws PSException
      Receives post information from Patreon after a post is either published, updated, or deleted, initiates cross posting
      Specified by:
      PatreonWebhook in interface ReceiverImpl
      Parameters:
      patreonSignature - is the HEX digest of the message body HMAC signed (with MD5) using your webhook's secret
      patreonEvent - is the event happening for the trigger request
      userAgent - is the user agent of the Patreon request
      webhookRequest - is the webhook request from Patreon
      webaccountId - is the user's web account id for the request
      Returns:
      HttpStatus.OK if successful
      Throws:
      PSException
    • sendDiscordMessage

      void sendDiscordMessage​(PatreonPostV2 patreonPost, java.lang.String webhookUrl)
      sends a message to Discord for a specific content creator
      Parameters:
      patreonPost - is the post data we want to send
      webhookUrl - is the Discord webhook url, used for sending a message to a specific Discord channel
    • sendTwitterPost

      void sendTwitterPost​(PatreonPostV2 patreonPost, WebAccount webAccount) throws PSException
      sends a message to Twitter for a specific content creator
      Parameters:
      patreonPost - is the post data we want to send
      webAccount - is the user we want to send a tweet for
      Throws:
      PSException - in case of a database problem or a user mismatch