chimps 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/.gitignore +17 -0
  2. data/LICENSE +674 -0
  3. data/README.rdoc +48 -0
  4. data/VERSION +1 -0
  5. data/bin/chimps +4 -0
  6. data/examples/batch.yaml +69 -0
  7. data/lib/chimps/cli.rb +102 -0
  8. data/lib/chimps/commands/base.rb +107 -0
  9. data/lib/chimps/commands/batch.rb +68 -0
  10. data/lib/chimps/commands/create.rb +33 -0
  11. data/lib/chimps/commands/destroy.rb +28 -0
  12. data/lib/chimps/commands/download.rb +76 -0
  13. data/lib/chimps/commands/help.rb +89 -0
  14. data/lib/chimps/commands/list.rb +54 -0
  15. data/lib/chimps/commands/query.rb +59 -0
  16. data/lib/chimps/commands/search.rb +59 -0
  17. data/lib/chimps/commands/show.rb +32 -0
  18. data/lib/chimps/commands/test.rb +40 -0
  19. data/lib/chimps/commands/update.rb +33 -0
  20. data/lib/chimps/commands/upload.rb +63 -0
  21. data/lib/chimps/commands.rb +46 -0
  22. data/lib/chimps/config.rb +57 -0
  23. data/lib/chimps/request.rb +302 -0
  24. data/lib/chimps/response.rb +146 -0
  25. data/lib/chimps/typewriter.rb +326 -0
  26. data/lib/chimps/utils/error.rb +40 -0
  27. data/lib/chimps/utils/extensions.rb +109 -0
  28. data/lib/chimps/utils/uses_curl.rb +26 -0
  29. data/lib/chimps/utils/uses_model.rb +51 -0
  30. data/lib/chimps/utils/uses_yaml_data.rb +94 -0
  31. data/lib/chimps/utils.rb +11 -0
  32. data/lib/chimps/workflows/batch.rb +127 -0
  33. data/lib/chimps/workflows/downloader.rb +102 -0
  34. data/lib/chimps/workflows/uploader.rb +238 -0
  35. data/lib/chimps/workflows.rb +11 -0
  36. data/lib/chimps.rb +22 -0
  37. data/spec/chimps/cli_spec.rb +22 -0
  38. data/spec/chimps/commands/base_spec.rb +25 -0
  39. data/spec/chimps/commands/list_spec.rb +25 -0
  40. data/spec/chimps/response_spec.rb +8 -0
  41. data/spec/chimps/typewriter_spec.rb +114 -0
  42. data/spec/spec_helper.rb +17 -0
  43. data/spec/support/custom_matchers.rb +6 -0
  44. metadata +133 -0
