browshot 1.7.0 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/browshot.rb +32 -28
- data/test/test_browshot.rb +45 -5
- metadata +19 -19
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.8.0
|
data/lib/browshot.rb
CHANGED
@@ -34,7 +34,7 @@ class Browshot
|
|
34
34
|
|
35
35
|
# Return the API version handled by the library. Note that this library can usually handle new arguments in requests without requiring an update.
|
36
36
|
def api_version()
|
37
|
-
return "1.
|
37
|
+
return "1.8"
|
38
38
|
end
|
39
39
|
|
40
40
|
# Retrieve a screenshot with one call. See http://browshot.com/api/documentation#simple for the full list of possible arguments.
|
@@ -126,45 +126,49 @@ class Browshot
|
|
126
126
|
return return_reply('screenshot/list', parameters)
|
127
127
|
end
|
128
128
|
|
129
|
-
# Retrieve the screenshot, or a thumbnail. See http://browshot.com/api/documentation#
|
129
|
+
# Retrieve the screenshot, or a thumbnail. See http://browshot.com/api/documentation#screenshot_thumbnails for the response format.
|
130
130
|
#
|
131
131
|
# Return an empty string if the image could not be retrieved.
|
132
132
|
# +id+:: screenshot ID
|
133
|
-
def screenshot_thumbnail(
|
134
|
-
|
135
|
-
url = URL.new(url)
|
136
|
-
|
137
|
-
parameters.each_pair do |key, value|
|
138
|
-
url.params[key] = value
|
139
|
-
end
|
140
|
-
|
141
|
-
puts "#{url}" if (@debug)
|
142
|
-
|
133
|
+
def screenshot_thumbnail(id=0, parameters={})
|
134
|
+
parameters[:id] = id
|
143
135
|
|
144
|
-
|
136
|
+
begin
|
137
|
+
url = make_url('screenshot/thumbnail', parameters)
|
138
|
+
response = fetch(url.to_s)
|
139
|
+
case response
|
140
|
+
when Net::HTTPSuccess then
|
141
|
+
return response.response.body
|
142
|
+
else
|
143
|
+
return ''
|
144
|
+
end
|
145
|
+
rescue Exception => e
|
146
|
+
puts "{e.message}" if (@debug)
|
147
|
+
raise e
|
148
|
+
end
|
149
|
+
end
|
145
150
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
raise e
|
155
|
-
end
|
151
|
+
# Hot a screenshot or thumbnail. See http://browshot.com/api/documentation#screenshot_host for the response format.
|
152
|
+
#
|
153
|
+
# +id+:: screenshot ID
|
154
|
+
# +hosting+:: hosting option: s3, cdn or browshot
|
155
|
+
def screenshot_host(id=0, hosting='browshot', parameters={})
|
156
|
+
parameters[:id] = id
|
157
|
+
parameters[:hosting] = hosting
|
158
|
+
return return_reply('screenshot/host', parameters)
|
156
159
|
end
|
157
160
|
|
158
|
-
|
161
|
+
|
162
|
+
# Retrieve the screenshot, or a thumbnail, and save it to a file. See http://browshot.com/api/documentation#screenshot_thumbnails for the response format.
|
159
163
|
#
|
160
164
|
# See http://browshot.com/api/documentation#thumbnails for the full list of possible arguments.
|
161
165
|
#
|
162
|
-
# +
|
166
|
+
# +id+:: screenshot ID
|
163
167
|
# +file+:: Local file name to write to.
|
164
|
-
def screenshot_thumbnail_file(
|
165
|
-
content = screenshot_thumbnail(
|
168
|
+
def screenshot_thumbnail_file(id=0, file='', parameters={})
|
169
|
+
content = screenshot_thumbnail(id, parameters);
|
166
170
|
|
167
|
-
if (
|
171
|
+
if (content != '')
|
168
172
|
File.open(file, 'w') {|f| f.write(content) }
|
169
173
|
return file
|
170
174
|
else
|
data/test/test_browshot.rb
CHANGED
@@ -14,7 +14,7 @@ class TestBrowshot < Test::Unit::TestCase
|
|
14
14
|
end
|
15
15
|
|
16
16
|
should "get the API version" do
|
17
|
-
assert_equal '1.
|
17
|
+
assert_equal '1.8', @browshot.api_version()
|
18
18
|
end
|
19
19
|
|
20
20
|
should "get a screenshot with the simple method" do
|
@@ -85,7 +85,7 @@ class TestBrowshot < Test::Unit::TestCase
|
|
85
85
|
assert_equal false, instance['status'].nil?, "Instance should not be found"
|
86
86
|
end
|
87
87
|
|
88
|
-
should "send an errror when creating a
|
88
|
+
should "send an errror when creating a instance with ivalid arguments" do
|
89
89
|
instance = @browshot.instance_create({'width' => 3000})
|
90
90
|
assert_equal false, instance['error'].nil?, "Instance width should be too large"
|
91
91
|
|
@@ -100,7 +100,7 @@ class TestBrowshot < Test::Unit::TestCase
|
|
100
100
|
# Option disabled for most accounts
|
101
101
|
instance = @browshot.instance_create()
|
102
102
|
|
103
|
-
|
103
|
+
assert_equal false, instance['error'].nil?, "Instance cannot be created for this account"
|
104
104
|
# assert_equal false, instance['id'].nil?, "Instance ID should be present"
|
105
105
|
# assert_equal false, instance['width'].nil?, "Instance screen width should be present"
|
106
106
|
# assert_equal false, instance['height'].nil?, "Instance screen height should be present"
|
@@ -139,7 +139,7 @@ class TestBrowshot < Test::Unit::TestCase
|
|
139
139
|
# Option disabled for most accounts
|
140
140
|
browser = @browshot.browser_create({'mobile' => 1, 'flash' => 1, 'user_agent' => 'test'})
|
141
141
|
|
142
|
-
|
142
|
+
assert_equal false, browser['error'].nil?, "Browser cannot be created for this account"
|
143
143
|
# assert_equal false, browser['name'].nil?, "Browser name should be present"
|
144
144
|
# assert_equal false, browser['user_agent'].nil?, "Browser user_agent should be present"
|
145
145
|
# assert_equal false, browser['appname'].nil?, "Browser appname should be present"
|
@@ -393,7 +393,47 @@ class TestBrowshot < Test::Unit::TestCase
|
|
393
393
|
end
|
394
394
|
|
395
395
|
should "retrieve a thumbnail" do
|
396
|
-
|
396
|
+
screenshots = @browshot.screenshot_list()
|
397
|
+
assert_equal true, screenshots.length > 0, "There should be multiple screenshots"
|
398
|
+
|
399
|
+
screenshot_id = 0
|
400
|
+
screenshots.each do |key, screenshot|
|
401
|
+
screenshot_id = key
|
402
|
+
break
|
403
|
+
end
|
404
|
+
|
405
|
+
assert_equal true, screenshot_id.to_i > 0, "Screenshot ID should be positive"
|
406
|
+
|
407
|
+
thumbnail = @browshot.screenshot_thumbnail(screenshot_id, { 'width' => 480 });
|
408
|
+
assert_equal 'PNG', thumbnail[1..3], "Thumbnail is a valid PNG"
|
409
|
+
end
|
410
|
+
|
411
|
+
should "Fail hosting screenshots" do
|
412
|
+
screenshots = @browshot.screenshot_list()
|
413
|
+
assert_equal true, screenshots.length > 0, "There should be multiple screenshots"
|
414
|
+
|
415
|
+
screenshot_id = 0
|
416
|
+
screenshots.each do |key, screenshot|
|
417
|
+
screenshot_id = key
|
418
|
+
break
|
419
|
+
end
|
420
|
+
|
421
|
+
assert_equal true, screenshot_id.to_i > 0, "Screenshot ID should be positive"
|
422
|
+
|
423
|
+
hosting = @browshot.screenshot_host(screenshot_id)
|
424
|
+
assert_equal 'error', hosting['status'], "Default hosting option not enabled for this account"
|
425
|
+
|
426
|
+
hosting = @browshot.screenshot_host(screenshot_id, { 'hosting' => 's3' })
|
427
|
+
assert_equal 'error', hosting['status'], "S3 hosting option not enabled for this account"
|
428
|
+
|
429
|
+
hosting = @browshot.screenshot_host(screenshot_id, { 'hosting' => 's3', 'bucket' => 'mine' })
|
430
|
+
assert_equal 'error', hosting['status'], "S3 hosting option not enabled for this account"
|
431
|
+
|
432
|
+
hosting = @browshot.screenshot_host(screenshot_id, { 'hosting' => 'cdn' })
|
433
|
+
assert_equal 'error', hosting['status'], "CDN hosting option not enabled for this account"
|
434
|
+
|
435
|
+
hosting = @browshot.screenshot_host(screenshot_id, { 'hosting' => 'browshot' })
|
436
|
+
assert_equal 'error', hosting['status'], "Browshot hosting option not enabled for this account"
|
397
437
|
end
|
398
438
|
|
399
439
|
should "retrieve account information" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: browshot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
16
|
-
requirement: &
|
16
|
+
requirement: &103460540 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *103460540
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: url
|
27
|
-
requirement: &
|
27
|
+
requirement: &103459740 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *103459740
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: json
|
38
|
-
requirement: &
|
38
|
+
requirement: &103459060 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *103459060
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: url
|
49
|
-
requirement: &
|
49
|
+
requirement: &103458360 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *103458360
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: shoulda
|
60
|
-
requirement: &
|
60
|
+
requirement: &103495140 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *103495140
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: bundler
|
71
|
-
requirement: &
|
71
|
+
requirement: &103494440 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 1.0.0
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *103494440
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: jeweler
|
82
|
-
requirement: &
|
82
|
+
requirement: &103493760 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: 1.6.4
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *103493760
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: rcov
|
93
|
-
requirement: &
|
93
|
+
requirement: &103492920 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,7 +98,7 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *103492920
|
102
102
|
description: ! 'Browshot (http://www.browshot.com/) is a web service to easily make
|
103
103
|
screenshots of web pages in any screen size, as any device: iPhone©, iPad©, Android©,
|
104
104
|
Nook©, PC, etc. Browshot has full Flash, JavaScript, CSS, & HTML5 support. The latest
|
@@ -141,7 +141,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
141
141
|
version: '0'
|
142
142
|
segments:
|
143
143
|
- 0
|
144
|
-
hash: -
|
144
|
+
hash: -73333035269990045
|
145
145
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
146
|
none: false
|
147
147
|
requirements:
|