class Robinhood::Api

Robinhood API's class methods

Public Class Methods

fix(var) click to toggle source
# File lib/robinhood/api.rb, line 188
def self.fix(var)
  if var.class == Hash
    fix_hash(var)
  elsif var.class == Array
    arr = []
    var.each do |ha|
      arr << fix_hash(ha)
    end
    arr
  end
end
fix_hash(var) click to toggle source
# File lib/robinhood/api.rb, line 200
def self.fix_hash(var)
  instance = var.clone
  instance = flatten(instance)
  instance = sanitize(instance)
  keys = %w[account instrument position quote market fundamentals]
  keys.each do |key|
    instance[key] = strip(instance[key]) if instance.key?(key)
  end

  instance
end
flatten(var) click to toggle source
# File lib/robinhood/api.rb, line 141
def self.flatten(var)
  new_var = {}
  var.each do |k, v|
    if v.class == Hash
      v.each do |l, w|
        new_var[l] = w
      end
    else
      new_var[k] = v
    end
  end
  new_var
end
methodlist() click to toggle source
# File lib/robinhood/api.rb, line 135
def self.methodlist
  %i[investment_profile accounts ach_iav_auth ach_relationships
     ach_transfers applications dividends edocuments margin_upgrade
     notifications orders password_reset document_requests user watchlists]
end
sanitize(var) click to toggle source
# File lib/robinhood/api.rb, line 155
def self.sanitize(var)
  var.delete('updated_at') if var.keys.include?('updated_at')

  var.delete('created_at') if var.keys.include?('created_at')

  new_var = {}
  var.each do |k, v|
    key = k
    key = 'object_type' if key == 'type'
    key = 'third_party_id' if key == 'id'
    if v.class == String
      if v.include?('T') && v.include?('Z')
        begin
          new_var[key] = Time.parse(v)
        rescue StandardError
          new_var[key] = v
        end
      else
        begin
          new_var[key] = Float(v)
        rescue StandardError
          new_var[key] = v
        end
      end
    end
  end
  new_var
end
strip(str) click to toggle source
# File lib/robinhood/api.rb, line 184
def self.strip(str)
  str.split('/').last
end