Class: Job

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(refine, id) ⇒ Job

Returns a new instance of Job.



24
25
26
27
# File 'lib/google_refine.rb', line 24

def initialize(refine, id)
  self.refine = refine
  self.id = id
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



21
22
23
# File 'lib/google_refine.rb', line 21

def id
  @id
end

#refineObject

Returns the value of attribute refine.



22
23
24
# File 'lib/google_refine.rb', line 22

def refine
  @refine
end

Instance Method Details

#cancelObject



54
55
56
# File 'lib/google_refine.rb', line 54

def cancel
  RestClient.post("#{self.refine.url}/command/core/cancel-importing-job?jobID=#{self.id}", nil)
end

#create_project(options) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/google_refine.rb', line 39

def create_project(options)
  RestClient.post("#{self.refine.url}/command/core/importing-controller?controller=core%2Fdefault-importing-controller&jobID=#{self.id}&subCommand=create-project",
    :format => "text/line-based/*sv",
    :options => options.to_json)

  project_id = nil
  while project_id.nil?
    sleep 2
    response = RestClient.post("#{self.refine.url}/command/core/get-importing-job-status?jobID=#{self.id}", nil)
    project_id = JSON[response]["job"]["config"]["projectID"]
  end

  Project.new(self.refine, project_id)
end

#load_raw_data(filename) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/google_refine.rb', line 29

def load_raw_data(filename)
  RestClient.post("#{self.refine.url}/command/core/importing-controller?controller=core%2Fdefault-importing-controller&jobID=#{self.id}&subCommand=load-raw-data", :upload => File.new(filename, "rb"))

  while true
    sleep 2
    status = RestClient.post("#{self.refine.url}/command/core/get-importing-job-status?jobID=#{self.id}", nil)
    break if JSON[status]["job"]["config"]["state"] == "ready"
  end
end