Class: QuickBlox::UserSession

Inherits:
Session
  • Object
show all
Defined in:
lib/quick_blox/user_session.rb

Instance Attribute Summary collapse

Attributes inherited from Session

#_id, #application_id, #created_at, #device_id, #id, #nonce, #token, #ts, #updated_at, #user_id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Session

#info, #initialize

Constructor Details

This class inherits a constructor from QuickBlox::Session

Instance Attribute Details

#userObject

Returns the value of attribute user.



4
5
6
# File 'lib/quick_blox/user_session.rb', line 4

def user
  @user
end

Class Method Details

.destroy_by_token(token) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/quick_blox/user_session.rb', line 56

def self.destroy_by_token(token)
  RestClient::Request.execute(
      method: :delete,
      url: "#{ QuickBlox.configuration.host }/login.json",
      headers: {
          'Content-Type': 'application/json',
          'QuickBlox-REST-API-Version': QuickBlox.configuration.api_version,
          'QB-Token': token
      }
  ){ |response, request, result|
    case result.code.to_i
      when 200

      else
        response = JSON.parse(response)
        raise QuickBlox::Exceptions::Response, response['errors']
    end
  }
end

.new(application_session, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/quick_blox/user_session.rb', line 6

def self.new(application_session, options={})

  raise QuickBlox::Exceptions::MissingConfiguration unless QuickBlox.configuration

  RestClient::Request.execute(
      method: :post,
      url: "#{ QuickBlox.configuration.host }/login.json",
      payload: {
          login: options[:login],
          password: options[:password]
      }.to_json,
      headers: {
          'Content-Type': 'application/json',
          'QuickBlox-REST-API-Version': QuickBlox.configuration.api_version,
          'QB-Token': application_session.token
      }
  ){ |response, request, result|
    response = JSON.parse(response)
    case result.code.to_i
      when 200, 201, 202
        user = QuickBlox::User.new
        response['user'].each do |k, v|
          user.instance_variable_set "@#{k}", v
        end
      else
        raise QuickBlox::Exceptions::Response, response['errors']
    end
  }
end

Instance Method Details

#destroy(application_session) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/quick_blox/user_session.rb', line 36

def destroy(application_session)
  RestClient::Request.execute(
      method: :delete,
      url: "#{ QuickBlox.configuration.host }/login.json",
      headers: {
          'Content-Type': 'application/json',
          'QuickBlox-REST-API-Version': QuickBlox.configuration.api_version,
          'QB-Token': application_session.token
      }
  ){ |response, request, result|
    case result.code.to_i
      when 200

      else
        response = JSON.parse(response)
        raise QuickBlox::Exceptions::Response, response['errors']
    end
  }
end