Class: QuestradeApi::REST::Order
- Inherits:
-
Base
- Object
- Base
- QuestradeApi::REST::Order
show all
- Defined in:
- lib/questrade_api/rest/order.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, #fetch, post, #url
Constructor Details
#initialize(authorization, params = {}) ⇒ Order
Returns a new instance of Order.
6
7
8
9
10
11
12
13
14
|
# File 'lib/questrade_api/rest/order.rb', line 6
def initialize(authorization, params = {})
super(authorization)
@id = params[:id]
@account_id = params[:account_id]
@raw_body = params[:data]
build_data(params[:data]) if @raw_body
end
|
Class Method Details
.create(authorization, account_number, params = {}) ⇒ Object
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/questrade_api/rest/order.rb', line 29
def self.create(authorization, account_number, params = {})
params[:accountNumber] = account_number
response = post(access_token: authorization.access_token,
endpoint: endpoint(account_number),
url: authorization.url,
body: params.to_json)
build_orders(authorization, account_number, response)
end
|
.endpoint(account_id) ⇒ Object
53
54
55
|
# File 'lib/questrade_api/rest/order.rb', line 53
def self.endpoint(account_id)
"#{BASE_ENDPOINT}/accounts/#{account_id}/orders"
end
|
.fetch(authorization, account_number, params) ⇒ Object
40
41
42
43
44
45
46
47
|
# File 'lib/questrade_api/rest/order.rb', line 40
def self.fetch(authorization, account_number, params)
response = super(access_token: authorization.access_token,
endpoint: endpoint(account_number),
url: authorization.url,
params: params)
build_orders(authorization, account_number, response)
end
|
Instance Method Details
#endpoint ⇒ Object
49
50
51
|
# File 'lib/questrade_api/rest/order.rb', line 49
def endpoint
self.class.endpoint(account_id) + "/#{id}"
end
|
#update(params = {}) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/questrade_api/rest/order.rb', line 16
def update(params = {})
params[:accountNumber] = account_id
response = self.class.post(access_token: authorization.access_token,
endpoint: endpoint,
url: authorization.url,
body: params.to_json)
parse_order(response.body) if response.status == 200
response
end
|