Class: Io::Flow::V0::Clients::Quotes
- Inherits:
-
Object
- Object
- Io::Flow::V0::Clients::Quotes
- Defined in:
- lib/flow_commerce/flow_api_v0_client.rb
Instance Method Summary collapse
-
#get(organization, incoming = {}) ⇒ Object
Search quotes.
- #get_by_id(organization, id) ⇒ Object
- #get_versions(organization, incoming = {}) ⇒ Object
-
#initialize(client) ⇒ Quotes
constructor
A new instance of Quotes.
- #post(organization, quote_form) ⇒ Object
Constructor Details
#initialize(client) ⇒ Quotes
Returns a new instance of Quotes.
3136 3137 3138 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3136 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.
3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3141 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
3161 3162 3163 3164 3165 3166 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3161 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
3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3168 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
3154 3155 3156 3157 3158 3159 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3154 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 |