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.



1104
1105
1106
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1104

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



1164
1165
1166
1167
1168
1169
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1164

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.



1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1109

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.



1147
1148
1149
1150
1151
1152
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1147

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



1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1132

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)



1124
1125
1126
1127
1128
1129
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1124

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.



1155
1156
1157
1158
1159
1160
1161
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1155

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.



1172
1173
1174
1175
1176
1177
1178
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1172

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