Class: QuestradeApi::REST::Option

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

Constant Summary

Constants inherited from Base

Base::BASE_ENDPOINT

Instance Attribute Summary

Attributes inherited from Base

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

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

Constructor Details

#initialize(params) ⇒ Option

Returns a new instance of Option.



6
7
8
9
# File 'lib/questrade_api/rest/option.rb', line 6

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

Class Method Details

.endpoint(symbol_id) ⇒ Object



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

def self.endpoint(symbol_id)
  "#{BASE_ENDPOINT}/symbol/#{symbol_id}/options"
end

.fetch(authorization, symbol_id) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/questrade_api/rest/option.rb', line 11

def self.fetch(authorization, symbol_id)
  response = super(access_token: authorization.access_token,
                   endpoint: endpoint(symbol_id),
                   url: authorization.url)

  if response.status == 200
    result = OpenStruct.new(options: [])
    result.options = parse_options(response.body)
    response = result
  end

  response
end