Class: Job

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

Instance Method Summary collapse

Constructor Details

#initialize(refine, id) ⇒ Job

Returns a new instance of Job.


17
18
19
20
# File 'lib/google_refine_api.rb', line 17

def initialize(refine, id)
  @refine = refine
  @id = id
end

Instance Method Details

#cancelObject


48
49
50
# File 'lib/google_refine_api.rb', line 48

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

#create_project(options) ⇒ Object


33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/google_refine_api.rb', line 33

def create_project(options)
  RestClient.post("#{@refine.uri}/command/core/importing-controller?controller=core%2Fdefault-importing-controller&jobID=#{@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("#{@refine.uri}/command/core/get-importing-job-status?jobID=#{@id}", nil)
    project_id = JSON[response]["job"]["config"]["projectID"]
  end

  Project.new(@refine, project_id)
end

#load_raw_data(upload) ⇒ Object


22
23
24
25
26
27
28
29
30
31
# File 'lib/google_refine_api.rb', line 22

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

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