Skip to content

Commit

Permalink
More reordering and hopefully-safe formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rattrayalex-stripe committed May 29, 2019
1 parent 91cfc0f commit 0d465ce
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 34 deletions.
25 changes: 13 additions & 12 deletions lib/stripe/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,32 @@ module Stripe
class Account < APIResource
extend Gem::Deprecate
extend Stripe::APIOperations::Create
extend Stripe::APIOperations::List
include Stripe::APIOperations::Delete
extend Stripe::APIOperations::List
include Stripe::APIOperations::Save
extend Stripe::APIOperations::NestedResource

OBJECT_NAME = "account".freeze

custom_method :reject, http_verb: :post

save_nested_resource :external_account
nested_resource_class_methods :capability,
operations: %i[retrieve update list],
resource_plural: "capabilities"
nested_resource_class_methods :person,
operations: %i[create retrieve update delete list]

def reject(params = {}, opts = {})
resp, opts = request(:post, resource_url + "/reject", params, opts)
initialize_from(resp.data, opts)
end

save_nested_resource :external_account

nested_resource_class_methods :external_account,
operations: %i[create retrieve update delete
list]
operations: %i[create retrieve update delete list]

nested_resource_class_methods :login_link, operations: %i[create]
nested_resource_class_methods :person,
operations: %i[create retrieve update delete
list]

# This method is deprecated. Please use `#external_account=` instead.
save_nested_resource :bank_account
Expand Down Expand Up @@ -66,11 +72,6 @@ def persons(params = {}, opts = {})
# already has a capabilities property which is a hash and not the sub-list
# of capabilities.

def reject(params = {}, opts = {})
resp, opts = request(:post, resource_url + "/reject", params, opts)
initialize_from(resp.data, opts)
end

# Somewhat unfortunately, we attempt to do a special encoding trick when
# serializing `additional_owners` under an account: when updating a value,
# we actually send the update parameters up as an integer-indexed hash
Expand Down
6 changes: 2 additions & 4 deletions lib/stripe/bank_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ def verify(params = {}, opts = {})

def resource_url
if respond_to?(:customer)
"#{Customer.resource_url}/#{CGI.escape(customer)}/sources" \
"/#{CGI.escape(id)}"
"#{Customer.resource_url}/#{CGI.escape(customer)}/sources/#{CGI.escape(id)}"
elsif respond_to?(:account)
"#{Account.resource_url}/#{CGI.escape(account)}/external_accounts" \
"/#{CGI.escape(id)}"
"#{Account.resource_url}/#{CGI.escape(account)}/external_accounts/#{CGI.escape(id)}"
end
end

Expand Down
10 changes: 5 additions & 5 deletions lib/stripe/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ module Stripe
class Customer < APIResource
extend Stripe::APIOperations::Create
include Stripe::APIOperations::Delete
include Stripe::APIOperations::Save
extend Stripe::APIOperations::List
include Stripe::APIOperations::Save
extend Stripe::APIOperations::NestedResource

OBJECT_NAME = "customer".freeze

nested_resource_class_methods :tax_id,
operations: %i[create retrieve delete list]

custom_method :delete_discount, http_verb: :delete, http_path: "discount"

save_nested_resource :source
nested_resource_class_methods :source,
operations: %i[create retrieve update delete
list]
nested_resource_class_methods :tax_id,
operations: %i[create retrieve delete list]
operations: %i[create retrieve update delete list]

# The API request for deleting a card or bank account and for detaching a
# source object are the same.
Expand Down
5 changes: 4 additions & 1 deletion lib/stripe/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ class File < APIResource
extend Stripe::APIOperations::Create
extend Stripe::APIOperations::List

OBJECT_NAME = "file".freeze

# This resource can have two different object names. In latter API
# versions, only `file` is used, but since stripe-ruby may be used with
# any API version, we need to support deserializing the older
# `file_upload` object into the same class.
OBJECT_NAME = "file".freeze
OBJECT_NAME_ALT = "file_upload".freeze

def self.resource_url
Expand All @@ -35,7 +36,9 @@ def self.create(params = {}, opts = {})
super
end
end
end

module Stripe
# For backwards compatibility, the `File` class is aliased to `FileUpload`.
FileUpload = File
end
10 changes: 5 additions & 5 deletions lib/stripe/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ class Source < APIResource

custom_method :verify, http_verb: :post

def verify(params = {}, opts = {})
resp, opts = request(:post, resource_url + "/verify", params, opts)
initialize_from(resp.data, opts)
end

def detach(params = {}, opts = {})
if !respond_to?(:customer) || customer.nil? || customer.empty?
raise NotImplementedError,
Expand All @@ -33,10 +38,5 @@ def source_transactions(params = {}, opts = {})
opts)
Util.convert_to_stripe_object(resp.data, opts)
end

def verify(params = {}, opts = {})
resp, opts = request(:post, resource_url + "/verify", params, opts)
initialize_from(resp.data, opts)
end
end
end
4 changes: 2 additions & 2 deletions lib/stripe/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

module Stripe
class Subscription < APIResource
extend Stripe::APIOperations::List
extend Stripe::APIOperations::Create
include Stripe::APIOperations::Save
include Stripe::APIOperations::Delete
extend Stripe::APIOperations::List
include Stripe::APIOperations::Save

OBJECT_NAME = "subscription".freeze

Expand Down
3 changes: 1 addition & 2 deletions lib/stripe/subscription_schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ class SubscriptionSchedule < APIResource
custom_method :cancel, http_verb: :post
custom_method :release, http_verb: :post

nested_resource_class_methods :revision,
operations: %i[retrieve list]
nested_resource_class_methods :revision, operations: %i[retrieve list]

def cancel(params = {}, opts = {})
resp, opts = request(:post, resource_url + "/cancel", params, opts)
Expand Down
6 changes: 3 additions & 3 deletions lib/stripe/transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class Transfer < APIResource
nested_resource_class_methods :reversal,
operations: %i[create retrieve update list]

def cancel
resp, api_key = request(:post, cancel_url)
initialize_from(resp.data, api_key)
def cancel(params = {}, opts = {})
resp, opts = request(:post, resource_url + "/cancel", params, opts)
initialize_from(resp.data, opts)
end

def cancel_url
Expand Down

0 comments on commit 0d465ce

Please sign in to comment.