@@ -0,0 +1,114 @@
1
+ require File.join(File.dirname(__FILE__), '../spec_helper')
2
+
3
+ describe Chimps::Typewriter do
4
+
5
+ def dataset_1
6
+ {
7
+ 'dataset' => {
8
+ 'id' => 39293,
9
+ 'cached_slug' => 'my-awesome-dataset',
10
+ 'updated_at' => 'tomorrow',
11
+ 'title' => 'My Awesome Dataset'
12
+ }
13
+ }
14
+ end
15
+
16
+ def dataset_2
17
+ {
18
+ 'dataset' => {
19
+ 'id' => 28998,
20
+ 'cached_slug' => 'my-other-awesome-dataset',
21
+ 'updated_at' => 'yesterday',
22
+ 'title' => 'My Other Awesome Dataset'
23
+ }
24
+ }
25
+ end
26
+
27
+ def source
28
+ {} # FIXME
29
+ end
30
+
31
+ def license
32
+ {} # FIXME
33
+ end
34
+
35
+ def resource
36
+ dataset_1
37
+ end
38
+
39
+ def resource_listing
40
+ [ dataset_1, dataset_2 ]
41
+ end
42
+
43
+ def errors
44
+ [
45
+ "A title is required.",
46
+ "A description is required."
47
+ ]
48
+ end
49
+
50
+ def batch
51
+ [
52
+ {
53
+ 'status' => 'created',
54
+ 'resource' => resource,
55
+ 'errors' => nil,
56
+ 'local_paths' => []
57
+ },
58
+ {
59
+ 'status' => 'invalid',
60
+ 'errors' => errors
61
+ }
62
+ ]
63
+ end
64
+
65
+ def search
66
+ {
67
+ 'results' => [
68
+ { 'dataset' => dataset_1 },
69
+ { 'dataset' => dataset_2 }
70
+ ]
71
+ }
72
+
73
+ end
74
+
75
+ def api_account
76
+ {
77
+ 'api_key' => "tie5TeeNei2aigie",
78
+ 'owner' => {
79
+ 'username' => 'Infochimps'
80
+ },
81
+ 'updated_at' => 'now'
82
+ }
83
+ end
84
+
85
+
86
+
87
+ before { @typewriter = Chimps::Typewriter.new([]) }
88
+
89
+ describe "formatting output" do
90
+
91
+ before do
92
+ @typewriter.concat([["short", "medium", "very_very_very_long"],
93
+ ["medium", "very_very_long", "short"],
94
+ "Some totally long but also ignored string", # ignores strings
95
+ ["very_long", ""]]) # doesn't mind mixed size rows
96
+ end
97
+
98
+ it "should calculate its column widths before printing" do
99
+ $stdout = File.open('/dev/null', 'w')
100
+ @typewriter.print
101
+ @typewriter.column_widths.should_not be_empty
102
+ end
103
+
104
+ it "should correctly calculate its column widths" do
105
+ @typewriter.send(:calculate_column_widths!)
106
+ @typewriter.column_widths.should == ["very_long", "very_very_long", "very_very_very_long"].map(&:size)
107
+ end
108
+
109
+ end
110
+
111
+
112
+
113
+ end
114
+
@@ -0,0 +1,17 @@
1
+ CHIMPS_ROOT_DIR = File.join(File.expand_path(File.dirname(__FILE__)), '..') unless defined? CHIMPS_ROOT_DIR
2
+ CHIMPS_SPEC_DIR = File.join(CHIMPS_ROOT_DIR, 'spec') unless defined? CHIMPS_SPEC_DIR
3
+ CHIMPS_LIB_DIR = File.join(CHIMPS_ROOT_DIR, 'lib') unless defined? CHIMPS_LIB_DIR
4
+ $: << CHIMPS_LIB_DIR
5
+
6
+ require 'rubygems'
7
+ require 'spec'
8
+ require 'chimps'
9
+
10
+ Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each { |path| require path }
11
+
12
+ Spec::Runner.configure do |config|
13
+ config.include Chimps::Test::CustomMatchers
14
+ end
15
+
16
+
17
+
@@ -0,0 +1,6 @@
1
+ module Chimps
2
+ module Test
3
+ module CustomMatchers
4
+ end
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chimps
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dhruv Bansal
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-05-20 00:00:00 -05:00
13
+ default_executable: chimps
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rest-client
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.5.1
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: json
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.4.3
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: imw
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.2.3
44
+ version:
45
+ 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. Chimps! also comes with a command-line tool to make it simple to query, create, update, upload, and download data on Infochimps
46
+ email: coders@infochimps.org
47
+ executables:
48
+ - chimps
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - LICENSE
53
+ - README.rdoc
54
+ files:
55
+ - .gitignore
56
+ - LICENSE
57
+ - README.rdoc
58
+ - VERSION
59
+ - bin/chimps
60
+ - examples/batch.yaml
61
+ - lib/chimps.rb
62
+ - lib/chimps/cli.rb
63
+ - lib/chimps/commands.rb
64
+ - lib/chimps/commands/base.rb
65
+ - lib/chimps/commands/batch.rb
66
+ - lib/chimps/commands/create.rb
67
+ - lib/chimps/commands/destroy.rb
68
+ - lib/chimps/commands/download.rb
69
+ - lib/chimps/commands/help.rb
70
+ - lib/chimps/commands/list.rb
71
+ - lib/chimps/commands/query.rb
72
+ - lib/chimps/commands/search.rb
73
+ - lib/chimps/commands/show.rb
74
+ - lib/chimps/commands/test.rb
75
+ - lib/chimps/commands/update.rb
76
+ - lib/chimps/commands/upload.rb
77
+ - lib/chimps/config.rb
78
+ - lib/chimps/request.rb
79
+ - lib/chimps/response.rb
80
+ - lib/chimps/typewriter.rb
81
+ - lib/chimps/utils.rb
82
+ - lib/chimps/utils/error.rb
83
+ - lib/chimps/utils/extensions.rb
84
+ - lib/chimps/utils/uses_curl.rb
85
+ - lib/chimps/utils/uses_model.rb
86
+ - lib/chimps/utils/uses_yaml_data.rb
87
+ - lib/chimps/workflows.rb
88
+ - lib/chimps/workflows/batch.rb
89
+ - lib/chimps/workflows/downloader.rb
90
+ - lib/chimps/workflows/uploader.rb
91
+ - spec/chimps/cli_spec.rb
92
+ - spec/chimps/commands/base_spec.rb
93
+ - spec/chimps/commands/list_spec.rb
94
+ - spec/chimps/response_spec.rb
95
+ - spec/chimps/typewriter_spec.rb
96
+ - spec/spec_helper.rb
97
+ - spec/support/custom_matchers.rb
98
+ has_rdoc: true
99
+ homepage: http://github.com/infochimps/chimps
100
+ licenses: []
101
+
102
+ post_install_message:
103
+ rdoc_options:
104
+ - --charset=UTF-8
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: "0"
112
+ version:
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: "0"
118
+ version:
119
+ requirements: []
120
+
121
+ rubyforge_project:
122
+ rubygems_version: 1.3.5
123
+ signing_key:
124
+ specification_version: 3
125
+ summary: Chimps! is a Ruby wrapper and command-line interface for the Infochimps APIs (http://infochimps.org/api, http://api.infochimps.com)
126
+ test_files:
127
+ - spec/spec_helper.rb
128
+ - spec/chimps/commands/base_spec.rb
129
+ - spec/chimps/commands/list_spec.rb
130
+ - spec/chimps/typewriter_spec.rb
131
+ - spec/chimps/cli_spec.rb
132
+ - spec/chimps/response_spec.rb
133
+ - spec/support/custom_matchers.rb