Class: Io::Flow::V0::Clients::Items
- Inherits:
-
Object
- Object
- Io::Flow::V0::Clients::Items
- Defined in:
- lib/flow_commerce/flow_api_v0_client.rb
Instance Method Summary collapse
-
#delete_by_number(organization, number) ⇒ Object
Delete the item with this number.
-
#get(organization, incoming = {}) ⇒ Object
Search items.
-
#get_by_number(organization, number) ⇒ Object
Returns information about a specific item.
-
#get_versions(organization, incoming = {}) ⇒ Object
Provides visibility into recent changes of each object, including deletion.
-
#initialize(client) ⇒ Items
constructor
A new instance of Items.
-
#post(organization, item_form) ⇒ Object
Add catalog item(s).
-
#put_by_number(organization, number, item_form) ⇒ Object
Update item with the specified number, creating if it does not exist.
Constructor Details
#initialize(client) ⇒ Items
Returns a new instance of Items.
780 781 782 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 780 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
825 826 827 828 829 830 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 825 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.
785 786 787 788 789 790 791 792 793 794 795 796 797 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 785 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.
808 809 810 811 812 813 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 808 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
833 834 835 836 837 838 839 840 841 842 843 844 845 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 833 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 |
#post(organization, item_form) ⇒ Object
Add catalog item(s)
800 801 802 803 804 805 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 800 def post(organization, item_form) HttpClient::Preconditions.assert_class('organization', organization, String) HttpClient::Preconditions.assert_class('item_form', item_form, ::Io::Flow::V0::Models::ItemForm) 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.
816 817 818 819 820 821 822 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 816 def put_by_number(organization, number, item_form) HttpClient::Preconditions.assert_class('organization', organization, String) HttpClient::Preconditions.assert_class('number', number, String) HttpClient::Preconditions.assert_class('item_form', item_form, ::Io::Flow::V0::Models::ItemForm) 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 |