capgun 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- capgun (0.0.3)
4
+ capgun (0.1.0)
5
5
  activesupport (>= 2.3.9, < 4)
6
6
  faraday (~> 0.8)
7
7
  json (~> 1.6.6)
@@ -10,18 +10,18 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- activesupport (3.2.12)
14
- i18n (~> 0.6)
13
+ activesupport (3.2.13)
14
+ i18n (= 0.6.1)
15
15
  multi_json (~> 1.0)
16
16
  addressable (2.2.8)
17
17
  crack (0.3.1)
18
18
  diff-lcs (1.1.3)
19
- faraday (0.8.5)
19
+ faraday (0.8.7)
20
20
  multipart-post (~> 1.1)
21
- i18n (0.6.4)
22
- json (1.6.7)
21
+ i18n (0.6.1)
22
+ json (1.6.8)
23
23
  multi_json (1.3.5)
24
- multipart-post (1.1.5)
24
+ multipart-post (1.2.0)
25
25
  rake (0.9.2.2)
26
26
  rspec (2.9.0)
27
27
  rspec-core (~> 2.9.0)
data/HISTORY.md CHANGED
@@ -1,14 +1,18 @@
1
1
  HISTORY
2
2
  =======
3
3
 
4
+ 0.1.0 - May 5, 2013
5
+ --------------------------------------------------------------------------------
6
+ * options for capture and estimate can be given in a block
7
+
4
8
  0.0.3 - April 17, 2013
5
- --------------------------
9
+ --------------------------------------------------------------------------------
6
10
  * Update docs
7
11
 
8
12
  0.0.2 - May 14, 2012
9
- --------------------------
13
+ --------------------------------------------------------------------------------
10
14
  * Basic implementation
11
15
 
12
16
  0.0.1 - April 4, 2012
13
- --------------------------
17
+ --------------------------------------------------------------------------------
14
18
  * Initial commit
@@ -1,5 +1,6 @@
1
1
  require 'json'
2
2
  require 'json/pure'
3
+ require 'ostruct'
3
4
  require 'capgun/base'
4
5
  require 'capgun/account'
5
6
  require 'capgun/estimate'
@@ -36,7 +37,8 @@ module Capgun
36
37
  # @param [String] url A url that will be captured.
37
38
  # @param [Hash] options Additional options to the capture request.
38
39
  # @return [Capgun::Estimate] The estimate for the capture request.
39
- def estimate(url, options = {})
40
+ def estimate(url, options = {}, &block)
41
+ options = with_options(options, &block)
40
42
  estimate = post("/v1/orders/estimate.json", options.merge(:url => url))
41
43
  Capgun::Estimate.new(estimate['order'])
42
44
  end
@@ -46,7 +48,8 @@ module Capgun
46
48
  # @param [String] url A url that will be captured.
47
49
  # @param [Hash] options Additional options to the capture request.
48
50
  # @return [Capgun::Order] The capture request order.
49
- def capture(url, options = {})
51
+ def capture(url, options = {}, &block)
52
+ options = with_options(options, &block)
50
53
  order = post("/v1/orders.json", options.merge(:url => url))
51
54
  Capgun::Order.new(order['order'])
52
55
  end
@@ -77,6 +80,17 @@ module Capgun
77
80
  Capgun::Account.new(account['account'])
78
81
  end
79
82
 
83
+ private
84
+
85
+ def with_options(options, &block)
86
+ if block_given?
87
+ options = OpenStruct.new(options)
88
+ yield(options)
89
+ options = options.marshal_dump
90
+ end
91
+ options
92
+ end
93
+
80
94
  end
81
95
 
82
96
  end
@@ -37,6 +37,8 @@ module Capgun
37
37
  :proxy,
38
38
  ]
39
39
 
40
+ #ORDER_OPTIONS = Struct.new(:id, :url, :notify, :cost, :viewport, :packages, :images, :asset_urls, :options, :job)
41
+
40
42
  attr_accessor *VALID_OPTIONS_KEYS
41
43
 
42
44
  # When this module is extended, set all configuration options to their default values
@@ -8,12 +8,12 @@ module Capgun
8
8
 
9
9
  # @return [Integer]
10
10
  def self.minor
11
- 0
11
+ 1
12
12
  end
13
13
 
14
14
  # @return [Integer]
15
15
  def self.patch
16
- 3
16
+ 0
17
17
  end
18
18
 
19
19
  # @return [String, NilClass]
