Module: Orchestrate::API::Helpers
Overview
Some convenience methods for constructing API requests or reading responses.
Instance Method Summary collapse
-
#format_ref(ref) ⇒ String
Formats the provided 'ref' to be quoted per API specification.
-
#range_keys!(suffix, params) ⇒ Object
Suffixes a params hash for range bounds with the given type.
-
#timestamp(time) ⇒ Integer
Coerces a Date or Time object to Integer Milliseconds, per the Timestamps documentation: http://orchestrate.io/docs/api/#events/timestamps If provided a value other than Date or Time, will return it untouched.
Instance Method Details
#format_ref(ref) ⇒ String
Formats the provided 'ref' to be quoted per API specification.
44 45 46 |
# File 'lib/orchestrate/api/helpers.rb', line 44 def format_ref(ref) "\"#{ref.gsub(/"/,'')}\"" end |
#range_keys!(suffix, params) ⇒ Object
Suffixes a params hash for range bounds with the given type. Modifies the hash in-place.
18 19 20 21 22 23 24 25 26 |
# File 'lib/orchestrate/api/helpers.rb', line 18 def range_keys!(suffix, params) suffix = suffix.capitalize [:start, :end, :before, :after].each do |key| if params[key] params["#{key}#{suffix}"] = params[key] params.delete(key) end end end |
#timestamp(time) ⇒ Integer
Coerces a Date or Time object to Integer Milliseconds, per the Timestamps documentation: http://orchestrate.io/docs/api/#events/timestamps If provided a value other than Date or Time, will return it untouched.
34 35 36 37 38 |
# File 'lib/orchestrate/api/helpers.rb', line 34 def (time) time = time.to_time if time.kind_of?(Date) time = (time.getutc.to_f * 1000).to_i if time.kind_of?(Time) time end |