Class: Io::Flow::V0::Models::Import

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

Overview

Imports allow you to upload data to Flow via files in batch. Each import fetches data from a given URL. The type of the import determines which file format to expect and what data to update

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ Import

Returns a new instance of Import.



16939
16940
16941
16942
16943
16944
16945
16946
16947
16948
16949
16950
16951
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16939

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:id, :type, :source_url, :status, :created_at, :deliveries], 'Import')
  @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
  @type = (x = opts.delete(:type); x.is_a?(::Io::Flow::V0::Models::ImportType) ? x : ::Io::Flow::V0::Models::ImportType.apply(x))
  @source_url = HttpClient::Preconditions.assert_class('source_url', opts.delete(:source_url), String)
  @status = (x = opts.delete(:status); x.is_a?(::Io::Flow::V0::Models::ExportStatus) ? x : ::Io::Flow::V0::Models::ExportStatus.apply(x))
  @created_at = HttpClient::Preconditions.assert_class('created_at', HttpClient::Helper.to_date_time_iso8601(opts.delete(:created_at)), DateTime)
  @started_at = (x = opts.delete(:started_at); x.nil? ? nil : HttpClient::Preconditions.assert_class('started_at', HttpClient::Helper.to_date_time_iso8601(x), DateTime))
  @completed_at = (x = opts.delete(:completed_at); x.nil? ? nil : HttpClient::Preconditions.assert_class('completed_at', HttpClient::Helper.to_date_time_iso8601(x), DateTime))
  @results = (x = opts.delete(:results); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::ImportResults) ? x : ::Io::Flow::V0::Models::ImportResults.new(x)))
  @deliveries = HttpClient::Preconditions.assert_class('deliveries', opts.delete(:deliveries), Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::ExportDelivery) ? x : ::Io::Flow::V0::Models::ExportDelivery.from_json(x)) }
end

Instance Attribute Details

#completed_atObject (readonly)

Returns the value of attribute completed_at.



16937
16938
16939
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16937

def completed_at
  @completed_at
end

#created_atObject (readonly)

Returns the value of attribute created_at.



16937
16938
16939
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16937

def created_at
  @created_at
end

#deliveriesObject (readonly)

Returns the value of attribute deliveries.



16937
16938
16939
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16937

def deliveries
  @deliveries
end

#idObject (readonly)

Returns the value of attribute id.



16937
16938
16939
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16937

def id
  @id
end

#resultsObject (readonly)

Returns the value of attribute results.



16937
16938
16939
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16937

def results
  @results
end

#source_urlObject (readonly)

Returns the value of attribute source_url.



16937
16938
16939
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16937

def source_url
  @source_url
end

#started_atObject (readonly)

Returns the value of attribute started_at.



16937
16938
16939
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16937

def started_at
  @started_at
end

#statusObject (readonly)

Returns the value of attribute status.



16937
16938
16939
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16937

def status
  @status
end

#typeObject (readonly)

Returns the value of attribute type.



16937
16938
16939
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16937

def type
  @type
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



16957
16958
16959
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16957

def copy(incoming={})
  Import.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
end

#to_hashObject



16961
16962
16963
16964
16965
16966
16967
16968
16969
16970
16971
16972
16973
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16961

def to_hash
  {
    :id => id,
    :type => type.value,
    :source_url => source_url,
    :status => status.value,
    :created_at => created_at,
    :started_at => started_at,
    :completed_at => completed_at,
    :results => results.nil? ? nil : results.to_hash,
    :deliveries => deliveries.map { |o| o.to_hash }
  }
end

#to_jsonObject



16953
16954
16955
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16953

def to_json
  JSON.dump(to_hash)
end