lib/stripe/util.rb in stripe-10.15.0.pre.beta.1 vs lib/stripe/util.rb in stripe-10.15.0

- old
+ new

@@ -5,11 +5,10 @@ module Stripe module Util # Options that a user is allowed to specify. OPTS_USER_SPECIFIED = Set[ :api_key, - :authenticator, :idempotency_key, :stripe_account, :stripe_version ].freeze @@ -89,11 +88,11 @@ url, params, opts ) - Util.convert_to_stripe_object_with_params(resp.data, params, opts) + Util.convert_to_stripe_object_with_params(resp.data, params, opts, resp) end end # Converts a hash of fields or an array of hashes into a +StripeObject+ or # array of +StripeObject+s. These new objects will be created as a concrete @@ -123,22 +122,22 @@ # ==== Attributes # # * +data+ - Hash of fields and values to be converted into a StripeObject. # * +opts+ - Options for +StripeObject+ like an API key that will be reused # on subsequent API calls. - def self.convert_to_stripe_object_with_params(data, params, opts = {}) + def self.convert_to_stripe_object_with_params(data, params, opts = {}, last_response = nil) opts = normalize_opts(opts) case data when Array data.map { |i| convert_to_stripe_object(i, opts) } when Hash # Try converting to a known object class. If none available, fall back # to generic StripeObject object_name = data[:object] || data["object"] obj = object_classes.fetch(object_name, StripeObject) - .construct_from(data, opts) + .construct_from(data, opts, last_response) # set filters so that we can fetch the same limit, expansions, and # predicates when accessing the next and previous pages obj.filters = params.dup if obj && (obj.is_a?(SearchResultObject) || obj.is_a?(ListObject)) @@ -278,16 +277,10 @@ def self.normalize_opts(opts) case opts when String { api_key: opts } when Hash - # If the user is using request signing for authentication, - # no need to check the api_key per request. - if !(opts.key?(:client) && - opts.fetch(:client).config.authenticator) && - opts.key?(:api_key) - check_api_key!(opts.fetch(:api_key)) - end + check_api_key!(opts.fetch(:api_key)) if opts.key?(:api_key) # Explicitly use dup here instead of clone to avoid preserving freeze # state on input params. opts.dup else raise TypeError, "normalize_opts expects a string or a hash"