Class: Synapsis::User

Inherits:
Object
  • Object
show all
Includes:
Utilities
Defined in:
lib/synapsis/user.rb

Constant Summary

Constants included from Utilities

Synapsis::Utilities::API_V2_PATH

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utilities

#build_json_from_params, #build_json_from_variable_hash, #build_params_from_string, #to_hash

Constructor Details

#initialize(params) ⇒ User

Returns a new instance of User.



21
22
23
24
25
# File 'lib/synapsis/user.rb', line 21

def initialize(params)
  params.each do |k, v|
    send("#{k}=", v)
  end
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



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

def access_token
  @access_token
end

#emailObject

Returns the value of attribute email.



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

def email
  @email
end

#fullnameObject

Returns the value of attribute fullname.



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

def fullname
  @fullname
end

#ip_addressObject

Returns the value of attribute ip_address.



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

def ip_address
  @ip_address
end

#passwordObject

Returns the value of attribute password.



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

def password
  @password
end

#phonenumberObject

Returns the value of attribute phonenumber.



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

def phonenumber
  @phonenumber
end

#refresh_tokenObject

Returns the value of attribute refresh_token.



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

def refresh_token
  @refresh_token
end

#usernameObject

Returns the value of attribute username.



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

def username
  @username
end

Class Method Details

.create(params) ⇒ Object



13
14
15
# File 'lib/synapsis/user.rb', line 13

def self.create(params)
  self.new(params).create
end

.view(params) ⇒ Object



17
18
19
# File 'lib/synapsis/user.rb', line 17

def self.view(params)
  self.new({}).view(params)
end

Instance Method Details

#createObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/synapsis/user.rb', line 27

def create
  response = Synapsis.connection.post do |req|
    req.headers['Content-Type'] = 'application/json'
    req.url "#{API_V2_PATH}user/create/"
    req.body = build_json_from_params
  end

  if response.success?
    update_attributes(response)
    return self
  else
    return response
  end
end

#view(oauth_token = @access_token) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/synapsis/user.rb', line 42

def view(oauth_token = @access_token)
  response = Synapsis.connection.post do |req|
    req.headers['Content-Type'] = 'application/json'
    req.url "#{API_V2_PATH}user/show/"
    req.body = JSON.generate({ 'oauth_consumer_key' => oauth_token})
  end

  if response.success?
    return Synapsis::RetrievedUser.new(response)
  else
    return response
  end
end