diff options
author | Steven Blowers <shdblowers@gmail.com> | 2016-10-30 17:48:18 +0000 |
---|---|---|
committer | Steven Blowers <shdblowers@gmail.com> | 2016-10-30 17:48:18 +0000 |
commit | 687caf80ebd23ab659bed97f5ee43f97a8b182df (patch) | |
tree | d72002f23295d0e90aaa1dfeddd1b875ca3db101 /lib | |
parent | 6894ba18c6da270cb387cf8fa974b1da259bf361 (diff) | |
download | zendex-687caf80ebd23ab659bed97f5ee43f97a8b182df.tar.gz zendex-687caf80ebd23ab659bed97f5ee43f97a8b182df.tar.xz |
adding functionality to list all users
Diffstat (limited to 'lib')
-rw-r--r-- | lib/http_client/in_memory.ex | 13 | ||||
-rw-r--r-- | lib/zendex/user.ex | 8 |
2 files changed, 19 insertions, 2 deletions
diff --git a/lib/http_client/in_memory.ex b/lib/http_client/in_memory.ex index 91e5d84..50c5436 100644 --- a/lib/http_client/in_memory.ex +++ b/lib/http_client/in_memory.ex @@ -21,11 +21,20 @@ defmodule Zendex.HttpClient.InMemory do fake_response(["Reginald Ticket 1", "Reginald Ticket 2"]) end - def post!(@base_url <> "/api/v2/tickets.json", "{\"ticket\":{}}", [{"Authorization", _authentication}, {"Content-Type", "application/json"}]) do + def get!(@base_url <> "/api/v2/users.json", + [{"Authorization", _authentication}]) do + fake_response("users") + end + + def post!(@base_url <> "/api/v2/tickets.json", + "{\"ticket\":{}}", + [{"Authorization", _authentication}, {"Content-Type", "application/json"}]) do fake_response("Ticket created successfully!") end - def post!(@base_url <> "/api/v2/users.json", "{\"user\":{\"name\":\"Roger\",\"email\":\"roger@dodger.com\"}}", [{"Authorization", _authentication}, {"Content-Type", "application/json"}]) do + def post!(@base_url <> "/api/v2/users.json", + "{\"user\":{\"name\":\"Roger\",\"email\":\"roger@dodger.com\"}}", + [{"Authorization", _authentication}, {"Content-Type", "application/json"}]) do fake_response(%{user: %{id: 1234, name: "Roger", email: "roger@dodger.com"}}) end diff --git a/lib/zendex/user.ex b/lib/zendex/user.ex index decb30b..2d5d2d8 100644 --- a/lib/zendex/user.ex +++ b/lib/zendex/user.ex @@ -8,6 +8,14 @@ defmodule Zendex.User do @url "/api/v2/users.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!(CommonHelpers.get_headers(connection.authentication)) + |> CommonHelpers.decode_response + end + @spec create(Zendex.Connection.t, map) :: map def create(connection, user) do connection.base_url |