Class: Origami::Importer::Batch

Inherits:
Object
  • Object
show all
Defined in:
lib/origami-importer/batch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Batch

Returns a new instance of Batch.



6
7
8
9
10
11
# File 'lib/origami-importer/batch.rb', line 6

def initialize(options)
  self.endpoint = options[:host]
  self.realm = options[:realm]
  self.source = options[:source]
  self.session = options[:session]
end

Instance Attribute Details

#endpointObject

Returns the value of attribute endpoint.



5
6
7
# File 'lib/origami-importer/batch.rb', line 5

def endpoint
  @endpoint
end

#realmObject

Returns the value of attribute realm.



5
6
7
# File 'lib/origami-importer/batch.rb', line 5

def realm
  @realm
end

#remoteObject

Returns the value of attribute remote.



5
6
7
# File 'lib/origami-importer/batch.rb', line 5

def remote
  @remote
end

#sessionObject

Returns the value of attribute session.



5
6
7
# File 'lib/origami-importer/batch.rb', line 5

def session
  @session
end

#sourceObject

Returns the value of attribute source.



5
6
7
# File 'lib/origami-importer/batch.rb', line 5

def source
  @source
end

Instance Method Details

#clientObject



13
14
15
16
17
18
19
20
# File 'lib/origami-importer/batch.rb', line 13

def client
  unless @client
    origami_host = endpoint
    Pebblebed.config { host origami_host }
    @client = Pebblebed::Connector.new(session).origami
  end
  @client
end

#close(data) ⇒ Object



35
36
37
38
39
# File 'lib/origami-importer/batch.rb', line 35

def close(data)
  url = "/#{realm}/batches/#{remote.id}/close"
  puts "posting to #{url}, :relay => #{data.inspect}"
  client.post url, :relay => data
end

#deleteObject



41
42
43
# File 'lib/origami-importer/batch.rb', line 41

def delete
  client.delete "/#{realm}/batches/#{remote.id}"
end

#openObject



22
23
24
25
# File 'lib/origami-importer/batch.rb', line 22

def open
  result = client.post "/#{realm}/batches", {:batch => {:source => source}}
  self.remote = result.batch
end

#relayObject



27
28
29
# File 'lib/origami-importer/batch.rb', line 27

def relay
  remote.relay || {:previous_import_at => Time.now.utc}
end

#save(records) ⇒ Object



31
32
33
# File 'lib/origami-importer/batch.rb', line 31

def save(records)
  client.post "/#{realm}/batches/#{remote.id}/items", records
end