From 687caf80ebd23ab659bed97f5ee43f97a8b182df Mon Sep 17 00:00:00 2001 From: Steven Blowers Date: Sun, 30 Oct 2016 17:48:18 +0000 Subject: adding functionality to list all users --- lib/http_client/in_memory.ex | 13 +++++++++++-- lib/zendex/user.ex | 8 ++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'lib') 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 -- cgit v1.2.1