Class: QuickBlox::User

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#blob_idObject

Returns the value of attribute blob_id.



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

def blob_id
  @blob_id
end

#created_atObject

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#custom_dataObject

Returns the value of attribute custom_data.



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

def custom_data
  @custom_data
end

#emailObject

Returns the value of attribute email.



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

def email
  @email
end

#external_user_idObject

Returns the value of attribute external_user_id.



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

def external_user_id
  @external_user_id
end

#facebook_idObject

Returns the value of attribute facebook_id.



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

def facebook_id
  @facebook_id
end

#full_nameObject

Returns the value of attribute full_name.



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

def full_name
  @full_name
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#last_request_atObject

Returns the value of attribute last_request_at.



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

def last_request_at
  @last_request_at
end

#loginObject

Returns the value of attribute login.



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

def 
  @login
end

#owner_idObject

Returns the value of attribute owner_id.



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

def owner_id
  @owner_id
end

#phoneObject

Returns the value of attribute phone.



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

def phone
  @phone
end

#twitter_digits_idObject

Returns the value of attribute twitter_digits_id.



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

def twitter_digits_id
  @twitter_digits_id
end

#twitter_idObject

Returns the value of attribute twitter_id.



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

def twitter_id
  @twitter_id
end

#updated_atObject

Returns the value of attribute updated_at.



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

def updated_at
  @updated_at
end

#user_tagsObject

Returns the value of attribute user_tags.



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

def user_tags
  @user_tags
end

#websiteObject

Returns the value of attribute website.



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

def website
  @website
end

Class Method Details

.create(application_session, options) ⇒ Object



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
35
36
37
38
39
# File 'lib/quick_blox/user.rb', line 7

def self.create(application_session, options)

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

  RestClient::Request.execute(
      method: :post,
      url: "#{ QuickBlox.configuration.host }/users.json",
      payload: {
          user: {
            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 201
        instance = QuickBlox::User.new
        response['user'].each do |k, v|
          instance.instance_variable_set "@#{k}", v
        end
        return instance
      else
        raise QuickBlox::Exceptions::Response, response['errors']
    end
  }
end

.show(application_session, user_id) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/quick_blox/user.rb', line 41

def self.show(application_session, user_id)
  RestClient::Request.execute(
      method: :get,
      url: "#{ QuickBlox.configuration.host }/users/#{ user_id }.json",
      headers: {
          '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
        instance = QuickBlox::User.new
        response['user'].each do |k, v|
          instance.instance_variable_set "@#{k}", v
        end
        return instance
      when 404
        raise QuickBlox::Exceptions::ResourceNotFound
      else
        raise QuickBlox::Exceptions::Response, response['errors']
    end
  }
end

Instance Method Details

#destroy(application_session) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/quick_blox/user.rb', line 67

def destroy(application_session)
  RestClient::Request.execute(
      method: :delete,
      url: "#{ QuickBlox.configuration.host }/users/#{ self.id }.json",
      headers: {
          '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