Class: Refine

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ Refine

Returns a new instance of Refine.


57
58
59
# File 'lib/google_refine_api.rb', line 57

def initialize (uri)
  @uri = uri
end

Instance Attribute Details

#uriObject

Returns the value of attribute uri


55
56
57
# File 'lib/google_refine_api.rb', line 55

def uri
  @uri
end

Instance Method Details

#create_importing_jobObject


61
62
63
64
65
66
# File 'lib/google_refine_api.rb', line 61

def create_importing_job
  response = RestClient.post("#{@uri}/command/core/create-importing-job", nil)
  job_id = JSON[response]["jobID"]
  warn response
  Job.new(self, job_id)
end

#create_project(upload, param = {}) ⇒ Object


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/google_refine_api.rb', line 68

def create_project (upload, param = {})

  default_options = {
    :"encoding" => "",
    :"separator" => "\\t",
    :"ignoreLines" => -1,
    :"headerLines" => 0,
    :"skipDataLines" => 0,
    :"limit" => 1000000,
    :"storeBlankRows" => true,
    :"guessCellValueTypes" => true,
    :"processQuotes" => false,
    :"storeBlankCellsAsNulls" => true,
    :"includeFileSources" => false,
    :"projectName" => "Uploaded by Google Refine API" 
  }

  format = param[:format]

  param[:options] ||= {}

  options = default_options.update(param[:options])

  job = create_importing_job
  job.load_raw_data(upload)
  project = job.create_project(options)
  project
  ensure
    job.cancel if job
end