aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Blowers <shdblowers@gmail.com>2016-11-22 13:48:03 +0000
committerSteven Blowers <shdblowers@gmail.com>2016-11-22 13:48:03 +0000
commit81db12eae482123f7b4d2dc5e138b15f3d6711f9 (patch)
treea62fa6c28bdd19a3cbd000fa044e4f477bc53907
parentd467b76c0da3fb4710161ce89a3bf994ae1483b4 (diff)
parent01b8203e4d97d08a6462c29bac8fccd11ee8fb97 (diff)
downloadzendex-81db12eae482123f7b4d2dc5e138b15f3d6711f9.tar.gz
zendex-81db12eae482123f7b4d2dc5e138b15f3d6711f9.tar.xz
Merge branch 'master' of https://github.com/shdblowers/zendex
-rw-r--r--README.md10
-rw-r--r--lib/http_client/in_memory.ex89
-rw-r--r--lib/zendex/user.ex120
-rw-r--r--mix.lock16
-rw-r--r--test/zendex/user_test.exs93
5 files changed, 316 insertions, 12 deletions
diff --git a/README.md b/README.md
index 786e2dc..797603d 100644
--- a/README.md
+++ b/README.md
@@ -8,6 +8,8 @@
An Elixir wrapper for the Zendesk API.
+[ExDoc Documentation](https://hexdocs.pm/zendex)
+
## Installation
1. Add `zendex` to your list of dependencies in `mix.exs`:
@@ -42,6 +44,14 @@ An Elixir wrapper for the Zendesk API.
%{"user": %{"id": 87, "name": "Quim Stroud", ...}}
```
+ 3. Using pipes:
+
+ ```elixir
+ "http://test.zendesk.com"
+ |> Zendex.Connection.setup("Username1", "password123")
+ |> Zendex.User.show(101)
+ ```
+
## Completeness and Contributions
This package far from complete in terms of utilising all of the Zendesk API, any contributions will be welcome. Please keep the code consistent with what I have already written here.
diff --git a/lib/http_client/in_memory.ex b/lib/http_client/in_memory.ex
index a448afd..4c43211 100644
--- a/lib/http_client/in_memory.ex
+++ b/lib/http_client/in_memory.ex
@@ -26,9 +26,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",
@@ -37,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
@@ -49,5 +96,43 @@ defmodule Zendex.HttpClient.InMemory 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
diff --git a/mix.lock b/mix.lock
index 97e7b95..123d113 100644
--- a/mix.lock
+++ b/mix.lock
@@ -1,16 +1,16 @@
-%{"bunt": {:hex, :bunt, "0.1.6", "5d95a6882f73f3b9969fdfd1953798046664e6f77ec4e486e6fafc7caad97c6f", [], []},
+%{"bunt": {:hex, :bunt, "0.1.6", "5d95a6882f73f3b9969fdfd1953798046664e6f77ec4e486e6fafc7caad97c6f", [:mix], []},
"certifi": {:hex, :certifi, "0.7.0", "861a57f3808f7eb0c2d1802afeaae0fa5de813b0df0979153cbafcd853ababaf", [:rebar3], []},
"credo": {:hex, :credo, "0.5.1", "2395862b94628cadf0f5c68975c1440393f425b955f1e70ce1aea267e00187a1", [:mix], [{:bunt, "~> 0.1.6", [hex: :bunt, optional: false]}]},
- "dialyxir": {:hex, :dialyxir, "0.3.5", "eaba092549e044c76f83165978979f60110dc58dd5b92fd952bf2312f64e9b14", [], []},
+ "dialyxir": {:hex, :dialyxir, "0.3.5", "eaba092549e044c76f83165978979f60110dc58dd5b92fd952bf2312f64e9b14", [:mix], []},
"earmark": {:hex, :earmark, "1.0.2", "a0b0904d74ecc14da8bd2e6e0248e1a409a2bc91aade75fcf428125603de3853", [:mix], []},
"ex_doc": {:hex, :ex_doc, "0.14.3", "e61cec6cf9731d7d23d254266ab06ac1decbb7651c3d1568402ec535d387b6f7", [:mix], [{:earmark, "~> 1.0", [hex: :earmark, optional: false]}]},
"excoveralls": {:hex, :excoveralls, "0.5.7", "5d26e4a7cdf08294217594a1b0643636accc2ad30e984d62f1d166f70629ff50", [:mix], [{:exjsx, "~> 3.0", [hex: :exjsx, optional: false]}, {:hackney, ">= 0.12.0", [hex: :hackney, optional: false]}]},
"exjsx": {:hex, :exjsx, "3.2.1", "1bc5bf1e4fd249104178f0885030bcd75a4526f4d2a1e976f4b428d347614f0f", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, optional: false]}]},
- "hackney": {:hex, :hackney, "1.6.3", "d489d7ca2d4323e307bedc4bfe684323a7bf773ecfd77938f3ee8074e488e140", [:mix, :rebar3], [{:certifi, "0.7.0", [hex: :certifi, optional: false]}, {:idna, "1.2.0", [hex: :idna, optional: false]}, {:metrics, "1.0.1", [hex: :metrics, optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, optional: false]}]},
+ "hackney": {:hex, :hackney, "1.6.3", "d489d7ca2d4323e307bedc4bfe684323a7bf773ecfd77938f3ee8074e488e140", [:rebar3, :mix], [{:certifi, "0.7.0", [hex: :certifi, optional: false]}, {:idna, "1.2.0", [hex: :idna, optional: false]}, {:metrics, "1.0.1", [hex: :metrics, optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, optional: false]}]},
"httpoison": {:hex, :httpoison, "0.9.2", "a211a8e87403a043c41218e64df250d321f236ac57f786c6a0ccf3e9e817c819", [:mix], [{:hackney, "~> 1.6.0", [hex: :hackney, optional: false]}]},
- "idna": {:hex, :idna, "1.2.0", "ac62ee99da068f43c50dc69acf700e03a62a348360126260e87f2b54eced86b2", [], []},
+ "idna": {:hex, :idna, "1.2.0", "ac62ee99da068f43c50dc69acf700e03a62a348360126260e87f2b54eced86b2", [:rebar3], []},
"jsx": {:hex, :jsx, "2.8.0", "749bec6d205c694ae1786d62cea6cc45a390437e24835fd16d12d74f07097727", [:mix, :rebar], []},
- "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [], []},
- "mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [], []},
- "poison": {:hex, :poison, "2.2.0", "4763b69a8a77bd77d26f477d196428b741261a761257ff1cf92753a0d4d24a63", [], []},
- "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], []}}
+ "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], []},
+ "mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], []},
+ "poison": {:hex, :poison, "2.2.0", "4763b69a8a77bd77d26f477d196428b741261a761257ff1cf92753a0d4d24a63", [:mix], []},
+ "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:rebar, :make], []}}
diff --git a/test/zendex/user_test.exs b/test/zendex/user_test.exs
index 2d9f04c..f260f62 100644
--- a/test/zendex/user_test.exs
+++ b/test/zendex/user_test.exs
@@ -1,6 +1,8 @@
defmodule Zendex.UserTest do
use ExUnit.Case, async: true
+ doctest Zendex.User
+
setup do
[conn: Zendex.Connection.setup("http://test.zendesk.com", "User1", "pass")]
end
@@ -13,8 +15,41 @@ defmodule Zendex.UserTest do
end
test "showing a user", context do
- expected = %{"user" => %{"id" => 87, "name" => "Quim Stroud"}}
- actual = Zendex.User.show(context[:conn], 87)
+ expected = %{"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"}}
+ actual = Zendex.User.show(context[:conn], 295204)
assert expected == actual
end
@@ -27,10 +62,64 @@ 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"}})
assert expected == actual
end
+
+ test "deleting a user", context do
+ expected = %{"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"}}
+ actual = Zendex.User.delete(context[:conn], 49043)
+
+ assert expected == actual
+ end
end