Package com.buttercms

Class ButterCMSClient

java.lang.Object
com.buttercms.ButterCMSClient
All Implemented Interfaces:
IButterCMSClient

public class ButterCMSClient
extends Object
implements IButterCMSClient
  • Constructor Details

    • ButterCMSClient

      public ButterCMSClient​(String authToken, boolean preview)
      Requests made with a missing or invalid token will get a 401 Unauthorized response. All requests must be made over HTTPS
      Parameters:
      authToken - ButterCMS auth_token
    • ButterCMSClient

      public ButterCMSClient​(String authToken, boolean preview, org.apache.http.client.HttpClient client)
      Requests made with a missing or invalid token will get a 401 Unauthorized response. All requests must be made over HTTPS
      Parameters:
      authToken - ButterCMS auth_token
      client - custom HttpClient
  • Method Details

    • getAuthToken

      public String getAuthToken()
      Specified by:
      getAuthToken in interface IButterCMSClient
      Returns:
      current auth_token
    • setAuthToken

      public void setAuthToken​(String authToken)
      Description copied from interface: IButterCMSClient
      sets new auth_token
      Specified by:
      setAuthToken in interface IButterCMSClient
      Parameters:
      authToken - new auth_token
    • getAuthor

      public AuthorResponse getAuthor​(String slug, Map<String,​String> queryParameters)
      Description copied from interface: IButterCMSClient
      Retrieves an author’s information
      Specified by:
      getAuthor in interface IButterCMSClient
      Parameters:
      slug - the slug of the author to be retrieved.
      queryParameters - query parameters as described in https://buttercms.com/docs/api/#authors
      Returns:
      author object
    • getAuthors

      public AuthorsResponse getAuthors​(Map<String,​String> queryParameters)
      Description copied from interface: IButterCMSClient
      Retrieves a list of authors
      Specified by:
      getAuthors in interface IButterCMSClient
      Parameters:
      queryParameters - query parameters as described in https://buttercms.com/docs/api/#authors
      Returns:
      a list of authors
    • getCategory

      public CategoryResponse getCategory​(String slug, Map<String,​String> queryParameters)
      Description copied from interface: IButterCMSClient
      Retrieves the details of a category
      Specified by:
      getCategory in interface IButterCMSClient
      Parameters:
      slug - The slug of the category to be retrieved
      queryParameters - query parameters as described in https://buttercms.com/docs/api/#categories
      Returns:
      a category object
    • getCategories

      public CategoriesResponse getCategories​(Map<String,​String> queryParameters)
      Description copied from interface: IButterCMSClient
      Returns a list of blog categories. You can include each category’s posts using the include=recent_posts query parameter.
      Specified by:
      getCategories in interface IButterCMSClient
      Parameters:
      queryParameters - query parameters as described in https://buttercms.com/docs/api/#categories
      Returns:
      an array of categories
    • getPage

      public <T> PageResponse<T> getPage​(String pageTypeSlug, String pageSlug, Map<String,​String> queryParameters, Class<T> classType)
      Description copied from interface: IButterCMSClient
      Get a single Page using its slug
      Specified by:
      getPage in interface IButterCMSClient
      Parameters:
      pageTypeSlug - Use '*'. If limiting to a Page Type, use the Page Type slug.
      pageSlug - The slug of the page.
      queryParameters - query parameters as described in https://buttercms.com/docs/api/#get-a-single-page
      classType - Object that Page should be deserialize in to
      Returns:
      A single page
    • getPages

      public <T> PagesResponse<T> getPages​(String pageTypeSlug, Map<String,​String> queryParameters, Class<T> classType)
      Description copied from interface: IButterCMSClient
      Get a list of all pages for a given Page Type using its slug.
      Specified by:
      getPages in interface IButterCMSClient
      Parameters:
      pageTypeSlug - The slug of the type of pages you want to retrieve
      queryParameters - query parameters as described in https://buttercms.com/docs/api/#get-multiple-pages-(page-type)
      classType - Object that Page should be deserialize in to
      Returns:
      A list of pages
    • getSearchPages

      public <T> PagesResponse<T> getSearchPages​(String pageTypeSlug, Map<String,​String> queryParameters, Class<T> classType)
      Description copied from interface: IButterCMSClient
      Get a list of all pages for a given Page Type using its slug.
      Specified by:
      getSearchPages in interface IButterCMSClient
      Parameters:
      pageTypeSlug - The slug of the type of pages you want to retrieve
      queryParameters - query parameters as described in https://buttercms.com/docs/api/#search-pages
      classType - Object that Page should be deserialize in to
      Returns:
      A list of pages
    • getCollection

      public <T> CollectionResponse<T> getCollection​(String collectionSlug, Map<String,​String> queryParameters, Class<T> classType)
      Description copied from interface: IButterCMSClient
      Returns values for the supplied Collection slug
      Specified by:
      getCollection in interface IButterCMSClient
      Parameters:
      collectionSlug - The slug of collection
      queryParameters - query parameters as described in https://buttercms.com/docs/api/#retrieve-a-collection
      classType - Object that Collection item should be deserialize in to
      Returns:
      a single collection
    • getPost

      public PostResponse getPost​(String slug)
      Description copied from interface: IButterCMSClient
      Get your Blog Post
      Specified by:
      getPost in interface IButterCMSClient
      Parameters:
      slug - The slug of post
      Returns:
      a single post
    • getPosts

      public PostsResponse getPosts​(Map<String,​String> queryParameters)
      Description copied from interface: IButterCMSClient
      Returns a list of published posts. The posts are returned sorted by publish date, with the most recent posts appearing first. The endpoint supports pagination and filtering.
      Specified by:
      getPosts in interface IButterCMSClient
      Parameters:
      queryParameters - query parameters as described in https://buttercms.com/docs/api/?shell#get-your-blog-posts
      Returns:
      a list of posts
    • getSearchPosts

      public PostsResponse getSearchPosts​(Map<String,​String> queryParameters)
      Description copied from interface: IButterCMSClient
      Returns a list of published posts searched by the given 'query' search term. The posts are returned sorted by publish date, with the most recent posts appearing first. The endpoint supports pagination and filtering.
      Specified by:
      getSearchPosts in interface IButterCMSClient
      Parameters:
      queryParameters - query parameters as described in https://buttercms.com/docs/api/?shell#search-posts
      Returns:
      a list of posts
    • getTag

      public TagResponse getTag​(String slug, Map<String,​String> queryParameters)
      Description copied from interface: IButterCMSClient
      Retrieves the details of a tag
      Specified by:
      getTag in interface IButterCMSClient
      Parameters:
      slug - Unique identifier
      queryParameters - query parameters as described in https://buttercms.com/docs/api/?shell#tags
      Returns:
      a single tag object
    • getTags

      public TagsResponse getTags​(Map<String,​String> queryParameters)
      Description copied from interface: IButterCMSClient
      Returns a list of blog tags. You can incude each tags’s posts using the include=recent_posts query parameter.
      Specified by:
      getTags in interface IButterCMSClient
      Parameters:
      queryParameters - query parameters as described in https://buttercms.com/docs/api/?shell#tags
      Returns:
      a list of blog tags
    • getSiteMap

      public Document getSiteMap()
      Specified by:
      getSiteMap in interface IButterCMSClient
      Returns:
      site map
    • getRSS

      public Document getRSS()
      Specified by:
      getRSS in interface IButterCMSClient
      Returns:
      an RSS feed
    • getAtom

      public Document getAtom()
      Specified by:
      getAtom in interface IButterCMSClient
      Returns:
      an ATOM feed