mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-05-14 00:02:13 -04:00
44 lines
1.4 KiB
Ruby
44 lines
1.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Stripe
|
|
class SingletonAPIResource < APIResource
|
|
def self.resource_url
|
|
if self == SingletonAPIResource
|
|
raise NotImplementedError,
|
|
"SingletonAPIResource is an abstract class. You should " \
|
|
"perform actions on its subclasses (Balance, etc.)"
|
|
end
|
|
# Namespaces are separated in object names with periods (.) and in URLs
|
|
# with forward slashes (/), so replace the former with the latter.
|
|
"/v1/#{object_name.downcase.tr('.', '/')}"
|
|
end
|
|
|
|
def resource_url
|
|
self.class.resource_url
|
|
end
|
|
|
|
def self.retrieve(params_or_opts = {}, definitely_opts = nil)
|
|
opts = nil
|
|
params = nil
|
|
if definitely_opts.nil?
|
|
unrecognized_key = params_or_opts.keys.find { |k| !RequestOptions::OPTS_USER_SPECIFIED.include?(k) }
|
|
if unrecognized_key
|
|
raise ArgumentError,
|
|
"Unrecognized request option: #{unrecognized_key}. Did you mean to specify this as retrieve params? " \
|
|
"If so, you must explicitly pass an opts hash as a second argument. " \
|
|
"For example: .retrieve({#{unrecognized_key}: 'foo'}, {})"
|
|
end
|
|
|
|
opts = params_or_opts
|
|
else
|
|
opts = definitely_opts
|
|
params = params_or_opts
|
|
end
|
|
|
|
instance = new(params, Util.normalize_opts(opts))
|
|
instance.refresh
|
|
instance
|
|
end
|
|
end
|
|
end
|