Class: Io::Flow::V0::Clients::Suggestions

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Suggestions

Returns a new instance of Suggestions.



8655
8656
8657
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 8655

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

Instance Method Details

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

Returns search suggestions for catalog items



8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 8660

def get_catalog(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),
    :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "-count" : x), String)
  }.delete_if { |k, v| v.nil? }
  r = @client.request("/#{CGI.escape(organization)}/suggestion/catalog").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::Suggestion.new(x) }
end