google_refine 0.1 → 0.2.1344409076

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/google_refine.rb +32 -9
  2. metadata +6 -5
data/lib/google_refine.rb CHANGED
@@ -58,6 +58,7 @@ class Job
58
58
  end
59
59
 
60
60
  class Refine
61
+
61
62
  attr_accessor :url
62
63
 
63
64
  def initialize(url)
@@ -77,12 +78,17 @@ class Refine
77
78
  Job.new(self, job_id)
78
79
  end
79
80
 
81
+ def version
82
+ response = RestClient.get("#{self.url}/command/core/get-version")
83
+ JSON[response]['version']
84
+ end
85
+
80
86
  def create_project(filename, param = {})
81
87
 
82
88
  options = {}
83
89
  options[:format] = param[:format]
84
- options[:projectName] = param[:name] || "File \"#{filename}\" uploaded on #{Time.now}"
85
- options[:encoding] = param[:encoding] || ""
90
+ options[:projectName] = param[:name] || "File \"#{filename}\""
91
+ options[:encoding] = param[:encoding] || "UTF-8"
86
92
  options[:separator] = param[:separator] || "\\t"
87
93
  options[:ignoreLines] = param[:ignoreLines] || -1
88
94
  options[:headerLines] = param[:headerLines] || 0
@@ -93,13 +99,30 @@ class Refine
93
99
  options[:processQuotes] = param[:processQuotes] || false
94
100
  options[:storeBlankCellsAsNulls] = param[:storeBlankCellsAsNulls] || true
95
101
  options[:includeFileSources] = param[:includeFileSources] || false
96
-
97
- job = create_importing_job
98
- job.load_raw_data(filename)
99
- project = job.create_project(options)
100
- project
101
- ensure
102
- job.cancel if job
102
+
103
+ if self.version >= "2.5"
104
+ begin
105
+ job = create_importing_job
106
+ job.load_raw_data(filename)
107
+ project = job.create_project(options)
108
+ project
109
+ ensure
110
+ job.cancel if job
111
+ end
112
+ elsif self.version == "2.0"
113
+ begin
114
+ 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"))
120
+ rescue RestClient::Found
121
+ project_id = $!.response.headers[:location].match(/project=(\d+)/)[1]
122
+ Project.new(self, project_id)
123
+ end
124
+ end
125
+
103
126
  end
104
127
 
105
128
  end
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.1'
4
+ version: 0.2.1344409076
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-07-01 00:00:00.000000000 Z
12
+ date: 2012-08-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -43,8 +43,9 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
- description:
47
- email: guangnan@chengguangnan.com
46
+ description: Ruby library and command line executables for uploading tab files into
47
+ Google Refine (v2.0 and v2.5).
48
+ email: me@chengguangnan.com
48
49
  executables:
49
50
  - upload-to-refine
50
51
  extensions: []
@@ -75,5 +76,5 @@ rubyforge_project:
75
76
  rubygems_version: 1.8.23
76
77
  signing_key:
77
78
  specification_version: 3
78
- summary: Upload files to refine using command line or programmtically.
79
+ summary: Upload to Google Refine.
79
80
  test_files: []