class QuestradeApi::REST::Activity

@author Bruno Meira <goesmeira@gmail.com>

Attributes

account_id[RW]

Public Class Methods

endpoint(account_id) click to toggle source
# File lib/questrade_api/rest/activity.rb, line 39
def self.endpoint(account_id)
  "#{BASE_ENDPOINT}/accounts/#{account_id}/activities"
end
fetch(authorization, account_number, params) click to toggle source

Fetch account activities

@param authorization [QuestradeApi::Authorization] with the authorized access_token and url. @param account_number [String] with the account the activities will be fetched @param params [Hash] with the range of dates the activities will be fetched @option params [String] :startTime The start time. ex: '2011-02-16T00:00:00.000000-05:00' @option params [String] :endTime The end time. ex: '2011-02-16T00:00:00.000000-05:00'

Calls superclass method QuestradeApi::REST::Base#fetch
# File lib/questrade_api/rest/activity.rb, line 24
def self.fetch(authorization, account_number, params)
  response = super(access_token: authorization.access_token,
                   endpoint: endpoint(account_number),
                   url: authorization.url,
                   params: params)

  result = OpenStruct.new(activities: [])

  if response.status == 200
    result.activities = parse_activities(account_number, response.body)
  end

  result
end
new(params) click to toggle source
# File lib/questrade_api/rest/activity.rb, line 9
def initialize(params)
  @account_id = params[:account_id]

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

Private Class Methods

parse_activities(account_number, body) click to toggle source
# File lib/questrade_api/rest/activity.rb, line 43
def self.parse_activities(account_number, body)
  raw = JSON.parse(body)

  activities = []

  raw['activities'].each do |activity|
    activities << new(account_id: account_number, data: activity)
  end

  activities
end