class Wavefront::Search

Manage and query Wavefront searches. The /search API path has a lot of paths, with a lot of duplication. The current state of this class covers the whole API with two methods, but leaves a lot up to the user. It may grow, with convenience methods.

Public Instance Methods

body(query, options) click to toggle source

Build a query body

# File lib/wavefront-sdk/search.rb, line 50
def body(query, options)
  ret = query_limits(options)

  if query && !query.empty?
    ret[:query] = [query].flatten.map do |q|
      q.tap { |iq| iq[:matchingMethod] ||= 'CONTAINS' }
    end

    ret[:sort] = sort_field(options, query)
  end

  ret
end
query_limits(options) click to toggle source
# File lib/wavefront-sdk/search.rb, line 64
def query_limits(options)
  { limit: options[:limit] || 10 }.tap do |ret|
    if options[:cursor]
      ret[:cursor] = options[:cursor]
    else
      ret[:offset] = options[:offset] || 0
    end
  end
end
sort_field(options, query) click to toggle source
# File lib/wavefront-sdk/search.rb, line 74
def sort_field(options, query)
  field = options[:sort_field] || [query].flatten.first[:key]

  { field: field,
    ascending: !options[:desc] || true }
end