Skip to content

Commit

Permalink
adding functionality to create user
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Blowers committed Sep 16, 2016
1 parent 0520954 commit 542a389
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/zendex/user.ex
@@ -0,0 +1,21 @@
defmodule Zendex.User do
@moduledoc """
Interact with Zendesk user.
"""

alias Zendex.CommonHelpers

@url "/api/v2/users.json"
@http_client Application.get_env(:zendex, :http_client)

@spec create(Zendex.Connection.t, map) :: map
def create(connection, user) do
connection.base_url
|> Kernel.<>(@url)
|> @http_client.post!(Poison.encode!(user),
CommonHelpers.get_headers(connection.authentication,
%{content_type: :json}))
|> CommonHelpers.decode_response
end

end
14 changes: 14 additions & 0 deletions test/zendex/user_test.exs
@@ -0,0 +1,14 @@
defmodule Zendex.UserTest do
use ExUnit.Case, async: true

setup do
[conn: Zendex.Connection.set_up("http://test.zendesk.com", "User1", "pass")]
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
end

0 comments on commit 542a389

Please sign in to comment.