@@ -74,6 +74,19 @@ describe Capgun::Client do
74
74
  estimate.cost.should == 1
75
75
  end
76
76
 
77
+ specify "estimate with options in a block" do
78
+ stub_request(:post, "https://api.capgun.io/v1/orders/estimate.json").
79
+ with(:body => '{"viewport":"1024x2048","packages":["images","viewport"],"url":"http://example.com/test"}',
80
+ :headers => {'Accept'=>'application/json', 'Authorization'=>'test', 'User-Agent'=>'Capgun.io Ruby Gem 0.0.3'}).
81
+ to_return(:status => 200, :body => fixture("estimate-with-options.json"), :headers => {})
82
+
83
+ estimate = Capgun.estimate("http://example.com/test", :viewport => "200x100") do |options|
84
+ options.packages = ['images', 'viewport']
85
+ options.viewport = '1024x2048'
86
+ end
87
+ estimate.cost.should == 3
88
+ end
89
+
77
90
  specify "urls are submitted for capture" do
78
91
  stub_request(:post, "https://api.capgun.io/v1/orders.json").
79
92
  with(:body => "{\"url\":\"http://example.com/test\"}",
@@ -85,6 +98,35 @@ describe Capgun::Client do
85
98
  order.cost.should == 1
86
99
  end
87
100
 
101
+ specify "capture with options can be in a block" do
102
+ stub_request(:post, "https://api.capgun.io/v1/orders.json").
103
+ with(:body => '{"packages":["images","viewport"],"viewport":"1024x2048","url":"http://example.com/test"}',
104
+ :headers => {'Accept'=>'application/json', 'Authorization'=>'test', 'User-Agent'=>'Capgun.io Ruby Gem 0.0.3'}).
105
+ to_return(:status => 200, :body => fixture("order-with-options.json"), :headers => {})
106
+
107
+ order = Capgun.capture("http://example.com/test", :packages => [ :images, :viewport ], :viewport => "1024x2048")
108
+ order.id.should == '4fd20a1288f560177600000a'
109
+ order.cost.should == 1
110
+ order.viewport.should == '1024x2048+0+0'
111
+ order.packages.should == ['base', 'images', 'viewport']
112
+ end
113
+
114
+ specify "capture with options can be in a block" do
115
+ stub_request(:post, "https://api.capgun.io/v1/orders.json").
116
+ with(:body => '{"viewport":"1024x2048","packages":["images","viewport"],"url":"http://example.com/test"}',
117
+ :headers => {'Accept'=>'application/json', 'Authorization'=>'test', 'User-Agent'=>'Capgun.io Ruby Gem 0.0.3'}).
118
+ to_return(:status => 200, :body => fixture("order-with-options.json"), :headers => {})
119
+
120
+ order = Capgun.capture("http://example.com/test", :viewport => "200x100") do |options|
121
+ options.packages = ['images', 'viewport']
122
+ options.viewport = '1024x2048'
123
+ end
124
+ order.id.should == '4fd20a1288f560177600000a'
125
+ order.cost.should == 1
126
+ order.viewport.should == '1024x2048+0+0'
127
+ order.packages.should == ['base', 'images', 'viewport']
128
+ end
129
+
88
130
  specify "showing a capture order" do
89
131
  stub_request(:get, "https://api.capgun.io/v1/orders/4fd20a1288f560177600000a.json").
90
132
  with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'test', 'User-Agent'=>'Capgun.io Ruby Gem 0.0.3'}).
