Class: Io::Flow::V0::Clients::ItemFunctions

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ ItemFunctions

Returns a new instance of ItemFunctions.



1396
1397
1398
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1396

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

Instance Method Details

#delete_by_key(organization, key) ⇒ Object

Delete the item function with this key



1441
1442
1443
1444
1445
1446
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1441

def delete_by_key(organization, key)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('key', key, String)
  r = @client.request("/#{CGI.escape(organization)}/item-functions/#{CGI.escape(key)}").delete
  nil
end

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

Search item functions. Always paginated.



1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1401

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) }),
    :key => (x = opts.delete(:key); x.nil? ? nil : HttpClient::Preconditions.assert_class('key', x, Array).map { |v| HttpClient::Preconditions.assert_class('key', 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)}/item-functions").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::ItemFunction.new(x) }
end

#get_by_key(organization, key) ⇒ Object

Returns information about a specific item function.



1424
1425
1426
1427
1428
1429
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1424

def get_by_key(organization, key)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('key', key, String)
  r = @client.request("/#{CGI.escape(organization)}/item-functions/#{CGI.escape(key)}").get
  ::Io::Flow::V0::Models::ItemFunction.new(r)
end

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

Provides visibility into recent changes of each object, including deletion



1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1449

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

#post(organization, item_function_post_form) ⇒ Object

Create item function



1416
1417
1418
1419
1420
1421
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1416

def post(organization, item_function_post_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('item_function_post_form', item_function_post_form, ::Io::Flow::V0::Models::ItemFunctionPostForm)
  r = @client.request("/#{CGI.escape(organization)}/item-functions").with_json(item_function_post_form.to_json).post
  ::Io::Flow::V0::Models::ItemFunction.new(r)
end

#put_by_key(organization, key, item_function_put_form) ⇒ Object

Upsert item function



1432
1433
1434
1435
1436
1437
1438
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1432

def put_by_key(organization, key, item_function_put_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('key', key, String)
  HttpClient::Preconditions.assert_class('item_function_put_form', item_function_put_form, ::Io::Flow::V0::Models::ItemFunctionPutForm)
  r = @client.request("/#{CGI.escape(organization)}/item-functions/#{CGI.escape(key)}").with_json(item_function_put_form.to_json).put
  ::Io::Flow::V0::Models::ItemFunction.new(r)
end