Class: DataCatalog::User
- Inherits:
-
Base
- Object
- Mash
- Base
- DataCatalog::User
show all
- Defined in:
- lib/resources/user.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
_first, check_status, cursor, error, filterize, filterize_hash, http_delete, http_get, http_post, http_put, one, query_hash
Class Method Details
.all(conditions = {}) ⇒ Object
5
6
7
|
# File 'lib/resources/user.rb', line 5
def self.all(conditions={})
cursor(uri, query_hash(conditions))
end
|
.create(params = {}) ⇒ Object
9
10
11
|
# File 'lib/resources/user.rb', line 9
def self.create(params={})
with_api_keys(one(http_post(uri, :body => params)))
end
|
.destroy(id) ⇒ Object
13
14
15
|
# File 'lib/resources/user.rb', line 13
def self.destroy(id)
one(http_delete(uri(id)))
end
|
.first(conditions = {}) ⇒ Object
17
18
19
|
# File 'lib/resources/user.rb', line 17
def self.first(conditions={})
_first(http_get(uri, :query => query_hash(conditions)))
end
|
.get(id) ⇒ Object
21
22
23
|
# File 'lib/resources/user.rb', line 21
def self.get(id)
with_api_keys(one(http_get(uri(id))))
end
|
.get_by_api_key(api_key) ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/resources/user.rb', line 25
def self.get_by_api_key(api_key)
DataCatalog.with_key(api_key) do
checkup = one(http_get("/checkup"))
raise NotFound if checkup.api_key != "valid"
get(checkup.user.id)
end
end
|
.update(id, params) ⇒ Object
33
34
35
|
# File 'lib/resources/user.rb', line 33
def self.update(id, params)
one(http_put(uri(id), :body => params))
end
|
.uri(id = nil) ⇒ Object
44
45
46
|
# File 'lib/resources/user.rb', line 44
def self.uri(id=nil)
"/users/#{id}"
end
|
.with_api_keys(user) ⇒ Object
39
40
41
42
|
# File 'lib/resources/user.rb', line 39
def self.with_api_keys(user)
user.api_keys = ApiKey.all(user.id) if user
user
end
|
Instance Method Details
#delete_api_key!(api_key_id) ⇒ Object
50
51
52
53
|
# File 'lib/resources/user.rb', line 50
def delete_api_key!(api_key_id)
ApiKey.destroy(self.id, api_key_id)
update_api_keys
end
|
#generate_api_key!(params) ⇒ Object
55
56
57
58
|
# File 'lib/resources/user.rb', line 55
def generate_api_key!(params)
ApiKey.create(self.id, params)
update_api_keys
end
|
#update_api_key!(api_key_id, params) ⇒ Object
60
61
62
63
|
# File 'lib/resources/user.rb', line 60
def update_api_key!(api_key_id, params)
ApiKey.update(self.id, api_key_id, params)
update_api_keys
end
|