Class: Grendel::User
- Inherits:
-
Object
- Object
- Grendel::User
- Defined in:
- lib/grendel/user.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#id ⇒ Object
Returns the value of attribute id.
-
#keys ⇒ Object
readonly
Returns the value of attribute keys.
-
#modified_at ⇒ Object
readonly
Returns the value of attribute modified_at.
-
#password ⇒ Object
Returns the value of attribute password.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
-
#auth ⇒ Object
return user’s creds in the form required by HTTParty.
-
#change_password(new_password) ⇒ Object
change the user’s password.
- #delete(uri = "", options = {}) ⇒ Object
-
#documents ⇒ Object
send documents calls to the DocumentManager.
-
#get(uri = "", options = {}) ⇒ Object
methods to do authenticated client calls with the user’s base_uri.
- #head(uri = "", options = {}) ⇒ Object
-
#initialize(client, params) ⇒ User
constructor
create a new Grendel::User object params: id uri password.
-
#linked_documents ⇒ Object
send linked documents calls to the LinkedDocumentManager.
- #post(uri = "", data = {}, options = {}) ⇒ Object
- #put(uri = "", data = {}, options = {}) ⇒ Object
Constructor Details
#initialize(client, params) ⇒ User
create a new Grendel::User object params:
id
uri
password
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/grendel/user.rb', line 11 def initialize(client, params) params = Mash.new(params) @client = client @id = params[:id] @uri = params[:uri] ? URI.parse(params[:uri]).path : "/users/" + @id # escape this? @password = params[:password] @modified_at = DateTime.parse(params[:"modified-at"]) if params[:"modified-at"] @created_at = DateTime.parse(params[:"created-at"]) if params[:"created-at"] @keys = params[:keys] end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
4 5 6 |
# File 'lib/grendel/user.rb', line 4 def client @client end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
4 5 6 |
# File 'lib/grendel/user.rb', line 4 def created_at @created_at end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/grendel/user.rb', line 3 def id @id end |
#keys ⇒ Object (readonly)
Returns the value of attribute keys.
4 5 6 |
# File 'lib/grendel/user.rb', line 4 def keys @keys end |
#modified_at ⇒ Object (readonly)
Returns the value of attribute modified_at.
4 5 6 |
# File 'lib/grendel/user.rb', line 4 def modified_at @modified_at end |
#password ⇒ Object
Returns the value of attribute password.
3 4 5 |
# File 'lib/grendel/user.rb', line 3 def password @password end |
#uri ⇒ Object
Returns the value of attribute uri.
3 4 5 |
# File 'lib/grendel/user.rb', line 3 def uri @uri end |
Instance Method Details
#auth ⇒ Object
return user’s creds in the form required by HTTParty
25 26 27 |
# File 'lib/grendel/user.rb', line 25 def auth {:basic_auth => {:username => id, :password => password}} end |
#change_password(new_password) ⇒ Object
change the user’s password
58 59 60 61 |
# File 'lib/grendel/user.rb', line 58 def change_password(new_password) put("", {:password => new_password}) @password = new_password end |
#delete(uri = "", options = {}) ⇒ Object
52 53 54 55 |
# File 'lib/grendel/user.rb', line 52 def delete(uri = "", = {}) .merge!(auth) @client.delete(child_uri(uri), ) end |
#documents ⇒ Object
send documents calls to the DocumentManager
64 65 66 |
# File 'lib/grendel/user.rb', line 64 def documents DocumentManager.new(self) end |
#get(uri = "", options = {}) ⇒ Object
methods to do authenticated client calls with the user’s base_uri
32 33 34 35 |
# File 'lib/grendel/user.rb', line 32 def get(uri = "", = {}) .merge!(auth) @client.get(child_uri(uri), ) end |
#head(uri = "", options = {}) ⇒ Object
37 38 39 40 |
# File 'lib/grendel/user.rb', line 37 def head(uri = "", = {}) .merge!(auth) @client.head(child_uri(uri), ) end |
#linked_documents ⇒ Object
send linked documents calls to the LinkedDocumentManager
69 70 71 |
# File 'lib/grendel/user.rb', line 69 def linked_documents LinkedDocumentManager.new(self) end |
#post(uri = "", data = {}, options = {}) ⇒ Object
42 43 44 45 |
# File 'lib/grendel/user.rb', line 42 def post(uri = "", data = {}, = {}) .merge!(auth) @client.post(child_uri(uri), data, ) end |
#put(uri = "", data = {}, options = {}) ⇒ Object
47 48 49 50 |
# File 'lib/grendel/user.rb', line 47 def put(uri = "", data = {}, = {}) .merge!(auth) @client.put(child_uri(uri), data, ) end |