aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Blowers <sblowers@findmypast.com>2016-11-01 14:19:53 (GMT)
committerSteven Blowers <sblowers@findmypast.com>2016-11-01 14:19:53 (GMT)
commitbf62e2d177726a5921b485988c89764dd34eae3f (patch)
tree0d544c3f9d6c713af3845b7ca73afa7d8b456d1c
parentdc3eabba821ff4f80ca417123629ca9ceb92eb51 (diff)
downloadzendex-bf62e2d177726a5921b485988c89764dd34eae3f.tar.gz
zendex-bf62e2d177726a5921b485988c89764dd34eae3f.tar.xz
adding ability to get related info on a user
-rw-r--r--lib/http_client/in_memory.ex14
-rw-r--r--lib/zendex/user.ex7
-rw-r--r--test/zendex/user_test.exs14
3 files changed, 35 insertions, 0 deletions
diff --git a/lib/http_client/in_memory.ex b/lib/http_client/in_memory.ex
index b74450e..4c43211 100644
--- a/lib/http_client/in_memory.ex
+++ b/lib/http_client/in_memory.ex
@@ -70,6 +70,20 @@ defmodule Zendex.HttpClient.InMemory do
%{id: 67, name: "Sarpedon Baumgartner"}]})
end
+ def get!("#{@base_url}/api/v2/users/649267/related.json",
+ [{"Authorization", _authentication}]) do
+ fake_response(%{"user_related" => %{"assigned_tickets" => 12,
+ "ccd_tickets" => 5,
+ "entry_subscriptions" => 1,
+ "forum_subscriptions" => 3,
+ "organization_subscriptions" => 1,
+ "requested_tickets" => 7,
+ "subscriptions" => 6,
+ "topic_comments" => 116,
+ "topics" => 5,
+ "votes" => 2001}})
+ 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 88487f3..3983432 100644
--- a/lib/zendex/user.ex
+++ b/lib/zendex/user.ex
@@ -81,6 +81,13 @@ defmodule Zendex.User do
|> CommonHelpers.decode_response
end
+ @spec related_information(Zendex.Connection.t, integer) :: map
+ def related_information(connection, id) do
+ "#{connection.base_url}#{@url}/#{id}/related.json"
+ |> @http_client.get!(CommonHelpers.get_headers(connection.authentication))
+ |> CommonHelpers.decode_response
+ end
+
@doc """
Create a new user.
"""
diff --git a/test/zendex/user_test.exs b/test/zendex/user_test.exs
index b4aaaec..f260f62 100644
--- a/test/zendex/user_test.exs
+++ b/test/zendex/user_test.exs
@@ -62,6 +62,20 @@ defmodule Zendex.UserTest do
assert expected == actual
end
+ test "getting related info on a user", context do
+ expected = %{"user_related" => %{"assigned_tickets" => 12,
+ "ccd_tickets" => 5,
+ "entry_subscriptions" => 1,
+ "forum_subscriptions" => 3,
+ "organization_subscriptions" => 1,
+ "requested_tickets" => 7,
+ "subscriptions" => 6,
+ "topic_comments" => 116,
+ "topics" => 5,
+ "votes" => 2001}}
+ actual = Zendex.User.related_information(context[:conn], 649267)
+ end
+
test "creating a user", context do
expected = %{"user" => %{"id" => 1234, "name" => "Roger", "email" => "roger@dodger.com"}}
actual = Zendex.User.create(context[:conn], %{user: %{name: "Roger", email: "roger@dodger.com"}})