Module: Manatoo
- Defined in:
- lib/manatoo.rb,
lib/manatoo/task.rb
Defined Under Namespace
Classes: ApiKeyError, Task
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.api_base ⇒ Object
Returns the value of attribute api_base.
18
19
20
|
# File 'lib/manatoo.rb', line 18
def api_base
@api_base
end
|
.api_key ⇒ Object
Returns the value of attribute api_key.
18
19
20
|
# File 'lib/manatoo.rb', line 18
def api_key
@api_key
end
|
.last_response_json ⇒ Object
Returns the value of attribute last_response_json.
19
20
21
|
# File 'lib/manatoo.rb', line 19
def last_response_json
@last_response_json
end
|
Class Method Details
.conn ⇒ Object
22
23
24
25
26
27
28
29
|
# File 'lib/manatoo.rb', line 22
def self.conn
raise ApiKeyError.new if self.api_key.nil?
Faraday.new(self.api_base) do |conn|
conn.basic_auth(self.api_key, '')
conn.adapter(Faraday.default_adapter)
end
end
|
.delete(url, payload) ⇒ Object
53
54
55
|
# File 'lib/manatoo.rb', line 53
def self.delete(url, payload)
self.request_with_payload(:delete, url, payload)
end
|
.get(url) ⇒ Object
31
32
33
34
35
|
# File 'lib/manatoo.rb', line 31
def self.get(url)
self.conn.get do |req|
req.url(url)
end
end
|
.post(url, payload) ⇒ Object
45
46
47
|
# File 'lib/manatoo.rb', line 45
def self.post(url, payload)
self.request_with_payload(:post, url, payload)
end
|
.put(url, payload) ⇒ Object
49
50
51
|
# File 'lib/manatoo.rb', line 49
def self.put(url, payload)
self.request_with_payload(:put, url, payload)
end
|
.request_with_payload(action, url, payload) ⇒ Object
37
38
39
40
41
42
43
|
# File 'lib/manatoo.rb', line 37
def self.request_with_payload(action, url, payload)
self.conn.send(action) do |req|
req.url(url)
req.['Content-Type'] = 'application/json'
req.body = payload.to_json
end
end
|