Sha256: 44f6aadc282a106b02666e1f462d33ac8e6029edbfca0c1d57a40f7671aabceb

Contents?: true

Size: 949 Bytes

Versions: 14

Compression:

Stored size: 949 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={})
      opts = Util.normalize_opts(opts)
      instance = self.new(id, opts)
      instance.refresh
      instance
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
stripe-1.29.1 lib/stripe/api_resource.rb
stripe-1.29.0 lib/stripe/api_resource.rb
stripe-1.28.1 lib/stripe/api_resource.rb
stripe-1.28.0 lib/stripe/api_resource.rb
stripe-1.27.2 lib/stripe/api_resource.rb
stripe-1.27.1 lib/stripe/api_resource.rb
stripe-1.27.0 lib/stripe/api_resource.rb
stripe-1.26.0 lib/stripe/api_resource.rb
stripe-1.25.0 lib/stripe/api_resource.rb
stripe-1.24.0 lib/stripe/api_resource.rb
stripe-1.23.0 lib/stripe/api_resource.rb
stripe-1.22.0 lib/stripe/api_resource.rb
stripe-1.21.0 lib/stripe/api_resource.rb
stripe-1.20.4 lib/stripe/api_resource.rb