Class: Io::Flow::V0::Clients::ItemQuerySuggestions

Inherits:
Object
  • Object
show all
Defined in:
lib/flow_commerce/flow_api_v0_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ ItemQuerySuggestions

Returns a new instance of ItemQuerySuggestions.



7316
7317
7318
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7316

def initialize(client)
  @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::V0::Client)
end

Instance Method Details

#get(organization, incoming = {}) ⇒ Object

Returns search suggestions for catalog items



7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7321

def get(organization, incoming={})
  HttpClient::Preconditions.assert_class('organization', organization, String)
  opts = HttpClient::Helper.symbolize_keys(incoming)
  query = {
    :q => (x = opts.delete(:q); x.nil? ? nil : HttpClient::Preconditions.assert_class('q', x, String)),
    :limit => HttpClient::Preconditions.assert_class('limit', (x = opts.delete(:limit); x.nil? ? 25 : x), Integer),
    :offset => HttpClient::Preconditions.assert_class('offset', (x = opts.delete(:offset); x.nil? ? 0 : x), Integer)
  }.delete_if { |k, v| v.nil? }
  r = @client.request("/#{CGI.escape(organization)}/search/item/query/suggestions").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::ItemQuerySuggestion.new(x) }
end