Skip to content

Commit

Permalink
Merge pull request #4 from compound-finance/aryan/add-http-mocking-ab…
Browse files Browse the repository at this point in the history
…ility

Add HTTPoison mocking ability
  • Loading branch information
aryanbhasin authored Aug 17, 2022
2 parents a87d55e + ab7b96a commit 10be759
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ by adding `circlex_api` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:circlex_api, "~> 0.1.6"}
{:circlex_api, "~> 0.1.7"}
]
end
```
Expand Down
8 changes: 7 additions & 1 deletion lib/circlex/api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ defmodule Circlex.Api do

def auth(), do: Application.get_env(:circlex_api, :auth)

# Has to conform to the HTTPoison interface
@http_client Application.get_env(:circlex_api, :http_client, HTTPoison)
def http_client(), do: @http_client


defmodule Tooling do
def not_implemented(), do: {:error, %{error: "Not implemented by Circlex client"}}

Expand All @@ -27,6 +32,7 @@ defmodule Circlex.Api do
host = Keyword.get(opts, :host, Circlex.Api.env_host())
auth = Keyword.get(opts, :auth, Circlex.Api.auth())
no_data_key = Keyword.get(opts, :no_data_key, false)
http_client = Keyword.get(opts, :http_client, Circlex.Api.http_client())

request = %HTTPoison.Request{
method: method,
Expand All @@ -39,7 +45,7 @@ defmodule Circlex.Api do
]
}

case HTTPoison.request(request) do
case http_client.request(request) do
{:ok, %HTTPoison.Response{status_code: status_code, body: body}} ->
with {:ok, json} <- Jason.decode(body) do
case status_code do
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Circlex.MixProject do
def project do
[
app: :circlex_api,
version: "0.1.6",
version: "0.1.7",
elixir: "~> 1.13",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
Expand Down

0 comments on commit 10be759

Please sign in to comment.