Class: Wes::Data::API::User
- Inherits:
-
Object
- Object
- Wes::Data::API::User
show all
- Defined in:
- lib/wes/data/api/user.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(attributes) ⇒ User
Returns a new instance of User.
10
11
12
|
# File 'lib/wes/data/api/user.rb', line 10
def initialize(attributes)
@attributes = attributes
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym) ⇒ Object
47
48
49
|
# File 'lib/wes/data/api/user.rb', line 47
def method_missing(method_sym)
attributes.send method_sym
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
8
9
10
|
# File 'lib/wes/data/api/user.rb', line 8
def attributes
@attributes
end
|
Class Method Details
.client ⇒ Object
15
16
17
|
# File 'lib/wes/data/api/user.rb', line 15
def client
Client.new
end
|
.configuration ⇒ Object
19
20
21
|
# File 'lib/wes/data/api/user.rb', line 19
def configuration
Configuration
end
|
.create(id) ⇒ Object
23
24
25
26
|
# File 'lib/wes/data/api/user.rb', line 23
def create(id)
attributes = client.post("#{routes.user}/#{id}", {}).first
new(attributes)
end
|
.find(key, value) ⇒ Object
28
29
30
31
32
|
# File 'lib/wes/data/api/user.rb', line 28
def find(key, value)
attrs = key == :id ? client.get("#{routes.user}/#{value}")
: client.get("#{routes.user}?#{key}=#{value}")
new(attrs.first)
end
|
.routes ⇒ Object
34
35
36
|
# File 'lib/wes/data/api/user.rb', line 34
def routes
configuration.routes
end
|
Instance Method Details
#assign_collectives(collective_ids) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/wes/data/api/user.rb', line 71
def assign_collectives(collective_ids)
unless collective_ids.kind_of?(Array)
raise ArgumentError, "List of collective ids must be an array"
end
if collective_ids.empty?
raise StandardError, "At least one collective_id must be specified"
end
client.post(
[routes.user, id, "collectives"].join("/"),
collective_ids
)
end
|
#closed_submissions ⇒ Object
39
40
41
|
# File 'lib/wes/data/api/user.rb', line 39
def closed_submissions
client.get "#{routes.user}/#{id}#{routes.submissions}/closed"
end
|
#exist? ⇒ Boolean
43
44
45
|
# File 'lib/wes/data/api/user.rb', line 43
def exist?
!@attributes.nil?
end
|
#open_submissions ⇒ Object
51
52
53
|
# File 'lib/wes/data/api/user.rb', line 51
def open_submissions
client.get("#{routes.user}/#{id}#{routes.submissions}/open")
end
|
#submissions ⇒ Object
55
56
57
|
# File 'lib/wes/data/api/user.rb', line 55
def submissions
client.get("#{routes.user}/#{id}#{routes.submissions}")
end
|
#update(changes) ⇒ Object
63
64
65
66
67
68
69
|
# File 'lib/wes/data/api/user.rb', line 63
def update(changes)
@attributes = client.put(
"#{routes.user}/#{id}",
@attributes.to_h.merge(changes)
).first
self
end
|
#videos ⇒ Object
59
60
61
|
# File 'lib/wes/data/api/user.rb', line 59
def videos
client.get("#{routes.user}/#{id}#{routes.videos}")
end
|