capgun 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/.gitignore +1 -0
  2. data/.rspec +3 -0
  3. data/Gemfile +1 -8
  4. data/Gemfile.lock +32 -0
  5. data/HISTORY.md +14 -3
  6. data/LICENSE.md +26 -0
  7. data/README.md +306 -4
  8. data/Rakefile +10 -2
  9. data/capgun.gemspec +27 -16
  10. data/examples/hubot/capgun.coffee +68 -0
  11. data/lib/capgun.rb +29 -1
  12. data/lib/capgun/account.rb +13 -0
  13. data/lib/capgun/base.rb +48 -0
  14. data/lib/capgun/client.rb +82 -0
  15. data/lib/capgun/config.rb +73 -0
  16. data/lib/capgun/connection.rb +36 -0
  17. data/lib/capgun/core_ext/hash.rb +19 -0
  18. data/lib/capgun/creatable.rb +21 -0
  19. data/lib/capgun/error.rb +17 -0
  20. data/lib/capgun/error/bad_gateway.rb +7 -0
  21. data/lib/capgun/error/bad_request.rb +7 -0
  22. data/lib/capgun/error/client_error.rb +7 -0
  23. data/lib/capgun/error/forbidden.rb +7 -0
  24. data/lib/capgun/error/internal_server_error.rb +7 -0
  25. data/lib/capgun/error/not_acceptable.rb +7 -0
  26. data/lib/capgun/error/not_found.rb +7 -0
  27. data/lib/capgun/error/server_error.rb +7 -0
  28. data/lib/capgun/error/service_unavailable.rb +7 -0
  29. data/lib/capgun/error/unauthorized.rb +7 -0
  30. data/lib/capgun/estimate.rb +11 -0
  31. data/lib/capgun/job.rb +13 -0
  32. data/lib/capgun/order.rb +13 -0
  33. data/lib/capgun/request.rb +33 -0
  34. data/lib/capgun/request/gateway.rb +20 -0
  35. data/lib/capgun/response/parse_json.rb +28 -0
  36. data/lib/capgun/response/raise_client_error.rb +48 -0
  37. data/lib/capgun/response/raise_server_error.rb +23 -0
  38. data/lib/capgun/version.rb +27 -7
  39. data/spec/capgun/account_spec.rb +45 -0
  40. data/spec/capgun/base_spec.rb +29 -0
  41. data/spec/capgun/client_spec.rb +181 -0
  42. data/spec/capgun/config_spec.rb +43 -0
  43. data/spec/capgun/estimate_spec.rb +7 -0
  44. data/spec/capgun/job_spec.rb +45 -0
  45. data/spec/capgun/order_spec.rb +45 -0
  46. data/spec/capgun/version_spec.rb +11 -0
  47. data/spec/capgun_spec.rb +17 -0
  48. data/spec/faraday/response_spec.rb +68 -0
  49. data/spec/fixtures/account.json +9 -0
  50. data/spec/fixtures/completed-order.json +46 -0
  51. data/spec/fixtures/estimate.json +34 -0
  52. data/spec/fixtures/job.json +9 -0
  53. data/spec/fixtures/notfound.json +1 -0
  54. data/spec/fixtures/order.json +43 -0
  55. data/spec/fixtures/unauthorized.json +1 -0
  56. data/spec/spec_helper.rb +27 -0
  57. metadata +218 -10
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  pkg/
3
3
  .*.swp
4
4
  .swp
5
+ coverage/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --colour
2
+ --format documentation
3
+ --backtrace
data/Gemfile CHANGED
@@ -1,10 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'rake'
4
-
5
- group :development do
6
- end
7
-
8
- group :test do
9
- gem 'rspec'
10
- end
3
+ gemspec
@@ -1,7 +1,27 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ capgun (0.0.3)
5
+ activesupport (>= 2.3.9, < 4)
6
+ faraday (~> 0.8)
7
+ json (~> 1.6.6)
8
+ multi_json (~> 1.3)
9
+
1
10
  GEM
2
11
  remote: https://rubygems.org/
3
12
  specs:
13
+ activesupport (3.2.12)
14
+ i18n (~> 0.6)
15
+ multi_json (~> 1.0)
16
+ addressable (2.2.8)
17
+ crack (0.3.1)
4
18
  diff-lcs (1.1.3)
19
+ faraday (0.8.5)
20
+ multipart-post (~> 1.1)
21
+ i18n (0.6.4)
22
+ json (1.6.7)
23
+ multi_json (1.3.5)
24
+ multipart-post (1.1.5)
5
25
  rake (0.9.2.2)
6
26
  rspec (2.9.0)