@@ -0,0 +1,68 @@
1
+ {
2
+ "order": {
3
+ "url": "http://example.com/",
4
+ "notify": null,
5
+ "cost": 3,
6
+ "viewport": "1024x2048",
7
+ "images": {
8
+ "xlarge": "640x1280",
9
+ "small": "80x160",
10
+ "medium": "160x320",
11
+ "large": "320x640",
12
+ "excerpt": "400x150+0+0"
13
+ },
14
+ "packages": [
15
+ "base",
16
+ "images",
17
+ "viewport"
18
+ ],
19
+ "options": [
20
+ {
21
+ "package": "base"
22
+ },
23
+ {
24
+ "package": "images"
25
+ },
26
+ {
27
+ "package": "viewport"
28
+ },
29
+ {
30
+ "url": "http://example.com/"
31
+ },
32
+ {
33
+ "notify": null
34
+ },
35
+ {
36
+ "timeout": 5000
37
+ },
38
+ {
39
+ "image": {
40
+ "xlarge": "640x480"
41
+ }
42
+ },
43
+ {
44
+ "image": {
45
+ "small": "80x60"
46
+ }
47
+ },
48
+ {
49
+ "image": {
50
+ "medium": "160x120"
51
+ }
52
+ },
53
+ {
54
+ "image": {
55
+ "large": "320x240"
56
+ }
57
+ },
58
+ {
59
+ "image": {
60
+ "excerpt": "400x150+0+0"
61
+ }
62
+ },
63
+ {
64
+ "viewport": "1024x2048"
65
+ }
66
+ ]
67
+ }
68
+ }
@@ -0,0 +1,74 @@
1
+
2
+ {
3
+ "order": {
4
+ "id": "4fd20a1288f560177600000a",
5
+ "created_at": "2012-06-08T14:20:02+00:00",
6
+ "updated_at": "2012-06-08T14:20:02+00:00",
7
+ "url": "http://example.com:4567/",
8
+ "notify": null,
9
+ "cost": 1,
10
+ "viewport": "1024x2048+0+0",
11
+ "images": [
12
+ "640x480"
13
+ ],
14
+ "packages": [
15
+ "base",
16
+ "images",
17
+ "viewport"
18
+ ],
19
+ "options": [
20
+ {
21
+ "package": "base"
22
+ },
23
+ {
24
+ "package": "images"
25
+ },
26
+ {
27
+ "package": "viewport"
28
+ },
29
+ {
30
+ "url": "http://example.com:4567/"
31
+ },
32
+ {
33
+ "timeout": "5000"
34
+ },
35
+ {
36
+ "delay": "0"
37
+ },
38
+ {
39
+ "viewport": "1024x2048"
40
+ },
41
+ {
42
+ "image": {
43
+ "xlarge": "640x480"
44
+ }
45
+ },
46
+ {
47
+ "image": {
48
+ "small": "80x60"
49
+ }
50
+ },
51
+ {
52
+ "image": {
53
+ "medium": "160x120"
54
+ }
55
+ },
56
+ {
57
+ "image": {
58
+ "large": "320x240"
59
+ }
60
+ },
61
+ {
62
+ "image": {
63
+ "excerpt": "400x150+0+0"
64
+ }
65
+ }
66
+ ],
67
+ "job": {
68
+ "id": "4fd20a1288f5601776000012",
69
+ "state": "initialized",
70
+ "created_at": "2012-06-08T14:20:02+00:00",
71
+ "updated_at": "2012-06-08T14:20:08+00:00"
72
+ }
73
+ }
74
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capgun
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
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: 2013-04-18 00:00:00.000000000 Z
12
+ date: 2013-05-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -218,9 +218,11 @@ files:
218
218
  - spec/faraday/response_spec.rb
219
219
  - spec/fixtures/account.json
220
220
  - spec/fixtures/completed-order.json
221
+ - spec/fixtures/estimate-with-options.json
221
222
  - spec/fixtures/estimate.json
222
223
  - spec/fixtures/job.json
223
224
  - spec/fixtures/notfound.json
225
+ - spec/fixtures/order-with-options.json
224
226
  - spec/fixtures/order.json
225
227
  - spec/fixtures/unauthorized.json
226
228
  - spec/spec_helper.rb
@@ -238,7 +240,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
238
240
  version: '0'
239
241
  segments:
240
242
  - 0
241
- hash: 3936620781114249947
243
+ hash: 2142080540201523708
242
244
  required_rubygems_version: !ruby/object:Gem::Requirement
243
245
  none: false
244
246
  requirements:
@@ -247,7 +249,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
247
249
  version: '0'
248
250
  segments:
249
251
  - 0
250
- hash: 3936620781114249947
252
+ hash: 2142080540201523708
251
253
  requirements: []
252
254
  rubyforge_project: capgun
253
255
  rubygems_version: 1.8.23
@@ -267,9 +269,11 @@ test_files:
267
269
  - spec/faraday/response_spec.rb
268
270
  - spec/fixtures/account.json
269
271
  - spec/fixtures/completed-order.json
272
+ - spec/fixtures/estimate-with-options.json
270
273
  - spec/fixtures/estimate.json
271
274
  - spec/fixtures/job.json
272
275
  - spec/fixtures/notfound.json
276
+ - spec/fixtures/order-with-options.json
273
277
  - spec/fixtures/order.json
274
278
  - spec/fixtures/unauthorized.json
275
279
  - spec/spec_helper.rb