blob: c1f3edcec1aa80a6988d99931761494a2d097487 (
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
34
|
defmodule Zendex.Ticket do
@moduledoc """
Allows interaction with the Zendesk Ticket API, to so things such as creating
and listing tickets.
"""
@url "/api/v2/tickets.json"
@http_client Application.get_env(:zendex, :http_client)
@spec list(Zendex.Connection.t) :: map
def list(connection) do
connection.base_url
|> Kernel.<>(@url)
|> @http_client.get!(headers(connection.authentication))
|> decode_response
end
@spec create(Zendex.Connection.t, map) :: map
def create(connection, ticket) do
response = @http_client.post!(connection.base_url <> @url,
Poison.encode!(ticket),
headers(connection.authentication) ++
[{"Content-Type", "application/json"}])
decode_response(response)
end
defp decode_response(%{body: body}), do: Poison.decode!(body)
defp headers(authentication) do
[{"Authorization", "Basic #{authentication}"}]
end
end
|