Module: Poms::Api::Search

Defined in:
lib/poms/api/search.rb

Overview

Map search parameters to POMS specific format

Constant Summary collapse

TIME_PARAMS =
{
  starts_at: 'begin',
  ends_at: 'end'
}.freeze

Class Method Summary collapse

Class Method Details

.build(options) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/poms/api/search.rb', line 12

def self.build(options)
  return {} if options.empty?
  all = options.map do |key, value|
    case key
    when :starts_at, :ends_at
      time_params(key, value)
    when :type
      { 'searches' => { 'types' => value } }
    end
  end
  all.reduce(&:deep_merge)
end

.time_params(key, value) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/poms/api/search.rb', line 27

def self.time_params(key, value)
  {
    'searches' => {
      'sortDates' => {
        TIME_PARAMS[key] => Timestamp.to_unix_ms(value)
      }
    }
  }
end