Module: Malartu
- Defined in:
- lib/malartu.rb,
lib/malartu/error.rb,
lib/malartu/metric.rb,
lib/malartu/version.rb,
lib/malartu/schedule.rb,
lib/malartu/tracking.rb,
lib/malartu/portfolio.rb,
lib/malartu/connection.rb,
lib/malartu/tracking/data.rb,
lib/malartu/malartu_object.rb
Defined Under Namespace
Modules: Error, Tracking
Classes: Connection, MalartuObject, Metric, Portfolio, Schedule
Constant Summary
collapse
- API_VERSION =
'v0'.freeze
- API_PATH =
'https://api.malartu.co'.freeze
- VERSION =
'0.1.3'.freeze
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.api_version ⇒ Object
Returns the value of attribute api_version.
17
18
19
|
# File 'lib/malartu.rb', line 17
def api_version
@api_version
end
|
.apikey ⇒ Object
Returns the value of attribute apikey.
17
18
19
|
# File 'lib/malartu.rb', line 17
def apikey
@apikey
end
|
.topics ⇒ Object
Returns the value of attribute topics.
17
18
19
|
# File 'lib/malartu.rb', line 17
def topics
@topics
end
|
Class Method Details
.auth_params ⇒ Object
32
33
34
35
|
# File 'lib/malartu.rb', line 32
def auth_params
fail 'No apikey present. Set it with `Malartu.apikey =`' if apikey.nil?
{ apikey: apikey }
end
|
.base_path ⇒ Object
37
38
39
|
# File 'lib/malartu.rb', line 37
def base_path
"#{API_PATH}/#{version}"
end
|
.check_for_errors(response, params) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/malartu.rb', line 45
def check_for_errors(response, params)
case response.code
when 401
fail Malartu::Error::AuthorizationError.new(
message: 'Credentials do not match',
parameters: {
apikey: params[:apikey]
},
json_body: JSON.parse(response.body)
)
when 404
fail Malartu::Error::RecordNotFoundError.new(
message: 'Record Not Found',
parameters: {
id: params[:id],
model: params[:model]
},
json_body: JSON.parse(response.body)
)
when 429
fail Malartu::Error::RateLimitError.new(
message: 'Rate Limited',
parameters: {
apikey: params[:apikey]
},
json_body: JSON.parse(response.body)
)
when 500
fail Malartu::Error::ServerError.new(
message: 'Server Error',
parameters: params,
json_body: JSON.parse(response.body)
)
end
end
|
.request(method, path, params = {}, _headers = {}) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/malartu.rb', line 19
def request(method, path, params = {}, = {})
url = "#{base_path}#{path}"
req_params = case method.to_s
when 'get'
{ params: params.merge(auth_params) }
else
{ json: params.merge(auth_params) }
end
response = HTTP.send(method, url, req_params)
check_for_errors(response, params.merge(auth_params))
JSON.parse(response.body)
end
|
.version ⇒ Object
41
42
43
|
# File 'lib/malartu.rb', line 41
def version
api_version || API_VERSION
end
|