Class: Amiando::User

Inherits:
Resource show all
Defined in:
lib/amiando/user.rb

Overview

Instance Attribute Summary

Attributes inherited from Resource

#request, #response, #success

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#extract_attributes_from, #initialize, method_missing, #populate_create

Methods included from Attributes

#[], #id, included, #method_missing, #respond_to?, #type

Methods included from Autorun

included

Constructor Details

This class inherits a constructor from Amiando::Resource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Amiando::Attributes

Class Method Details

.create(attributes) ⇒ Object

Creates a user. It will not return the full user and only the id attribute will be available.


39
40
41
42
43
44
45
46
# File 'lib/amiando/user.rb', line 39

def self.create(attributes)
  object  = new
  post object, '/api/user/create',
    :params          => attributes,
    :populate_method => :populate_create

  object
end

.delete(user_id) ⇒ Object

Deletes a user Returns a Boolean with the result of the operation


78
79
80
81
82
83
# File 'lib/amiando/user.rb', line 78

def self.delete(user_id)
  object = Boolean.new('deleted')
  do_request object, :delete, "/api/user/#{user_id}"

  object
end

.exists?(username) ⇒ Boolean

Will return a Boolean deferred object containing the result


10
11
12
13
14
15
16
# File 'lib/amiando/user.rb', line 10

def self.exists?(username)
  object  = Boolean.new('exists')
  get object, "api/user/exists",
    :params => { :username => username }

  object
end

.find(user_id) ⇒ Object

Find a user. Will return a user


66
67
68
69
70
71
# File 'lib/amiando/user.rb', line 66

def self.find(user_id)
  object = new
  get object, "api/user/#{user_id}"

  object
end

.find_by_username(username) ⇒ Result

Find a user given the username (email)


23
24
25
26
27
28
29
30
31
32
# File 'lib/amiando/user.rb', line 23

def self.find_by_username(username)
  object = Result.new do |response_body|
    response_body['ids'].first
  end

  get object, "api/user/find",
    :params => { :username => username }

  object
end

.logout(user_id) ⇒ Object

Tries to log out the user_id. Will raise Error::NotAuthorized if trying to logout a user you don't have permission for.


101
102
103
104
105
106
# File 'lib/amiando/user.rb', line 101

def self.logout(user_id)
  object = Boolean.new('success')
  post object, "/api/user/#{user_id}/logout"

  object
end

.request_permission(user_id, password) ⇒ Object

Request permission to use and api key on behalf of a user


89
90
91
92
93
94
# File 'lib/amiando/user.rb', line 89

def self.request_permission(user_id, password)
  object  = Result.new
  post object, "api/user/#{user_id}/requestPermission", :params => { :password => password }

  object
end

.update(user_id, attributes) ⇒ Object

Updates a user. Will return a Boolean deferred object indicating the result of the update


54
55
56
57
58
59
# File 'lib/amiando/user.rb', line 54

def self.update(user_id, attributes)
  object  = Boolean.new('success')
  post object, "/api/user/#{user_id}", :params => attributes

  object
end

Instance Method Details

#==(user) ⇒ Object


108
109
110
# File 'lib/amiando/user.rb', line 108

def ==(user)
  id == user.id
end