Sha256: 8bff73400e5ac681ce5b1cfc55a550e1ab7b3aef0e2615a3539a1d60f39ed27f

Contents?: true

Size: 910 Bytes

Versions: 19

Compression:

Stored size: 910 Bytes

Contents

module Stripe
  class APIResource < StripeObject
    def self.class_name
      self.name.split('::')[-1]
    end

    def self.url()
      if self == APIResource
        raise NotImplementedError.new('APIResource is an abstract class.  You should perform actions on its subclasses (Charge, Customer, etc.)')
      end
      "/v1/#{CGI.escape(class_name.downcase)}s"
    end

    def url
      unless id = self['id']
        raise InvalidRequestError.new("Could not determine which URL to request: #{self.class} instance has invalid ID: #{id.inspect}", 'id')
      end
      "#{self.class.url}/#{CGI.escape(id)}"
    end

    def refresh
      response, api_key = Stripe.request(:get, url, @api_key, @retrieve_options)
      refresh_from(response, api_key)
      self
    end

    def self.retrieve(id, api_key=nil)
      instance = self.new(id, api_key)
      instance.refresh
      instance
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
stripe-1.16.0 lib/stripe/api_resource.rb
stripe-1.15.0 lib/stripe/api_resource.rb
stripe-1.14.0 lib/stripe/api_resource.rb
stripe-1.13.0 lib/stripe/api_resource.rb
stripe-1.12.0 lib/stripe/api_resource.rb
stripe-1.11.0 lib/stripe/api_resource.rb
stripe-1.10.1 lib/stripe/api_resource.rb
stripe-1.10.0 lib/stripe/api_resource.rb
stripe-1.9.9 lib/stripe/api_resource.rb
stripe-1.8.8 lib/stripe/api_resource.rb
stripe-1.8.7 lib/stripe/api_resource.rb
stripe-1.8.6 lib/stripe/api_resource.rb
stripe-1.8.5 lib/stripe/api_resource.rb
stripe-1.8.4 lib/stripe/api_resource.rb
stripe-1.8.3 lib/stripe/api_resource.rb
stripe-1.8.2 lib/stripe/api_resource.rb
stripe-1.8.1 lib/stripe/api_resource.rb
stripe-1.7.11 lib/stripe/api_resource.rb
stripe-1.7.10 lib/stripe/api_resource.rb