Class: Io::Flow::V0::Clients::InventoryRules

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ InventoryRules

Returns a new instance of InventoryRules.



2430
2431
2432
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2430

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

Instance Method Details

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



2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2434

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)}/inventory_rules").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::InventoryRule.new(x) }
end

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



2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2454

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) }),
    :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)}/inventory_rules/versions").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::InventoryRuleVersion.new(x) }
end

#post(organization, inventory_rule_form) ⇒ Object



2447
2448
2449
2450
2451
2452
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2447

def post(organization, inventory_rule_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('inventory_rule_form', inventory_rule_form, ::Io::Flow::V0::Models::InventoryRuleForm)
  r = @client.request("/#{CGI.escape(organization)}/inventory_rules").with_json(inventory_rule_form.to_json).post
  ::Io::Flow::V0::Models::InventoryRule.new(r)
end