chimps 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -9
- data/Gemfile.lock +14 -10
- data/README.rdoc +146 -240
- data/Rakefile +4 -33
- data/VERSION +1 -1
- data/lib/chimps/config.rb +35 -21
- data/lib/chimps/{utils/error.rb → error.rb} +1 -12
- data/lib/chimps/query_request.rb +67 -0
- data/lib/chimps/request.rb +82 -108
- data/lib/chimps/response.rb +62 -22
- data/lib/chimps/utils/typewriter.rb +90 -0
- data/lib/chimps/utils/uses_curl.rb +22 -12
- data/lib/chimps/utils.rb +50 -6
- data/lib/chimps/workflows/download.rb +72 -0
- data/lib/chimps/workflows/upload.rb +113 -0
- data/lib/chimps.rb +12 -12
- data/spec/chimps/query_request_spec.rb +44 -0
- data/spec/chimps/request_spec.rb +92 -0
- data/spec/chimps/response_spec.rb +0 -1
- data/spec/chimps/workflows/download_spec.rb +48 -0
- data/spec/spec_helper.rb +2 -19
- metadata +46 -91
- data/.document +0 -5
- data/.gitignore +0 -32
- data/CHANGELOG.textile +0 -4
- data/bin/chimps +0 -5
- data/lib/chimps/cli.rb +0 -28
- data/lib/chimps/commands/base.rb +0 -65
- data/lib/chimps/commands/batch.rb +0 -40
- data/lib/chimps/commands/create.rb +0 -31
- data/lib/chimps/commands/destroy.rb +0 -26
- data/lib/chimps/commands/download.rb +0 -46
- data/lib/chimps/commands/help.rb +0 -100
- data/lib/chimps/commands/list.rb +0 -41
- data/lib/chimps/commands/query.rb +0 -82
- data/lib/chimps/commands/search.rb +0 -48
- data/lib/chimps/commands/show.rb +0 -30
- data/lib/chimps/commands/test.rb +0 -39
- data/lib/chimps/commands/update.rb +0 -34
- data/lib/chimps/commands/upload.rb +0 -50
- data/lib/chimps/commands.rb +0 -125
- data/lib/chimps/typewriter.rb +0 -349
- data/lib/chimps/utils/log.rb +0 -48
- data/lib/chimps/utils/uses_model.rb +0 -34
- data/lib/chimps/utils/uses_yaml_data.rb +0 -93
- data/lib/chimps/workflows/batch.rb +0 -127
- data/lib/chimps/workflows/downloader.rb +0 -102
- data/lib/chimps/workflows/up.rb +0 -149
- data/lib/chimps/workflows/upload/bundler.rb +0 -249
- data/lib/chimps/workflows/upload/notifier.rb +0 -59
- data/lib/chimps/workflows/upload/token.rb +0 -77
- data/lib/chimps/workflows/upload/uploader.rb +0 -51
- data/lib/chimps/workflows.rb +0 -12
- data/spec/chimps/typewriter_spec.rb +0 -114
- data/spec/chimps/workflows/upload/bundler_spec.rb +0 -75
- data/spec/chimps/workflows/upload/token_spec.rb +0 -6
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dhruv Bansal
|
@@ -15,61 +15,43 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
19
|
-
default_executable:
|
18
|
+
date: 2011-03-25 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name: rest-client
|
23
22
|
prerelease: false
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
hash: 1
|
30
|
-
segments:
|
31
|
-
- 1
|
32
|
-
- 5
|
33
|
-
- 1
|
34
|
-
version: 1.5.1
|
35
|
-
type: :runtime
|
36
|
-
version_requirements: *id001
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
23
|
name: json
|
39
|
-
|
40
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
24
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
41
25
|
none: false
|
42
26
|
requirements:
|
43
27
|
- - ">="
|
44
28
|
- !ruby/object:Gem::Version
|
45
|
-
hash:
|
29
|
+
hash: 3
|
46
30
|
segments:
|
47
|
-
-
|
48
|
-
|
49
|
-
|
50
|
-
version: 1.4.3
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
requirement: *id001
|
51
34
|
type: :runtime
|
52
|
-
version_requirements: *id002
|
53
35
|
- !ruby/object:Gem::Dependency
|
54
|
-
name: imw
|
55
36
|
prerelease: false
|
56
|
-
|
37
|
+
name: configliere
|
38
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
57
39
|
none: false
|
58
40
|
requirements:
|
59
41
|
- - ">="
|
60
42
|
- !ruby/object:Gem::Version
|
61
|
-
hash:
|
43
|
+
hash: 23
|
62
44
|
segments:
|
63
45
|
- 0
|
64
|
-
- 2
|
65
46
|
- 3
|
66
|
-
|
47
|
+
- 2
|
48
|
+
version: 0.3.2
|
49
|
+
requirement: *id002
|
67
50
|
type: :runtime
|
68
|
-
version_requirements: *id003
|
69
51
|
- !ruby/object:Gem::Dependency
|
70
|
-
name: rspec
|
71
52
|
prerelease: false
|
72
|
-
|
53
|
+
name: rest-client
|
54
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
73
55
|
none: false
|
74
56
|
requirements:
|
75
57
|
- - ">="
|
@@ -77,15 +59,15 @@ dependencies:
|
|
77
59
|
hash: 13
|
78
60
|
segments:
|
79
61
|
- 1
|
80
|
-
-
|
81
|
-
-
|
82
|
-
version: 1.
|
83
|
-
|
84
|
-
|
62
|
+
- 6
|
63
|
+
- 1
|
64
|
+
version: 1.6.1
|
65
|
+
requirement: *id003
|
66
|
+
type: :runtime
|
85
67
|
- !ruby/object:Gem::Dependency
|
86
|
-
name: yard
|
87
68
|
prerelease: false
|
88
|
-
|
69
|
+
name: addressable
|
70
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
89
71
|
none: false
|
90
72
|
requirements:
|
91
73
|
- - ">="
|
@@ -94,69 +76,42 @@ dependencies:
|
|
94
76
|
segments:
|
95
77
|
- 0
|
96
78
|
version: "0"
|
97
|
-
|
98
|
-
|
99
|
-
description: Chimps
|
100
|
-
email: coders@infochimps.
|
101
|
-
executables:
|
102
|
-
|
79
|
+
requirement: *id004
|
80
|
+
type: :runtime
|
81
|
+
description: Chimps allows you to easily make API calls against Infochimps web services. Chimps!'s Request and Response classes take care of all the details so you can remain calm and RESTful.
|
82
|
+
email: coders@infochimps.com
|
83
|
+
executables: []
|
84
|
+
|
103
85
|
extensions: []
|
104
86
|
|
105
87
|
extra_rdoc_files:
|
106
88
|
- LICENSE
|
107
89
|
- README.rdoc
|
108
90
|
files:
|
109
|
-
- .document
|
110
|
-
- .gitignore
|
111
|
-
- CHANGELOG.textile
|
112
91
|
- Gemfile
|
113
92
|
- Gemfile.lock
|
114
93
|
- LICENSE
|
115
94
|
- README.rdoc
|
116
95
|
- Rakefile
|
117
96
|
- VERSION
|
118
|
-
- bin/chimps
|
119
97
|
- examples/batch.yaml
|
120
98
|
- examples/query.yaml
|
121
99
|
- lib/chimps.rb
|
122
|
-
- lib/chimps/cli.rb
|
123
|
-
- lib/chimps/commands.rb
|
124
|
-
- lib/chimps/commands/base.rb
|
125
|
-
- lib/chimps/commands/batch.rb
|
126
|
-
- lib/chimps/commands/create.rb
|
127
|
-
- lib/chimps/commands/destroy.rb
|
128
|
-
- lib/chimps/commands/download.rb
|
129
|
-
- lib/chimps/commands/help.rb
|
130
|
-
- lib/chimps/commands/list.rb
|
131
|
-
- lib/chimps/commands/query.rb
|
132
|
-
- lib/chimps/commands/search.rb
|
133
|
-
- lib/chimps/commands/show.rb
|
134
|
-
- lib/chimps/commands/test.rb
|
135
|
-
- lib/chimps/commands/update.rb
|
136
|
-
- lib/chimps/commands/upload.rb
|
137
100
|
- lib/chimps/config.rb
|
101
|
+
- lib/chimps/error.rb
|
102
|
+
- lib/chimps/query_request.rb
|
138
103
|
- lib/chimps/request.rb
|
139
104
|
- lib/chimps/response.rb
|
140
|
-
- lib/chimps/typewriter.rb
|
141
105
|
- lib/chimps/utils.rb
|
142
|
-
- lib/chimps/utils/error.rb
|
143
106
|
- lib/chimps/utils/extensions.rb
|
144
|
-
- lib/chimps/utils/
|
107
|
+
- lib/chimps/utils/typewriter.rb
|
145
108
|
- lib/chimps/utils/uses_curl.rb
|
146
|
-
- lib/chimps/
|
147
|
-
- lib/chimps/
|
148
|
-
-
|
149
|
-
-
|
150
|
-
- lib/chimps/workflows/downloader.rb
|
151
|
-
- lib/chimps/workflows/up.rb
|
152
|
-
- lib/chimps/workflows/upload/bundler.rb
|
153
|
-
- lib/chimps/workflows/upload/notifier.rb
|
154
|
-
- lib/chimps/workflows/upload/token.rb
|
155
|
-
- lib/chimps/workflows/upload/uploader.rb
|
109
|
+
- lib/chimps/workflows/download.rb
|
110
|
+
- lib/chimps/workflows/upload.rb
|
111
|
+
- spec/chimps/query_request_spec.rb
|
112
|
+
- spec/chimps/request_spec.rb
|
156
113
|
- spec/chimps/response_spec.rb
|
157
|
-
- spec/chimps/
|
158
|
-
- spec/chimps/workflows/upload/bundler_spec.rb
|
159
|
-
- spec/chimps/workflows/upload/token_spec.rb
|
114
|
+
- spec/chimps/workflows/download_spec.rb
|
160
115
|
- spec/spec_helper.rb
|
161
116
|
- spec/support/custom_matchers.rb
|
162
117
|
has_rdoc: true
|
@@ -164,8 +119,8 @@ homepage: http://github.com/infochimps/chimps
|
|
164
119
|
licenses: []
|
165
120
|
|
166
121
|
post_install_message:
|
167
|
-
rdoc_options:
|
168
|
-
|
122
|
+
rdoc_options: []
|
123
|
+
|
169
124
|
require_paths:
|
170
125
|
- lib
|
171
126
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -192,11 +147,11 @@ rubyforge_project:
|
|
192
147
|
rubygems_version: 1.3.7
|
193
148
|
signing_key:
|
194
149
|
specification_version: 3
|
195
|
-
summary: Chimps
|
150
|
+
summary: Chimps is a Ruby interface for the Infochimps Dataset & Query APIs (http://www.infochimps.com/api)
|
196
151
|
test_files:
|
197
|
-
- spec/
|
198
|
-
- spec/chimps/
|
199
|
-
- spec/chimps/workflows/upload/token_spec.rb
|
200
|
-
- spec/chimps/typewriter_spec.rb
|
152
|
+
- spec/chimps/query_request_spec.rb
|
153
|
+
- spec/chimps/request_spec.rb
|
201
154
|
- spec/chimps/response_spec.rb
|
155
|
+
- spec/chimps/workflows/download_spec.rb
|
156
|
+
- spec/spec_helper.rb
|
202
157
|
- spec/support/custom_matchers.rb
|
data/.document
DELETED
data/.gitignore
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
|
2
|
-
# editors
|
3
|
-
*~
|
4
|
-
\#*
|
5
|
-
\.#*
|
6
|
-
*.tmproj
|
7
|
-
tmtags
|
8
|
-
TAGS
|
9
|
-
*.swp
|
10
|
-
|
11
|
-
## PROJECT::GENERAL
|
12
|
-
coverage
|
13
|
-
rdoc
|
14
|
-
pkg
|
15
|
-
|
16
|
-
# editors
|
17
|
-
# miscellaneous
|
18
|
-
# version control
|
19
|
-
*.tmproj
|
20
|
-
*DO_NOT_VERSION*
|
21
|
-
*~
|
22
|
-
.#*
|
23
|
-
.DS_Store
|
24
|
-
.bak
|
25
|
-
.bzr
|
26
|
-
.hg
|
27
|
-
.svn
|
28
|
-
/chimps.gemspec
|
29
|
-
TAGS
|
30
|
-
\#*
|
31
|
-
\.#*
|
32
|
-
pkg/*
|
data/CHANGELOG.textile
DELETED
data/bin/chimps
DELETED
data/lib/chimps/cli.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
module Chimps
|
2
|
-
|
3
|
-
# Defines methods for choosing which Chimps::Command class should be
|
4
|
-
# instantiated from the ARGV passed in on the command line.
|
5
|
-
module CLI
|
6
|
-
|
7
|
-
include Chimps::Commands
|
8
|
-
|
9
|
-
# Execute the Chimps command specified on the command line.
|
10
|
-
#
|
11
|
-
# Will exit the Ruby process with 0 on success or 1 on an error.
|
12
|
-
def self.execute!
|
13
|
-
begin
|
14
|
-
Chimps.boot!
|
15
|
-
command.execute!
|
16
|
-
return 0
|
17
|
-
rescue Chimps::Error, Configliere::Error => e
|
18
|
-
puts e.message
|
19
|
-
return 1
|
20
|
-
rescue => e
|
21
|
-
$stderr.puts("#{e.message} (#{e.class})")
|
22
|
-
$stderr.puts(e.backtrace.join("\n"))
|
23
|
-
return 2
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
data/lib/chimps/commands/base.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
module Chimps
|
2
|
-
|
3
|
-
# A base class from which to subclass specific commands. A subclass
|
4
|
-
# should
|
5
|
-
#
|
6
|
-
# - define class constants <tt>BANNER</tt> and <tt>HELP</tt> which
|
7
|
-
# - will display the appropriate help to the user.
|
8
|
-
#
|
9
|
-
# - add specific options by defining a method that begins with
|
10
|
-
# +define+ and ends with +options+ (i.e. - +define_output_options+
|
11
|
-
# to add options related to output).
|
12
|
-
#
|
13
|
-
# - define a method <tt>execute!</tt> which will actually run the
|
14
|
-
# command.
|
15
|
-
class Command
|
16
|
-
|
17
|
-
# Appears when printing help for this command, as the very first
|
18
|
-
# line. Should be one-line summary of how to use this command.
|
19
|
-
USAGE = "Define #{self}::USAGE when you subclass Chimps::Command"
|
20
|
-
|
21
|
-
# Appears when printing help for this command. Should consist of
|
22
|
-
# general help or examples of the command iteslf. Help on
|
23
|
-
# specific options is automatically generated.
|
24
|
-
HELP = "Define #{self}::HELP when you subclass Chimps::Command"
|
25
|
-
|
26
|
-
# The configuration settings for this command.
|
27
|
-
#
|
28
|
-
# @return [Configliere::Param]
|
29
|
-
attr_accessor :config
|
30
|
-
|
31
|
-
# Create a new command. Will define options specific to
|
32
|
-
# subclases, parse the given +argv+, and load the global Chimps
|
33
|
-
# configuration. Will _not_ execute the command.
|
34
|
-
#
|
35
|
-
# @param [Configliere::Param]
|
36
|
-
# @return [Chimps::Command]
|
37
|
-
def initialize config
|
38
|
-
self.config = config
|
39
|
-
end
|
40
|
-
|
41
|
-
# The name of this command, including the
|
42
|
-
# <tt>Chimps::Commands</tt> prefix.
|
43
|
-
#
|
44
|
-
# @return [String]
|
45
|
-
def self.name
|
46
|
-
self.to_s.downcase
|
47
|
-
end
|
48
|
-
|
49
|
-
# The name of this command, excluding the
|
50
|
-
# <tt>Chimps::Commands</tt> prefix.
|
51
|
-
#
|
52
|
-
# @return [String]
|
53
|
-
def name
|
54
|
-
self.class.name.split('::').last
|
55
|
-
end
|
56
|
-
|
57
|
-
# Run this command.
|
58
|
-
#
|
59
|
-
# Will raise a NotImplementedError for Chimps::Command itself --
|
60
|
-
# subclasses are expected to redefine this method.
|
61
|
-
def execute!
|
62
|
-
raise NotImplementedError.new("Redefine the `execute!' method in a subclass of #{self.class}.")
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
module Chimps
|
2
|
-
module Commands
|
3
|
-
|
4
|
-
# A command for performing batch updates.
|
5
|
-
class Batch < Chimps::Command
|
6
|
-
|
7
|
-
USAGE = "usage: chimps batch [OPTIONS] [INPUT_PATH] ..."
|
8
|
-
HELP = <<EOF
|
9
|
-
|
10
|
-
Perform a batch operation on Infochimps by reading YAML input files.
|
11
|
-
|
12
|
-
The input files should collectively define an array of resources to
|
13
|
-
make create or update requests on. Each request in the array is
|
14
|
-
treated separately (even though the entire array is processed as one
|
15
|
-
POST request) and so it is possible that some will succeed and others
|
16
|
-
fail.
|
17
|
-
|
18
|
-
It is also possible to upload data in this batch process. Each
|
19
|
-
(successful) request which defined a 'local_paths' property in the
|
20
|
-
original input files will have the data at these paths uploaded to
|
21
|
-
Infochimps. These uploads will proceed one at a time following the
|
22
|
-
initial batch POST request.
|
23
|
-
|
24
|
-
The format of the YAML input files is given at
|
25
|
-
|
26
|
-
http://infochimps.org/api
|
27
|
-
EOF
|
28
|
-
|
29
|
-
include Chimps::Utils::UsesYamlData
|
30
|
-
|
31
|
-
# Perform the batch update and upload.
|
32
|
-
def execute!
|
33
|
-
ensure_data_is_present!
|
34
|
-
Chimps::Workflows::BatchUpdater.new(data, :output_path => config[:output], :upload_even_if_errors => config[:force], :fmt => config[:format]).execute!
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module Chimps
|
2
|
-
module Commands
|
3
|
-
|
4
|
-
# A command to issue a POST requst to create a resource at
|
5
|
-
# Infochimps.
|
6
|
-
class Create < Chimps::Command
|
7
|
-
|
8
|
-
USAGE = "usage: chimps create [OPTIONS] [PROP=VALUE] ..."
|
9
|
-
HELP = <<EOF
|
10
|
-
|
11
|
-
Create a single resource (defaults to a dataset) using the properties
|
12
|
-
and values supplied.
|
13
|
-
|
14
|
-
Properties and values can be supplied directly on the command line,
|
15
|
-
from an input YAML file, or multiple YAML documents streamed in via
|
16
|
-
STDIN, in order of decreasing precedence.
|
17
|
-
EOF
|
18
|
-
|
19
|
-
include Chimps::Utils::UsesModel
|
20
|
-
include Chimps::Utils::UsesYamlData
|
21
|
-
|
22
|
-
# Issue the POST request.
|
23
|
-
def execute!
|
24
|
-
ensure_data_is_present!
|
25
|
-
Request.new(models_path, :data => {model.to_sym => data } , :authenticate => true).post.print
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module Chimps
|
2
|
-
module Commands
|
3
|
-
|
4
|
-
# A command to issue a DELETE request against a resource at
|
5
|
-
# Infochimps.
|
6
|
-
class Destroy < Chimps::Command
|
7
|
-
|
8
|
-
USAGE = "usage: chimps destroy [OPTIONS] ID_OR_HANDLE"
|
9
|
-
HELP = <<EOF
|
10
|
-
|
11
|
-
Destroys a resource of a given type (defaults to dataset) identified
|
12
|
-
by ID_OR_HANDLE.
|
13
|
-
|
14
|
-
EOF
|
15
|
-
|
16
|
-
include Chimps::Utils::UsesModel
|
17
|
-
|
18
|
-
# Issue the DELETE request.
|
19
|
-
def execute!
|
20
|
-
Request.new(model_path, :authenticate => true).delete.print
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
@@ -1,46 +0,0 @@
|
|
1
|
-
module Chimps
|
2
|
-
module Commands
|
3
|
-
|
4
|
-
# A command to download data from Infochimps.
|
5
|
-
class Download < Chimps::Command
|
6
|
-
|
7
|
-
USAGE = "usage: chimps download [OPTIONS] ID_OR_HANDLE"
|
8
|
-
HELP = <<EOF
|
9
|
-
|
10
|
-
Download a dataset identified by the given ID_OR_HANDLE to the current
|
11
|
-
directory (you can also specify a particular path).
|
12
|
-
|
13
|
-
If the dataset isn't freely downloadable, you'll have to have
|
14
|
-
purchased it first via the Web.
|
15
|
-
EOF
|
16
|
-
|
17
|
-
# Return the given string downcased and stripped of leading
|
18
|
-
# periods.
|
19
|
-
#
|
20
|
-
# @param [String] string
|
21
|
-
# @return [String, nil]
|
22
|
-
def normalize string
|
23
|
-
return string if string.blank?
|
24
|
-
string.downcase.strip.gsub(/^\./, '')
|
25
|
-
end
|
26
|
-
|
27
|
-
# The ID of the package to download.
|
28
|
-
def dataset
|
29
|
-
raise CLIError.new("Must provide an ID or handle of a dataset to download.") if config.argv.first.blank?
|
30
|
-
config.argv.first
|
31
|
-
end
|
32
|
-
|
33
|
-
def local_path
|
34
|
-
config[:output].blank? ? config[:output] : File.expand_path(config[:output])
|
35
|
-
end
|
36
|
-
|
37
|
-
# Issue the request for the token and the request for the
|
38
|
-
# download.
|
39
|
-
def execute!
|
40
|
-
Chimps::Workflows::Downloader.new(:dataset => dataset, :fmt => normalize(config[:format]), :pkg_fmt => normalize(config[:pkg_fmt]), :local_path => local_path).execute!
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
data/lib/chimps/commands/help.rb
DELETED
@@ -1,100 +0,0 @@
|
|
1
|
-
module Chimps
|
2
|
-
module Commands
|
3
|
-
class Help < Chimps::Command
|
4
|
-
|
5
|
-
USAGE = "usage: chimps help [OPTIONS] [COMMAND]"
|
6
|
-
|
7
|
-
HELP = <<EOF
|
8
|
-
|
9
|
-
This is the Infochimps command-line client. You can use it to search,
|
10
|
-
browse, create, edit, or delete data and metadata in the Infochimps
|
11
|
-
repository at http://infochimps.org.
|
12
|
-
|
13
|
-
Before you can create, edit, or delete anything you'll need to get an
|
14
|
-
Infochimps account and sign up for an API key:
|
15
|
-
|
16
|
-
http://infochimps.org/signup
|
17
|
-
|
18
|
-
But you can still browse, search, and download (free) data
|
19
|
-
immediately.
|
20
|
-
|
21
|
-
Learn more about the Infochimps API which powers this tool at
|
22
|
-
|
23
|
-
http://infochimps.org/api
|
24
|
-
|
25
|
-
= Commands
|
26
|
-
|
27
|
-
chimps is a wrapper over the RESTful Infochimps API. It exposes the
|
28
|
-
following actions
|
29
|
-
|
30
|
-
chimps list
|
31
|
-
chimps show
|
32
|
-
chimps create
|
33
|
-
chimps update
|
34
|
-
chimps destroy
|
35
|
-
|
36
|
-
for datasets (as well as other selected resources). It also helps
|
37
|
-
automate the workflow of uploading and downloading data and making
|
38
|
-
batch changes with
|
39
|
-
|
40
|
-
chimps upload
|
41
|
-
chimps download
|
42
|
-
chimps batch
|
43
|
-
|
44
|
-
You can also make queries against the Infochimps paid query API with
|
45
|
-
|
46
|
-
chimps query
|
47
|
-
|
48
|
-
Finally, you can test that your system is configured properly and that
|
49
|
-
you can authenticate with Infochimps with
|
50
|
-
|
51
|
-
chimps test
|
52
|
-
|
53
|
-
If you're confused try running
|
54
|
-
|
55
|
-
chimps help COMMAND
|
56
|
-
|
57
|
-
for any of the commands above.
|
58
|
-
|
59
|
-
= Setup
|
60
|
-
|
61
|
-
Once you have obtained an API key and secret from Infochimps, place
|
62
|
-
them in a file Chimps::Config[:config] in your home directory
|
63
|
-
with the following format
|
64
|
-
|
65
|
-
---
|
66
|
-
# API credentials for use on the main Infochimps site
|
67
|
-
:site:
|
68
|
-
:username: your_site_name
|
69
|
-
:key: oreeph6giedaeL3
|
70
|
-
:secret: Queechei6cu8chiuyiig8cheg5Ahx0boolaizi1ohtarooFu1doo5ohj5ohp9eehae5hakoongahghohgoi7yeihohx1eidaeng0eaveefohchoh6WeeV1EM
|
71
|
-
|
72
|
-
# API credentials for use on the Infochimps paid query API
|
73
|
-
:query:
|
74
|
-
:username: your_query_name
|
75
|
-
:key: zei7eeloShoah3Ce
|
76
|
-
:secret: eixairaichaxaaRe8eeya5moh8Uthahf0pi4eig7SoirohPhei6sai8aereu0yuepiefeipoozoegahchaeheedee8uphohoo9moongae8Fa0aih4BooSeiM
|
77
|
-
EOF
|
78
|
-
|
79
|
-
|
80
|
-
def fake_command name
|
81
|
-
Chimps::Commands.class_for(name).new(Chimps::Config.commands[name][:config])
|
82
|
-
end
|
83
|
-
|
84
|
-
def execute!
|
85
|
-
if Chimps::Config.command?(config.argv.first)
|
86
|
-
command = fake_command(config.argv.first)
|
87
|
-
$stderr.puts command.class::USAGE
|
88
|
-
$stderr.puts command.class::HELP
|
89
|
-
command.config.dump_basic_help
|
90
|
-
Chimps::Config.dump_basic_help
|
91
|
-
else
|
92
|
-
$stderr.puts Chimps::Config.usage
|
93
|
-
Chimps::Config.dump_help
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
data/lib/chimps/commands/list.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
module Chimps
|
2
|
-
module Commands
|
3
|
-
|
4
|
-
# A command to issue a GET request against an index of resources
|
5
|
-
# at Infochimps.
|
6
|
-
class List < Chimps::Command
|
7
|
-
|
8
|
-
USAGE = "usage: chimps list [OPTIONS]"
|
9
|
-
HELP = <<EOF
|
10
|
-
|
11
|
-
List resources of a given type (defaults to dataset).
|
12
|
-
|
13
|
-
Lists your resources by default but see options below.
|
14
|
-
|
15
|
-
EOF
|
16
|
-
|
17
|
-
include Chimps::Utils::UsesModel
|
18
|
-
|
19
|
-
# List all resources or just those owned by the Chimps user?
|
20
|
-
def all?
|
21
|
-
config[:all]
|
22
|
-
end
|
23
|
-
|
24
|
-
# Parameters to include in the query.
|
25
|
-
#
|
26
|
-
# If listing all resources, then return +nil+.
|
27
|
-
#
|
28
|
-
# @return [Hash, nil]
|
29
|
-
def params
|
30
|
-
return { :id => Chimps.username } unless all?
|
31
|
-
end
|
32
|
-
|
33
|
-
# Issue the GET request.
|
34
|
-
def execute!
|
35
|
-
Request.new(models_path, :params => params).get.print(:skip_column_names => config[:skip_column_names])
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|