google_refine 0.2.1344409076 → 0.3.1348632596

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/upload-to-refine +5 -1
  2. data/lib/google_refine.rb +23 -20
  3. metadata +3 -3
data/bin/upload-to-refine CHANGED
@@ -7,6 +7,10 @@ require 'tempfile'
7
7
 
8
8
  opts = Trollop::options do
9
9
  opt :host, "Address of Google Refine", :default => '0.0.0.0:3333'
10
+ opt :project_name, 'Project name'
11
+ opt :header_lines, 'Header lines', :default => 0
12
+ opt :process_qoutes
13
+ opt :limit, :default => 0
10
14
  end
11
15
 
12
16
 
@@ -38,6 +42,6 @@ end
38
42
 
39
43
  refine = Refine.new(host)
40
44
 
41
- puts refine.create_project(file, :projectName => file)
45
+ puts refine.create_project(file, opts)
42
46
 
43
47
  tempfile.unlink if not tempfile.nil?
data/lib/google_refine.rb CHANGED
@@ -83,25 +83,23 @@ class Refine
83
83
  JSON[response]['version']
84
84
  end
85
85
 
86
+
86
87
  def create_project(filename, param = {})
87
88
 
88
- options = {}
89
- options[:format] = param[:format]
90
- options[:projectName] = param[:name] || "File \"#{filename}\""
91
- options[:encoding] = param[:encoding] || "UTF-8"
92
- options[:separator] = param[:separator] || "\\t"
93
- options[:ignoreLines] = param[:ignoreLines] || -1
94
- options[:headerLines] = param[:headerLines] || 0
95
- options[:skipDataLines] = param[:skipDataLines] || 0
96
- options[:limit] = param[:limit] || 1_000_000
97
- options[:storeBlankRows] = param[:storeBlankRows] || true
98
- options[:guessCellValueTypes] = param[:guessCellValueTypes] || true
99
- options[:processQuotes] = param[:processQuotes] || false
100
- options[:storeBlankCellsAsNulls] = param[:storeBlankCellsAsNulls] || true
101
- options[:includeFileSources] = param[:includeFileSources] || false
89
+
90
+ param[:project_name] ||= File.basename(filename)
102
91
 
103
92
  if self.version >= "2.5"
104
93
  begin
94
+ options = {}
95
+ options[:projectName] = param[:project_name]
96
+ options[:encoding] = param[:encoding] || "UTF-8"
97
+ options[:separator] = param[:separator] || "\\t"
98
+ options[:headerLines] = param[:header_lines] || 0
99
+ options[:limit] = param[:limit]
100
+ options[:guessCellValueTypes] = param[:guess_value_type] || false
101
+ options[:processQuotes] = param[:process_quotes] || false
102
+
105
103
  job = create_importing_job
106
104
  job.load_raw_data(filename)
107
105
  project = job.create_project(options)
@@ -109,14 +107,19 @@ class Refine
109
107
  ensure
110
108
  job.cancel if job
111
109
  end
112
- elsif self.version == "2.0"
110
+ elsif [ "2.0", "2.1" ].include?(self.version)
113
111
  begin
114
112
  RestClient.post("#{self.url}/command/core/create-project-from-upload",
115
- :'project-name' => options[:projectName],
116
- :'guess-value-type' => options[:guessCellValueTypes],
117
- :'header-lines' => options[:headerLines],
118
- :'limit' => options[:limit],
119
- :'project-file' => File.new(filename, "rb"))
113
+ Hash[
114
+ { project_name: param[:project_name],
115
+ header_lines: param[:header_lines],
116
+ limit: param[:limit],
117
+ guess_value_type: param[:guess_value_type],
118
+ ignore_quotes: ! param[:process_quotes],
119
+ project_file: File.new(filename, "rb")
120
+ }.map { |key, value| [ key.to_s.gsub('_', '-'), value ] }
121
+ ]
122
+ )
120
123
  rescue RestClient::Found
121
124
  project_id = $!.response.headers[:location].match(/project=(\d+)/)[1]
122
125
  Project.new(self, project_id)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_refine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1344409076
4
+ version: 0.3.1348632596
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-08 00:00:00.000000000 Z
12
+ date: 2012-09-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
73
  version: '0'
74
74
  requirements: []
75
75
  rubyforge_project:
76
- rubygems_version: 1.8.23
76
+ rubygems_version: 1.8.24
77
77
  signing_key:
78
78
  specification_version: 3
79
79
  summary: Upload to Google Refine.