Class: QuickBlox::Session
- Inherits:
-
Object
- Object
- QuickBlox::Session
- Defined in:
- lib/quick_blox/session.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#_id ⇒ Object
Returns the value of attribute _id.
-
#application_id ⇒ Object
Returns the value of attribute application_id.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#device_id ⇒ Object
Returns the value of attribute device_id.
-
#id ⇒ Object
Returns the value of attribute id.
-
#nonce ⇒ Object
Returns the value of attribute nonce.
-
#token ⇒ Object
Returns the value of attribute token.
-
#ts ⇒ Object
Returns the value of attribute ts.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
Instance Method Summary collapse
- #destroy ⇒ Object
- #info ⇒ Object
-
#initialize ⇒ Session
constructor
A new instance of Session.
Constructor Details
#initialize ⇒ Session
Returns a new instance of Session.
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 |
# File 'lib/quick_blox/session.rb', line 20 def initialize raise QuickBlox::Exceptions::MissingConfiguration unless QuickBlox.configuration = Time.now.in_time_zone('UTC').to_i nonce = -425346 signature = HMAC::SHA1.hexdigest(QuickBlox.configuration.auth_secret, "application_id=#{ QuickBlox.configuration.application_id }&auth_key=#{ QuickBlox.configuration.auth_key }&nonce=#{ nonce }×tamp=#{ }") RestClient::Request.execute( method: :post, url: "#{ QuickBlox.configuration.host }/session.json", payload: { application_id: QuickBlox.configuration.application_id, auth_key: QuickBlox.configuration.auth_key, signature: signature, timestamp: , nonce: nonce }.to_json, headers: { 'Content-Type': 'application/json', 'QuickBlox-REST-API-Version': QuickBlox.configuration.api_version, } ){ |response, request, result| response = JSON.parse(response) case result.code.to_i when 201 response['session'].each do |k, v| self.instance_variable_set "@#{k}", v end when 422 raise QuickBlox::Exceptions::Response, response['errors'] end } end |
Instance Attribute Details
#_id ⇒ Object
Returns the value of attribute _id.
9 10 11 |
# File 'lib/quick_blox/session.rb', line 9 def _id @_id end |
#application_id ⇒ Object
Returns the value of attribute application_id.
10 11 12 |
# File 'lib/quick_blox/session.rb', line 10 def application_id @application_id end |
#created_at ⇒ Object
Returns the value of attribute created_at.
11 12 13 |
# File 'lib/quick_blox/session.rb', line 11 def created_at @created_at end |
#device_id ⇒ Object
Returns the value of attribute device_id.
12 13 14 |
# File 'lib/quick_blox/session.rb', line 12 def device_id @device_id end |
#id ⇒ Object
Returns the value of attribute id.
18 19 20 |
# File 'lib/quick_blox/session.rb', line 18 def id @id end |
#nonce ⇒ Object
Returns the value of attribute nonce.
13 14 15 |
# File 'lib/quick_blox/session.rb', line 13 def nonce @nonce end |
#token ⇒ Object
Returns the value of attribute token.
14 15 16 |
# File 'lib/quick_blox/session.rb', line 14 def token @token end |
#ts ⇒ Object
Returns the value of attribute ts.
15 16 17 |
# File 'lib/quick_blox/session.rb', line 15 def ts @ts end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
16 17 18 |
# File 'lib/quick_blox/session.rb', line 16 def updated_at @updated_at end |
#user_id ⇒ Object
Returns the value of attribute user_id.
17 18 19 |
# File 'lib/quick_blox/session.rb', line 17 def user_id @user_id end |
Instance Method Details
#destroy ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/quick_blox/session.rb', line 79 def destroy RestClient::Request.execute( method: :delete, url: "#{ QuickBlox.configuration.host }/session.json", headers: { 'Content-Type': 'application/json', 'QuickBlox-REST-API-Version': QuickBlox.configuration.api_version, 'QB-Token': self.token } ){ |response, request, result| case result.code.to_i when 200 else response = JSON.parse(response) raise QuickBlox::Exceptions::Response, response['errors'] end } end |
#info ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/quick_blox/session.rb', line 56 def info RestClient::Request.execute( method: :get, url: "#{ QuickBlox.configuration.host }/session.json", headers: { 'Content-Type': 'application/json', 'QuickBlox-REST-API-Version': QuickBlox.configuration.api_version, 'QB-Token': self.token } ){ |response, request, result| response = JSON.parse(response) case result.code.to_i when 201 response['session'].each do |k, v| self.instance_variable_set "@#{k}", v end when 422 raise QuickBlox::Exceptions::Response, response['errors'] end } self end |