Class: Grendel::User

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#clientObject (readonly)

Returns the value of attribute client.



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

def client
  @client
end

#created_atObject (readonly)

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/grendel/user.rb', line 3

def id
  @id
end

#keysObject (readonly)

Returns the value of attribute keys.



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

def keys
  @keys
end

#modified_atObject (readonly)

Returns the value of attribute modified_at.



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

def modified_at
  @modified_at
end

#passwordObject

Returns the value of attribute password.



3
4
5
# File 'lib/grendel/user.rb', line 3

def password
  @password
end

#uriObject

Returns the value of attribute uri.



3
4
5
# File 'lib/grendel/user.rb', line 3

def uri
  @uri
end

Instance Method Details

#authObject

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 = "", options = {})
  options.merge!(auth)
  @client.delete(child_uri(uri), options)
end

#documentsObject

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 = "", options = {})
  options.merge!(auth)
  @client.get(child_uri(uri), options)
end

#head(uri = "", options = {}) ⇒ Object



37
38
39
40
# File 'lib/grendel/user.rb', line 37

def head(uri = "", options = {})
  options.merge!(auth)
  @client.head(child_uri(uri), options)
end

#linked_documentsObject

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 = {}, options = {})
  options.merge!(auth)
  @client.post(child_uri(uri), data, options)
end

#put(uri = "", data = {}, options = {}) ⇒ Object



47
48
49
50
# File 'lib/grendel/user.rb', line 47

def put(uri = "", data = {}, options = {})
  options.merge!(auth)
  @client.put(child_uri(uri), data, options)
end