aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Blowers <sblowers@findmypast.com>2016-09-13 15:32:32 (GMT)
committerSteven Blowers <sblowers@findmypast.com>2016-09-13 15:32:32 (GMT)
commit951a6942656965b0a1e6be0761cda8deddd9fd38 (patch)
treeccb2af16ac005c0809129843d25273731ac35ab7
parentb036ecfc34bc283b143aca540253918e6d8eda5c (diff)
downloadzendex-951a6942656965b0a1e6be0761cda8deddd9fd38.tar.gz
zendex-951a6942656965b0a1e6be0761cda8deddd9fd38.tar.xz
Ticket module now decodes response
-rw-r--r--lib/http_client/in_memory.ex6
-rw-r--r--lib/zendex/ticket.ex23
2 files changed, 18 insertions, 11 deletions
diff --git a/lib/http_client/in_memory.ex b/lib/http_client/in_memory.ex
index 67f4d31..924f743 100644
--- a/lib/http_client/in_memory.ex
+++ b/lib/http_client/in_memory.ex
@@ -6,7 +6,7 @@ defmodule Zendex.HttpClient.InMemory do
def get!("http://test.zendesk.com/api/v2/tickets.json",
[{"Authorization", _authentication}]) do
- "ticket"
+ fake_response("ticket")
end
def get!("http://test.zendesk.com/api/v2/search.json?query=requester%3AJimbob+type%3Aticket",
@@ -20,6 +20,8 @@ defmodule Zendex.HttpClient.InMemory do
end
def post!("http://test.zendesk.com/api/v2/tickets.json", "{\"ticket\":{}}", [{"Authorization", _authentication}, {"Content-Type", "application/json"}]) do
- "Ticket created successfully!"
+ fake_response("Ticket created successfully!")
end
+
+ defp fake_response(body), do: %{body: Poison.encode!(body)}
end
diff --git a/lib/zendex/ticket.ex b/lib/zendex/ticket.ex
index b6ccad9..c1f3edc 100644
--- a/lib/zendex/ticket.ex
+++ b/lib/zendex/ticket.ex
@@ -8,21 +8,26 @@ defmodule Zendex.Ticket do
@http_client Application.get_env(:zendex, :http_client)
- @spec list(Zendex.Connection.t) :: HTTPoison.Response.t
+ @spec list(Zendex.Connection.t) :: map
def list(connection) do
- full_url = connection.base_url <> @url
-
- @http_client.get!(full_url, headers(connection.authentication))
+ connection.base_url
+ |> Kernel.<>(@url)
+ |> @http_client.get!(headers(connection.authentication))
+ |> decode_response
end
- @spec create(Zendex.Connection.t, map) :: HTTPoison.Response.t
+ @spec create(Zendex.Connection.t, map) :: map
def create(connection, ticket) do
- @http_client.post!(connection.base_url <> @url,
- Poison.encode!(ticket),
- headers(connection.authentication) ++
- [{"Content-Type", "application/json"}])
+ 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