Package com.patreonshout.patreon
Class CustomPatreonAPI
java.lang.Object
com.patreonshout.patreon.CustomPatreonAPI
public class CustomPatreonAPI
extends java.lang.Object
Used to send Patreon API requests
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
accessToken
accessToken is used to access the patreon API for different usersprivate com.github.jasminb.jsonapi.ResourceConverter
converter
converter is used to convert the json data returned into an object of our choosingprivate static org.slf4j.Logger
log
log is used to send log output to the terminal -
Constructor Summary
Constructors Constructor Description CustomPatreonAPI(java.lang.String accessToken)
Initializes variables needed for sending requests to the Patreon API -
Method Summary
Modifier and Type Method Description private org.apache.http.client.utils.URIBuilder
addFieldsParam(org.apache.http.client.utils.URIBuilder builder, java.lang.Class<? extends com.patreon.resources.shared.BaseResource> type, java.util.Collection<? extends com.patreon.resources.shared.Field> fields)
Adds Field parameters to the Patreon request urljava.util.List<com.patreon.resources.Pledge>
fetchAllPledges(java.lang.String campaignId)
Gets all the pledges from Patreon APIcom.github.jasminb.jsonapi.JSONAPIDocument<java.util.List<com.patreon.resources.Campaign>>
fetchCampaigns()
Gets the campaigns of a given access_tokenjava.util.List<MembershipBean>
fetchFollowingCampaigns()
Gets the list of campaigns that the user is either following or pledged tocom.github.jasminb.jsonapi.JSONAPIDocument<java.util.List<com.patreon.resources.Pledge>>
fetchPageOfPledges(java.lang.String campaignId, int pageSize, java.lang.String pageCursor)
Wrapper for fetching a page of pledgescom.github.jasminb.jsonapi.JSONAPIDocument<java.util.List<com.patreon.resources.Pledge>>
fetchPageOfPledges(java.lang.String campaignId, int pageSize, java.lang.String pageCursor, java.util.Collection<com.patreon.resources.Pledge.PledgeField> optionalFields)
Gets a page of pledges from Patreon APIcom.github.jasminb.jsonapi.JSONAPIDocument<java.util.List<PostBean>>
fetchPosts(java.lang.String campaignId)
Gets the Patreon posts from a given campaignIdcom.github.jasminb.jsonapi.JSONAPIDocument<com.patreon.resources.User>
fetchUser()
Gets the Patreon User informationprivate java.io.InputStream
getDataStream(java.lang.String suffix, boolean apiV2)
Wrapper for the request() functionjava.lang.String
getNextCursorFromDocument(com.github.jasminb.jsonapi.JSONAPIDocument document)
Gets the cursor from aJSONAPIDocument
objectprivate java.lang.String
getVersion()
Gets the versions of different items from the place that the request is sentprivate java.io.InputStream
request(java.lang.String pathSuffix, java.lang.String accessToken, boolean apiV2)
Gets theInputStream
for the Patreon API request link we want to useMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
log
private static final org.slf4j.Logger loglog is used to send log output to the terminal -
accessToken
private final java.lang.String accessTokenaccessToken is used to access the patreon API for different users -
converter
private com.github.jasminb.jsonapi.ResourceConverter converterconverter is used to convert the json data returned into an object of our choosing
-
-
Constructor Details
-
CustomPatreonAPI
public CustomPatreonAPI(java.lang.String accessToken)Initializes variables needed for sending requests to the Patreon API- Parameters:
accessToken
- is used to access the patreon API for different users
-
-
Method Details
-
fetchPosts
public com.github.jasminb.jsonapi.JSONAPIDocument<java.util.List<PostBean>> fetchPosts(java.lang.String campaignId) throws java.io.IOExceptionGets the Patreon posts from a given campaignId- Parameters:
campaignId
- is the id of the campaign we want to get posts from- Returns:
- a
JSONAPIDocument
containing a list ofPostBean
objects - Throws:
java.io.IOException
- when it can't parse the json request
-
fetchFollowingCampaigns
Gets the list of campaigns that the user is either following or pledged to- Returns:
- a list of
MembershipBean
objects - Throws:
java.io.IOException
- when it can't parse the json request
-
fetchUser
public com.github.jasminb.jsonapi.JSONAPIDocument<com.patreon.resources.User> fetchUser() throws java.io.IOExceptionGets the Patreon User information- Returns:
- User object containing user information
- Throws:
java.io.IOException
- when it can't parse the json request
-
fetchCampaigns
public com.github.jasminb.jsonapi.JSONAPIDocument<java.util.List<com.patreon.resources.Campaign>> fetchCampaigns() throws java.io.IOExceptionGets the campaigns of a given access_token- Returns:
JSONAPIDocument
with a list ofCampaign
objects- Throws:
java.io.IOException
- when it can't parse the json request
-
fetchPageOfPledges
public com.github.jasminb.jsonapi.JSONAPIDocument<java.util.List<com.patreon.resources.Pledge>> fetchPageOfPledges(java.lang.String campaignId, int pageSize, java.lang.String pageCursor) throws java.io.IOExceptionWrapper for fetching a page of pledges- Parameters:
campaignId
- is the id of a campaignpageSize
- is the size of a pagepageCursor
- is the page cursor- Returns:
- Throws:
java.io.IOException
- when it can't parse the json request
-
fetchPageOfPledges
public com.github.jasminb.jsonapi.JSONAPIDocument<java.util.List<com.patreon.resources.Pledge>> fetchPageOfPledges(java.lang.String campaignId, int pageSize, java.lang.String pageCursor, java.util.Collection<com.patreon.resources.Pledge.PledgeField> optionalFields) throws java.io.IOExceptionGets a page of pledges from Patreon API- Parameters:
campaignId
- is the id of a campaignpageSize
- is the size of a pagepageCursor
- is the page cursoroptionalFields
- are the optional fields a user may want to provide for more information- Returns:
- a
JSONAPIDocument
with a list ofPledge
objects - Throws:
java.io.IOException
- when it can't parse the json request
-
getNextCursorFromDocument
public java.lang.String getNextCursorFromDocument(com.github.jasminb.jsonapi.JSONAPIDocument document)Gets the cursor from aJSONAPIDocument
object- Parameters:
document
- is the document to be parsed for a cursor- Returns:
- a String containing the cursor
-
fetchAllPledges
public java.util.List<com.patreon.resources.Pledge> fetchAllPledges(java.lang.String campaignId) throws java.io.IOExceptionGets all the pledges from Patreon API- Parameters:
campaignId
- is the id of a campaign- Returns:
- a list of
Pledge
objects - Throws:
java.io.IOException
- when it can't parse the json request
-
getDataStream
private java.io.InputStream getDataStream(java.lang.String suffix, boolean apiV2) throws java.io.IOExceptionWrapper for the request() function- Parameters:
suffix
- the suffix of the Patreon request urlapiV2
- is the version of the endpoint we will be calling from Patreon- Returns:
- an
InputStream
object pointing to the Patreon api - Throws:
java.io.IOException
- when it can't parse the json request
-
addFieldsParam
private org.apache.http.client.utils.URIBuilder addFieldsParam(org.apache.http.client.utils.URIBuilder builder, java.lang.Class<? extends com.patreon.resources.shared.BaseResource> type, java.util.Collection<? extends com.patreon.resources.shared.Field> fields)Adds Field parameters to the Patreon request url- Parameters:
builder
- is the uri request buildertype
- is the type of param given to Patreonfields
- are the fields we want from Patreon's type of param- Returns:
- a
URIBuilder
of the field params we want to add
-
request
private java.io.InputStream request(java.lang.String pathSuffix, java.lang.String accessToken, boolean apiV2) throws java.io.IOExceptionGets theInputStream
for the Patreon API request link we want to use- Parameters:
pathSuffix
- is the suffix of the Patreon request urlaccessToken
- is used to access the patreon API for a specific user's dataapiV2
- is a boolean representing what version of the Patreon API we want to use- Returns:
- an
InputStream
object pointing to our Patreon API request link - Throws:
java.io.IOException
- when it can't parse the json request
-
getVersion
private java.lang.String getVersion() throws java.io.IOExceptionGets the versions of different items from the place that the request is sent- Returns:
- a String holding the versions of different items fromt he place that the request is sent
- Throws:
java.io.IOException
- when it can't parse the json request
-