Module: Orchestrate::API::Helpers

Extended by:
Helpers
Included in:
Helpers
Defined in:
lib/orchestrate/api/helpers.rb

Overview

Some convenience methods for constructing API requests or reading responses.

Instance Method Summary collapse

Instance Method Details

#format_ref(ref) ⇒ String

Formats the provided 'ref' to be quoted per API specification.

Parameters:

  • ref (String)

    The ref desired.

Returns:

  • (String)

    The ref, quoted. If already quoted, does not double-quote.



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.

Examples:

Transforming an Event Range

keys = { start: Value }
Orchestrate::Helpers.range_keys!('event', keys)
keys #=> { startEvent: Value }

Parameters:

  • suffix (String)

    the suffix for the range keys

  • params (Hash{Symbol=>Value})

Options Hash (params):

  • :start (Object)

    The inclusive start of the range

  • :after (Object)

    The exclusive start of the range

  • :before (Object)

    The exclusive end of the range

  • :end (Object)

    The inclusive end of the range



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.

Returns The timestamp in integer milliseconds since epoch.

Parameters:

  • time (Date, Time)

    The timestamp in Date or Time form.

Returns:

  • (Integer)

    The timestamp in integer milliseconds since epoch.



34
35
36
37
38
# File 'lib/orchestrate/api/helpers.rb', line 34

def timestamp(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