Class: Io::Flow::V0::Clients::Items

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Items

Returns a new instance of Items.



1799
1800
1801
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1799

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

Instance Method Details

#delete_by_number(organization, number) ⇒ Object

Delete the item with this number



1859
1860
1861
1862
1863
1864
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1859

def delete_by_number(organization, number)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('number', number, String)
  r = @client.request("/#{CGI.escape(organization)}/catalog/items/#{CGI.escape(number)}").delete
  nil
end

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

Search items. Always paginated.



1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1804

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

#get_by_number(organization, number) ⇒ Object

Returns information about a specific item.



1842
1843
1844
1845
1846
1847
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1842

def get_by_number(organization, number)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('number', number, String)
  r = @client.request("/#{CGI.escape(organization)}/catalog/items/#{CGI.escape(number)}").get
  ::Io::Flow::V0::Models::Item.new(r)
end

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

Provides visibility into recent changes of each object, including deletion



1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1827

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

#patch_attributes_by_number(organization, number, item_attributes_patch_form) ⇒ Object

Update item with the specified attributes.



1867
1868
1869
1870
1871
1872
1873
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1867

def patch_attributes_by_number(organization, number, item_attributes_patch_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('number', number, String)
  (x = item_attributes_patch_form; x.is_a?(::Io::Flow::V0::Models::ItemAttributesPatchForm) ? x : ::Io::Flow::V0::Models::ItemAttributesPatchForm.new(x))
  r = @client.request("/#{CGI.escape(organization)}/catalog/items/#{CGI.escape(number)}/attributes").with_json(item_attributes_patch_form.to_json).patch
  ::Io::Flow::V0::Models::Item.new(r)
end

#post(organization, item_form) ⇒ Object

Add catalog item(s)



1819
1820
1821
1822
1823
1824
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1819

def post(organization, item_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  (x = item_form; x.is_a?(::Io::Flow::V0::Models::ItemForm) ? x : ::Io::Flow::V0::Models::ItemForm.new(x))
  r = @client.request("/#{CGI.escape(organization)}/catalog/items").with_json(item_form.to_json).post
  ::Io::Flow::V0::Models::Item.new(r)
end

#put_by_number(organization, number, item_form) ⇒ Object

Update item with the specified number, creating if it does not exist.



1850
1851
1852
1853
1854
1855
1856
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1850

def put_by_number(organization, number, item_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('number', number, String)
  (x = item_form; x.is_a?(::Io::Flow::V0::Models::ItemForm) ? x : ::Io::Flow::V0::Models::ItemForm.new(x))
  r = @client.request("/#{CGI.escape(organization)}/catalog/items/#{CGI.escape(number)}").with_json(item_form.to_json).put
  ::Io::Flow::V0::Models::Item.new(r)
end

#put_price_by_number(organization, number, item_price_update_put_form) ⇒ Object

Update item with the specified number, creating if it does not exist.



1876
1877
1878
1879
1880
1881
1882
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1876

def put_price_by_number(organization, number, item_price_update_put_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('number', number, String)
  (x = item_price_update_put_form; x.is_a?(::Io::Flow::V0::Models::ItemPriceUpdatePutForm) ? x : ::Io::Flow::V0::Models::ItemPriceUpdatePutForm.new(x))
  r = @client.request("/#{CGI.escape(organization)}/catalog/items/#{CGI.escape(number)}/price").with_json(item_price_update_put_form.to_json).put
  ::Io::Flow::V0::Models::Item.new(r)
end