Class: Scottrade::Session

Inherits:
Base
  • Object
show all
Defined in:
lib/scottrade/session.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#cookies, #session_token

Instance Method Summary collapse

Methods inherited from Base

#get, #post

Constructor Details

#initialize(account, password) ⇒ Session

Returns a new instance of Session.


11
12
13
14
15
# File 'lib/scottrade/session.rb', line 11

def initialize(, password)
  @account = 
  @password = password
  @cookies = nil
end

Instance Attribute Details

#encrypted_idObject (readonly)

Returns the value of attribute encrypted_id.


9
10
11
# File 'lib/scottrade/session.rb', line 9

def encrypted_id
  @encrypted_id
end

#mask_idObject (readonly)

Returns the value of attribute mask_id.


9
10
11
# File 'lib/scottrade/session.rb', line 9

def mask_id
  @mask_id
end

Instance Method Details

#authenticateObject


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/scottrade/session.rb', line 19

def authenticate
  params = {}
  params["appID"] = "Scottrade"
  params["appName"] = "ScottradeMobileApplication"
  params["rcid"] = "iPhone"
  params["osName"] = "iPhone"
  params["platform"] = "iPhone"
  params["cacheid"] = ""
  params["osVer"] = "6"
  params["appver"] = "1.1.4"
  params["appVer"] = "1.1.4"
  params["isRemAcc"] = "true"
  params["page"] = "LogIn"
  params["serviceID"] = "VerifyLogin"
  params["channel"] = "rc"
  params["langId"] = "English"      
  
  params["acc"] = @account
  params["pwd"] = @password
  params["isEncrypted"] = "false"
        
  response = post(params, nil)
  all_cookies = response.get_fields('set-cookie') # only cookies are set on valid credentials
  parsed_response = JSON.parse(response.body)
  if parsed_response["error"] == "false" and !parsed_response.has_key?("errmsg")
    cookies = []
    all_cookies.each { | cookie |
        cookies.push(cookie.split('; ')[0])
    }
    @cookies = cookies
    @encrypted_dd = parsed_response["encryptedId"]
    @mask_id = parsed_response["maskId"]
    
    return self
  elsif parsed_response["msg"]
    raise AuthenticationError, parsed_response["msg"]
  elsif parsed_response["errmsg"]
    raise AuthenticationError, parsed_response["errmsg"]
  else
    raise AuthenticationError
  end   
end

#authenticated?Boolean

Returns:

  • (Boolean)

16
17
18
# File 'lib/scottrade/session.rb', line 16

def authenticated?
  return (@cookies != nil)
end