Skip to content

Commit

Permalink
Add formatter (#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
snewcomer authored Feb 6, 2019
1 parent 0c94360 commit 4d2f943
Show file tree
Hide file tree
Showing 48 changed files with 619 additions and 489 deletions.
27 changes: 27 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export_locals_without_parens = [
plug: 1,
plug: 2,
forward: 2,
forward: 3,
forward: 4,
match: 2,
match: 3,
get: 2,
get: 3,
post: 2,
post: 3,
put: 2,
put: 3,
patch: 2,
patch: 3,
delete: 2,
delete: 3,
options: 2,
options: 3
]

[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"],
locals_without_parens: export_locals_without_parens,
export: [locals_without_parens: export_locals_without_parens]
]
10 changes: 5 additions & 5 deletions lib/stripe.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ defmodule Stripe do

@type id :: String.t()
@type date_query :: %{
optional(:gt) => timestamp,
optional(:gte) => timestamp,
optional(:lt) => timestamp,
optional(:lte) => timestamp
}
optional(:gt) => timestamp,
optional(:gte) => timestamp,
optional(:lt) => timestamp,
optional(:lte) => timestamp
}
@type options :: Keyword.t()
@type timestamp :: pos_integer

Expand Down
7 changes: 5 additions & 2 deletions lib/stripe/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ defmodule Stripe.Config do
"""
@spec resolve(atom, any) :: any
def resolve(key, default \\ nil)

def resolve(key, default) when is_atom(key) do
Application.get_env(:stripity_stripe, key, default)
|> expand_value()
end

def resolve(key, _) do
raise(
ArgumentError,
Expand All @@ -22,12 +24,13 @@ defmodule Stripe.Config do
end

defp expand_value({module, function, args})
when is_atom(function) and is_list(args)
do
when is_atom(function) and is_list(args) do
apply(module, function, args)
end

defp expand_value(value) when is_function(value) do
value.()
end

defp expand_value(value), do: value
end
16 changes: 9 additions & 7 deletions lib/stripe/connect/application_fee.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ defmodule Stripe.ApplicationFee do
List all application fees
"""
@spec list(params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()}
when params: %{
optional(:charge) => Stripe.id(),
optional(:created) => Stripe.date_query(),
optional(:ending_before) => t | Stripe.id(),
optional(:limit) => 1..100,
optional(:starting_after) => t | Stripe.id()
} | %{}
when params:
%{
optional(:charge) => Stripe.id(),
optional(:created) => Stripe.date_query(),
optional(:ending_before) => t | Stripe.id(),
optional(:limit) => 1..100,
optional(:starting_after) => t | Stripe.id()
}
| %{}
def list(params \\ %{}, opts \\ []) do
new_request(opts)
|> prefix_expansions()
Expand Down
12 changes: 7 additions & 5 deletions lib/stripe/connect/country_spec.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ defmodule Stripe.CountrySpec do
List all country specs.
"""
@spec list(params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()}
when params: %{
optional(:ending_before) => t | Stripe.id(),
optional(:limit) => 1..100,
optional(:starting_after) => t | Stripe.id()
} | %{}
when params:
%{
optional(:ending_before) => t | Stripe.id(),
optional(:limit) => 1..100,
optional(:starting_after) => t | Stripe.id()
}
| %{}
def list(params \\ %{}, opts \\ []) do
new_request(opts)
|> put_endpoint(@plural_endpoint)
Expand Down
8 changes: 6 additions & 2 deletions lib/stripe/connect/external_account.ex
Original file line number Diff line number Diff line change
Expand Up @@ -93,26 +93,30 @@ defmodule Stripe.ExternalAccount do
Takes either `:bank_account` or `:card` to determine which object to list.
"""
@spec list(atom, params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()}
@spec list(atom, params, Stripe.options()) ::
{:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()}
when params: %{
:account => Stripe.id(),
optional(:ending_before) => t | Stripe.id(),
optional(:limit) => 1..100,
optional(:starting_after) => t | Stripe.id()
}
def list(atom, params, opts \\ [])

def list(:bank_account, %{account: _} = params, opts) do
endpoint = params |> accounts_plural_endpoint()
params = params |> Map.put(:object, "bank_account")
do_list(endpoint, params, opts)
end

def list(:card, %{account: _} = params, opts) do
endpoint = params |> accounts_plural_endpoint()
params = params |> Map.put(:object, "card")
do_list(endpoint, params, opts)
end

