Class: Investolink::Resource

Inherits:
InvestolinkObject show all
Defined in:
lib/investolink/resource.rb

Instance Attribute Summary

Attributes inherited from InvestolinkObject

#api_key, #api_token

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from InvestolinkObject

#[], #[]=, #as_json, construct_from, #each, #initialize, #inspect, #keys, #refresh_from, #to_hash, #to_json, #to_s, #values

Constructor Details

This class inherits a constructor from Investolink::InvestolinkObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Investolink::InvestolinkObject

Class Method Details

.resource_urlObject



3
4
5
6
7
8
9
10
# File 'lib/investolink/resource.rb', line 3

def self.resource_url
  if self == Resource
    raise NotImplementedError.new('Resource is an abstract class.  You should perform actions on its subclasses (Issuer, Issue, etc.)')
  end
  shortname = self.name.split('::')[-1]
  shortname = Util.to_underscore(shortname.to_s)
  "/#{CGI.escape(shortname.downcase)}s"
end

.retrieve(id, api_key = nil, api_token = nil) ⇒ Object



25
26
27
28
29
# File 'lib/investolink/resource.rb', line 25

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

Instance Method Details

#refreshObject



19
20
21
22
23
# File 'lib/investolink/resource.rb', line 19

def refresh
  response, api_key, api_token = Investolink.request(:get, resource_url, @api_key, @api_token)
  refresh_from(response, api_key, api_token)
  self
end

#resource_urlObject



12
13
14
15
16
17
# File 'lib/investolink/resource.rb', line 12

def resource_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.resource_url}/#{CGI.escape(id.to_s)}"
end