Class: QuestradeApi::REST::Symbol

Inherits:
Base
  • Object
show all
Defined in:
lib/questrade_api/rest/symbol.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(authorization, params = {}) ⇒ Symbol

Returns a new instance of Symbol.



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

def initialize(authorization, params = {})
  super(authorization)

  @id = params[:id]

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

Class Method Details

.endpoint(extra = '') ⇒ Object



29
30
31
# File 'lib/questrade_api/rest/symbol.rb', line 29

def self.endpoint(extra = '')
  "#{BASE_ENDPOINT}/symbols/#{extra}"
end

.fetch(authorization, params = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/questrade_api/rest/symbol.rb', line 42

def self.fetch(authorization, params = {})
  params[:ids] = params[:ids].join(',') if params[:ids]
  params[:names] = params[:names].join(',') if params[:names]

  response = super(access_token: authorization.access_token,
                   endpoint: endpoint,
                   url: authorization.url,
                   params: params)

  build_symbols(authorization, response)
end

.search(authorization, params = {}) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/questrade_api/rest/symbol.rb', line 33

def self.search(authorization, params = {})
  response = superclass.fetch(access_token: authorization.access_token,
                              endpoint: endpoint('search'),
                              url: authorization.url,
                              params: params)

  build_symbols(authorization, response)
end

Instance Method Details

#endpointObject



25
26
27
# File 'lib/questrade_api/rest/symbol.rb', line 25

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

#fetchObject



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

def fetch
  response = super(endpoint: endpoint)

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

  response
end