Skip to content

Commit

Permalink
Get api_base_url from config or else apply default (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
anronin authored Apr 13, 2017
1 parent 5a48cac commit 05ca35b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/stripe.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,25 @@ defmodule Stripe do
end

@doc """
Creates the URL for our endpoint.
Creates the URL for our endpoint. You can also manually set API base url
for testing purpose by configuring the :stripity_stripe application
with `:api_base_url` key. By default `https://api.stripe.com/v1/`.
Here is an example:
iex> Application.put_env(:stripity_stripe, :api_base_url, "http://localhost:4004")
:ok
iex> Stripe.process_url("/plans")
"http://localhost:4004/plans"
Args:
* endpoint - part of the API we're hitting
Returns string
"""
def process_url(endpoint) do
"https://api.stripe.com/v1/" <> endpoint
api_base_url = Application.get_env(:stripity_stripe, :api_base_url, "https://api.stripe.com/v1/")
api_base_url <> endpoint
end

@doc """
Expand Down
8 changes: 8 additions & 0 deletions test/stripe/stripe_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ defmodule Stripe.StripeTest do
assert Stripe.process_url("payment") == "https://api.stripe.com/v1/payment"
end

test "process_url when base_url from config" do
:ok = Application.put_env(:stripity_stripe, :api_base_url, "http://localhost:4000/")

assert Stripe.process_url("plans") == "http://localhost:4000/plans"

:ok = Application.delete_env(:stripity_stripe, :api_base_url)
end

# test "make_request_with_key fails when no key is supplied on environment config" do
# with_mock System, [get_env: fn(_opts) -> nil end] do
# assert_raise Stripe.MissingSecretKeyError, fn ->
Expand Down

0 comments on commit 05ca35b

Please sign in to comment.