aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSteven Blowers <shdblowers@gmail.com>2016-11-22 13:51:50 +0000
committerSteven Blowers <shdblowers@gmail.com>2016-11-22 13:51:50 +0000
commit8ca99bdea1f8900442b32b65edfaada4378eeed3 (patch)
tree15c16af0e8b2d981ac72df2886ec6c1e49982be9 /lib
parente08eb7c1f4f9b2ac56433a465a4b07bbfc7e8530 (diff)
parent81db12eae482123f7b4d2dc5e138b15f3d6711f9 (diff)
downloadzendex-8ca99bdea1f8900442b32b65edfaada4378eeed3.tar.gz
zendex-8ca99bdea1f8900442b32b65edfaada4378eeed3.tar.xz
Merge branch 'master' into meck
Diffstat (limited to 'lib')
-rw-r--r--lib/http_client/in_memory.ex89
-rw-r--r--lib/zendex/user.ex120
2 files changed, 207 insertions, 2 deletions
diff --git a/lib/http_client/in_memory.ex b/lib/http_client/in_memory.ex
index eabe99f..934115f 100644
--- a/lib/http_client/in_memory.ex
+++ b/lib/http_client/in_memory.ex
@@ -21,9 +21,42 @@ defmodule Zendex.HttpClient.InMemory do
fake_response("users")
end
- def get!("#{@base_url}/api/v2/users/87.json",
+ def get!("#{@base_url}/api/v2/users/295204.json",
[{"Authorization", _authentication}]) do
- fake_response(%{"user": %{"id": 87, "name": "Quim Stroud"}})
+ fake_response(%{"user" => %{"ticket_restriction" => nil,
+ "chat_only" => false,
+ "shared_phone_number" => nil,
+ "notes" => "",
+ "phone" => nil,
+ "organization_id" => 11129520411,
+ "last_login_at" => "2016-10-28T21:08:23Z",
+ "moderator" => true,
+ "shared" => false,
+ "id" => 295204,
+ "role" => "admin",
+ "external_id" => nil,
+ "shared_agent" => false,
+ "photo" => nil,
+ "verified" => true,
+ "active" => true,
+ "locale_id" => 1,
+ "suspended" => false,
+ "created_at" => "2015-05-28T09:12:45Z",
+ "name" => "Nikolao Aikema",
+ "restricted_agent" => false,
+ "locale" => "en-US",
+ "details" => "",
+ "alias" => nil,
+ "url" => "https://test.zendesk.com/api/v2/users/295204.json",
+ "custom_role_id" => nil,
+ "email" => "nikolao.aikema@test.com",
+ "signature" => nil,
+ "two_factor_auth_enabled" => nil,
+ "time_zone" => "London",
+ "only_private_comments" => false,
+ "user_fields" => %{"customer_complaint" => nil},
+ "tags" => [],
+ "updated_at" => "2016-10-28T21:08:23Z"}})
end
def get!("#{@base_url}/api/v2/users/show_many.json?ids=6,67",
@@ -32,11 +65,63 @@ 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/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
+ def delete!("#{@base_url}/api/v2/users/49043.json",
+ [{"Authorization", _authentication}]) do
+ fake_response(%{"user" => %{"ticket_restriction" => nil,
+ "chat_only" => false,
+ "shared_phone_number" => nil,
+ "notes" => "",
+ "phone" => nil,
+ "organization_id" => 149043,
+ "last_login_at" => "2016-10-28T21:08:23Z",
+ "moderator" => true,
+ "shared" => false,
+ "id" => 49043,
+ "role" => "admin",
+ "external_id" => nil,
+ "shared_agent" => false,
+ "photo" => nil,
+ "verified" => true,
+ "active" => false,
+ "locale_id" => 1,
+ "suspended" => false,
+ "created_at" => "2015-05-28T09:12:45Z",
+ "name" => "Rian Hawkins",
+ "restricted_agent" => false,
+ "locale" => "en-US",
+ "details" => "",
+ "alias" => nil,
+ "url" => "https://test.zendesk.com/api/v2/users/49043.json",
+ "custom_role_id" => nil,
+ "email" => "rian.hawkins@test.com",
+ "signature" => nil,
+ "two_factor_auth_enabled" => nil,
+ "time_zone" => "London",
+ "only_private_comments" => false,
+ "user_fields" => %{"customer_complaint" => nil},
+ "tags" => [],
+ "updated_at" => "2016-10-28T21:08:23Z"}})
+ end
+
defp fake_response(body), do: %{body: Poison.encode!(body)}
end
diff --git a/lib/zendex/user.ex b/lib/zendex/user.ex
index 31c3a06..9112b7f 100644
--- a/lib/zendex/user.ex
+++ b/lib/zendex/user.ex
@@ -20,6 +20,47 @@ defmodule Zendex.User do
@doc """
Show a specific user, given their id.
+
+ ## Examples
+
+ iex> conn = Zendex.Connection.setup("http://test.zendesk.com", "ZendeskUser", "Password1")
+ %{authentication: "WmVuZGVza1VzZXI6UGFzc3dvcmQx", base_url: "http://test.zendesk.com"}
+ iex> Zendex.User.show(conn, 295204)
+ %{"user" => %{"ticket_restriction" => nil,
+ "chat_only" => false,
+ "shared_phone_number" => nil,
+ "notes" => "",
+ "phone" => nil,
+ "organization_id" => 11129520411,
+ "last_login_at" => "2016-10-28T21:08:23Z",
+ "moderator" => true,
+ "shared" => false,
+ "id" => 295204,
+ "role" => "admin",
+ "external_id" => nil,
+ "shared_agent" => false,
+ "photo" => nil,
+ "verified" => true,
+ "active" => true,
+ "locale_id" => 1,
+ "suspended" => false,
+ "created_at" => "2015-05-28T09:12:45Z",
+ "name" => "Nikolao Aikema",
+ "restricted_agent" => false,
+ "locale" => "en-US",
+ "details" => "",
+ "alias" => nil,
+ "url" => "https://test.zendesk.com/api/v2/users/295204.json",
+ "custom_role_id" => nil,
+ "email" => "nikolao.aikema@test.com",
+ "signature" => nil,
+ "two_factor_auth_enabled" => nil,
+ "time_zone" => "London",
+ "only_private_comments" => false,
+ "user_fields" => %{"customer_complaint" => nil},
+ "tags" => [],
+ "updated_at" => "2016-10-28T21:08:23Z"}}
+
"""
@spec show(Zendex.Connection.t, integer) :: map
def show(connection, id) do
@@ -41,6 +82,33 @@ defmodule Zendex.User do
end
@doc """
+ Show information relating to the user, example: number of assigned tickets.
+
+ ## Examples
+
+ iex> conn = Zendex.Connection.setup("http://test.zendesk.com", "ZendeskUser", "Password1")
+ %{authentication: "WmVuZGVza1VzZXI6UGFzc3dvcmQx", base_url: "http://test.zendesk.com"}
+ iex> Zendex.User.related_information(conn, 649267)
+ %{"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}}
+
+ """
+ @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.
"""
@spec create(Zendex.Connection.t, map) :: map
@@ -52,4 +120,56 @@ defmodule Zendex.User do
|> CommonHelpers.decode_response
end
+ @doc """
+ Delete a user.
+
+ ## Examples
+
+ iex> conn = Zendex.Connection.setup("http://test.zendesk.com", "ZendeskUser", "Password1")
+ %{authentication: "WmVuZGVza1VzZXI6UGFzc3dvcmQx", base_url: "http://test.zendesk.com"}
+ iex> Zendex.User.delete(conn, 49043)
+ %{"user" => %{"ticket_restriction" => nil,
+ "chat_only" => false,
+ "shared_phone_number" => nil,
+ "notes" => "",
+ "phone" => nil,
+ "organization_id" => 149043,
+ "last_login_at" => "2016-10-28T21:08:23Z",
+ "moderator" => true,
+ "shared" => false,
+ "id" => 49043,
+ "role" => "admin",
+ "external_id" => nil,
+ "shared_agent" => false,
+ "photo" => nil,
+ "verified" => true,
+ "active" => false,
+ "locale_id" => 1,
+ "suspended" => false,
+ "created_at" => "2015-05-28T09:12:45Z",
+ "name" => "Rian Hawkins",
+ "restricted_agent" => false,
+ "locale" => "en-US",
+ "details" => "",
+ "alias" => nil,
+ "url" => "https://test.zendesk.com/api/v2/users/49043.json",
+ "custom_role_id" => nil,
+ "email" => "rian.hawkins@test.com",
+ "signature" => nil,
+ "two_factor_auth_enabled" => nil,
+ "time_zone" => "London",
+ "only_private_comments" => false,
+ "user_fields" => %{"customer_complaint" => nil},
+ "tags" => [],
+ "updated_at" => "2016-10-28T21:08:23Z"}}
+
+
+ """
+ @spec show(Zendex.Connection.t, integer) :: map
+ def delete(connection, id) do
+ "#{connection.base_url}#{@url}/#{id}.json"
+ |> @http_client.delete!(CommonHelpers.get_headers(connection.authentication))
+ |> CommonHelpers.decode_response
+ end
+
end