diff options
author | Steven Blowers <sblowers@findmypast.com> | 2016-09-07 10:17:17 +0100 |
---|---|---|
committer | Steven Blowers <sblowers@findmypast.com> | 2016-09-07 10:17:17 +0100 |
commit | ffc64c707a04c5a55de9132ad6b6949ff74efcc7 (patch) | |
tree | 003905a5ecfe9fc3a8074a9093670235df7f4bd6 | |
parent | 2371d345c69455882df9d9d9f7692804f9aa5001 (diff) | |
download | zendex-ffc64c707a04c5a55de9132ad6b6949ff74efcc7.tar.gz zendex-ffc64c707a04c5a55de9132ad6b6949ff74efcc7.tar.xz |
Adding tests and creating a ticket.
-rw-r--r-- | config/config.exs | 29 | ||||
-rw-r--r-- | config/test.exs | 3 | ||||
-rw-r--r-- | lib/http_client/in_memory.ex | 6 | ||||
-rw-r--r-- | lib/zendex/ticket.ex | 15 | ||||
-rw-r--r-- | mix.exs | 3 | ||||
-rw-r--r-- | mix.lock | 1 | ||||
-rw-r--r-- | test/zendex/ticket_test.exs | 8 |
7 files changed, 34 insertions, 31 deletions
diff --git a/config/config.exs b/config/config.exs index 62393db..dd0aa56 100644 --- a/config/config.exs +++ b/config/config.exs @@ -1,30 +1,5 @@ -# This file is responsible for configuring your application -# and its dependencies with the aid of the Mix.Config module. use Mix.Config -# This configuration is loaded before any dependency and is restricted -# to this project. If another project depends on this project, this -# file won't be loaded nor affect the parent project. For this reason, -# if you want to provide default values for your application for -# 3rd-party users, it should be done in your "mix.exs" file. +config :zendex, :http_client, HTTPoison -# You can configure for your application as: -# -# config :zendex, key: :value -# -# And access this configuration in your application as: -# -# Application.get_env(:zendex, :key) -# -# Or configure a 3rd-party app: -# -# config :logger, level: :info -# - -# It is also possible to import configuration files, relative to this -# directory. For example, you can emulate configuration per environment -# by uncommenting the line below and defining dev.exs, test.exs and such. -# Configuration from the imported file will override the ones defined -# here (which is why it is important to import them last). -# -# import_config "#{Mix.env}.exs" +import_config "#{Mix.env}.exs" diff --git a/config/test.exs b/config/test.exs new file mode 100644 index 0000000..b2a3ed8 --- /dev/null +++ b/config/test.exs @@ -0,0 +1,3 @@ +use Mix.Config + +config :zendex, :http_client, Zendex.HttpClient.InMemory diff --git a/lib/http_client/in_memory.ex b/lib/http_client/in_memory.ex new file mode 100644 index 0000000..cdb4ef3 --- /dev/null +++ b/lib/http_client/in_memory.ex @@ -0,0 +1,6 @@ +defmodule Zendex.HttpClient.InMemory do + + def get!("http://test.zendesk.com/api/v2/tickets.json", [{"Authorization", authentication}]) do + "ticket" + end +end diff --git a/lib/zendex/ticket.ex b/lib/zendex/ticket.ex index d7c9e4b..87395be 100644 --- a/lib/zendex/ticket.ex +++ b/lib/zendex/ticket.ex @@ -1,11 +1,20 @@ defmodule Zendex.Ticket do + @url "/api/v2/tickets.json" + + @http_client Application.get_env(:zendex, :http_client) + @spec list(Zendex.Connection.t) :: String.t def list(connection) do - tickets_url = "/api/v2/tickets.json" - - HTTPoison.get!(connection.base_url <> tickets_url, [{"Authorization", + @http_client.get!(connection.base_url <> @url, [{"Authorization", "Basic #{connection.authentication}"}]) end + def create(connection, ticket) do + @http_client.post!(connection.base_url <> @url, + Poison.encode!(ticket), + [{"Authorization", "Basic #{connection.authentication}"}, + {"Content-Type", "application/json"}]) + end + end @@ -18,7 +18,8 @@ defmodule Zendex.Mixfile do defp deps do [{:ex_doc, ">= 0.0.0", only: :dev}, - {:httpoison, "~> 0.9"}] + {:httpoison, "~> 0.9"}, + {:poison, "~> 2.2"}] end defp description do @@ -6,4 +6,5 @@ "idna": {:hex, :idna, "1.2.0", "ac62ee99da068f43c50dc69acf700e03a62a348360126260e87f2b54eced86b2", [:rebar3], []}, "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.0", "edee20847c42e379bf91261db474ffbe373f8acb56e9079acb6038d4e0bf414f", [:rebar, :make], []}} diff --git a/test/zendex/ticket_test.exs b/test/zendex/ticket_test.exs new file mode 100644 index 0000000..39ac8ad --- /dev/null +++ b/test/zendex/ticket_test.exs @@ -0,0 +1,8 @@ +defmodule Zendex.TicketTest do + use ExUnit.Case + + test "getting tickets" do + conn = Zendex.Connection.set_up("http://test.zendesk.com", "User", "Pass") + assert "ticket" == Zendex.Ticket.list(conn) + end +end |