Module: DisplayWords::Request::Authentication
- Defined in:
- lib/display_words/authentication.rb
Constant Summary collapse
- ENDPOINT =
'/auth'
Instance Attribute Summary collapse
-
#token ⇒ Object
Returns the value of attribute token.
-
#token_expire ⇒ Object
Returns the value of attribute token_expire.
Instance Method Summary collapse
- #authenticate(username, password) ⇒ Object
- #authentication_needed? ⇒ Boolean
- #authentication_options(username, password) ⇒ Object
- #expired_token? ⇒ Boolean
Instance Attribute Details
#token ⇒ Object
Returns the value of attribute token.
6 7 8 |
# File 'lib/display_words/authentication.rb', line 6 def token @token end |
#token_expire ⇒ Object
Returns the value of attribute token_expire.
6 7 8 |
# File 'lib/display_words/authentication.rb', line 6 def token_expire @token_expire end |
Instance Method Details
#authenticate(username, password) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/display_words/authentication.rb', line 8 def authenticate(username, password) = (username, password) response = post(ENDPOINT, ) @token_expire = Time.now + (2 * 60 * 60) #Token expires two hours from when it was given @token = response['token'] end |
#authentication_needed? ⇒ Boolean
21 22 23 |
# File 'lib/display_words/authentication.rb', line 21 def authentication_needed? !token || expired_token? end |
#authentication_options(username, password) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/display_words/authentication.rb', line 25 def (username, password) credentials = { :auth => { :username => username, :password => password } } { :body => credentials.to_json, :headers => { "content_type" => "json" } } end |
#expired_token? ⇒ Boolean
17 18 19 |
# File 'lib/display_words/authentication.rb', line 17 def expired_token? token_expire <= Time.now end |