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 users
    private com.github.jasminb.jsonapi.ResourceConverter converter
    converter is used to convert the json data returned into an object of our choosing
    private 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 url
    java.util.List<com.patreon.resources.Pledge> fetchAllPledges​(java.lang.String campaignId)
    Gets all the pledges from Patreon API
    com.github.jasminb.jsonapi.JSONAPIDocument<java.util.List<com.patreon.resources.Campaign>> fetchCampaigns()
    Gets the campaigns of a given access_token
    java.util.List<MembershipBean> fetchFollowingCampaigns()
    Gets the list of campaigns that the user is either following or pledged to
    com.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 pledges
    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)
    Gets a page of pledges from Patreon API
    com.github.jasminb.jsonapi.JSONAPIDocument<java.util.List<PostBean>> fetchPosts​(java.lang.String campaignId)
    Gets the Patreon posts from a given campaignId
    com.github.jasminb.jsonapi.JSONAPIDocument<com.patreon.resources.User> fetchUser()
    Gets the Patreon User information
    private java.io.InputStream getDataStream​(java.lang.String suffix, boolean apiV2)
    Wrapper for the request() function
    java.lang.String getNextCursorFromDocument​(com.github.jasminb.jsonapi.JSONAPIDocument document)
    Gets the cursor from a JSONAPIDocument object
    private java.lang.String getVersion()
    Gets the versions of different items from the place that the request is sent
    private java.io.InputStream request​(java.lang.String pathSuffix, java.lang.String accessToken, boolean apiV2)
    Gets the InputStream for the Patreon API request link we want to use

    Methods 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 log
      log is used to send log output to the terminal
    • accessToken

      private final java.lang.String accessToken
      accessToken is used to access the patreon API for different users
    • converter

      private com.github.jasminb.jsonapi.ResourceConverter converter
      converter 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.IOException
      Gets 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 of PostBean objects
      Throws:
      java.io.IOException - when it can't parse the json request
    • fetchFollowingCampaigns

      public java.util.List<MembershipBean> fetchFollowingCampaigns() throws java.io.IOException
      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.IOException
      Gets 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.IOException
      Gets the campaigns of a given access_token
      Returns:
      JSONAPIDocument with a list of Campaign 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.IOException
      Wrapper for fetching a page of pledges
      Parameters:
      campaignId - is the id of a campaign
      pageSize - is the size of a page
      pageCursor - 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.IOException
      Gets a page of pledges from Patreon API
      Parameters:
      campaignId - is the id of a campaign
      pageSize - is the size of a page
      pageCursor - is the page cursor
      optionalFields - are the optional fields a user may want to provide for more information
      Returns:
      a JSONAPIDocument with a list of Pledge 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 a JSONAPIDocument 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.IOException
      Gets 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.IOException
      Wrapper for the request() function
      Parameters:
      suffix - the suffix of the Patreon request url
      apiV2 - 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 builder
      type - is the type of param given to Patreon
      fields - 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.IOException
      Gets the InputStream for the Patreon API request link we want to use
      Parameters:
      pathSuffix - is the suffix of the Patreon request url
      accessToken - is used to access the patreon API for a specific user's data
      apiV2 - 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.IOException
      Gets 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