From c052c6a774629457eabd50df89bd493732821597 Mon Sep 17 00:00:00 2001 From: Jaime Iniesta Date: Wed, 3 Jul 2019 14:06:13 +0200 Subject: [PATCH 01/13] sets a default timeout of 10 seconds (instead of 5) (#18) * sets a default timeout of 10 seconds (instead of 5) * makes params clearer in test. Thx @schurig --- lib/stuart_client_elixir/http_client.ex | 8 ++++++-- test/stuart_client_elixir/http_client_test.exs | 13 +++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/stuart_client_elixir/http_client.ex b/lib/stuart_client_elixir/http_client.ex index 8acbc71..ba26d37 100644 --- a/lib/stuart_client_elixir/http_client.ex +++ b/lib/stuart_client_elixir/http_client.ex @@ -14,7 +14,7 @@ defmodule StuartClientElixir.HttpClient do with url <- url(resource, environment), {:ok, access_token} <- Authenticator.access_token(environment, credentials), headers <- default_headers(access_token) do - HTTPoison.get(url, headers) + HTTPoison.get(url, headers, default_options()) |> to_api_response() else {:error, %OAuth2.Response{}} = oauth_error -> to_api_response(oauth_error) @@ -25,7 +25,7 @@ defmodule StuartClientElixir.HttpClient do with url <- url(resource, environment), {:ok, access_token} <- Authenticator.access_token(environment, credentials), headers <- default_headers(access_token) do - HTTPoison.post(url, body, headers) + HTTPoison.post(url, body, headers, default_options()) |> to_api_response() else {:error, %OAuth2.Response{}} = oauth_error -> to_api_response(oauth_error) @@ -36,6 +36,10 @@ defmodule StuartClientElixir.HttpClient do # Private functions # ##################### + defp default_options do + [recv_timeout: 10_000] + end + defp url(resource, %Environment{base_url: base_url}), do: "#{base_url}#{resource}" defp default_headers(access_token) do diff --git a/test/stuart_client_elixir/http_client_test.exs b/test/stuart_client_elixir/http_client_test.exs index f4c12d2..2734f43 100644 --- a/test/stuart_client_elixir/http_client_test.exs +++ b/test/stuart_client_elixir/http_client_test.exs @@ -26,8 +26,8 @@ defmodule StuartClientElixirTest.HttpClientTest do HTTPoison, [], [ - get: fn url, _ -> response(:get, url) end, - post: fn url, _, _ -> response(:post, url) end + get: fn url, _headers, _options -> response(:get, url) end, + post: fn url, _body, _headers, _options -> response(:post, url) end ] } ]) do @@ -43,7 +43,8 @@ defmodule StuartClientElixirTest.HttpClientTest do assert called( HTTPoison.get( "https://sandbox-api.stuart.com/sample-endpoint", - expected_headers() + expected_headers(), + expected_options() ) ) end @@ -72,7 +73,8 @@ defmodule StuartClientElixirTest.HttpClientTest do HTTPoison.post( "https://sandbox-api.stuart.com/sample-endpoint", sample_request_body(), - expected_headers() + expected_headers(), + expected_options() ) ) end @@ -128,6 +130,9 @@ defmodule StuartClientElixirTest.HttpClientTest do "Content-Type": "application/json" ] + defp expected_options, + do: [recv_timeout: 10_000] + defp config(credentials \\ @good_credentials), do: %{ environment: Environment.sandbox(), From cd768dbad3403067ce0dbc44940c927e33f00fe9 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 29 Jul 2019 12:26:46 +0200 Subject: [PATCH 02/13] Removes obsolete instructions Mix infers the list of OTP applications the project depends on since version 1.4. --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index 67ea662..f207221 100644 --- a/README.md +++ b/README.md @@ -9,10 +9,6 @@ For a complete documentation of all endpoints offered by the Stuart API, you can ```elixir # mix.exs -def application do - [applications: [:stuart_client_elixir]] -end - def deps do [ {:stuart_client_elixir, "~> 1.2.0"} From baa5fc1e5c233ffe9a123a03d3f560fab8578909 Mon Sep 17 00:00:00 2001 From: Jaime Iniesta Date: Fri, 9 Aug 2019 13:26:03 +0200 Subject: [PATCH 03/13] Handles OAuth2.Error (#19) The OAuth library can return also this, and not only an OAuth2.Response: https://hexdocs.pm/oauth2/0.9.4/OAuth2.Client.html#get_token/4 This patch adds handling for both cases of error result. --- lib/stuart_client_elixir/authenticator.ex | 1 + lib/stuart_client_elixir/http_client.ex | 14 ++++---- .../authenticator_test.exs | 24 +++++++++++++ .../stuart_client_elixir/http_client_test.exs | 35 +++++++++++++++++-- 4 files changed, 66 insertions(+), 8 deletions(-) diff --git a/lib/stuart_client_elixir/authenticator.ex b/lib/stuart_client_elixir/authenticator.ex index 86d08e7..57e2b34 100644 --- a/lib/stuart_client_elixir/authenticator.ex +++ b/lib/stuart_client_elixir/authenticator.ex @@ -33,6 +33,7 @@ defmodule StuartClientElixir.Authenticator do {:ok, access_token} else {:error, %OAuth2.Response{} = oauth_response} -> {:error, oauth_response} + {:error, %OAuth2.Error{} = oauth_error} -> {:error, oauth_error} end end diff --git a/lib/stuart_client_elixir/http_client.ex b/lib/stuart_client_elixir/http_client.ex index ba26d37..d996864 100644 --- a/lib/stuart_client_elixir/http_client.ex +++ b/lib/stuart_client_elixir/http_client.ex @@ -17,7 +17,8 @@ defmodule StuartClientElixir.HttpClient do HTTPoison.get(url, headers, default_options()) |> to_api_response() else - {:error, %OAuth2.Response{}} = oauth_error -> to_api_response(oauth_error) + {:error, %OAuth2.Response{}} = oauth_response -> to_api_response(oauth_response) + {:error, %OAuth2.Error{}} = oauth_error -> to_api_response(oauth_error) end end @@ -28,7 +29,8 @@ defmodule StuartClientElixir.HttpClient do HTTPoison.post(url, body, headers, default_options()) |> to_api_response() else - {:error, %OAuth2.Response{}} = oauth_error -> to_api_response(oauth_error) + {:error, %OAuth2.Response{}} = oauth_response -> to_api_response(oauth_response) + {:error, %OAuth2.Error{}} = oauth_error -> to_api_response(oauth_error) end end @@ -54,11 +56,11 @@ defmodule StuartClientElixir.HttpClient do %{status_code: status_code, body: Jason.decode!(body)} end - defp to_api_response({:error, %HTTPoison.Error{} = error}) do - {:error, error} - end - defp to_api_response({:error, %OAuth2.Response{status_code: status_code, body: body}}) do %{status_code: status_code, body: body} end + + defp to_api_response({:error, error}) do + {:error, error} + end end diff --git a/test/stuart_client_elixir/authenticator_test.exs b/test/stuart_client_elixir/authenticator_test.exs index ccc5472..2f7580b 100644 --- a/test/stuart_client_elixir/authenticator_test.exs +++ b/test/stuart_client_elixir/authenticator_test.exs @@ -43,6 +43,17 @@ defmodule StuartClientElixirTest.AuthenticatorTest do }} end + test "returns an error for OAuth2.Error" do + assert Authenticator.access_token(Environment.sandbox(), error_credentials()) == + {:error, + %OAuth2.Error{ + reason: + {:options, + {:socket_options, + [packet_size: 0, packet: 0, header: 0, active: false, mode: :binary]}} + }} + end + test "returns a new access token when no access token exists" do # when {:ok, access_token} = Authenticator.access_token(Environment.sandbox(), good_credentials()) @@ -121,6 +132,10 @@ defmodule StuartClientElixirTest.AuthenticatorTest do %Credentials{client_id: "client-id", client_secret: "bad"} end + defp error_credentials do + %Credentials{client_id: "client-id", client_secret: "error"} + end + defp sample_client( strategy: OAuth2.Strategy.ClientCredentials, client_id: client_id, @@ -164,6 +179,15 @@ defmodule StuartClientElixirTest.AuthenticatorTest do }} end + defp get_token_response(%OAuth2.Client{client_secret: "error"}) do + {:error, + %OAuth2.Error{ + reason: + {:options, + {:socket_options, [packet_size: 0, packet: 0, header: 0, active: false, mode: :binary]}} + }} + end + defp sample_token(access_token: access_token, expires_at: expires_at) do %OAuth2.AccessToken{ access_token: access_token, diff --git a/test/stuart_client_elixir/http_client_test.exs b/test/stuart_client_elixir/http_client_test.exs index 2734f43..d04601c 100644 --- a/test/stuart_client_elixir/http_client_test.exs +++ b/test/stuart_client_elixir/http_client_test.exs @@ -14,6 +14,11 @@ defmodule StuartClientElixirTest.HttpClientTest do client_secret: "bad-secret" } + @oauth_error %Credentials{ + client_id: "oauth-error", + client_secret: "oauth-error" + } + setup_with_mocks([ { Authenticator, @@ -49,12 +54,19 @@ defmodule StuartClientElixirTest.HttpClientTest do ) end - test "returns explicit error when authentication fails" do + test "returns explicit error when authentication fails because of bad credentials" do expected_response = %{body: %{"error" => "Bad credentials"}, status_code: 401} assert HttpClient.get("/sample-endpoint", config(@bad_credentials)) == expected_response end + test "returns explicit error when authentication fails because of other OAuth error" do + expected_response = {:error, oauth2_error()} + + assert HttpClient.get("/sample-endpoint", config(@oauth_error)) == + expected_response + end + test "returns explicit error when GET request fails" do expected_response = {:error, %HTTPoison.Error{id: nil, reason: :timeout}} @@ -79,13 +91,20 @@ defmodule StuartClientElixirTest.HttpClientTest do ) end - test "returns explicit error when authentication fails" do + test "returns explicit error when authentication fails because of bad credentials" do expected_response = %{body: %{"error" => "Bad credentials"}, status_code: 401} assert HttpClient.post("/sample-endpoint", sample_request_body(), config(@bad_credentials)) == expected_response end + test "returns explicit error when authentication fails because of other OAuth error" do + expected_response = {:error, oauth2_error()} + + assert HttpClient.post("/sample-endpoint", sample_request_body(), config(@oauth_error)) == + expected_response + end + test "returns explicit error when POST request fails" do expected_response = {:error, %HTTPoison.Error{id: nil, reason: :timeout}} @@ -121,6 +140,18 @@ defmodule StuartClientElixirTest.HttpClientTest do {:error, %OAuth2.Response{status_code: 401, body: %{"error" => "Bad credentials"}}} end + defp authenticator_response(@oauth_error) do + {:error, oauth2_error()} + end + + defp oauth2_error do + %OAuth2.Error{ + reason: + {:options, + {:socket_options, [packet_size: 0, packet: 0, header: 0, active: false, mode: :binary]}} + } + end + defp sample_request_body, do: Jason.encode!(%{sample: "request"}) defp expected_headers, From 248497c211ca567568470e68151b157ee7e23035 Mon Sep 17 00:00:00 2001 From: Jaime Iniesta Date: Mon, 16 Sep 2019 11:27:24 +0200 Subject: [PATCH 04/13] Patch requests (#21) * relax required Elixir version * add support for PATCH requests * moves timeout url to module attribute in test. Thx @seanhandley --- README.md | 41 +++++++++++++ lib/stuart_client_elixir.ex | 1 + lib/stuart_client_elixir/http_client.ex | 46 +++++++++----- mix.exs | 2 +- .../stuart_client_elixir/http_client_test.exs | 60 +++++++++++++++---- 5 files changed, 123 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index f207221..f841b9c 100644 --- a/README.md +++ b/README.md @@ -70,3 +70,44 @@ job = %{ credentials = %Credentials{client_id: "...", client_secret: "..."} StuartClientElixir.post("/v2/jobs", Jason.encode!(job), %{environment: Environment.sandbox(), credentials: credentials}) ``` + +#### Send a PATCH request to the Stuart API + +```elixir +alias StuartClientElixir.{Environment, Credentials} + +job = %{ + job: %{ + deliveries: [ + %{ + id: "43035", + client_reference: "new_client_reference", + package_description: "new_package_description", + pickup: %{ + comment: "new_comment", + contact: %{ + firstname: "new_firstname", + lastname: "new_lastname", + phone: "+33628046091", + email: "sd@df.com", + company: "new_company" + } + }, + dropoff: %{ + comment: "new_comment", + contact: %{ + firstname: "new_firstname", + lastname: "new_lastname", + phone: "+33628046095", + email: "new_email@mymail.com", + company: "new_company" + } + } + } + ] + } +} + +credentials = %Credentials{client_id: "...", client_secret: "..."} +StuartClientElixir.patch("/v2/jobs/1234", Jason.encode!(job), %{environment: Environment.sandbox(), credentials: credentials}) +``` diff --git a/lib/stuart_client_elixir.ex b/lib/stuart_client_elixir.ex index 6b93ed7..04fc670 100644 --- a/lib/stuart_client_elixir.ex +++ b/lib/stuart_client_elixir.ex @@ -3,5 +3,6 @@ defmodule StuartClientElixir do defdelegate get(resource, options), to: HttpClient defdelegate post(resource, body, options), to: HttpClient + defdelegate patch(resource, body, options), to: HttpClient defdelegate forget_token!(client_id), to: Authenticator end diff --git a/lib/stuart_client_elixir/http_client.ex b/lib/stuart_client_elixir/http_client.ex index d996864..f221480 100644 --- a/lib/stuart_client_elixir/http_client.ex +++ b/lib/stuart_client_elixir/http_client.ex @@ -9,24 +9,42 @@ defmodule StuartClientElixir.HttpClient do @callback get(url, options) :: ok_response | error_response @callback post(url, body, options) :: ok_response | error_response + @callback patch(url, body, options) :: ok_response | error_response - def get(resource, %{environment: environment, credentials: credentials}) do - with url <- url(resource, environment), - {:ok, access_token} <- Authenticator.access_token(environment, credentials), - headers <- default_headers(access_token) do - HTTPoison.get(url, headers, default_options()) - |> to_api_response() - else - {:error, %OAuth2.Response{}} = oauth_response -> to_api_response(oauth_response) - {:error, %OAuth2.Error{}} = oauth_error -> to_api_response(oauth_error) - end + def get(resource, options) do + perform_request(:get, options, resource) + end + + def post(resource, body, options) do + perform_request(:post, options, resource, body) end - def post(resource, body, %{environment: environment, credentials: credentials}) do + def patch(resource, body, options) do + perform_request(:patch, options, resource, body) + end + + ##################### + # Private functions # + ##################### + + def perform_request( + method, + %{ + environment: environment, + credentials: credentials + }, + resource, + body \\ nil + ) + when method in [:get, :post, :patch] do with url <- url(resource, environment), {:ok, access_token} <- Authenticator.access_token(environment, credentials), headers <- default_headers(access_token) do - HTTPoison.post(url, body, headers, default_options()) + case method do + :get -> HTTPoison.get(url, headers, default_options()) + :post -> HTTPoison.post(url, body, headers, default_options()) + :patch -> HTTPoison.patch(url, body, headers, default_options()) + end |> to_api_response() else {:error, %OAuth2.Response{}} = oauth_response -> to_api_response(oauth_response) @@ -34,10 +52,6 @@ defmodule StuartClientElixir.HttpClient do end end - ##################### - # Private functions # - ##################### - defp default_options do [recv_timeout: 10_000] end diff --git a/mix.exs b/mix.exs index 1be1d8a..af40603 100644 --- a/mix.exs +++ b/mix.exs @@ -12,7 +12,7 @@ defmodule StuartClientElixir.MixProject do } }, version: "1.2.0", - elixir: "~> 1.7", + elixir: "~> 1.6", start_permanent: Mix.env() == :prod, deps: deps() ] diff --git a/test/stuart_client_elixir/http_client_test.exs b/test/stuart_client_elixir/http_client_test.exs index d04601c..9b8e2fb 100644 --- a/test/stuart_client_elixir/http_client_test.exs +++ b/test/stuart_client_elixir/http_client_test.exs @@ -32,7 +32,8 @@ defmodule StuartClientElixirTest.HttpClientTest do [], [ get: fn url, _headers, _options -> response(:get, url) end, - post: fn url, _body, _headers, _options -> response(:post, url) end + post: fn url, _body, _headers, _options -> response(:post, url) end, + patch: fn url, _body, _headers, _options -> response(:patch, url) end ] } ]) do @@ -41,7 +42,7 @@ defmodule StuartClientElixirTest.HttpClientTest do describe "get" do test "calls HTTPoison with correct parameters" do - expected_response = %{body: %{"sample" => "get response"}, status_code: 201} + expected_response = %{body: %{"sample" => "get response"}, status_code: 200} assert HttpClient.get("/sample-endpoint", config()) == expected_response @@ -63,8 +64,7 @@ defmodule StuartClientElixirTest.HttpClientTest do test "returns explicit error when authentication fails because of other OAuth error" do expected_response = {:error, oauth2_error()} - assert HttpClient.get("/sample-endpoint", config(@oauth_error)) == - expected_response + assert HttpClient.get("/sample-endpoint", config(@oauth_error)) == expected_response end test "returns explicit error when GET request fails" do @@ -112,26 +112,66 @@ defmodule StuartClientElixirTest.HttpClientTest do end end + describe "patch" do + test "calls HTTPoison with correct parameters" do + expected_response = %{body: %{"sample" => "patch response"}, status_code: 200} + + assert HttpClient.patch("/sample-endpoint", sample_request_body(), config()) == + expected_response + + assert called( + HTTPoison.patch( + "https://sandbox-api.stuart.com/sample-endpoint", + sample_request_body(), + expected_headers(), + expected_options() + ) + ) + end + + test "returns explicit error when authentication fails because of bad credentials" do + expected_response = %{body: %{"error" => "Bad credentials"}, status_code: 401} + + assert HttpClient.patch("/sample-endpoint", sample_request_body(), config(@bad_credentials)) == + expected_response + end + + test "returns explicit error when authentication fails because of other OAuth error" do + expected_response = {:error, oauth2_error()} + + assert HttpClient.patch("/sample-endpoint", sample_request_body(), config(@oauth_error)) == + expected_response + end + + test "returns explicit error when PATCH request fails" do + expected_response = {:error, %HTTPoison.Error{id: nil, reason: :timeout}} + + assert HttpClient.patch("/timeout", sample_request_body(), config()) == expected_response + end + end + ##################### # Private functions # ##################### - defp response(:get, "https://sandbox-api.stuart.com/timeout") do + @timeout_url "https://sandbox-api.stuart.com/timeout" + + defp response(_, @timeout_url) do {:error, %HTTPoison.Error{id: nil, reason: :timeout}} end defp response(:get, _) do - {:ok, %HTTPoison.Response{status_code: 201, body: Jason.encode!(%{sample: "get response"})}} - end - - defp response(:post, "https://sandbox-api.stuart.com/timeout") do - {:error, %HTTPoison.Error{id: nil, reason: :timeout}} + {:ok, %HTTPoison.Response{status_code: 200, body: Jason.encode!(%{sample: "get response"})}} end defp response(:post, _) do {:ok, %HTTPoison.Response{status_code: 201, body: Jason.encode!(%{sample: "post response"})}} end + defp response(:patch, _) do + {:ok, %HTTPoison.Response{status_code: 200, body: Jason.encode!(%{sample: "patch response"})}} + end + defp authenticator_response(@good_credentials) do {:ok, "sample-access-token"} end From d244379ebecf0c079121a21fd9c49a2f2af46153 Mon Sep 17 00:00:00 2001 From: Jaime Iniesta Date: Tue, 24 Sep 2019 09:22:43 +0200 Subject: [PATCH 05/13] handle 204 No Content response --- lib/stuart_client_elixir/http_client.ex | 4 ++++ .../stuart_client_elixir/http_client_test.exs | 23 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/stuart_client_elixir/http_client.ex b/lib/stuart_client_elixir/http_client.ex index f221480..56bfd22 100644 --- a/lib/stuart_client_elixir/http_client.ex +++ b/lib/stuart_client_elixir/http_client.ex @@ -66,6 +66,10 @@ defmodule StuartClientElixir.HttpClient do ] end + defp to_api_response({:ok, %HTTPoison.Response{status_code: 204}}) do + %{status_code: 204, body: ""} + end + defp to_api_response({:ok, %HTTPoison.Response{status_code: status_code, body: body}}) do %{status_code: status_code, body: Jason.decode!(body)} end diff --git a/test/stuart_client_elixir/http_client_test.exs b/test/stuart_client_elixir/http_client_test.exs index 9b8e2fb..a256522 100644 --- a/test/stuart_client_elixir/http_client_test.exs +++ b/test/stuart_client_elixir/http_client_test.exs @@ -150,16 +150,39 @@ defmodule StuartClientElixirTest.HttpClientTest do end end + describe "handles 204 no content response" do + @expected_no_content_response %{status_code: 204, body: ""} + + test "204 no content in GET" do + assert HttpClient.get("/no_content", config()) == @expected_no_content_response + end + + test "204 no content in POST" do + assert HttpClient.post("/no_content", sample_request_body(), config()) == + @expected_no_content_response + end + + test "204 no content in PATCH" do + assert HttpClient.patch("/no_content", sample_request_body(), config()) == + @expected_no_content_response + end + end + ##################### # Private functions # ##################### @timeout_url "https://sandbox-api.stuart.com/timeout" + @no_content_url "https://sandbox-api.stuart.com/no_content" defp response(_, @timeout_url) do {:error, %HTTPoison.Error{id: nil, reason: :timeout}} end + defp response(_, @no_content_url) do + {:ok, %HTTPoison.Response{status_code: 204, body: ""}} + end + defp response(:get, _) do {:ok, %HTTPoison.Response{status_code: 200, body: Jason.encode!(%{sample: "get response"})}} end From 34e936126eb8793e1b4419b85f407f97302c551f Mon Sep 17 00:00:00 2001 From: Jaime Iniesta Date: Wed, 23 Oct 2019 15:05:30 +0200 Subject: [PATCH 06/13] upgrade dependencies (#23) * upgrade dependencies * fix codeship badge --- README.md | 2 +- mix.exs | 12 ++++++------ mix.lock | 17 +++++++++-------- test/stuart_client_elixir/queue_test.exs | 4 ++-- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index f841b9c..982ad67 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[ ![Codeship Status for StuartApp/stuart-client-elixir](https://app.codeship.com/projects/832b17c0-77a6-0136-8b5b-3e7b2f9f0830/status?branch=master)](https://app.codeship.com/projects/300202) +[![Codeship Status for StuartApp/stuart-client-elixir](https://app.codeship.com/projects/f9859ab0-b145-0137-da11-3e6824a8821c/status?branch=develop)](https://app.codeship.com/projects/363007) # Stuart Elixir Client diff --git a/mix.exs b/mix.exs index af40603..e43af9a 100644 --- a/mix.exs +++ b/mix.exs @@ -32,12 +32,12 @@ defmodule StuartClientElixir.MixProject do [ # {:dep_from_hexpm, "~> 0.3.0"}, # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}, - {:httpoison, "~> 1.5"}, - {:oauth2, "~> 0.9.4"}, - {:jason, "~> 1.1.2"}, - {:cachex, "~> 3.1"}, - {:mox, "~> 0.4.0", only: :test}, - {:mock, "~> 0.3.2", only: :test} + {:httpoison, "~> 1.6"}, + {:oauth2, "~> 2.0"}, + {:jason, "~> 1.1"}, + {:cachex, "~> 3.2"}, + {:mox, "~> 0.5", only: :test}, + {:mock, "~> 0.3", only: :test} ] end end diff --git a/mix.lock b/mix.lock index 78703d4..559f653 100644 --- a/mix.lock +++ b/mix.lock @@ -1,20 +1,21 @@ %{ - "cachex": {:hex, :cachex, "3.1.1", "588bcf48d20eddad7bff5172f5453090a071eba3191a03f51f779f88e3ac1900", [:mix], [{:eternal, "~> 1.2", [hex: :eternal, repo: "hexpm", optional: false]}, {:jumper, "~> 1.0", [hex: :jumper, repo: "hexpm", optional: false]}, {:unsafe, "~> 1.0", [hex: :unsafe, repo: "hexpm", optional: false]}], "hexpm"}, - "certifi": {:hex, :certifi, "2.4.2", "75424ff0f3baaccfd34b1214184b6ef616d89e420b258bb0a5ea7d7bc628f7f0", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"}, + "cachex": {:hex, :cachex, "3.2.0", "a596476c781b0646e6cb5cd9751af2e2974c3e0d5498a8cab71807618b74fe2f", [:mix], [{:eternal, "~> 1.2", [hex: :eternal, repo: "hexpm", optional: false]}, {:jumper, "~> 1.0", [hex: :jumper, repo: "hexpm", optional: false]}, {:sleeplocks, "~> 1.1", [hex: :sleeplocks, repo: "hexpm", optional: false]}, {:unsafe, "~> 1.0", [hex: :unsafe, repo: "hexpm", optional: false]}], "hexpm"}, + "certifi": {:hex, :certifi, "2.5.1", "867ce347f7c7d78563450a18a6a28a8090331e77fa02380b4a21962a65d36ee5", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"}, "eternal": {:hex, :eternal, "1.2.1", "d5b6b2499ba876c57be2581b5b999ee9bdf861c647401066d3eeed111d096bc4", [:mix], [], "hexpm"}, - "hackney": {:hex, :hackney, "1.14.3", "b5f6f5dcc4f1fba340762738759209e21914516df6be440d85772542d4a5e412", [:rebar3], [{:certifi, "2.4.2", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.4", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"}, - "httpoison": {:hex, :httpoison, "1.5.0", "71ae9f304bdf7f00e9cd1823f275c955bdfc68282bc5eb5c85c3a9ade865d68e", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"}, + "hackney": {:hex, :hackney, "1.15.2", "07e33c794f8f8964ee86cebec1a8ed88db5070e52e904b8f12209773c1036085", [:rebar3], [{:certifi, "2.5.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.5", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"}, + "httpoison": {:hex, :httpoison, "1.6.1", "2ce5bf6e535cd0ab02e905ba8c276580bab80052c5c549f53ddea52d72e81f33", [:mix], [{:hackney, "~> 1.15 and >= 1.15.2", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"}, "idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"}, "jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"}, "jumper": {:hex, :jumper, "1.0.1", "3c00542ef1a83532b72269fab9f0f0c82bf23a35e27d278bfd9ed0865cecabff", [:mix], [], "hexpm"}, "meck": {:hex, :meck, "0.8.12", "1f7b1a9f5d12c511848fec26bbefd09a21e1432eadb8982d9a8aceb9891a3cf2", [:rebar3], [], "hexpm"}, "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"}, - "mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], [], "hexpm"}, + "mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm"}, "mock": {:hex, :mock, "0.3.2", "e98e998fd76c191c7e1a9557c8617912c53df3d4a6132f561eb762b699ef59fa", [:mix], [{:meck, "~> 0.8.8", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm"}, - "mox": {:hex, :mox, "0.4.0", "7f120840f7d626184a3d65de36189ca6f37d432e5d63acd80045198e4c5f7e6e", [:mix], [], "hexpm"}, - "oauth2": {:hex, :oauth2, "0.9.4", "632e8e8826a45e33ac2ea5ac66dcc019ba6bb5a0d2ba77e342d33e3b7b252c6e", [:mix], [{:hackney, "~> 1.7", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"}, + "mox": {:hex, :mox, "0.5.1", "f86bb36026aac1e6f924a4b6d024b05e9adbed5c63e8daa069bd66fb3292165b", [:mix], [], "hexpm"}, + "oauth2": {:hex, :oauth2, "2.0.0", "338382079fe16c514420fa218b0903f8ad2d4bfc0ad0c9f988867dfa246731b0", [:mix], [{:hackney, "~> 1.13", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"}, "parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm"}, - "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.4", "f0eafff810d2041e93f915ef59899c923f4568f4585904d010387ed74988e77b", [:make, :mix, :rebar3], [], "hexpm"}, + "sleeplocks": {:hex, :sleeplocks, "1.1.1", "3d462a0639a6ef36cc75d6038b7393ae537ab394641beb59830a1b8271faeed3", [:rebar3], [], "hexpm"}, + "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.5", "6eaf7ad16cb568bb01753dbbd7a95ff8b91c7979482b95f38443fe2c8852a79b", [:make, :mix, :rebar3], [], "hexpm"}, "unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm"}, "unsafe": {:hex, :unsafe, "1.0.1", "a27e1874f72ee49312e0a9ec2e0b27924214a05e3ddac90e91727bc76f8613d8", [:mix], [], "hexpm"}, } diff --git a/test/stuart_client_elixir/queue_test.exs b/test/stuart_client_elixir/queue_test.exs index 4ed75fa..976cede 100644 --- a/test/stuart_client_elixir/queue_test.exs +++ b/test/stuart_client_elixir/queue_test.exs @@ -25,8 +25,8 @@ defmodule StuartClientElixirTest.QueueTest do Queue.enqueue(:second) # when - first = Queue.unqueue - second = Queue.unqueue + first = Queue.unqueue() + second = Queue.unqueue() # then assert first == :first From d1a44d512cbb3dd35662c559419a764b24dcdbf7 Mon Sep 17 00:00:00 2001 From: Victor Viruete Date: Tue, 3 Dec 2019 15:58:23 +0100 Subject: [PATCH 07/13] Handling invalid json errors (#24) --- lib/stuart_client_elixir/http_client.ex | 4 +++- .../stuart_client_elixir/http_client_test.exs | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/stuart_client_elixir/http_client.ex b/lib/stuart_client_elixir/http_client.ex index 56bfd22..5c90353 100644 --- a/lib/stuart_client_elixir/http_client.ex +++ b/lib/stuart_client_elixir/http_client.ex @@ -71,7 +71,9 @@ defmodule StuartClientElixir.HttpClient do end defp to_api_response({:ok, %HTTPoison.Response{status_code: status_code, body: body}}) do - %{status_code: status_code, body: Jason.decode!(body)} + with {:ok, decoded_body} <- Jason.decode(body) do + %{status_code: status_code, body: decoded_body} + end end defp to_api_response({:error, %OAuth2.Response{status_code: status_code, body: body}}) do diff --git a/test/stuart_client_elixir/http_client_test.exs b/test/stuart_client_elixir/http_client_test.exs index a256522..0eb68e8 100644 --- a/test/stuart_client_elixir/http_client_test.exs +++ b/test/stuart_client_elixir/http_client_test.exs @@ -168,12 +168,32 @@ defmodule StuartClientElixirTest.HttpClientTest do end end + describe "handles invalid json response" do + @expected_invalid_json_response {:error, + %Jason.DecodeError{data: "", position: 0, token: nil}} + + test "invalid json in GET" do + assert HttpClient.get("/invalid_json", config()) == @expected_invalid_json_response + end + + test "invalid json in POST" do + assert HttpClient.post("/invalid_json", sample_request_body(), config()) == + @expected_invalid_json_response + end + + test "invalid json in PATCH" do + assert HttpClient.patch("/invalid_json", sample_request_body(), config()) == + @expected_invalid_json_response + end + end + ##################### # Private functions # ##################### @timeout_url "https://sandbox-api.stuart.com/timeout" @no_content_url "https://sandbox-api.stuart.com/no_content" + @invalid_json_url "https://sandbox-api.stuart.com/invalid_json" defp response(_, @timeout_url) do {:error, %HTTPoison.Error{id: nil, reason: :timeout}} @@ -183,6 +203,10 @@ defmodule StuartClientElixirTest.HttpClientTest do {:ok, %HTTPoison.Response{status_code: 204, body: ""}} end + defp response(_, @invalid_json_url) do + {:ok, %HTTPoison.Response{status_code: 500, body: ""}} + end + defp response(:get, _) do {:ok, %HTTPoison.Response{status_code: 200, body: Jason.encode!(%{sample: "get response"})}} end From 2e9e0a92ee90323cf561dd43e66056d8260e63ba Mon Sep 17 00:00:00 2001 From: Victor Viruete Date: Wed, 4 Dec 2019 15:44:23 +0100 Subject: [PATCH 08/13] Fix oauth new behavior after upgrading to v2 (#25) After including latest changes in a new monocle branch some e2e tests were broken when accessing stuart-api. Part of those changes were upgrading oauth version from 0.9 to 2.0. When reading the changelog we realized "application/json" serializing wasn't the default anymore so after the upgrade the token was being stored as the full json string. With this change we explicitly set "application/json" as the content type and Jason as the serializer. Changelog: https://github.com/scrogson/oauth2/blob/master/CHANGELOG.md#v100-2019-03-13 --- lib/stuart_client_elixir/authenticator.ex | 1 + test/stuart_client_elixir/authenticator_test.exs | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/lib/stuart_client_elixir/authenticator.ex b/lib/stuart_client_elixir/authenticator.ex index 57e2b34..237c1b1 100644 --- a/lib/stuart_client_elixir/authenticator.ex +++ b/lib/stuart_client_elixir/authenticator.ex @@ -48,6 +48,7 @@ defmodule StuartClientElixir.Authenticator do client_secret: client_secret, site: site ) + |> OAuth2.Client.put_serializer("application/json", Jason) end defp cache_exists?(%Credentials{client_id: client_id}), diff --git a/test/stuart_client_elixir/authenticator_test.exs b/test/stuart_client_elixir/authenticator_test.exs index 2f7580b..522e377 100644 --- a/test/stuart_client_elixir/authenticator_test.exs +++ b/test/stuart_client_elixir/authenticator_test.exs @@ -19,6 +19,9 @@ defmodule StuartClientElixirTest.AuthenticatorTest do new: fn oauth_params -> sample_client(oauth_params) end, + put_serializer: fn oauth_client, content_type, serializer -> + client_with_serializer(oauth_client, content_type, serializer) + end, get_token: fn oauth_client -> get_token_response(oauth_client) end @@ -158,6 +161,10 @@ defmodule StuartClientElixirTest.AuthenticatorTest do } end + defp client_with_serializer(oauth_client, content_type, serializer) do + %{oauth_client | serializers: %{content_type => serializer}} + end + defp get_token_response(%OAuth2.Client{client_secret: "client-secret"}) do {:ok, sample_client_with_token( From de961f0872296831d0af4a2535e1ee8c751a1ad3 Mon Sep 17 00:00:00 2001 From: Victor Viruete Date: Wed, 20 Jan 2021 11:57:06 +0100 Subject: [PATCH 09/13] [CHORE] Updated sandbox url. the old one is deprecated (#26) --- lib/stuart_client_elixir/environment.ex | 2 +- test/stuart_client_elixir/authenticator_test.exs | 2 +- test/stuart_client_elixir/environment_test.exs | 2 +- test/stuart_client_elixir/http_client_test.exs | 12 ++++++------ 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/stuart_client_elixir/environment.ex b/lib/stuart_client_elixir/environment.ex index 4126c9b..6e65675 100644 --- a/lib/stuart_client_elixir/environment.ex +++ b/lib/stuart_client_elixir/environment.ex @@ -2,6 +2,6 @@ defmodule StuartClientElixir.Environment do @enforce_keys [:base_url] defstruct @enforce_keys - def sandbox, do: %__MODULE__{base_url: "https://sandbox-api.stuart.com"} + def sandbox, do: %__MODULE__{base_url: "https://api.sandbox.stuart.com"} def production, do: %__MODULE__{base_url: "https://api.stuart.com"} end diff --git a/test/stuart_client_elixir/authenticator_test.exs b/test/stuart_client_elixir/authenticator_test.exs index 522e377..64d5307 100644 --- a/test/stuart_client_elixir/authenticator_test.exs +++ b/test/stuart_client_elixir/authenticator_test.exs @@ -216,7 +216,7 @@ defmodule StuartClientElixirTest.AuthenticatorTest do ref: nil, request_opts: [], token: sample_token(access_token: access_token, expires_at: expires_at), - site: "https://sandbox-api.stuart.com", + site: "https://api.sandbox.stuart.com", strategy: OAuth2.Strategy.ClientCredentials, token_method: :post, token_url: "/oauth/token" diff --git a/test/stuart_client_elixir/environment_test.exs b/test/stuart_client_elixir/environment_test.exs index 6bb50ba..02bf1da 100644 --- a/test/stuart_client_elixir/environment_test.exs +++ b/test/stuart_client_elixir/environment_test.exs @@ -4,7 +4,7 @@ defmodule StuartClientElixirTest.EnvironmentTest do alias StuartClientElixir.Environment test "sandbox" do - assert Environment.sandbox() == %Environment{base_url: "https://sandbox-api.stuart.com"} + assert Environment.sandbox() == %Environment{base_url: "https://api.sandbox.stuart.com"} end test "production" do diff --git a/test/stuart_client_elixir/http_client_test.exs b/test/stuart_client_elixir/http_client_test.exs index 0eb68e8..c25cf24 100644 --- a/test/stuart_client_elixir/http_client_test.exs +++ b/test/stuart_client_elixir/http_client_test.exs @@ -48,7 +48,7 @@ defmodule StuartClientElixirTest.HttpClientTest do assert called( HTTPoison.get( - "https://sandbox-api.stuart.com/sample-endpoint", + "https://api.sandbox.stuart.com/sample-endpoint", expected_headers(), expected_options() ) @@ -83,7 +83,7 @@ defmodule StuartClientElixirTest.HttpClientTest do assert called( HTTPoison.post( - "https://sandbox-api.stuart.com/sample-endpoint", + "https://api.sandbox.stuart.com/sample-endpoint", sample_request_body(), expected_headers(), expected_options() @@ -121,7 +121,7 @@ defmodule StuartClientElixirTest.HttpClientTest do assert called( HTTPoison.patch( - "https://sandbox-api.stuart.com/sample-endpoint", + "https://api.sandbox.stuart.com/sample-endpoint", sample_request_body(), expected_headers(), expected_options() @@ -191,9 +191,9 @@ defmodule StuartClientElixirTest.HttpClientTest do # Private functions # ##################### - @timeout_url "https://sandbox-api.stuart.com/timeout" - @no_content_url "https://sandbox-api.stuart.com/no_content" - @invalid_json_url "https://sandbox-api.stuart.com/invalid_json" + @timeout_url "https://api.sandbox.stuart.com/timeout" + @no_content_url "https://api.sandbox.stuart.com/no_content" + @invalid_json_url "https://api.sandbox.stuart.com/invalid_json" defp response(_, @timeout_url) do {:error, %HTTPoison.Error{id: nil, reason: :timeout}} From 8bbc50b36bdda0a0c673913e748c792c93ec6f08 Mon Sep 17 00:00:00 2001 From: Victor Viruete Date: Wed, 20 Jan 2021 17:05:35 +0100 Subject: [PATCH 10/13] version bump 1.2.1 (#27) --- README.md | 2 +- mix.exs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 982ad67..10e873f 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ For a complete documentation of all endpoints offered by the Stuart API, you can def deps do [ - {:stuart_client_elixir, "~> 1.2.0"} + {:stuart_client_elixir, "~> 1.2.1"} ] end ``` diff --git a/mix.exs b/mix.exs index e43af9a..eb70b04 100644 --- a/mix.exs +++ b/mix.exs @@ -11,7 +11,7 @@ defmodule StuartClientElixir.MixProject do "GitHub" => "https://github.com/StuartApp/stuart-client-elixir" } }, - version: "1.2.0", + version: "1.2.1", elixir: "~> 1.6", start_permanent: Mix.env() == :prod, deps: deps() From 3b356d5d8f2adcbac8aa568f7c03ee9cc39bde20 Mon Sep 17 00:00:00 2001 From: Victor Viruete Date: Thu, 21 Jan 2021 13:12:08 +0100 Subject: [PATCH 11/13] Version bump to 1.3.0 (#29) --- README.md | 2 +- mix.exs | 2 +- mix.lock | 38 +++++++++++++++++++------------------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 10e873f..225fcce 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ For a complete documentation of all endpoints offered by the Stuart API, you can def deps do [ - {:stuart_client_elixir, "~> 1.2.1"} + {:stuart_client_elixir, "~> 1.3.0"} ] end ``` diff --git a/mix.exs b/mix.exs index eb70b04..7ecb57a 100644 --- a/mix.exs +++ b/mix.exs @@ -11,7 +11,7 @@ defmodule StuartClientElixir.MixProject do "GitHub" => "https://github.com/StuartApp/stuart-client-elixir" } }, - version: "1.2.1", + version: "1.3.0", elixir: "~> 1.6", start_permanent: Mix.env() == :prod, deps: deps() diff --git a/mix.lock b/mix.lock index 559f653..1e8b0b8 100644 --- a/mix.lock +++ b/mix.lock @@ -1,21 +1,21 @@ %{ - "cachex": {:hex, :cachex, "3.2.0", "a596476c781b0646e6cb5cd9751af2e2974c3e0d5498a8cab71807618b74fe2f", [:mix], [{:eternal, "~> 1.2", [hex: :eternal, repo: "hexpm", optional: false]}, {:jumper, "~> 1.0", [hex: :jumper, repo: "hexpm", optional: false]}, {:sleeplocks, "~> 1.1", [hex: :sleeplocks, repo: "hexpm", optional: false]}, {:unsafe, "~> 1.0", [hex: :unsafe, repo: "hexpm", optional: false]}], "hexpm"}, - "certifi": {:hex, :certifi, "2.5.1", "867ce347f7c7d78563450a18a6a28a8090331e77fa02380b4a21962a65d36ee5", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"}, - "eternal": {:hex, :eternal, "1.2.1", "d5b6b2499ba876c57be2581b5b999ee9bdf861c647401066d3eeed111d096bc4", [:mix], [], "hexpm"}, - "hackney": {:hex, :hackney, "1.15.2", "07e33c794f8f8964ee86cebec1a8ed88db5070e52e904b8f12209773c1036085", [:rebar3], [{:certifi, "2.5.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.5", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"}, - "httpoison": {:hex, :httpoison, "1.6.1", "2ce5bf6e535cd0ab02e905ba8c276580bab80052c5c549f53ddea52d72e81f33", [:mix], [{:hackney, "~> 1.15 and >= 1.15.2", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"}, - "idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"}, - "jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"}, - "jumper": {:hex, :jumper, "1.0.1", "3c00542ef1a83532b72269fab9f0f0c82bf23a35e27d278bfd9ed0865cecabff", [:mix], [], "hexpm"}, - "meck": {:hex, :meck, "0.8.12", "1f7b1a9f5d12c511848fec26bbefd09a21e1432eadb8982d9a8aceb9891a3cf2", [:rebar3], [], "hexpm"}, - "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"}, - "mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm"}, - "mock": {:hex, :mock, "0.3.2", "e98e998fd76c191c7e1a9557c8617912c53df3d4a6132f561eb762b699ef59fa", [:mix], [{:meck, "~> 0.8.8", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm"}, - "mox": {:hex, :mox, "0.5.1", "f86bb36026aac1e6f924a4b6d024b05e9adbed5c63e8daa069bd66fb3292165b", [:mix], [], "hexpm"}, - "oauth2": {:hex, :oauth2, "2.0.0", "338382079fe16c514420fa218b0903f8ad2d4bfc0ad0c9f988867dfa246731b0", [:mix], [{:hackney, "~> 1.13", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"}, - "parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm"}, - "sleeplocks": {:hex, :sleeplocks, "1.1.1", "3d462a0639a6ef36cc75d6038b7393ae537ab394641beb59830a1b8271faeed3", [:rebar3], [], "hexpm"}, - "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.5", "6eaf7ad16cb568bb01753dbbd7a95ff8b91c7979482b95f38443fe2c8852a79b", [:make, :mix, :rebar3], [], "hexpm"}, - "unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm"}, - "unsafe": {:hex, :unsafe, "1.0.1", "a27e1874f72ee49312e0a9ec2e0b27924214a05e3ddac90e91727bc76f8613d8", [:mix], [], "hexpm"}, + "cachex": {:hex, :cachex, "3.2.0", "a596476c781b0646e6cb5cd9751af2e2974c3e0d5498a8cab71807618b74fe2f", [:mix], [{:eternal, "~> 1.2", [hex: :eternal, repo: "hexpm", optional: false]}, {:jumper, "~> 1.0", [hex: :jumper, repo: "hexpm", optional: false]}, {:sleeplocks, "~> 1.1", [hex: :sleeplocks, repo: "hexpm", optional: false]}, {:unsafe, "~> 1.0", [hex: :unsafe, repo: "hexpm", optional: false]}], "hexpm", "aef93694067a43697ae0531727e097754a9e992a1e7946296f5969d6dd9ac986"}, + "certifi": {:hex, :certifi, "2.5.1", "867ce347f7c7d78563450a18a6a28a8090331e77fa02380b4a21962a65d36ee5", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm", "805abd97539caf89ec6d4732c91e62ba9da0cda51ac462380bbd28ee697a8c42"}, + "eternal": {:hex, :eternal, "1.2.1", "d5b6b2499ba876c57be2581b5b999ee9bdf861c647401066d3eeed111d096bc4", [:mix], [], "hexpm", "b14f1dc204321429479c569cfbe8fb287541184ed040956c8862cb7a677b8406"}, + "hackney": {:hex, :hackney, "1.15.2", "07e33c794f8f8964ee86cebec1a8ed88db5070e52e904b8f12209773c1036085", [:rebar3], [{:certifi, "2.5.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.5", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm", "e0100f8ef7d1124222c11ad362c857d3df7cb5f4204054f9f0f4a728666591fc"}, + "httpoison": {:hex, :httpoison, "1.6.1", "2ce5bf6e535cd0ab02e905ba8c276580bab80052c5c549f53ddea52d72e81f33", [:mix], [{:hackney, "~> 1.15 and >= 1.15.2", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "89149056039084024a284cd703b2d1900d584958dba432132cb21ef35aed7487"}, + "idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "4bdd305eb64e18b0273864920695cb18d7a2021f31a11b9c5fbcd9a253f936e2"}, + "jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fdf843bca858203ae1de16da2ee206f53416bbda5dc8c9e78f43243de4bc3afe"}, + "jumper": {:hex, :jumper, "1.0.1", "3c00542ef1a83532b72269fab9f0f0c82bf23a35e27d278bfd9ed0865cecabff", [:mix], [], "hexpm", "318c59078ac220e966d27af3646026db9b5a5e6703cb2aa3e26bcfaba65b7433"}, + "meck": {:hex, :meck, "0.8.12", "1f7b1a9f5d12c511848fec26bbefd09a21e1432eadb8982d9a8aceb9891a3cf2", [:rebar3], [], "hexpm", "7a6ab35a42e6c846636e8ecd6fdf2cc2e3f09dbee1abb15c1a7c705c10775787"}, + "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"}, + "mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"}, + "mock": {:hex, :mock, "0.3.2", "e98e998fd76c191c7e1a9557c8617912c53df3d4a6132f561eb762b699ef59fa", [:mix], [{:meck, "~> 0.8.8", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm", "1d63e81180518c413647e97ad141beeb9b75046715731ed3fca58c0232a4201d"}, + "mox": {:hex, :mox, "0.5.1", "f86bb36026aac1e6f924a4b6d024b05e9adbed5c63e8daa069bd66fb3292165b", [:mix], [], "hexpm", "052346cf322311c49a0f22789f3698eea030eec09b8c47367f0686ef2634ae14"}, + "oauth2": {:hex, :oauth2, "2.0.0", "338382079fe16c514420fa218b0903f8ad2d4bfc0ad0c9f988867dfa246731b0", [:mix], [{:hackney, "~> 1.13", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "881b8364ac7385f9fddc7949379cbe3f7081da37233a1aa7aab844670a91e7e7"}, + "parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm", "17ef63abde837ad30680ea7f857dd9e7ced9476cdd7b0394432af4bfc241b960"}, + "sleeplocks": {:hex, :sleeplocks, "1.1.1", "3d462a0639a6ef36cc75d6038b7393ae537ab394641beb59830a1b8271faeed3", [:rebar3], [], "hexpm", "84ee37aeff4d0d92b290fff986d6a95ac5eedf9b383fadfd1d88e9b84a1c02e1"}, + "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.5", "6eaf7ad16cb568bb01753dbbd7a95ff8b91c7979482b95f38443fe2c8852a79b", [:make, :mix, :rebar3], [], "hexpm", "13104d7897e38ed7f044c4de953a6c28597d1c952075eb2e328bc6d6f2bfc496"}, + "unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm", "1d1848c40487cdb0b30e8ed975e34e025860c02e419cb615d255849f3427439d"}, + "unsafe": {:hex, :unsafe, "1.0.1", "a27e1874f72ee49312e0a9ec2e0b27924214a05e3ddac90e91727bc76f8613d8", [:mix], [], "hexpm", "6c7729a2d214806450d29766abc2afaa7a2cbecf415be64f36a6691afebb50e5"}, } From eee19a108ceafc7bfc9b0ffdfedd6139a0ceceea Mon Sep 17 00:00:00 2001 From: adrien-eba-stuart <112413734+adrien-eba-stuart@users.noreply.github.com> Date: Wed, 7 Sep 2022 11:59:12 +0200 Subject: [PATCH 12/13] Change documentation link on README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 225fcce..cddd508 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # Stuart Elixir Client -For a complete documentation of all endpoints offered by the Stuart API, you can read the [Stuart API documentation](https://stuart.api-docs.io). +For a complete documentation of all endpoints offered by the Stuart API, you can read the [Stuart API documentation](https://api-docs.stuart.com/). ## Install From 6f5f991b6c225a775e9eafa5c5c3b826f57998a7 Mon Sep 17 00:00:00 2001 From: Telmo Barbosa Date: Thu, 20 Apr 2023 10:57:00 +0100 Subject: [PATCH 13/13] Increase timeout value to 60s (#31) --- README.md | 2 +- lib/stuart_client_elixir/http_client.ex | 2 +- mix.exs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cddd508..43af376 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ For a complete documentation of all endpoints offered by the Stuart API, you can def deps do [ - {:stuart_client_elixir, "~> 1.3.0"} + {:stuart_client_elixir, "~> 1.3.1"} ] end ``` diff --git a/lib/stuart_client_elixir/http_client.ex b/lib/stuart_client_elixir/http_client.ex index 5c90353..6d78841 100644 --- a/lib/stuart_client_elixir/http_client.ex +++ b/lib/stuart_client_elixir/http_client.ex @@ -53,7 +53,7 @@ defmodule StuartClientElixir.HttpClient do end defp default_options do - [recv_timeout: 10_000] + [recv_timeout: 60_000] end defp url(resource, %Environment{base_url: base_url}), do: "#{base_url}#{resource}" diff --git a/mix.exs b/mix.exs index 7ecb57a..7352c63 100644 --- a/mix.exs +++ b/mix.exs @@ -11,7 +11,7 @@ defmodule StuartClientElixir.MixProject do "GitHub" => "https://github.com/StuartApp/stuart-client-elixir" } }, - version: "1.3.0", + version: "1.3.1", elixir: "~> 1.6", start_permanent: Mix.env() == :prod, deps: deps()