Class: Dropcam::Session
Instance Attribute Summary collapse
-
#cookies ⇒ Object
Returns the value of attribute cookies.
-
#session_token ⇒ Object
Returns the value of attribute session_token.
Instance Method Summary collapse
- #authenticate ⇒ Object
-
#initialize(username, password) ⇒ Session
constructor
A new instance of Session.
Methods inherited from Base
Constructor Details
#initialize(username, password) ⇒ Session
Returns a new instance of Session.
6 7 8 9 |
# File 'lib/dropcam/session.rb', line 6 def initialize(username, password) @username = username @password = password end |
Instance Attribute Details
#cookies ⇒ Object
Returns the value of attribute cookies.
5 6 7 |
# File 'lib/dropcam/session.rb', line 5 def @cookies end |
#session_token ⇒ Object
Returns the value of attribute session_token.
5 6 7 |
# File 'lib/dropcam/session.rb', line 5 def session_token @session_token end |
Instance Method Details
#authenticate ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/dropcam/session.rb', line 11 def authenticate params = {"username" => @username, "password" => @password} response = post(::USERS_LOGIN, params, nil) = response.get_fields('set-cookie') # only cookies are set on valid credentials ## for some reason, dropcam responds with 200 on invalid credentials if = [] .each { | | .push(.split('; ')[0]) } @cookies = @session_token = _session_token # this value is embedded in the cookie but leaving this as is incase the API changes else raise AuthenticationError, "Invalid Credentials" end end |