7
27
  rspec-core (~> 2.9.0)
@@ -11,10 +31,22 @@ GEM
11
31
  rspec-expectations (2.9.1)
12
32
  diff-lcs (~> 1.1.3)
13
33
  rspec-mocks (2.9.0)
34
+ simplecov (0.6.4)
35
+ multi_json (~> 1.0)
36
+ simplecov-html (~> 0.5.3)
37
+ simplecov-html (0.5.3)
38
+ webmock (1.8.7)
39
+ addressable (>= 2.2.7)
40
+ crack (>= 0.1.7)
41
+ yard (0.8.1)
14
42
 
15
43
  PLATFORMS
16
44
  ruby
17
45
 
18
46
  DEPENDENCIES
47
+ capgun!
19
48
  rake
20
49
  rspec
50
+ simplecov
51
+ webmock
52
+ yard
data/HISTORY.md CHANGED
@@ -1,3 +1,14 @@
1
- 2012-04-11
2
- ==================
3
- * Initial commit
1
+ HISTORY
2
+ =======
3
+
4
+ 0.0.3 - April 17, 2013
5
+ --------------------------
6
+ * Update docs
7
+
8
+ 0.0.2 - May 14, 2012
9
+ --------------------------
10
+ * Basic implementation
11
+
12
+ 0.0.1 - April 4, 2012
13
+ --------------------------
14
+ * Initial commit
@@ -0,0 +1,26 @@
1
+ (The MIT License)
2
+
3
+ (From Twitter Gem http://github.com/jnunemaker/twitter)
4
+ Copyright (c) 2011 John Nunemaker, Wynn Netherland, Erik Michaels-Ober, Steve Richert
5
+
6
+ (Capgun Gem)
7
+ Copyright (c) 2012 Mike Mondragon (mikemondragon@gmail.com)
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining
10
+ a copy of this software and associated documentation files (the
11
+ "Software"), to deal in the Software without restriction, including
12
+ without limitation the rights to use, copy, modify, merge, publish,
13
+ distribute, sublicense, and/or sell copies of the Software, and to
14
+ permit persons to whom the Software is furnished to do so, subject to
15
+ the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be
18
+ included in all copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,5 +1,307 @@
1
- Capgun
2
- ======
1
+ # capgun.io API gem
3
2
 
4
- Place holder gem for Ruby gem that will be created to interface the capgun.io
5
- web thumb service.
3
+ A Ruby wrapper for the capgun.io web thumb service API
4
+
5
+ ## Installation
6
+
7
+ gem install capgun
8
+
9
+ ## Credits
10
+
11
+ The capgun's gem organization is based (and inspired!) by jnunemaker's
12
+ [https://github.com/jnunemaker/twitter][twitter gem], see LICENSE.md.
13
+ jnunemaker's style of coding is very elegant in its simplicity and a joy to
14
+ read.
15
+
16
+ ## Configuration
17
+
18
+ The gem is easy to configure with the global configure block. Its most basic
19
+ invocation needs to set the authorization token issued to the API.
20
+
21
+ ```ruby
22
+ Capgun.configure do |config|
23
+ config.auth_token = "YOUR-AUTH-TOKEN"
24
+ end
25
+ ```
26
+
27
+ The configuration has the following attributes to be assigned values.
28
+
29
+ * adapter
30
+ * connection_options
31
+ * endpoint
32
+ * gateway
33
+ * auth_token
34
+ * user_agent
35
+ * proxy
36
+
37
+ ## Actions
38
+
39
+ There are five actions exposed by the capgun gem.
40
+
41
+ 1. account
42
+ 1. estimate
43
+ 1. capture
44
+ 1. status
45
+ 1. order
46
+
47
+ ## account
48
+
49
+ Fetches the account owner's information.
50
+
51
+ ```ruby
52
+ # returns a Capgun::Account object
53
+ account = Capgun.account
54
+ # attributes: id, :name, :balance
55
+ account.balance
56
+ ```
57
+
58
+ example JSON responses from the capgun service.
59
+
60
+ ```shell
61
+ curl -H 'Authorization: abc123' 'https://api.capgun.io/v1/account'
62
+ ```
63
+
64
+ ```json
65
+ {
66
+ "account": {
67
+ "id": "vexuq9ff",
68
+ "name": "Acme Co.",
69
+ "notify": "http://example.com/notify",
70
+ "balance": 200,
71
+ "created_at": "2012-06-08T05:55:39+00:00",
72
+ "updated_at": "2012-06-08T05:55:39+00:00"
73
+ }
74
+ }
75
+ ```
76
+
77
+
78
+ ## estimate
79
+
80
+ An estimate is an order that has not been executed. It lists the assets that
81
+ will be delivered in the order and its cost.
82
+
83
+ ```ruby
84
+ # returns a Capgun::Order object
85
+ estimate = Capgun.estimate("http://www.google.com/")
86
+ # attributes: url, notify, cost, viewport, packages, images, options
87
+ estimate.cost
88
+ ```
89
+
90
+ example JSON responses from the capgun service.
91
+
92
+ ```shell
93
+ curl -H 'Authorization: abc123' \
94
+ --data '{"url":"http://rubygems.org/"}' \
95
+ 'https://api.capgun.io/v1/orders/estimate.json'
96
+ ```
97
+
98
+ ```json
99
+ {
100
+ "order": {
101
+ "url": "http://rubygems.org/",
102
+ "notify": null,
103
+ "cost": 1,
104
+ "viewport": "1024x768",
105
+ "images": {
106
+ "xlarge": "640x480"
107
+ },
108
+ "packages": [
109
+ "base"
110
+ ],
111
+ "options": [
112
+ {
113
+ "package": "base"
114
+ },
115
+ {
116
+ "url": "http://rubygems.org/"
117
+ },
118
+ {
119
+ "notify": null
120
+ },
121
+ {
122
+ "timeout": 5000
123
+ },
124
+ {
125
+ "viewport": "1024x768"
126
+ },
127
+ {
128
+ "image": {
129
+ "xlarge": "640x480"
130
+ }
131
+ }
132
+ ]
133
+ }
134
+ }
135
+ ```
136
+
137
+
138
+ ## capture
139
+
140
+ Capture executes an order. The order object lists the assets that will be
141
+ delivered in the order, the order's cost, and the job representing the order.
142
+
143
+ ```ruby
144
+ # returns a Capgun::Order object
145
+ order = Capgun.capture("http://www.google.com/")
146
+ # attributes: id, url, notify, cost, viewport, packages, images, asset_urls, options, job
147
+ order.viewport
148
+ ```
149
+
150
+ example JSON responses from the capgun service.
151
+
152
+ ```shell
153
+ curl -H 'Authorization: abc123' \
154
+ --data '{"url":"http://rubygems.org/"}' \
155
+ 'https://api.capgun.io/v1/orders.json'
156
+ ```
157
+
158
+ ```json
159
+ {
160
+ "order": {
161
+ "created_at": "2013-04-17T20:23:29-07:00",
162
+ "url": "http://rubygems.org/",
163
+ "notify": null,
164
+ "cost": 1,
165
+ "viewport": "1024x768",
166
+ "images": {
167
+ "xlarge": "640x480"
168
+ },
169
+ "packages": [
170
+ "base"
171
+ ],
172
+ "id": "u1qj2mz1",
173
+ "options": [
174
+ {
175
+ "package": "base"
176
+ },
177
+ {
178
+ "url": "http://rubygems.org/"
179
+ },
180
+ {
181
+ "notify": null
182
+ },
183
+ {
184
+ "timeout": 5000
185
+ },
186
+ {
187
+ "viewport": "1024x768"
188
+ },
189
+ {
190
+ "image": {
191
+ "xlarge": "640x480"
192
+ }
193
+ }
194
+ ],
195
+ "job": {
196
+ "state": "initialized",
197
+ "transition": "capturing",
198
+ "id": "qy9ujcly"
199
+ }
200
+ }
201
+ }
202
+ ```
203
+
204
+
205
+ ## status
206
+
207
+ Status is a lighter call to get the status of an order.
208
+
209
+ ```ruby
210
+ # returns a Capgun::Job object
211
+ job = Capgun.status("qy9ujcly")
212
+ # attributes: id, state, order_id
213
+ job.state
214
+ ```
215
+
216
+ example JSON responses from the capgun service.
217
+
218
+ ```shell
219
+ curl -H 'Authorization: abc123' 'https://api.capgun.io/v1/jobs/qy9ujcly'
220
+ ```
221
+
222
+ ```json
223
+ {
224
+ "job": {
225
+ "state": "initialized",
226
+ "transition": "capturing",
227
+ "created_at": "2013-04-17T20:23:29-07:00",
228
+ "id": "qy9ujcly",
229
+ "order_id": "u1qj2mz1"
230
+ }
231
+ }
232
+ ```
233
+
234
+
235
+ ## order
236
+
237
+ Fetches an existing order object and lists the assets that it delivers in the
238
+ order, the order's cost, and the job representing the order.
239
+
240
+ ```ruby
241
+ # returns a Capgun::Order object
242
+ order = Capgun.order("u9qj2mc9")
243
+ # attributes: url, notify, cost, viewport, packages, images, options
244
+ order.asset_urls
245
+ order.asset_urls["xlarge"]
246
+ order.asset_urls["package"]
247
+ ```
248
+
249
+ example JSON responses from the capgun service.
250
+
251
+ ```shell
252
+ curl -H 'Authorization: abc123' 'https://api.capgun.io/v1/orders/u9qj2mc9'
253
+ ```
254
+
255
+ ```json
256
+ {
257
+ "order": {
258
+ "created_at": "2013-02-17T22:45:20-08:00",
259
+ "url": "http://rubygems.org/",
260
+ "notify": null,
261
+ "cost": 1,
262
+ "viewport": "1024x768",
263
+ "images": {
264
+ "xlarge": "640x480"
265
+ },
266
+ "asset_urls": {
267
+ "xlarge": "https://api.capgun.io/v1/orders/u9qj2mc9/640x480.png",
268
+ "package": "https://api.capgun.io/v1/orders/u9qj2mc9/package.zip"
269
+ },
270
+ "packages": [
271
+ "base"
272
+ ],
273
+ "id": "u9qj2mc9",
274
+ "options": [
275
+ {
276
+ "package": "base"
277
+ },
278
+ {
279
+ "url": "http://rubygems.org/"
280
+ },
281
+ {
282
+ "notify": null
283
+ },
284
+ {
285
+ "timeout": 5000
286
+ },
287
+ {
288
+ "viewport": "1024x768"
289
+ },
290
+ {
291
+ "image": {
292
+ "xlarge": "640x480"
293
+ }
294
+ }
295
+ ],
296
+ "job": {
297
+ "state": "completed",
298
+ "transition": "complete",
299
+ "queued": 1.2787141799926758,
300
+ "capturing": 25.210319995880127,
301
+ "processing": 4.529249906539917,
302
+ "duration": 31.01828408241272,
303
+ "id": "5dlj5i1u"
304
+ }
305
+ }
306
+ }
307
+ ```
data/Rakefile CHANGED
@@ -1,3 +1,11 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
1
+ require 'bundler'
3
2
  Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :test => :spec
8
+ task :default => :spec
9
+
10
+ require 'yard'
11
+ YARD::Rake::YardocTask.new
@@ -1,23 +1,34 @@
1
1
  $:.unshift File.expand_path("../lib", __FILE__)
2
2
  require "capgun/version"
3
3
 
4
- Gem::Specification.new do |s|
5
- s.name = "capgun"
6
- s.version = Capgun::VERSION::STRING
7
- s.platform = Gem::Platform::RUBY
8
- s.authors = ["Mike Mondragon"]
9
- s.email = ["mikemondragon@gmail.com"]
10
- s.homepage = "http://capgun.io/"
11
- s.summary = "Ruby API to capgun.io web thumb service"
12
- s.description = "Ruby API to capgun.io web thumb service"
4
+ Gem::Specification.new do |gem|
13
5
 
14
- s.rubyforge_project = "capgun"
15
- s.rubygems_version = ">= 1.3.6"
6
+ gem.add_dependency 'activesupport', ['>= 2.3.9', '< 4']
7
+ gem.add_dependency 'faraday', '~> 0.8'
8
+ gem.add_dependency 'json', '~> 1.6.6'
9
+ gem.add_dependency 'multi_json', '~> 1.3'
16
10
 
17
- s.add_development_dependency "rspect"
11
+ gem.add_development_dependency "rake"
12
+ gem.add_development_dependency "rspec"
13
+ gem.add_development_dependency 'simplecov'
14
+ gem.add_development_dependency 'webmock'
15
+ gem.add_development_dependency 'yard'
18
16
 
19
- s.files = `git ls-files`.split("\n")
20
- s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
21
- s.require_path = 'lib'
22
- end
17
+ gem.name = "capgun"
18
+ gem.version = Capgun::Version.to_s
19
+ gem.platform = Gem::Platform::RUBY
20
+ gem.authors = ["Mike Mondragon"]
21
+ gem.email = ["mikemondragon@gmail.com"]
22
+ gem.homepage = "http://capgun.io/"
23
+ gem.summary = "capgun.io API wrapper"
24
+ gem.description = "Ruby wrapper for the capgun.io web thumb service API"
25
+
26
+ gem.rubyforge_project = "capgun"
27
+ gem.rubygems_version = ">= 1.3.6"
23
28
 
29
+ gem.files = `git ls-files`.split("\n")
30
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
31
+ gem.require_path = 'lib'
32
+
33
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
34
+ end