Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatting changes from codegen #790

Merged
merged 10 commits into from
May 30, 2019
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Layout/IndentHash:
Metrics/LineLength:
Exclude:
- "test/**/*.rb"
- "lib/stripe/**/*.rb"
ob-stripe marked this conversation as resolved.
Show resolved Hide resolved

Metrics/MethodLength:
# There's ~2 long methods in `StripeClient`. If we want to truncate those a
Expand Down
77 changes: 2 additions & 75 deletions lib/stripe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

# API resource support classes
require "stripe/errors"
require "stripe/object_types"
require "stripe/util"
require "stripe/stripe_client"
require "stripe/stripe_object"
Expand All @@ -36,81 +37,7 @@
require "stripe/webhook"

# Named API resources
require "stripe/account"
require "stripe/account_link"
require "stripe/alipay_account"
require "stripe/apple_pay_domain"
require "stripe/application_fee"
require "stripe/application_fee_refund"
require "stripe/balance"
require "stripe/balance_transaction"
require "stripe/bank_account"
require "stripe/bitcoin_receiver"
require "stripe/bitcoin_transaction"
require "stripe/capability"
require "stripe/card"
require "stripe/charge"
require "stripe/checkout/session"
require "stripe/country_spec"
require "stripe/coupon"
require "stripe/credit_note"
require "stripe/customer"
require "stripe/discount"
require "stripe/dispute"
require "stripe/ephemeral_key"
require "stripe/event"
require "stripe/exchange_rate"
require "stripe/file"
require "stripe/file_link"
require "stripe/invoice"
require "stripe/invoice_item"
require "stripe/invoice_line_item"
require "stripe/issuer_fraud_record"
require "stripe/issuing/authorization"
require "stripe/issuing/card"
require "stripe/issuing/card_details"
require "stripe/issuing/cardholder"
require "stripe/issuing/dispute"
require "stripe/issuing/transaction"
require "stripe/login_link"
require "stripe/order"
require "stripe/order_return"
require "stripe/payment_intent"
require "stripe/payment_method"
require "stripe/payout"
require "stripe/person"
require "stripe/plan"
require "stripe/product"
require "stripe/radar/early_fraud_warning"
require "stripe/radar/value_list"
require "stripe/radar/value_list_item"
require "stripe/recipient"
require "stripe/recipient_transfer"
require "stripe/refund"
require "stripe/reporting/report_run"
require "stripe/reporting/report_type"
require "stripe/reversal"
require "stripe/review"
require "stripe/sigma/scheduled_query_run"
require "stripe/sku"
require "stripe/source"
require "stripe/source_transaction"
require "stripe/subscription"
require "stripe/subscription_item"
require "stripe/subscription_schedule"
require "stripe/subscription_schedule_revision"
require "stripe/tax_id"
require "stripe/tax_rate"
require "stripe/terminal/connection_token"
require "stripe/terminal/location"
require "stripe/terminal/reader"
require "stripe/three_d_secure"
require "stripe/token"
require "stripe/topup"
require "stripe/transfer"
require "stripe/usage_record"
require "stripe/usage_record_summary"
require "stripe/webhook_endpoint"
require "stripe/resources"

# OAuth
require "stripe/oauth"
Expand Down
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)
Util.convert_to_stripe_object(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
2 changes: 1 addition & 1 deletion lib/stripe/apple_pay_domain.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# Domains registered for Apple Pay on the Web
ob-stripe marked this conversation as resolved.
Show resolved Hide resolved
module Stripe
# Domains registered for Apple Pay on the Web
class ApplePayDomain < APIResource
extend Stripe::APIOperations::Create
include Stripe::APIOperations::Delete
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
7 changes: 3 additions & 4 deletions lib/stripe/bitcoin_receiver.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

# Directly creating or retrieving BitcoinReceivers is deprecated. Please use
# the Sources API instead: https://stripe.com/docs/sources/bitcoin
ob-stripe marked this conversation as resolved.
Show resolved Hide resolved
module Stripe
class BitcoinReceiver < APIResource
# Directly creating or retrieving BitcoinReceivers is deprecated. Please use
# the Sources API instead: https://stripe.com/docs/sources/bitcoin
extend Stripe::APIOperations::List

OBJECT_NAME = "bitcoin_receiver".freeze
Expand All @@ -14,8 +14,7 @@ def self.resource_url

def resource_url
if respond_to?(:customer) && !customer.nil? && customer != ""
"#{Customer.resource_url}/#{CGI.escape(customer)}/sources" \
"/#{CGI.escape(id)}"
"#{Customer.resource_url}/#{CGI.escape(customer)}/sources/#{CGI.escape(id)}"
else
"#{self.class.resource_url}/#{CGI.escape(id)}"
end
Expand Down
9 changes: 3 additions & 6 deletions lib/stripe/card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@ class Card < APIResource

def resource_url
if respond_to?(:recipient) && !recipient.nil? && !recipient.empty?
"#{Recipient.resource_url}/#{CGI.escape(recipient)}/cards" \
"/#{CGI.escape(id)}"
"#{Recipient.resource_url}/#{CGI.escape(recipient)}/cards/#{CGI.escape(id)}"
elsif respond_to?(:customer) && !customer.nil? && !customer.empty?
"#{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.nil? && !account.empty?
"#{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
2 changes: 1 addition & 1 deletion lib/stripe/credit_note.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CreditNote < APIResource

def void_credit_note(params = {}, opts = {})
resp, opts = request(:post, resource_url + "/void", params, opts)
initialize_from(resp.data, opts)
Util.convert_to_stripe_object(resp.data, opts)
end
end
end
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
2 changes: 1 addition & 1 deletion lib/stripe/dispute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Dispute < APIResource

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

def close_url
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
13 changes: 6 additions & 7 deletions lib/stripe/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,27 @@ class Invoice < APIResource

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

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

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

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

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

def self.upcoming(params, opts = {})
Expand Down
4 changes: 2 additions & 2 deletions lib/stripe/issuing/authorization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ class Authorization < APIResource

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

def decline(params = {}, opts = {})
resp, opts = request(:post, resource_url + "/decline", params, opts)
initialize_from(resp.data, opts)
Util.convert_to_stripe_object(resp.data, opts)
end
end
end
Expand Down
Loading