Class: Io::Flow::V0::Clients::Quotes

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Quotes

Returns a new instance of Quotes.



4336
4337
4338
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4336

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

Instance Method Details

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

Search quotes. Always paginated.



4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4341

def get(organization, incoming={})
  HttpClient::Preconditions.assert_class('organization', organization, String)
  opts = HttpClient::Helper.symbolize_keys(incoming)
  query = {
    :id => (x = opts.delete(:id); x.nil? ? nil : HttpClient::Preconditions.assert_class('id', x, Array).map { |v| HttpClient::Preconditions.assert_class('id', v, 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? ? "-created_at" : x), String)
  }.delete_if { |k, v| v.nil? }
  r = @client.request("/#{CGI.escape(organization)}/quotes").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::Quote.new(x) }
end

#get_by_id(organization, id) ⇒ Object



4365
4366
4367
4368
4369
4370
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4365

def get_by_id(organization, id)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('id', id, String)
  r = @client.request("/#{CGI.escape(organization)}/quotes/#{CGI.escape(id)}").get
  ::Io::Flow::V0::Models::Quote.new(r)
end

#post(organization, quote_form, incoming = {}) ⇒ Object



4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4354

def post(organization, quote_form, incoming={})
  HttpClient::Preconditions.assert_class('organization', organization, String)
  opts = HttpClient::Helper.symbolize_keys(incoming)
  query = {
    :context => (x = opts.delete(:context); x.nil? ? nil : HttpClient::Preconditions.assert_class('context', x, String))
  }.delete_if { |k, v| v.nil? }
  (x = quote_form; x.is_a?(::Io::Flow::V0::Models::QuoteForm) ? x : ::Io::Flow::V0::Models::QuoteForm.new(x))
  r = @client.request("/#{CGI.escape(organization)}/quotes").with_query(query).with_json(quote_form.to_json).post
  ::Io::Flow::V0::Models::Quote.new(r)
end