Skip to content

Commit

Permalink
Merge pull request #242 from jayjun/2.0-lists
Browse files Browse the repository at this point in the history
Add listing resources (#203)
  • Loading branch information
begedin authored Jul 4, 2017
2 parents 981ff45 + 292593d commit b3d7f22
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 3 deletions.
9 changes: 9 additions & 0 deletions lib/stripe/account.ex
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,13 @@ defmodule Stripe.Account do
endpoint = @plural_endpoint <> "/" <> id
Stripe.Request.update(endpoint, changes, @schema, @nullable_keys, opts)
end

@doc """
List all connected accounts.
"""
@spec list(map, Keyword.t) :: {:ok, Stripe.List.t} | {:error, Stripe.api_error_struct}
def list(params \\ %{}, opts \\ []) do
endpoint = @plural_endpoint
Stripe.Request.retrieve(params, endpoint, opts)
end
end
13 changes: 12 additions & 1 deletion lib/stripe/card.ex
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ defmodule Stripe.Card do
defp endpoint_for_owner(owner_type, owner_id) do
case owner_type do
:customer -> "customers/#{owner_id}/sources"
:recipient -> "recipients/#{owner_id}/cards"
:account -> "accounts/#{owner_id}/external_accounts"
:recipient -> "recipients/#{owner_id}/cards" # Deprecated
end
end

Expand Down Expand Up @@ -138,4 +139,14 @@ defmodule Stripe.Card do
endpoint = endpoint_for_owner(owner_type, owner_id) <> "/" <> card_id
Stripe.Request.delete(endpoint, %{}, opts)
end

@doc """
List all cards.
"""
@spec list(source, String.t, map, Keyword.t) :: {:ok, Stripe.List.t} | {:error, Stripe.api_error_struct}
def list(owner_type, owner_id, params \\ %{}, opts \\ []) do
endpoint = endpoint_for_owner(owner_type, owner_id)
params = Map.merge(params, %{"object" => "card"})
Stripe.Request.retrieve(params, endpoint, opts)
end
end
9 changes: 9 additions & 0 deletions lib/stripe/charge.ex
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,13 @@ defmodule Stripe.Charge do
endpoint = @plural_endpoint <> "/" <> id
Stripe.Request.retrieve(endpoint, opts)
end

@doc """
List all charges.
"""
@spec list(map, Keyword.t) :: {:ok, Stripe.List.t} | {:error, Stripe.api_error_struct}
def list(params \\ %{}, opts \\ []) do
endpoint = @plural_endpoint
Stripe.Request.retrieve(params, endpoint, opts)
end
end
11 changes: 10 additions & 1 deletion lib/stripe/coupon.ex
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,13 @@ defmodule Stripe.Coupon do
endpoint = @plural_endpoint <> "/" <> id
Stripe.Request.delete(endpoint, %{}, opts)
end
end

@doc """
List all coupons.
"""
@spec list(map, Keyword.t) :: {:ok, Stripe.List.t} | {:error, Stripe.api_error_struct}
def list(params \\ %{}, opts \\ []) do
endpoint = @plural_endpoint
Stripe.Request.retrieve(params, endpoint, opts)
end
end
9 changes: 9 additions & 0 deletions lib/stripe/customer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,13 @@ defmodule Stripe.Customer do
endpoint = @plural_endpoint <> "/" <> id
Stripe.Request.delete(endpoint, %{}, opts)
end

@doc """
List all customers.
"""
@spec list(map, Keyword.t) :: {:ok, Stripe.List.t} | {:error, Stripe.api_error_struct}
def list(params \\ %{}, opts \\ []) do
endpoint = @plural_endpoint
Stripe.Request.retrieve(params, endpoint, opts)
end
end
9 changes: 9 additions & 0 deletions lib/stripe/event.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,13 @@ defmodule Stripe.Event do
endpoint = @plural_endpoint <> "/" <> id
Stripe.Request.retrieve(endpoint, opts)
end

@doc """
List all events.
"""
@spec list(map, Keyword.t) :: {:ok, Stripe.List.t} | {:error, Stripe.api_error_struct}
def list(params \\ %{}, opts \\ []) do
endpoint = @plural_endpoint
Stripe.Request.retrieve(params, endpoint, opts)
end
end
10 changes: 10 additions & 0 deletions lib/stripe/external_account.ex
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,14 @@ defmodule Stripe.ExternalAccount do
endpoint = endpoint(managed_account_id) <> "/" <> id
Stripe.Request.delete(endpoint, %{}, opts)
end

@doc """
List all external accounts.
"""
@spec list(map, Keyword.t) :: {:ok, Stripe.List.t} | {:error, Stripe.api_error_struct}
def list(params \\ %{}, opts = [connect_account: managed_account_id]) do
endpoint = endpoint(managed_account_id)
params = Map.merge(params, %{"object" => "bank_account"})
Stripe.Request.retrieve(params, endpoint, opts)
end
end
8 changes: 8 additions & 0 deletions lib/stripe/file_upload.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,12 @@ defmodule Stripe.FileUpload do
Stripe.Request.retrieve_file_upload(endpoint, opts)
end

@doc """
List all file uploads.
"""
@spec list(map, Keyword.t) :: {:ok, Stripe.List.t} | {:error, Stripe.api_error_struct}
def list(params \\ %{}, opts \\ []) do
endpoint = @plural_endpoint
Stripe.Request.retrieve(params, endpoint, opts)
end
end
9 changes: 9 additions & 0 deletions lib/stripe/invoice.ex
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,13 @@ defmodule Stripe.Invoice do
endpoint = @plural_endpoint <> "/upcoming"
Stripe.Request.retrieve(changes, endpoint, opts)
end

@doc """
List all invoices.
"""
@spec list(map, Keyword.t) :: {:ok, Stripe.List.t} | {:error, Stripe.api_error_struct}
def list(params \\ %{}, opts \\ []) do
endpoint = @plural_endpoint
Stripe.Request.retrieve(params, endpoint, opts)
end
end
9 changes: 9 additions & 0 deletions lib/stripe/plan.ex
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,13 @@ defmodule Stripe.Plan do
endpoint = @plural_endpoint <> "/" <> id
Stripe.Request.delete(endpoint, %{}, opts)
end

@doc """
List all plans.
"""
@spec list(map, Keyword.t) :: {:ok, Stripe.List.t} | {:error, Stripe.api_error_struct}
def list(params \\ %{}, opts \\ []) do
endpoint = @plural_endpoint
Stripe.Request.retrieve(params, endpoint, opts)
end
end
10 changes: 9 additions & 1 deletion lib/stripe/refund.ex
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,13 @@ defmodule Stripe.Refund do
endpoint = @plural_endpoint <> "/" <> id
Stripe.Request.update(endpoint, changes, @schema, @nullable_keys, opts)
end
end

@doc """
List all refunds.
"""
@spec list(map, Keyword.t) :: {:ok, Stripe.List.t} | {:error, Stripe.api_error_struct}
def list(params \\ %{}, opts \\ []) do
endpoint = @plural_endpoint
Stripe.Request.retrieve(params, endpoint, opts)
end
end
9 changes: 9 additions & 0 deletions lib/stripe/subscription.ex
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,13 @@ defmodule Stripe.Subscription do
endpoint = @plural_endpoint <> "/" <> id
Stripe.Request.delete(endpoint, params, opts)
end

@doc """
List all subscriptions.
"""
@spec list(map, Keyword.t) :: {:ok, Stripe.List.t} | {:error, Stripe.api_error_struct}
def list(params \\ %{}, opts \\ []) do
endpoint = @plural_endpoint
Stripe.Request.retrieve(endpoint, opts)
end
end

0 comments on commit b3d7f22

Please sign in to comment.