Skip to content

Commit

Permalink
chore(httpoison): upgrades to v1.x, renames response type (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
coop authored and itsachen committed Feb 1, 2019
1 parent e772c8e commit 63cb751
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/lob/bank_account.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Lob.BankAccount do

use Lob.ResourceBase, endpoint: "bank_accounts", methods: [:create, :retrieve, :list, :delete]

@spec verify(String.t, map, map) :: Client.response
@spec verify(String.t, map, map) :: Client.client_response
def verify(id, data, headers \\ %{}) do
Client.post_request(verify_url(id), Util.build_body(data), Util.build_headers(headers))
end
Expand Down
10 changes: 5 additions & 5 deletions lib/lob/client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule Lob.Client do

@client_version Mix.Project.config[:version]

@type response :: {:ok, map, list} | {:error, map}
@type client_response :: {:ok, map, list} | {:error, map}

defmodule MissingAPIKeyError do
@moduledoc """
Expand Down Expand Up @@ -60,21 +60,21 @@ defmodule Lob.Client do
# Client API
# #########################

@spec get_request(String.t, HTTPoison.Base.headers) :: response
@spec get_request(String.t, HTTPoison.Base.headers) :: client_response
def get_request(url, headers \\ []) do
url
|> get(headers, build_options())
|> handle_response
end

@spec post_request(String.t, {:multipart, list}, HTTPoison.Base.headers) :: response
@spec post_request(String.t, {:multipart, list}, HTTPoison.Base.headers) :: client_response
def post_request(url, body, headers \\ []) do
url
|> post(body, headers, build_options())
|> handle_response
end

@spec delete_request(String.t, HTTPoison.Base.headers) :: response
@spec delete_request(String.t, HTTPoison.Base.headers) :: client_response
def delete_request(url, headers \\ []) do
url
|> delete(headers, build_options())
Expand All @@ -85,7 +85,7 @@ defmodule Lob.Client do
# Response handlers
# #########################

@spec handle_response({:ok | :error, Response.t | Error.t}) :: response
@spec handle_response({:ok | :error, Response.t | Error.t}) :: client_response
defp handle_response({:ok, %{body: body, headers: headers, status_code: code}})
when code >= 200 and code < 300 do
{:ok, body, headers}
Expand Down
2 changes: 1 addition & 1 deletion lib/lob/intl_verification.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Lob.IntlVerification do

use Lob.ResourceBase, endpoint: "intl_verifications", methods: []

@spec verify(map, map) :: Client.response
@spec verify(map, map) :: Client.client_response
def verify(data, headers \\ %{}) do
Client.post_request(base_url(), Util.build_body(data), Util.build_headers(headers))
end
Expand Down
8 changes: 4 additions & 4 deletions lib/lob/resource_base.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defmodule Lob.ResourceBase do
alias Lob.Client

if :list in unquote(methods) do
@spec list(map, map) :: Client.response
@spec list(map, map) :: Client.client_response
def list(params \\ %{}, headers \\ %{}) do
Client.get_request("#{base_url()}?#{Util.build_query_string(params)}" , Util.build_headers(headers))
end
Expand All @@ -29,7 +29,7 @@ defmodule Lob.ResourceBase do
end

if :retrieve in unquote(methods) do
@spec retrieve(String.t, map) :: Client.response
@spec retrieve(String.t, map) :: Client.client_response
def retrieve(id, headers \\ %{}) do
Client.get_request(resource_url(id), Util.build_headers(headers))
end
Expand All @@ -44,7 +44,7 @@ defmodule Lob.ResourceBase do
end

if :create in unquote(methods) do
@spec create(map, map) :: Client.response
@spec create(map, map) :: Client.client_response
def create(data, headers \\ %{}) do
Client.post_request(base_url(), Util.build_body(data), Util.build_headers(headers))
end
Expand All @@ -59,7 +59,7 @@ defmodule Lob.ResourceBase do
end

if :delete in unquote(methods) do
@spec delete(String.t, map) :: Client.response
@spec delete(String.t, map) :: Client.client_response
def delete(id, headers \\ %{}) do
Client.delete_request(resource_url(id), Util.build_headers(headers))
end
Expand Down
2 changes: 1 addition & 1 deletion lib/lob/us_autocompletion.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Lob.USAutocompletion do

use Lob.ResourceBase, endpoint: "us_autocompletions", methods: []

@spec autocomplete(map, map) :: Client.response
@spec autocomplete(map, map) :: Client.client_response
def autocomplete(data, headers \\ %{}) do
Client.post_request(base_url(), Util.build_body(data), Util.build_headers(headers))
end
Expand Down
2 changes: 1 addition & 1 deletion lib/lob/us_verification.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Lob.USVerification do

use Lob.ResourceBase, endpoint: "us_verifications", methods: []

@spec verify(map, map) :: Client.response
@spec verify(map, map) :: Client.client_response
def verify(data, headers \\ %{}) do
Client.post_request(base_url(), Util.build_body(data), Util.build_headers(headers))
end
Expand Down
2 changes: 1 addition & 1 deletion lib/lob/us_zip_lookup.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Lob.USZipLookup do

use Lob.ResourceBase, endpoint: "us_zip_lookups", methods: []

@spec lookup(map, map) :: Client.response
@spec lookup(map, map) :: Client.client_response
def lookup(data, headers \\ %{}) do
Client.post_request(base_url(), Util.build_body(data), Util.build_headers(headers))
end
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ defmodule Lob.Mixfile do
{:credo, "~> 0.8", only: [:dev, :test], runtime: false},
{:dialyxir, "~> 0.5.1", only: [:dev, :test], runtime: false},
{:excoveralls, "~> 0.7.4", only: :test},
{:httpoison, "~> 0.13"},
{:httpoison, "~> 1.0"},
{:poison, "~> 3.1"},
{:uuid, "~> 1.1", only: :test}
]
Expand Down
13 changes: 7 additions & 6 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
%{
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"},
"bypass": {:hex, :bypass, "0.8.1", "16d409e05530ece4a72fabcf021a3e5c7e15dcc77f911423196a0c551f2a15ca", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, repo: "hexpm", optional: false]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
"certifi": {:hex, :certifi, "2.0.0", "a0c0e475107135f76b8c1d5bc7efb33cd3815cb3cf3dea7aefdd174dabead064", [:rebar3], [], "hexpm"},
"certifi": {:hex, :certifi, "2.4.2", "75424ff0f3baaccfd34b1214184b6ef616d89e420b258bb0a5ea7d7bc628f7f0", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"},
"cowboy": {:hex, :cowboy, "1.1.2", "61ac29ea970389a88eca5a65601460162d370a70018afe6f949a29dca91f3bb0", [:rebar3], [{:cowlib, "~> 1.0.2", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.3.2", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm"},
"cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [:make], [], "hexpm"},
"credo": {:hex, :credo, "0.8.10", "261862bb7363247762e1063713bb85df2bbd84af8d8610d1272cd9c1943bba63", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}], "hexpm"},
"dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [:mix], [], "hexpm"},
"excoveralls": {:hex, :excoveralls, "0.7.5", "339e433e5d3bce09400dc8de7b9040741a409c93917849916c136a0f51fdc183", [:mix], [{:exjsx, ">= 3.0.0", [hex: :exjsx, repo: "hexpm", optional: false]}, {:hackney, ">= 0.12.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
"exjsx": {:hex, :exjsx, "4.0.0", "60548841e0212df401e38e63c0078ec57b33e7ea49b032c796ccad8cde794b5c", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, repo: "hexpm", optional: false]}], "hexpm"},
"hackney": {:hex, :hackney, "1.10.1", "c38d0ca52ea80254936a32c45bb7eb414e7a96a521b4ce76d00a69753b157f21", [:rebar3], [{:certifi, "2.0.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "5.1.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.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"},
"httpoison": {:hex, :httpoison, "0.13.0", "bfaf44d9f133a6599886720f3937a7699466d23bb0cd7a88b6ba011f53c6f562", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
"idna": {:hex, :idna, "5.1.0", "d72b4effeb324ad5da3cab1767cb16b17939004e789d8c0ad5b70f3cea20c89a", [:rebar3], [{:unicode_util_compat, "0.3.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"},
"hackney": {:hex, :hackney, "1.15.0", "287a5d2304d516f63e56c469511c42b016423bcb167e61b611f6bad47e3ca60e", [: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"},
"idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"},
"jsx": {:hex, :jsx, "2.8.3", "a05252d381885240744d955fbe3cf810504eb2567164824e19303ea59eef62cf", [:mix, :rebar3], [], "hexpm"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"},
"mime": {:hex, :mime, "1.1.0", "01c1d6f4083d8aa5c7b8c246ade95139620ef8effb009edde934e0ec3b28090a", [:mix], [], "hexpm"},
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], [], "hexpm"},
"parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm"},
"plug": {:hex, :plug, "1.4.3", "236d77ce7bf3e3a2668dc0d32a9b6f1f9b1f05361019946aae49874904be4aed", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1", [hex: :cowboy, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}], "hexpm"},
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
"ranch": {:hex, :ranch, "1.3.2", "e4965a144dc9fbe70e5c077c65e73c57165416a901bd02ea899cfd95aa890986", [:rebar3], [], "hexpm"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], [], "hexpm"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.3.1", "a1f612a7b512638634a603c8f401892afbf99b8ce93a45041f8aaca99cadb85e", [:rebar3], [], "hexpm"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.4", "f0eafff810d2041e93f915ef59899c923f4568f4585904d010387ed74988e77b", [:make, :mix, :rebar3], [], "hexpm"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm"},
"uuid": {:hex, :uuid, "1.1.8", "e22fc04499de0de3ed1116b770c7737779f226ceefa0badb3592e64d5cfb4eb9", [:mix], [], "hexpm"},
}

0 comments on commit 63cb751

Please sign in to comment.