aboutsummaryrefslogtreecommitdiff
path: root/lib/zendex/ticket.ex
blob: 9232d6ed49006c8438f7a97325705728dee7f452 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
defmodule Zendex.Ticket do
  @moduledoc """
  Allows interaction with the Zendesk Ticket API, to so things such as creating
  and listing tickets.
  """

  alias Zendex.CommonHelpers

  @url "/api/v2/tickets.json"
  @http_client Application.get_env(:zendex, :http_client)

  @doc """
  List all tickets.
  """
  @spec list(Zendex.Connection.t) :: map
  def list(connection) do
    "#{connection.base_url}#{@url}"
    |> @http_client.get!(CommonHelpers.get_headers(connection.authentication))
    |> CommonHelpers.decode_response
  end

  @doc """
  Create a new ticket.
  """
  @spec create(Zendex.Connection.t, map) :: map
  def create(connection, ticket) do
    "#{connection.base_url}#{@url}"
    |> @http_client.post!(Poison.encode!(ticket),
                          CommonHelpers.get_headers(connection.authentication,
                                                    %{content_type: :json}))
    |> CommonHelpers.decode_response
  end
end