Sha256: 41030b7006c54e311f5f7da1249d068dcbdc73767922437d2ee78c740919fb51

Contents?: true

Size: 950 Bytes

Versions: 5

Compression:

Stored size: 950 Bytes

Contents

module Stripe
  class APIResource < StripeObject
    include Stripe::APIOperations::Request

    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, opts = request(:get, url, @retrieve_params)
      refresh_from(response, opts)
    end

    def self.retrieve(id, opts=nil)
      opts = Util.normalize_opts(opts)
      instance = self.new(id, opts)
      instance.refresh
      instance
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
stripe-1.20.3 lib/stripe/api_resource.rb
stripe-1.20.2 lib/stripe/api_resource.rb
stripe-1.20.1 lib/stripe/api_resource.rb
stripe-1.20.0 lib/stripe/api_resource.rb
stripe-1.19.0 lib/stripe/api_resource.rb