Class: Amiando::User

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

Overview

Instance Attribute Summary

Attributes inherited from Resource

#attributes, #request, #response, #success

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Resource

#[], #extract_attributes_from, #id, #initialize, map, map_params, mapping, method_missing, #method_missing, #populate_create, reverse_map_params, typecasting

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::Resource

Class Method Details

+ (Object) create(attributes)

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

Parameters:

  • attributes (Hash)


42
43
44
45
46
47
48
49
# File 'lib/amiando/user.rb', line 42

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

  object
end

+ (Object) delete(user_id)

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

Parameters:

  • user_id


81
82
83
84
85
86
# File 'lib/amiando/user.rb', line 81

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

  object
end

+ (Boolean) exists?(username)

Will return a Boolean deferred object containing the result

Parameters:

  • username (String)

Returns:



13
14
15
16
17
18
19
# File 'lib/amiando/user.rb', line 13

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

  object
end

+ (Object) find(user_id)

Find a user. Will return a user

Parameters:

  • user_id


69
70
71
72
73
74
# File 'lib/amiando/user.rb', line 69

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

  object
end

+ (Result) find_by_username(username)

Find a user given the username (email)

Parameters:

  • username (String)

Returns:

  • (Result)

    with the user's id



26
27
28
29
30
31
32
33
34
35
# File 'lib/amiando/user.rb', line 26

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

+ (Object) logout(user_id)

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

Parameters:

  • user_id


104
105
106
107
108
109
# File 'lib/amiando/user.rb', line 104

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

  object
end

+ (Object) request_permission(user_id, password)

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

Parameters:

  • user_id
  • password (String)


92
93
94
95
96
97
# File 'lib/amiando/user.rb', line 92

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

  object
end

+ (Object) update(user_id, attributes)

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

Parameters:

  • username (String)


57
58
59
60
61
62
# File 'lib/amiando/user.rb', line 57

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

  object
end

Instance Method Details

- (Object) ==(user)



111
112
113
# File 'lib/amiando/user.rb', line 111

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