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.



2865
2866
2867
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2865

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.



2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2870

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



2890
2891
2892
2893
2894
2895
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2890

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

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



2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2897

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

#post(organization, quote_form) ⇒ Object



2883
2884
2885
2886
2887
2888
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2883

def post(organization, quote_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  (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_json(quote_form.to_json).post
  ::Io::Flow::V0::Models::Quote.new(r)
end