Package com.patreonshout.rest
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 databaseprivate 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 typeObject
to custom POJOs.(package private) PatreonCampaignsFunctions
patreonCampaignsFunctions
An autowired Spring component that endpoints utilize to send or receive data from the databaseprivate 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 databaseprivate 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 publishedprivate java.lang.Object
getCampaignData(java.lang.String accessToken)
Gets the campaign data for a content creator on patreonjava.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 OAuthorg.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 postingvoid
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 creatorjava.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 OAuthMethods 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
An autowired Spring component that endpoints utilize to send or receive data from the database -
creatorPageFunctions
An autowired Spring component that endpoints utilize to send or receive data from the database -
patreonCampaignsFunctions
An autowired Spring component that endpoints utilize to send or receive data from the database -
postsRepository
An autowired Spring component that endpoints utilize to send or receive data from the database -
oauthClient
@Autowired private com.patreon.PatreonOAuth oauthClientoauthClient is a communication layer to Patreon utilized for acquiring tokens when users link accounts via OAuth -
twitterCredentials
twitterCredentials is a Spring bean that holds our Twitter app credentials -
patreonCredentials
patreonCredentials is a Spring bean that holds our Patreon client credentials -
objectMapper
@Autowired com.fasterxml.jackson.databind.ObjectMapper objectMapperJackson object mapper that allows converting Java typeObject
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, PSExceptionIs called by Patreon in order to give us information for linking a user's account via OAuth- Specified by:
PatreonOAuth
in interfaceReceiverImpl
- Parameters:
code
- is used to fetch access tokens for the session that just signed in with PatreonloginToken
- 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 inputPSException
- 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, PSExceptionIs called by Twitter in order to give us information for linking a user's account via OAuth- Specified by:
TwitterOAuth
in interfaceReceiverImpl
- Parameters:
code
- is used to fetch access tokens for the session that just signed in with Patreonstate
- 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'sWebAccount
objectaccessToken
- is the access token of the usercampaignId
- is the Patreon campaign id of the user
-
getCampaignData
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.IOExceptionfetches posts from patreon and saves them in the database- Parameters:
accessToken
- Patreon access token for a creatorcampaignId
- 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 PSExceptionReceives post information from Patreon after a post is either published, updated, or deleted, initiates cross posting- Specified by:
PatreonWebhook
in interfaceReceiverImpl
- Parameters:
patreonSignature
- is the HEX digest of the message body HMAC signed (with MD5) using your webhook's secretpatreonEvent
- is the event happening for the trigger requestuserAgent
- is the user agent of the Patreon requestwebhookRequest
- is the webhook request from PatreonwebaccountId
- is the user's web account id for the request- Returns:
HttpStatus.OK
if successful- Throws:
PSException
-
sendDiscordMessage
sends a message to Discord for a specific content creator- Parameters:
patreonPost
- is the post data we want to sendwebhookUrl
- is the Discord webhook url, used for sending a message to a specific Discord channel
-
sendTwitterPost
sends a message to Twitter for a specific content creator- Parameters:
patreonPost
- is the post data we want to sendwebAccount
- is the user we want to send a tweet for- Throws:
PSException
- in case of a database problem or a user mismatch
-