aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSteven Blowers <shdblowers@gmail.com>2016-10-30 18:11:42 +0000
committerSteven Blowers <shdblowers@gmail.com>2016-10-30 18:11:42 +0000
commit7ed1bfc69b7efd31a04c7fc09cdd6f0432e45131 (patch)
treee6fe31b982fd98360f13196f9d7808e5624dd9d1 /lib
parenta85e7fe79318422b8623423c0520a80cc1d0d643 (diff)
downloadzendex-7ed1bfc69b7efd31a04c7fc09cdd6f0432e45131.tar.gz
zendex-7ed1bfc69b7efd31a04c7fc09cdd6f0432e45131.tar.xz
adding ability to show user
Diffstat (limited to 'lib')
-rw-r--r--lib/http_client/in_memory.ex5
-rw-r--r--lib/zendex/user.ex13
2 files changed, 17 insertions, 1 deletions
diff --git a/lib/http_client/in_memory.ex b/lib/http_client/in_memory.ex
index 50c5436..d05bcea 100644
--- a/lib/http_client/in_memory.ex
+++ b/lib/http_client/in_memory.ex
@@ -26,6 +26,11 @@ defmodule Zendex.HttpClient.InMemory do
fake_response("users")
end
+ def get!("#{@base_url}/api/v2/users/87.json",
+ [{"Authorization", _authentication}]) do
+ fake_response(%{"user": %{"id": 87, "name": "Quim Stroud"}})
+ end
+
def post!(@base_url <> "/api/v2/tickets.json",
"{\"ticket\":{}}",
[{"Authorization", _authentication}, {"Content-Type", "application/json"}]) do
diff --git a/lib/zendex/user.ex b/lib/zendex/user.ex
index 2d5d2d8..a62a05e 100644
--- a/lib/zendex/user.ex
+++ b/lib/zendex/user.ex
@@ -5,13 +5,23 @@ defmodule Zendex.User do
alias Zendex.CommonHelpers
- @url "/api/v2/users.json"
+ @url "/api/v2/users"
@http_client Application.get_env(:zendex, :http_client)
@spec list(Zendex.Connection.t) :: map
def list(connection) do
connection.base_url
|> Kernel.<>(@url)
+ |> Kernel.<>(".json")
+ |> @http_client.get!(CommonHelpers.get_headers(connection.authentication))
+ |> CommonHelpers.decode_response
+ end
+
+ @spec show(Zendex.Connection.t, integer) :: map
+ def show(connection, id) do
+ connection.base_url
+ |> Kernel.<>(@url)
+ |> Kernel.<>("/#{id}.json")
|> @http_client.get!(CommonHelpers.get_headers(connection.authentication))
|> CommonHelpers.decode_response
end
@@ -20,6 +30,7 @@ defmodule Zendex.User do
def create(connection, user) do
connection.base_url
|> Kernel.<>(@url)
+ |> Kernel.<>(".json")
|> @http_client.post!(Poison.encode!(user),
CommonHelpers.get_headers(connection.authentication,
%{content_type: :json}))