Skip to content

Commit

Permalink
Add method parameter type classes to all resources and services (#1505)
Browse files Browse the repository at this point in the history
* barebones request params

* fixes

* manual changes

* Generated changes

* Add search params

* manual change - update to cast params

* add more test

* add newliens (generated)
  • Loading branch information
helenye-stripe authored Dec 20, 2024
1 parent beda56c commit bc1d5a8
Show file tree
Hide file tree
Showing 723 changed files with 352,358 additions and 4,897 deletions.
23 changes: 21 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ Layout/LineLength:
- "lib/stripe/services/**/*.rb"
- "test/**/*.rb"


Lint/MissingSuper:
Exclude:
- "lib/stripe/resources/**/*.rb"
- "lib/stripe/services/**/*.rb"
- "test/stripe/request_params_test.rb"

Metrics/AbcSize:
Enabled: false

Expand Down Expand Up @@ -53,22 +60,34 @@ Metrics/MethodLength:
Max: 55
Exclude:
- "lib/stripe/services/v1_services.rb"
AllowedMethods:
- initialize

Metrics/ModuleLength:
Enabled: false

Metrics/ParameterLists:
# There's 2 methods in `StripeClient` that have long parameter lists.
Max: 8
# Optional parameters should be consistent across libraries, we need not be
# concerned about this. Was introduced with adding `base_address`
Exclude:
- "lib/stripe/api_operations/request.rb"
- "lib/stripe/stripe_object.rb"
- "lib/stripe/stripe_client.rb"
- "lib/stripe/resources/**/*.rb"
- "lib/stripe/services/**/*.rb"

Naming/MethodParameterName:
# We have many parameters that are less than 3 characters for tax codes
Exclude:
- "lib/stripe/resources/**/*.rb"
- "lib/stripe/services/**/*.rb"

Naming/VariableNumber:
# We use a variety of variable number syntaxes
Enabled: false
Exclude:
- "lib/stripe/resources/**/*.rb"
- "lib/stripe/services/**/*.rb"

Style/AccessModifierDeclarations:
EnforcedStyle: inline
Expand Down
1 change: 1 addition & 0 deletions lib/stripe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
require "stripe/object_types"
require "stripe/event_types"
require "stripe/request_options"
require "stripe/request_params"
require "stripe/util"
require "stripe/connection_manager"
require "stripe/multipart_encoder"
Expand Down
1 change: 1 addition & 0 deletions lib/stripe/api_operations/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def execute_resource_request_stream(method, url, base_address = :api,
method, url, base_address,
params, opts, usage,
&read_body_chunk_block)
params = params.to_h if params.is_a?(Stripe::RequestParams)
params ||= {}

error_on_invalid_params(params)
Expand Down
1 change: 1 addition & 0 deletions lib/stripe/api_requestor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ def request

def execute_request(method, path, base_address,
params: {}, opts: {}, usage: [])
params = params.to_h if params.is_a?(RequestParams)
http_resp, req_opts = execute_request_internal(
method, path, base_address, params, opts, usage
)
Expand Down
24 changes: 24 additions & 0 deletions lib/stripe/request_params.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true
# typed: true

module Stripe
# For internal use only. Does not provide a stable API and may be broken
# with future non-major changes.
class RequestParams
def to_h
instance_variables.each_with_object({}) do |var, hash|
key = var.to_s.delete("@").to_sym
value = instance_variable_get(var)

hash[key] = if value.is_a?(RequestParams)
value.to_h
# Check if value is an array and contains RequestParams objects
elsif value.is_a?(Array)
value.map { |item| item.is_a?(RequestParams) ? item.to_h : item }
else
value
end
end
end
end
end
5,739 changes: 5,651 additions & 88 deletions lib/stripe/resources/account.rb

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions lib/stripe/resources/account_link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,67 @@ def self.object_name
"account_link"
end

class CreateParams < Stripe::RequestParams
class CollectionOptions < Stripe::RequestParams
# Specifies whether the platform collects only currently_due requirements (`currently_due`) or both currently_due and eventually_due requirements (`eventually_due`). If you don't specify `collection_options`, the default value is `currently_due`.
attr_accessor :fields

# Specifies whether the platform collects future_requirements in addition to requirements in Connect Onboarding. The default value is `omit`.
attr_accessor :future_requirements

def initialize(fields: nil, future_requirements: nil)
@fields = fields
@future_requirements = future_requirements
end
end
# The identifier of the account to create an account link for.
attr_accessor :account

# The collect parameter is deprecated. Use `collection_options` instead.
attr_accessor :collect

# Specifies the requirements that Stripe collects from connected accounts in the Connect Onboarding flow.
attr_accessor :collection_options

# Specifies which fields in the response should be expanded.
attr_accessor :expand

# The URL the user will be redirected to if the account link is expired, has been previously-visited, or is otherwise invalid. The URL you specify should attempt to generate a new account link with the same parameters used to create the original account link, then redirect the user to the new account link's URL so they can continue with Connect Onboarding. If a new account link cannot be generated or the redirect fails you should display a useful error to the user.
attr_accessor :refresh_url

# The URL that the user will be redirected to upon leaving or completing the linked flow.
attr_accessor :return_url

# The type of account link the user is requesting. Possible values are `account_onboarding` or `account_update`.
attr_accessor :type

def initialize(
account: nil,
collect: nil,
collection_options: nil,
expand: nil,
refresh_url: nil,
return_url: nil,
type: nil
)
@account = account
@collect = collect
@collection_options = collection_options
@expand = expand
@refresh_url = refresh_url
@return_url = return_url
@type = type
end
end
# Time at which the object was created. Measured in seconds since the Unix epoch.
attr_reader :created

# The timestamp at which this account link will expire.
attr_reader :expires_at

# String representing the object's type. Objects of the same type share the same value.
attr_reader :object

# The URL for the account link.
attr_reader :url

Expand Down
102 changes: 98 additions & 4 deletions lib/stripe/resources/account_notice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,130 @@ def self.object_name
end

class Email < Stripe::StripeObject
attr_reader :plain_text, :recipient, :subject
# Content of the email in plain text. The copy must match exactly the language that Stripe Compliance has approved for use.
attr_reader :plain_text

# Email address of the recipient.
attr_reader :recipient

# Subject of the email.
attr_reader :subject
end

class LinkedObjects < Stripe::StripeObject
attr_reader :capability, :issuing_credit_underwriting_record, :issuing_dispute
# Associated [Capability](https://stripe.com/docs/api/capabilities)
attr_reader :capability

# Associated [Credit Underwriting Record](https://stripe.com/docs/api/issuing/credit_underwriting_record)
attr_reader :issuing_credit_underwriting_record

# Associated [Issuing Dispute](https://stripe.com/docs/api/issuing/disputes)
attr_reader :issuing_dispute
end

class ListParams < Stripe::RequestParams
# A cursor for use in pagination. `ending_before` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with `obj_bar`, your subsequent call can include `ending_before=obj_bar` in order to fetch the previous page of the list.
attr_accessor :ending_before

# Specifies which fields in the response should be expanded.
attr_accessor :expand

# A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
attr_accessor :limit

# Set to false to only return unsent AccountNotices.
attr_accessor :sent

# A cursor for use in pagination. `starting_after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with `obj_foo`, your subsequent call can include `starting_after=obj_foo` in order to fetch the next page of the list.
attr_accessor :starting_after

def initialize(ending_before: nil, expand: nil, limit: nil, sent: nil, starting_after: nil)
@ending_before = ending_before
@expand = expand
@limit = limit
@sent = sent
@starting_after = starting_after
end
end

class RetrieveParams < Stripe::RequestParams
# Specifies which fields in the response should be expanded.
attr_accessor :expand

def initialize(expand: nil)
@expand = expand
end
end

class UpdateParams < Stripe::RequestParams
class Email < Stripe::RequestParams
# Content of the email in plain text. The copy must match exactly the language that Stripe Compliance has approved for use.
attr_accessor :plain_text

# Email address of the recipient.
attr_accessor :recipient

# Subject of the email.
attr_accessor :subject

def initialize(plain_text: nil, recipient: nil, subject: nil)
@plain_text = plain_text
@recipient = recipient
@subject = subject
end
end
# Information about the email you sent.
attr_accessor :email

# Specifies which fields in the response should be expanded.
attr_accessor :expand

# Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`.
attr_accessor :metadata

# Date when you sent the notice.
attr_accessor :sent_at

def initialize(email: nil, expand: nil, metadata: nil, sent_at: nil)
@email = email
@expand = expand
@metadata = metadata
@sent_at = sent_at
end
end
# Time at which the object was created. Measured in seconds since the Unix epoch.
attr_reader :created

# When present, the deadline for sending the notice to meet the relevant regulations.
attr_reader :deadline

# Information about the email when sent.
attr_reader :email

# Unique identifier for the object.
attr_reader :id

# Information about objects related to the notice.
attr_reader :linked_objects

# Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
attr_reader :livemode

# Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
attr_reader :metadata

# String representing the object's type. Objects of the same type share the same value.
attr_reader :object

# Reason the notice is being sent. The reason determines what copy the notice must contain. See the [regulated customer notices](https://stripe.com/docs/issuing/compliance-us/issuing-regulated-customer-notices) guide. All reasons might not apply to your integration, and Stripe might add new reasons in the future, so we recommend an internal warning when you receive an unknown reason.
attr_reader :reason

# Date when the notice was sent. When absent, you must send the notice, update the content of the email and date when it was sent.
attr_reader :sent_at

# Retrieves a list of AccountNotice objects. The objects are sorted in descending order by creation date, with the most-recently-created object appearing first.
def self.list(filters = {}, opts = {})
request_stripe_object(method: :get, path: "/v1/account_notices", params: filters, opts: opts)
def self.list(params = {}, opts = {})
request_stripe_object(method: :get, path: "/v1/account_notices", params: params, opts: opts)
end

# Updates an AccountNotice object.
Expand Down
Loading

0 comments on commit bc1d5a8

Please sign in to comment.