Class: Scottrade::Session
Instance Attribute Summary collapse
-
#encrypted_id ⇒ Object
readonly
Returns the value of attribute encrypted_id.
-
#mask_id ⇒ Object
readonly
Returns the value of attribute mask_id.
Attributes inherited from Base
Instance Method Summary collapse
- #authenticate ⇒ Object
- #authenticated? ⇒ Boolean
-
#initialize(account, password) ⇒ Session
constructor
A new instance of Session.
Methods inherited from Base
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(account, password) @account = account @password = password @cookies = nil end |
Instance Attribute Details
#encrypted_id ⇒ Object (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_id ⇒ Object (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
#authenticate ⇒ Object
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) = 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") = [] .each { | | .push(.split('; ')[0]) } @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
16 17 18 |
# File 'lib/scottrade/session.rb', line 16 def authenticated? return (@cookies != nil) end |