Package zendeskapi.requests

Source Code of zendeskapi.requests.Categories

package zendeskapi.requests;

import zendeskapi.ZendeskHttpHelper;
import zendeskapi.exception.ZendeskApiException;
import zendeskapi.models.categories.Category;
import zendeskapi.models.categories.GroupCategoryResponse;
import zendeskapi.models.categories.IndividualCategoryResponse;

public class Categories extends ZendeskHttpHelper {

  /**
   *
   * @param yourZendeskUrl
   * @param user
   * @param password
   */
  public Categories(String yourZendeskUrl, String user, String password) {
    super(yourZendeskUrl, user, password);
  }

  /**
   *
   * @return
   * @throws ZendeskApiException
   */
  public GroupCategoryResponse getCategories() throws ZendeskApiException {
    try {
      return genericGet("categories.json", GroupCategoryResponse.class);
    } catch (Exception e) {
      throw new ZendeskApiException("Getting categories failed", e);
    }
  }

  /**
   *
   * @param id
   * @return
   * @throws ZendeskApiException
   */
  public IndividualCategoryResponse getCategoryById(long id) throws ZendeskApiException {
    try {
      return genericGet("categories/" + id + ".json", IndividualCategoryResponse.class);
    } catch (Exception e) {
      throw new ZendeskApiException("Getting category with id " + id + " failed", e);
    }
  }

  /**
   *
   * @param category
   * @return
   * @throws ZendeskApiException
   */
  public IndividualCategoryResponse createCategory(Category category) throws ZendeskApiException {
    IndividualCategoryResponse categoryToCreate = new IndividualCategoryResponse();
    categoryToCreate.setCategory(category);
    try {
      return genericPost("categories.json", categoryToCreate, IndividualCategoryResponse.class);
    } catch (Exception e) {
      throw new ZendeskApiException("Faled to create categery " + category.getName(), e);
    }
  }

  /**
   *
   * @param category
   * @return
   * @throws ZendeskApiException
   */
  public IndividualCategoryResponse updateCategory(Category category) throws ZendeskApiException {
    IndividualCategoryResponse categoryToUpdate = new IndividualCategoryResponse();
    categoryToUpdate.setCategory(category);
    try {
      return genericPut("categories/" + category.getId() + ".json", categoryToUpdate, IndividualCategoryResponse.class);
    } catch (Exception e) {
      throw new ZendeskApiException("Update of category " + category.getName() + " failed", e);
    }
  }

  /**
   *
   * @param id
   * @return
   * @throws ZendeskApiException
   */
  public boolean deleteCategory(long id) throws ZendeskApiException {
    try {
      return genericDelete("categories/" + id + ".json");
    } catch (Exception e) {
      throw new ZendeskApiException("Deletion of category with id " + id + " failed", e);
    }
  }
}
TOP

Related Classes of zendeskapi.requests.Categories

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.