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.



1757
1758
1759
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1757

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



1802
1803
1804
1805
1806
1807
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1802

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.



1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1762

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.



1785
1786
1787
1788
1789
1790
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1785

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



1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1810

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



1777
1778
1779
1780
1781
1782
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1777

def post(organization, item_function_post_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  (x = item_function_post_form; x.is_a?(::Io::Flow::V0::Models::ItemFunctionPostForm) ? x : ::Io::Flow::V0::Models::ItemFunctionPostForm.new(x))
  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



1793
1794
1795
1796
1797
1798
1799
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1793

def put_by_key(organization, key, item_function_put_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('key', key, String)
  (x = item_function_put_form; x.is_a?(::Io::Flow::V0::Models::ItemFunctionPutForm) ? x : ::Io::Flow::V0::Models::ItemFunctionPutForm.new(x))
  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