Class: Wes::Data::API::Base
- Inherits:
-
Object
- Object
- Wes::Data::API::Base
show all
- Defined in:
- lib/wes/data/api/base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(attributes) ⇒ Base
Returns a new instance of Base.
10
11
12
|
# File 'lib/wes/data/api/base.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
46
47
48
|
# File 'lib/wes/data/api/base.rb', line 46
def method_missing(method_sym)
attributes.to_h.fetch(method_sym, nil)
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
8
9
10
|
# File 'lib/wes/data/api/base.rb', line 8
def attributes
@attributes
end
|
Class Method Details
.client ⇒ Object
15
16
17
|
# File 'lib/wes/data/api/base.rb', line 15
def client
Client.new
end
|
.configuration ⇒ Object
19
20
21
|
# File 'lib/wes/data/api/base.rb', line 19
def configuration
Configuration
end
|
.create(route, payload = {}) ⇒ Object
27
28
29
|
# File 'lib/wes/data/api/base.rb', line 27
def create(route, payload = {})
new(client.post(route, payload).first)
end
|
.find(route) ⇒ Object
23
24
25
|
# File 'lib/wes/data/api/base.rb', line 23
def find(route)
new(client.get(route).first)
end
|
.mapped_objects(route) ⇒ Object
35
36
37
38
39
|
# File 'lib/wes/data/api/base.rb', line 35
def mapped_objects(route)
client.get(route).map do |item|
new(item)
end
end
|
.routes ⇒ Object
31
32
33
|
# File 'lib/wes/data/api/base.rb', line 31
def routes
configuration.routes
end
|
Instance Method Details
#exist? ⇒ Boolean
42
43
44
|
# File 'lib/wes/data/api/base.rb', line 42
def exist?
!attributes.nil?
end
|
#update(route, changes) ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/wes/data/api/base.rb', line 50
def update(route, changes)
@attributes = client.put(
route,
@attributes.to_h.merge(changes)
).first
self
end
|