aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSteven Blowers <sblowers@findmypast.com>2016-09-16 15:31:09 +0100
committerSteven Blowers <sblowers@findmypast.com>2016-09-16 15:31:09 +0100
commit1b6d6fc8e83c594653a3f19490c9d1e4cb80234f (patch)
tree4cb50fd3cde6e8e7b223e46ecaa9b6409c124ac8 /lib
parent2587b9fda4ef351cfa3e05d3de1f76ee125f2914 (diff)
downloadzendex-1b6d6fc8e83c594653a3f19490c9d1e4cb80234f.tar.gz
zendex-1b6d6fc8e83c594653a3f19490c9d1e4cb80234f.tar.xz
refactoring adding headers to common helpers
Diffstat (limited to 'lib')
-rw-r--r--lib/zendex/common_helpers.ex7
-rw-r--r--lib/zendex/search.ex4
-rw-r--r--lib/zendex/ticket.ex10
3 files changed, 12 insertions, 9 deletions
diff --git a/lib/zendex/common_helpers.ex b/lib/zendex/common_helpers.ex
index 34aac30..dceb56d 100644
--- a/lib/zendex/common_helpers.ex
+++ b/lib/zendex/common_helpers.ex
@@ -5,4 +5,11 @@ defmodule Zendex.CommonHelpers do
def decode_response(%{body: body}), do: Poison.decode!(body)
+ def get_headers(authentication) do
+ [{"Authorization", "Basic #{authentication}"}]
+ end
+
+ def get_headers(authentication, %{content_type: :json}) do
+ get_headers(authentication) ++ [{"Content-Type", "application/json"}]
+ end
end
diff --git a/lib/zendex/search.ex b/lib/zendex/search.ex
index 13843d4..badf0bb 100644
--- a/lib/zendex/search.ex
+++ b/lib/zendex/search.ex
@@ -10,14 +10,14 @@ defmodule Zendex.Search do
@spec query(Zendex.Connection.t, map, String.t, String.t) :: map
def query(connection, query, sort_by \\ "", sort_order \\ "desc") do
+
search_string = create_search_string(query)
sort_string = create_sort_string(sort_by, sort_order)
full_uri = connection.base_url <> @url <> search_string <> sort_string
full_uri
- |> @http_client.get!([{"Authorization",
- "Basic #{connection.authentication}"}])
+ |> @http_client.get!(CommonHelpers.get_headers(connection.authentication))
|> CommonHelpers.decode_response
end
diff --git a/lib/zendex/ticket.ex b/lib/zendex/ticket.ex
index 6d2d75b..3be6789 100644
--- a/lib/zendex/ticket.ex
+++ b/lib/zendex/ticket.ex
@@ -13,7 +13,7 @@ defmodule Zendex.Ticket do
def list(connection) do
connection.base_url
|> Kernel.<>(@url)
- |> @http_client.get!(headers(connection.authentication))
+ |> @http_client.get!(CommonHelpers.get_headers(connection.authentication))
|> CommonHelpers.decode_response
end
@@ -22,12 +22,8 @@ defmodule Zendex.Ticket do
connection.base_url
|> Kernel.<>(@url)
|> @http_client.post!(Poison.encode!(ticket),
- headers(connection.authentication) ++
- [{"Content-Type", "application/json"}])
+ CommonHelpers.get_headers(connection.authentication,
+ %{content_type: :json}))
|> CommonHelpers.decode_response
end
-
- defp headers(authentication) do
- [{"Authorization", "Basic #{authentication}"}]
- end
end