Class: CapitalIQ::ApiResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/capital-iq/api_response.rb

Defined Under Namespace

Classes: IdentifierResultGroup

Instance Method Summary collapse

Constructor Details

#initialize(response_data) ⇒ ApiResponse

Returns a new instance of ApiResponse.



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/capital-iq/api_response.rb', line 32

def initialize(response_data)
  @response_data = response_data

  @results = []
  @identifier_results = Hash.new {|hash, key| hash[key] = IdentifierResultGroup.new(key)}
  raw_results = response_data["GDSSDKResponse"]
  return if !raw_results.is_a?(Array)

  # create wrappers for each response
  @results = raw_results.collect { |r| RequestResult.new(r) }
  # build a map from header to corresponding result wrappers
  @results.each { |r| @identifier_results[r.Identifier] << r }
end

Instance Method Details

#[](identifier) ⇒ Object



51
52
53
54
# File 'lib/capital-iq/api_response.rb', line 51

def [](identifier)
  return nil unless @identifier_results.has_key?(identifier)
  @identifier_results[identifier]
end

#has_errors?(header = nil) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
# File 'lib/capital-iq/api_response.rb', line 46

def has_errors?(header=nil)
  return true if @response_data.include?("Errors")
  @results.find { |r| r.has_errors?(header)}
end

#identifiersObject



61
62
63
# File 'lib/capital-iq/api_response.rb', line 61

def identifiers
  @identifier_results.keys
end

#scalarObject



56
57
58
59
# File 'lib/capital-iq/api_response.rb', line 56

def scalar
  return nil if @identifier_results.length == 0
  @identifier_results.first[1]
end

#to_hashObject



65
66
67
# File 'lib/capital-iq/api_response.rb', line 65

def to_hash
  Hash[self.identifiers.collect { |id| [id, self[id]] }]
end

#to_sObject



69
70
71
# File 'lib/capital-iq/api_response.rb', line 69

def to_s
  to_hash().to_s()
end