Class: QuestradeApi::REST::Quote

Inherits:
Base
  • Object
show all
Defined in:
lib/questrade_api/rest/quote.rb

Constant Summary

Constants inherited from Base

Base::BASE_ENDPOINT

Instance Attribute Summary

Attributes inherited from Base

#account_id, #authorization, #connection, #data, #id, #raw_body

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#build_attributes, #build_data, connection, post, #url

Constructor Details

#initialize(params) ⇒ Quote

Returns a new instance of Quote.



6
7
8
9
10
11
12
# File 'lib/questrade_api/rest/quote.rb', line 6

def initialize(params)
  super(params[:authorization])
  @id = params[:id]

  @raw_body = params[:data]
  build_data(params[:data]) if @raw_body
end

Class Method Details

.endpointObject



43
44
45
# File 'lib/questrade_api/rest/quote.rb', line 43

def self.endpoint
  "#{BASE_ENDPOINT}/markets/quotes"
end

.fetch(authorization, ids) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/questrade_api/rest/quote.rb', line 24

def self.fetch(authorization, ids)
  response = super(access_token: authorization.access_token,
                   endpoint: endpoint,
                   url: authorization.url,
                   params: { ids: ids.join(',') })

  if response.status == 200
    result = OpenStruct.new(quotes: [])
    result.quotes = parse_quotes(authorization, response.body)
    response = result
  end

  response
end

Instance Method Details

#endpointObject



39
40
41
# File 'lib/questrade_api/rest/quote.rb', line 39

def endpoint
  self.class.endpoint + "/#{id}"
end

#fetchObject



14
15
16
17
18
19
20
21
22
# File 'lib/questrade_api/rest/quote.rb', line 14

def fetch
  response = super(endpoint: endpoint)

  if response.status == 200
    parse_quotes(response.body)
  end

  response
end