Sha256: 8ac5832845fc28e9d941738a2981bb0b5e33b9fc6f93359df686e72f5193c256

Contents?: true

Size: 902 Bytes

Versions: 18

Compression:

Stored size: 902 Bytes

Contents

module Nurego
  class APIResource < NuregoObject
    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 (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 = Nurego.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

18 entries across 18 versions & 1 rubygems

Version Path
nurego-1.1.20 lib/nurego/api_resource.rb
nurego-1.1.19 lib/nurego/api_resource.rb
nurego-1.1.18 lib/nurego/api_resource.rb
nurego-1.1.17 lib/nurego/api_resource.rb
nurego-1.1.16 lib/nurego/api_resource.rb
nurego-1.1.15 lib/nurego/api_resource.rb
nurego-1.1.14 lib/nurego/api_resource.rb
nurego-1.1.13 lib/nurego/api_resource.rb
nurego-1.1.12 lib/nurego/api_resource.rb
nurego-1.1.11 lib/nurego/api_resource.rb
nurego-1.0.10 lib/nurego/api_resource.rb
nurego-1.0.9 lib/nurego/api_resource.rb
nurego-1.0.8 lib/nurego/api_resource.rb
nurego-1.0.7 lib/nurego/api_resource.rb
nurego-1.0.6 lib/nurego/api_resource.rb
nurego-1.0.5 lib/nurego/api_resource.rb
nurego-1.0.4 lib/nurego/api_resource.rb
nurego-1.0.1 lib/nurego/api_resource.rb