aboutsummaryrefslogtreecommitdiff
path: root/lib/zendex/user.ex
blob: a62a05ed2244e2633f8a56ebeb9a9603b4b0be0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
defmodule Zendex.User do
  @moduledoc """
  Interact with Zendesk user.
  """

  alias Zendex.CommonHelpers

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

  @spec list(Zendex.Connection.t) :: map
  def list(connection) do
    connection.base_url
    |> Kernel.<>(@url)
    |> Kernel.<>(".json")
    |> @http_client.get!(CommonHelpers.get_headers(connection.authentication))
    |> CommonHelpers.decode_response
  end

  @spec show(Zendex.Connection.t, integer) :: map
  def show(connection, id) do
    connection.base_url
    |> Kernel.<>(@url)
    |> Kernel.<>("/#{id}.json")
    |> @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
    |> Kernel.<>(@url)
    |> Kernel.<>(".json")
    |> @http_client.post!(Poison.encode!(user),
                          CommonHelpers.get_headers(connection.authentication,
                                                    %{content_type: :json}))
    |> CommonHelpers.decode_response
  end

end