Class: GLogin::Cookie::Open
- Inherits:
-
Object
- Object
- GLogin::Cookie::Open
- Defined in:
- lib/glogin/cookie.rb
Overview
Open
Instance Attribute Summary collapse
-
#avatar_url ⇒ Object
readonly
Returns the value of attribute avatar_url.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#login ⇒ Object
readonly
Returns the value of attribute login.
Instance Method Summary collapse
-
#initialize(json, secret, context = '') ⇒ Open
constructor
Here comes the JSON you receive from Auth.user().
-
#to_s ⇒ Object
Returns the text you should drop back to the user as a cookie.
Constructor Details
#initialize(json, secret, context = '') ⇒ Open
Here comes the JSON you receive from Auth.user().
The JSON is a Hash where every key is a string. When the class is instantiated, its methods ‘id`, `login`, and `avatar_url` may be used to retrieve the data inside the JSON, but this is not what this class is mainly about.
The method to_s
returns an encrypted cookie string, that may be sent to the user as a Set-Cookie
HTTP header.
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/glogin/cookie.rb', line 91 def initialize(json, secret, context = '') raise 'JSON can\'t be nil' if json.nil? raise 'JSON must contain "id" key' if json['id'].nil? @id = json['id'].to_s @login = (json['login'] || '').to_s @avatar_url = (json['avatar_url'] || '').to_s @bearer = (json['bearer'] || '').to_s raise 'Secret can\'t be nil' if secret.nil? @secret = secret raise 'Context can\'t be nil' if context.nil? @context = context.to_s end |
Instance Attribute Details
#avatar_url ⇒ Object (readonly)
Returns the value of attribute avatar_url.
81 82 83 |
# File 'lib/glogin/cookie.rb', line 81 def avatar_url @avatar_url end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
81 82 83 |
# File 'lib/glogin/cookie.rb', line 81 def id @id end |
#login ⇒ Object (readonly)
Returns the value of attribute login.
81 82 83 |
# File 'lib/glogin/cookie.rb', line 81 def login @login end |