Module: TimestampAPI
- Defined in:
- lib/timestamp_api.rb,
lib/timestamp_api/errors.rb,
lib/timestamp_api/project.rb,
lib/timestamp_api/version.rb
Defined Under Namespace
Classes: InvalidServerResponse, MissingAPIKey, Project
Constant Summary collapse
- VERSION =
"0.2.0"
Class Attribute Summary collapse
-
.api_endpoint ⇒ Object
Returns the value of attribute api_endpoint.
-
.api_key ⇒ Object
Returns the value of attribute api_key.
Class Method Summary collapse
Class Attribute Details
.api_endpoint ⇒ Object
Returns the value of attribute api_endpoint.
12 13 14 |
# File 'lib/timestamp_api.rb', line 12 def api_endpoint @api_endpoint end |
.api_key ⇒ Object
Returns the value of attribute api_key.
12 13 14 |
# File 'lib/timestamp_api.rb', line 12 def api_key @api_key end |
Class Method Details
.objectify(json) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/timestamp_api.rb', line 34 def self.objectify(json) case json when Array then json.map { |item| RecursiveOpenStruct.new(item, recurse_over_arrays: true) } when Hash then RecursiveOpenStruct.new(json, recurse_over_arrays: true) else json end end |
.request(method, url) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/timestamp_api.rb', line 15 def self.request(method, url) response = RestClient::Request.execute((method, url)) objectify(JSON.parse(response)) rescue JSON::ParserError raise InvalidServerResponse end |
.request_options(method, url) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/timestamp_api.rb', line 22 def self.(method, url) { method: method, url: api_endpoint + url, headers: { "X-API-Key" => api_key || ENV["TIMESTAMP_API_KEY"] || raise(MissingAPIKey), :accept => :json, :user_agent => "TimestampAPI Ruby gem https://github.com/alpinelab/timestamp_api" } } end |