Sha256: 53ae44b1c665f9d6b70044e046d4b420208ec5517dff18cfed296ffe774c8040

Contents?: true

Size: 809 Bytes

Versions: 6

Compression:

Stored size: 809 Bytes

Contents

require 'poms/timestamp'

module Poms
  module Api
    # Map search parameters to POMS specific format
    module Search
      TIME_PARAMS = {
        starts_at: 'begin',
        ends_at: 'end'
      }.freeze

      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

      private_class_method

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
poms-2.1.3 lib/poms/api/search.rb
poms-2.1.2.1 lib/poms/api/search.rb
poms-2.1.2 lib/poms/api/search.rb
poms-2.1.1 lib/poms/api/search.rb
poms-2.1.0 lib/poms/api/search.rb
poms-2.0.1 lib/poms/api/search.rb