google-refine 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +3 -1
- data/google-refine.gemspec +8 -24
- data/lib/google-refine.rb +75 -21
- metadata +52 -68
data/README.textile
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
<h1>google-refine</h1> is a Ruby Gem client library for "Google Refine":http://code.google.com/p/google-refine/
|
2
2
|
|
3
|
+
If you want to port this to another language, check out the "Refine API":https://github.com/maxogden/refine-python/wiki/Refine-API documentation.
|
4
|
+
|
3
5
|
h2. Install
|
4
6
|
|
5
7
|
@gem install google-refine@
|
@@ -76,5 +78,5 @@ Which outputs:
|
|
76
78
|
|
77
79
|
h2. Copyright
|
78
80
|
|
79
|
-
Copyright (c)
|
81
|
+
Copyright (c) 2011 David Huynh and Max Ogden. See LICENSE for details.
|
80
82
|
|
data/google-refine.gemspec
CHANGED
@@ -5,13 +5,12 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{google-refine}
|
8
|
-
s.version = "0.0
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Max Ogden"]
|
8
|
+
s.version = "0.1.0"
|
9
|
+
s.authors = ["Max Ogden", "Michael Bianco"]
|
12
10
|
s.date = %q{2011-01-22}
|
13
|
-
s.
|
14
|
-
s.
|
11
|
+
s.summary = %q{Client library for interacting with Google Refine instances}
|
12
|
+
s.description = %q{Client library for interacting with Google Refine instances. Easily work with CSVs from the command line}
|
13
|
+
s.email = ['max@maxogden.com', 'info@cliffsidedev.com']
|
15
14
|
s.extra_rdoc_files = [
|
16
15
|
"LICENSE",
|
17
16
|
"README.textile"
|
@@ -27,28 +26,13 @@ Gem::Specification.new do |s|
|
|
27
26
|
"test/operations.json",
|
28
27
|
"test/test.rb"
|
29
28
|
]
|
30
|
-
s.homepage =
|
29
|
+
s.homepage = "http://github.com/maxogden/refine-ruby"
|
31
30
|
s.require_paths = ["lib"]
|
32
|
-
s.rubygems_version = %q{1.3.7}
|
33
|
-
s.summary = %q{Client library for interacting with Google Refine instances}
|
34
31
|
s.test_files = [
|
35
32
|
"test/test.rb"
|
36
33
|
]
|
37
34
|
|
38
|
-
|
39
|
-
|
40
|
-
s.specification_version = 3
|
41
|
-
|
42
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
43
|
-
s.add_runtime_dependency(%q<json>, [">= 1.4.6"])
|
44
|
-
s.add_runtime_dependency(%q<httpclient>, [">= 2.1.6.1"])
|
45
|
-
else
|
46
|
-
s.add_dependency(%q<json>, [">= 1.4.6"])
|
47
|
-
s.add_dependency(%q<httpclient>, [">= 2.1.6.1"])
|
48
|
-
end
|
49
|
-
else
|
50
|
-
s.add_dependency(%q<json>, [">= 1.4.6"])
|
51
|
-
s.add_dependency(%q<httpclient>, [">= 2.1.6.1"])
|
52
|
-
end
|
35
|
+
s.add_dependency('json', ">= 1.4.6")
|
36
|
+
s.add_dependency('httpclient', ">= 2.1.6.1")
|
53
37
|
end
|
54
38
|
|
data/lib/google-refine.rb
CHANGED
@@ -3,21 +3,38 @@ require 'cgi'
|
|
3
3
|
require 'json'
|
4
4
|
|
5
5
|
class Refine
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
attr_reader :project_name
|
7
|
+
attr_reader :project_id
|
8
|
+
|
9
|
+
def self.get_all_project_metadata(server="http://127.0.0.1:3333")
|
10
|
+
uri = "#{server}/command/core/get-all-project-metadata"
|
11
|
+
response = HTTPClient.new(server).get(uri)
|
12
|
+
JSON.parse(response.body)
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(opts = {})
|
16
|
+
@server = opts["server"] || "http://127.0.0.1:3333"
|
17
|
+
@throws_exceptions = opts["throws_exceptions"] || true
|
18
|
+
|
19
|
+
if opts["file_name"] && !opts["file_name"].empty? && opts["project_name"] && !opts["project_name"].empty?
|
20
|
+
project_name = CGI.escape(opts["project_name"])
|
21
|
+
@project_id = create_project(project_name, opts["file_name"])
|
22
|
+
@project_name = project_name if @project_id
|
23
|
+
else
|
24
|
+
@project_id = opts["project_id"]
|
25
|
+
|
26
|
+
metadata = self.get_project_metadata
|
27
|
+
@project_name = CGI.escape(metadata["name"])
|
28
|
+
end
|
11
29
|
end
|
12
30
|
|
13
31
|
def create_project(project_name, file_name)
|
14
32
|
uri = @server + "/command/core/create-project-from-upload"
|
15
33
|
project_id = false
|
16
|
-
client = HTTPClient.new(@server)
|
17
34
|
File.open(file_name) do |file|
|
18
35
|
body = {
|
19
36
|
'project-file' => file,
|
20
|
-
'project-name' =>
|
37
|
+
'project-name' => project_name
|
21
38
|
}
|
22
39
|
response = client.post(uri, body)
|
23
40
|
url = response.header['Location']
|
@@ -29,38 +46,75 @@ class Refine
|
|
29
46
|
project_id
|
30
47
|
end
|
31
48
|
|
32
|
-
def apply_operations(
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
body = {
|
38
|
-
'operations' => file.read
|
39
|
-
}
|
40
|
-
@response = client.post(uri, body)
|
49
|
+
def apply_operations(file_name_or_string)
|
50
|
+
if File.exists?(file_name_or_string)
|
51
|
+
operations = File.read(file_name_or_string)
|
52
|
+
else
|
53
|
+
operations = file_name_or_string
|
41
54
|
end
|
42
|
-
|
55
|
+
|
56
|
+
call('apply-operations', 'operations' => file_name_or_string)
|
43
57
|
end
|
44
58
|
|
45
|
-
def export_rows(
|
59
|
+
def export_rows(opts={})
|
60
|
+
format = opts["format"] || 'tsv'
|
46
61
|
uri = @server + "/command/core/export-rows/#{@project_name}.#{format}"
|
47
|
-
|
62
|
+
|
48
63
|
body = {
|
49
|
-
'engine' =>
|
64
|
+
'engine' => {
|
65
|
+
"facets" => opts["facets"] || [],
|
66
|
+
"mode" => "row-based"
|
67
|
+
}.to_json,
|
68
|
+
'options' => opts["options"] || '',
|
50
69
|
'project' => @project_id,
|
51
70
|
'format' => format
|
52
71
|
}
|
72
|
+
|
53
73
|
@response = client.post(uri, body)
|
54
74
|
@response.content
|
55
75
|
end
|
56
76
|
|
57
77
|
def delete_project
|
58
78
|
uri = @server + "/command/core/delete-project"
|
59
|
-
client = HTTPClient.new(@server)
|
60
79
|
body = {
|
61
80
|
'project' => @project_id
|
62
81
|
}
|
63
82
|
@response = client.post(uri, body)
|
64
83
|
JSON.parse(@response.content)['code'] rescue false
|
65
84
|
end
|
85
|
+
|
86
|
+
# this pattern is pulled from mailchimp/mailchimp-gem
|
87
|
+
|
88
|
+
def call(method, params = {})
|
89
|
+
uri = "#{@server}/command/core/#{method}"
|
90
|
+
params = { "project" => @project_id }.merge(params)
|
91
|
+
|
92
|
+
response = if method.start_with?('get-')
|
93
|
+
client.get(uri, params)
|
94
|
+
else
|
95
|
+
client.post(uri, params)
|
96
|
+
end
|
97
|
+
|
98
|
+
begin
|
99
|
+
response = JSON.parse(response.body)
|
100
|
+
rescue
|
101
|
+
response = JSON.parse('[' + response.body + ']').first
|
102
|
+
end
|
103
|
+
|
104
|
+
if @throws_exceptions && response.is_a?(Hash) && response["code"] && response["code"] == "error"
|
105
|
+
raise "API Error: #{response}"
|
106
|
+
end
|
107
|
+
|
108
|
+
response
|
109
|
+
end
|
110
|
+
|
111
|
+
def method_missing(method, *args)
|
112
|
+
# translate: get_column_info --> get-column-info
|
113
|
+
call(method.to_s.gsub('_', '-'), *args)
|
114
|
+
end
|
115
|
+
|
116
|
+
protected
|
117
|
+
def client
|
118
|
+
@client ||= HTTPClient.new(@server)
|
119
|
+
end
|
66
120
|
end
|
metadata
CHANGED
@@ -1,66 +1,60 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-refine
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 1
|
10
|
-
version: 0.0.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Max Ogden
|
9
|
+
- Michael Bianco
|
14
10
|
autorequire:
|
15
11
|
bindir: bin
|
16
12
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
13
|
+
date: 2011-01-22 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
22
16
|
name: json
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
25
18
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
hash: 11
|
30
|
-
segments:
|
31
|
-
- 1
|
32
|
-
- 4
|
33
|
-
- 6
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
34
22
|
version: 1.4.6
|
35
23
|
type: :runtime
|
36
|
-
version_requirements: *id001
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: httpclient
|
39
24
|
prerelease: false
|
40
|
-
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
26
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 1.4.6
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: httpclient
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
51
38
|
version: 2.1.6.1
|
52
39
|
type: :runtime
|
53
|
-
|
54
|
-
|
55
|
-
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.1.6.1
|
47
|
+
description: Client library for interacting with Google Refine instances. Easily work
|
48
|
+
with CSVs from the command line
|
49
|
+
email:
|
50
|
+
- max@maxogden.com
|
51
|
+
- info@cliffsidedev.com
|
56
52
|
executables: []
|
57
|
-
|
58
53
|
extensions: []
|
59
|
-
|
60
|
-
extra_rdoc_files:
|
54
|
+
extra_rdoc_files:
|
61
55
|
- LICENSE
|
62
56
|
- README.textile
|
63
|
-
files:
|
57
|
+
files:
|
64
58
|
- LICENSE
|
65
59
|
- README.textile
|
66
60
|
- Rakefile
|
@@ -70,39 +64,29 @@ files:
|
|
70
64
|
- test/dates.txt
|
71
65
|
- test/operations.json
|
72
66
|
- test/test.rb
|
73
|
-
has_rdoc: true
|
74
67
|
homepage: http://github.com/maxogden/refine-ruby
|
75
68
|
licenses: []
|
76
|
-
|
77
69
|
post_install_message:
|
78
70
|
rdoc_options: []
|
79
|
-
|
80
|
-
require_paths:
|
71
|
+
require_paths:
|
81
72
|
- lib
|
82
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
74
|
none: false
|
84
|
-
requirements:
|
85
|
-
- -
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
|
88
|
-
|
89
|
-
- 0
|
90
|
-
version: "0"
|
91
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
80
|
none: false
|
93
|
-
requirements:
|
94
|
-
- -
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
|
97
|
-
segments:
|
98
|
-
- 0
|
99
|
-
version: "0"
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
100
85
|
requirements: []
|
101
|
-
|
102
86
|
rubyforge_project:
|
103
|
-
rubygems_version: 1.
|
87
|
+
rubygems_version: 1.8.23
|
104
88
|
signing_key:
|
105
89
|
specification_version: 3
|
106
90
|
summary: Client library for interacting with Google Refine instances
|
107
|
-
test_files:
|
91
|
+
test_files:
|
108
92
|
- test/test.rb
|