Class: CapitalIQ::Client
- Inherits:
-
Object
- Object
- CapitalIQ::Client
- Includes:
- HTTParty
- Defined in:
- lib/capital-iq/client.rb
Constant Summary collapse
- ENDPOINT =
'https://sdk.gds.standardandpoors.com/gdssdk/rest/v2/clientservice.json'
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
Instance Method Summary collapse
- #base_request(requests) ⇒ Object
-
#initialize(username, password, cache_store = nil, cache_prefix = "CAPIQ_") ⇒ Client
constructor
A new instance of Client.
- #method_missing(meth, *args, &block) ⇒ Object
- #request(function, identifiers, mnemonics, properties = nil) ⇒ Object
Constructor Details
#initialize(username, password, cache_store = nil, cache_prefix = "CAPIQ_") ⇒ Client
Returns a new instance of Client.
9 10 11 12 |
# File 'lib/capital-iq/client.rb', line 9 def initialize(username, password, cache_store=nil, cache_prefix="CAPIQ_") @auth = {username: username, password: password} @cache = Cache.new(cache_store, cache_prefix) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/capital-iq/client.rb', line 42 def method_missing(meth, *args, &block) if meth.to_s =~ /^request_(.+)$/ function = $1.upcase if Functions.all.include?(function) request(*([function]+args)) else super end else super end end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
3 4 5 |
# File 'lib/capital-iq/client.rb', line 3 def cache @cache end |
Instance Method Details
#base_request(requests) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/capital-iq/client.rb', line 14 def base_request(requests) # build request requests = [requests] unless requests.class == Array request_array = requests.collect { |r| r.to_hash } request_body = {inputRequests: {inputRequests: request_array}.to_json} # send request response_data = from_cache(request_body) || self.class.post( ENDPOINT, body: request_body, basic_auth: @auth, ssl_version: :TLSv1 ).parsed_response # analyze response response = ApiResponse.new(response_data) raise ApiError.new(response_data) if response.has_errors? to_cache(request_body, response_data) response end |
#request(function, identifiers, mnemonics, properties = nil) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/capital-iq/client.rb', line 32 def request(function, identifiers, mnemonics, properties=nil) mnemonics = [mnemonics] unless mnemonics.is_a? Enumerable identifiers = [identifiers] unless identifiers.is_a? Enumerable requests = [] identifiers.each do |identifier| requests.unshift(*mnemonics.collect {|m| CapitalIQ::Request.new(function, identifier, m, properties)}) end base_request(requests) end |