Class: Io::Flow::V0::Clients::HarmonizedItems

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ HarmonizedItems

Returns a new instance of HarmonizedItems.



2131
2132
2133
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2131

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

Instance Method Details

#delete_by_number(organization, number) ⇒ Object



2172
2173
2174
2175
2176
2177
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2172

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)}/harmonization/items/#{CGI.escape(number)}").delete
  nil
end

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



2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2135

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

#get_by_number(organization, number) ⇒ Object



2156
2157
2158
2159
2160
2161
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2156

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)}/harmonization/items/#{CGI.escape(number)}").get
  ::Io::Flow::V0::Models::HarmonizedItem.new(r)
end

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

Provides visibility into recent changes of each object, including deletion



2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2180

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

#post(organization, harmonized_item_form) ⇒ Object



2149
2150
2151
2152
2153
2154
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2149

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

#put_by_number(organization, number, harmonized_item_put_form) ⇒ Object

Create or update an item to harmonize



2164
2165
2166
2167
2168
2169
2170
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2164

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