@spec do_list(String.t, map, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()}
@spec do_list(String.t(), map, Stripe.options()) ::
{:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()}
defp do_list(endpoint, params, opts) do
new_request(opts)
|> put_endpoint(endpoint)
Expand Down
11 changes: 7 additions & 4 deletions lib/stripe/connect/fee_refund.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ defmodule Stripe.FeeRefund do
@doc """
Retrieve a application fee refund.
"""
@spec retrieve(Stripe.id() | t, Stripe.id() | t, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()}
@spec retrieve(Stripe.id() | t, Stripe.id() | t, Stripe.options()) ::
{:ok, t} | {:error, Stripe.Error.t()}
def retrieve(id, fee_id, opts \\ []) do
new_request(opts)
|> put_endpoint(@endpoint <> "/#{id}/refunds/#{fee_id}")
Expand All @@ -64,9 +65,10 @@ defmodule Stripe.FeeRefund do
Takes the `id` and a map of changes.
"""
@spec update(Stripe.id() | t, Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()}
@spec update(Stripe.id() | t, Stripe.id() | t, params, Stripe.options()) ::
{:ok, t} | {:error, Stripe.Error.t()}
when params: %{
optional(:metadata) => Stripe.Types.metadata(),
optional(:metadata) => Stripe.Types.metadata()
}
def update(id, fee_id, params, opts \\ []) do
new_request(opts)
Expand All @@ -79,7 +81,8 @@ defmodule Stripe.FeeRefund do
@doc """
List all transfers.
"""
@spec list(Stripe.id() | t, params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()}
@spec list(Stripe.id() | t, params, Stripe.options()) ::
{:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()}
when params: %{
optional(:ending_before) => t | Stripe.id(),
optional(:limit) => 1..100,
Expand Down
50 changes: 25 additions & 25 deletions lib/stripe/connect/recipient.ex
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ defmodule Stripe.Recipient do
"""
@spec create(params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()}
when params: %{
:name => String.t(),
:type => String.t(),
optional(:bank_account) => Stripe.id() | Stripe.BankAccount.t(),
optional(:recipient) => Stripe.id() | Stripe.Card.t(),
optional(:description) => String.t(),
optional(:email) => String.t(),
optional(:metadata) => Stripe.Types.metadata(),
optional(:tax_id) => String.t()
}
:name => String.t(),
:type => String.t(),
optional(:bank_account) => Stripe.id() | Stripe.BankAccount.t(),
optional(:recipient) => Stripe.id() | Stripe.Card.t(),
optional(:description) => String.t(),
optional(:email) => String.t(),
optional(:metadata) => Stripe.Types.metadata(),
optional(:tax_id) => String.t()
}
def create(%{name: _, type: _} = params, opts \\ []) do
new_request(opts)
|> put_endpoint(@plural_endpoint)
Expand All @@ -102,15 +102,15 @@ defmodule Stripe.Recipient do
"""
@spec update(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()}
when params: %{
optional(:bank_account) => Stripe.id() | Stripe.BankAccount.t(),
optional(:card) => Stripe.id() | Stripe.Card.t(),
optional(:default_card) => Stripe.id() | Stripe.Card.t(),
optional(:description) => String.t(),
optional(:email) => String.t(),
optional(:metadata) => Stripe.Types.metadata(),
optional(:name) => String.t(),
optional(:tax_id) => String.t()
}
optional(:bank_account) => Stripe.id() | Stripe.BankAccount.t(),
optional(:card) => Stripe.id() | Stripe.Card.t(),
optional(:default_card) => Stripe.id() | Stripe.Card.t(),
optional(:description) => String.t(),
optional(:email) => String.t(),
optional(:metadata) => Stripe.Types.metadata(),
optional(:name) => String.t(),
optional(:tax_id) => String.t()
}
def update(id, params \\ %{}, opts \\ []) do
new_request(opts)
|> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}")
Expand All @@ -135,13 +135,13 @@ defmodule Stripe.Recipient do
"""
@spec list(params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()}
when params: %{
optional(:created) => Stripe.timestamp(),
optional(:ending_before) => t | Stripe.id(),
optional(:limit) => 1..100,
optional(:starting_after) => t | Stripe.id(),
optional(:type) => String.t(),
optional(:verified) => boolean
}
optional(:created) => Stripe.timestamp(),
optional(:ending_before) => t | Stripe.id(),
optional(:limit) => 1..100,
optional(:starting_after) => t | Stripe.id(),
optional(:type) => String.t(),
optional(:verified) => boolean
}
def list(params \\ %{}, opts \\ []) do
new_request(opts)
|> prefix_expansions()
Expand Down
9 changes: 6 additions & 3 deletions lib/stripe/connect/transfer_reversal.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ defmodule Stripe.TransferReversal do
@doc """
Retrieve a transfer reversal.
"""
@spec retrieve(Stripe.id() | t, Stripe.id() | t, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()}
@spec retrieve(Stripe.id() | t, Stripe.id() | t, Stripe.options()) ::
{:ok, t} | {:error, Stripe.Error.t()}
def retrieve(id, reversal_id, opts \\ []) do
new_request(opts)
|> put_endpoint(@endpoint <> "/#{id}/reversals/#{reversal_id}")
Expand All @@ -68,7 +69,8 @@ defmodule Stripe.TransferReversal do
Takes the `id` and a map of changes.
"""
@spec update(Stripe.id() | t, Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()}
@spec update(Stripe.id() | t, Stripe.id() | t, params, Stripe.options()) ::
{:ok, t} | {:error, Stripe.Error.t()}
when params: %{
optional(:metadata) => Stripe.Types.metadata()
}
Expand All @@ -83,7 +85,8 @@ defmodule Stripe.TransferReversal do
@doc """
List all transfers.
"""
@spec list(Stripe.id() | t, params, Stripe.options()) :: {:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()}
@spec list(Stripe.id() | t, params, Stripe.options()) ::
{:ok, Stripe.List.t(t)} | {:error, Stripe.Error.t()}
when params: %{
optional(:ending_before) => t | Stripe.id(),
optional(:limit) => 1..100,
Expand Down
3 changes: 2 additions & 1 deletion lib/stripe/core_resources/balance.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ defmodule Stripe.Balance do
See the [Stripe docs](https://stripe.com/docs/api#balance_transaction_retrieve).
"""
@spec retrieve_transaction(String.t(), Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()}
@spec retrieve_transaction(String.t(), Stripe.options()) ::
{:ok, t} | {:error, Stripe.Error.t()}
def retrieve_transaction(id, opts \\ []) do
new_request(opts)
|> put_endpoint(@endpoint <> "/history/" <> id)
Expand Down
60 changes: 32 additions & 28 deletions lib/stripe/core_resources/charge.ex
Original file line number Diff line number Diff line change
Expand Up @@ -142,25 +142,27 @@ defmodule Stripe.Charge do
See the [Stripe docs](https://stripe.com/docs/api#create_charge).
"""
@spec create(params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()}
when params: %{
:amount => pos_integer,
:currency => String.t(),
optional(:application_fee) => non_neg_integer,
optional(:capture) => boolean,
optional(:description) => String.t(),
optional(:destination) => %{
:account => Stripe.id() | Stripe.Account.t(),
optional(:amount) => non_neg_integer
},
optional(:transfer_group) => String.t(),
optional(:on_behalf_of) => Stripe.id() | Stripe.Account.t(),
optional(:metadata) => map,
optional(:receipt_email) => String.t(),
optional(:shipping) => Stripe.Types.shipping(),
optional(:customer) => Stripe.id() | Stripe.Customer.t(),
optional(:source) => Stripe.id() | Stripe.Card.t() | card_info,
optional(:statement_descriptor) => String.t()
} | %{}
when params:
%{
:amount => pos_integer,
:currency => String.t(),
optional(:application_fee) => non_neg_integer,
optional(:capture) => boolean,
optional(:description) => String.t(),
optional(:destination) => %{
:account => Stripe.id() | Stripe.Account.t(),
optional(:amount) => non_neg_integer
},
optional(:transfer_group) => String.t(),
optional(:on_behalf_of) => Stripe.id() | Stripe.Account.t(),
optional(:metadata) => map,
optional(:receipt_email) => String.t(),
optional(:shipping) => Stripe.Types.shipping(),
optional(:customer) => Stripe.id() | Stripe.Customer.t(),
optional(:source) => Stripe.id() | Stripe.Card.t() | card_info,
optional(:statement_descriptor) => String.t()
}
| %{}
def create(params, opts \\ []) do
new_request(opts)
|> put_endpoint(@plural_endpoint)
Expand Down Expand Up @@ -203,15 +205,17 @@ defmodule Stripe.Charge do
See the [Stripe docs](https://stripe.com/docs/api#update_charge).
"""
@spec update(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()}
when params: %{
optional(:customer) => Stripe.id() | Stripe.Customer.t(),
optional(:description) => String.t(),
optional(:fraud_details) => user_fraud_report,
optional(:metadata) => Stripe.Types.metadata(),
optional(:receipt_email) => String.t(),
optional(:shipping) => Stripe.Types.shipping(),
optional(:transfer_group) => String.t()
} | %{}
when params:
%{
optional(:customer) => Stripe.id() | Stripe.Customer.t(),
optional(:description) => String.t(),
optional(:fraud_details) => user_fraud_report,
optional(:metadata) => Stripe.Types.metadata(),
optional(:receipt_email) => String.t(),
optional(:shipping) => Stripe.Types.shipping(),
optional(:transfer_group) => String.t()
}
| %{}
def update(id, params, opts \\ []) do
new_request(opts)
|> put_endpoint(@plural_endpoint <> "/#{get_id!(id)}")
Expand Down
Loading

0 comments on commit 4d2f943

Please sign in to comment.