Class: Io::Flow::V0::Clients::Imports

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Imports



4234
4235
4236
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4234

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

Instance Method Details

#delete_by_id(organization, id) ⇒ Object



4270
4271
4272
4273
4274
4275
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4270

def delete_by_id(organization, id)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('id', id, String)
  r = @client.request("/#{CGI.escape(organization)}/imports/#{CGI.escape(id)}").delete
  nil
end

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

Search imports. Always paginated.



4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4239

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) }),
    :created_by_user_id => (x = opts.delete(:created_by_user_id); x.nil? ? nil : HttpClient::Preconditions.assert_class('created_by_user_id', x, String)),
    :type => (x = opts.delete(:type); x.nil? ? nil : HttpClient::Preconditions.assert_class('type', x, 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)}/imports").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::Import.new(x) }
end

#get_by_id(organization, id) ⇒ Object

Get a single import.



4263
4264
4265
4266
4267
4268
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4263

def get_by_id(organization, id)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('id', id, String)
  r = @client.request("/#{CGI.escape(organization)}/imports/#{CGI.escape(id)}").get
  ::Io::Flow::V0::Models::Import.new(r)
end

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

Provides visibility into recent changes of each import, including deletion.



4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4278

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

#post(organization, import_form) ⇒ Object

Create an import.



4255
4256
4257
4258
4259
4260
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4255

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