browshot 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Dependencies required to use browshot
3
+
4
+ gem "json", ">= 0"
5
+ gem "url", ">= 0"
6
+
7
+ # Dependencies to develop browshot.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.6.4"
12
+ gem "rcov", ">= 0"
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,24 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.6.4)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ json (1.6.1)
10
+ rake (0.9.2.2)
11
+ rcov (0.9.11)
12
+ shoulda (2.11.3)
13
+ url (0.3.1)
14
+
15
+ PLATFORMS
16
+ ruby
17
+
18
+ DEPENDENCIES
19
+ bundler (~> 1.0.0)
20
+ jeweler (~> 1.6.4)
21
+ json
22
+ rcov
23
+ shoulda
24
+ url
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Julien Sobrier
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,31 @@
1
+ = browshot
2
+
3
+ Browshot (http://www.browshot.com/) is a web service to easily make screenshots of web pages in any screen size, as any device: iPhone©, iPad©, Android©, Nook©, PC, etc. Browshot has full Flash, JavaScript, CSS, & HTML5 support.
4
+
5
+ The latest API version is detailed at http://browshot.com/api/documentation. browshot follows the API documentation very closely: the function names are similar to the URLs used (screenshot/create becomes screenshot_create(), instance/list becomes instance_list(), etc.), the request arguments are exactly the same, etc.
6
+
7
+ The library version matches closely the API version it handles: browshot 1.0.0 is the first release for the API 1.0, browshot 1.1.1 is the second release for the API 1.1, etc.
8
+
9
+ browshot can handle most the API updates within the same major version, e.g. browshot 1.0.0 should be compatible with the API 1.1 or 1.2.
10
+
11
+ == Build and install browshot
12
+
13
+ git clone https://github.com/juliensobrier/browshot-ruby
14
+ rake build
15
+ rake test
16
+ rake install
17
+
18
+ == Contributing to browshot
19
+
20
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
21
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
22
+ * Fork the project
23
+ * Start a feature/bugfix branch
24
+ * Commit and push until you are happy with your contribution
25
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
26
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
27
+
28
+ == Copyright
29
+
30
+ Copyright (c) 2011 Julien Sobrier. See LICENSE.txt for
31
+ further details.
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "browshot"
18
+ gem.homepage = "http://github.com/juliensobrier/browshot-ruby"
19
+ gem.license = "MIT"
20
+ gem.summary = "Ruby library for Browshot (L<http://www.browshot.com/>), a web service to create website screenshots."
21
+ gem.description = "Browshot (http://www.browshot.com/) is a web service to easily make screenshots of web pages in any screen size, as any device: iPhone©, iPad©, Android©, Nook©, PC, etc. Browshot has full Flash, JavaScript, CSS, & HTML5 support. The latest API version is detailed at http://browshot.com/api/documentation. browshot.rb follows the API documentation very closely: the function names are similar to the URLs used (screenshot/create becomes screenshot_create(), instance/list becomes instance_list(), etc.), the request arguments are exactly the same, etc. The library version matches closely the API version it handles: browshot 1.0.0 is the first release for the API 1.0, browshot 1.1.1 is the second release for the API 1.1, etc. browshot.rb can handle most the API updates within the same major version, e.g. browshot.rb 1.0.0 should be compatible with the API 1.1 or 1.2."
22
+ gem.email = "julien@sobrier.net"
23
+ gem.authors = ["Julien Sobrier"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ test.rcov_opts << '--exclude "gems/*"'
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "browshot #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.2.1
data/lib/browshot.rb ADDED
@@ -0,0 +1,179 @@
1
+ # The library requires an API key from Browshot.
2
+ # Sign up fpr a free account a http://browshot.com/
3
+ #
4
+ # See README.rdoc for more information abouth Browshot
5
+ # and this library.
6
+ #
7
+ # Author:: Julien Sobrier (mailto:jsobrier@browshot.com)
8
+ # Copyright:: Copyright (c) 2011 Browshot
9
+ # License:: Distributes under the same terms as Ruby
10
+
11
+ require 'url'
12
+ require 'json'
13
+ require 'net/http'
14
+ require 'net/https'
15
+
16
+ class Browshot
17
+ # API key
18
+ attr_reader :key
19
+ # Base URL for all API requests. You should use the default base provided by the library. Be careful if you decide to use HTTP instead of HTTPS as your API key could be sniffed and your account could be used without your consent.
20
+ attr_reader :base
21
+ # print debug output to the standard output
22
+ attr_reader :debug
23
+
24
+ # New client
25
+ #
26
+ # +key+:: API key
27
+ # +base+:: Base URL for all API requests. You should use the default base provided by the library. Be careful if you decide to use HTTP instead of HTTPS as your API key could be sniffed and your account could be used without your consent.
28
+ # +debug+:: Set to true to print debug output to the standard output. false (disabled) by default.
29
+ def initialize(key='', base='https://api.browshot.com/api/v1/', debug=false)
30
+ @key = key || ''
31
+ @base = base || 'http://127.0.0.1:3000/api/v1/'
32
+ @debug = debug || false
33
+ end
34
+
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
+ def api_version()
37
+ return "1.2"
38
+ end
39
+
40
+ # Return the list of instances. See http://browshot.com/api/documentation#instance_list for the response format.
41
+ def instance_list()
42
+ return return_reply('instance/list')
43
+ end
44
+
45
+ # Return the details of an instance. See http://browshot.com/api/documentation#instance_info for the response format.
46
+ #
47
+ # +id+:: Instance ID
48
+ def instance_info(id=0)
49
+ return return_reply('instance/info', { 'id' => id })
50
+ end
51
+
52
+ # Create a private instance. See http://browshot.com/api/documentation#instance_create for the response format.
53
+ def instance_create(parameters={})
54
+ return return_reply('instance/create', parameters)
55
+ end
56
+
57
+ # Return the list of browsers. See http://browshot.com/api/documentation#browser_list for the response format.
58
+ def browser_list()
59
+ return return_reply('browser/list')
60
+ end
61
+
62
+ # Return the details of a browser. See http://browshot.com/api/documentation#browser_info for the response format.
63
+ #
64
+ # +id+:: Browser ID
65
+ def browser_info(id=0)
66
+ return return_reply('browser/info', { 'id' => id })
67
+ end
68
+
69
+ # Create a custom browser. See http://browshot.com/api/documentation#browser_create for the response format.
70
+ def browser_create(parameters={})
71
+ return return_reply('browser/create', parameters)
72
+ end
73
+
74
+ # Request a screenshot. See http://browshot.com/api/documentation#screenshot_create for the response format.
75
+ #
76
+ # +url+:: URL of the website to create a screenshot of.
77
+ def screenshot_create(url='', parameters={})
78
+ parameters[:url] = url
79
+ return return_reply('screenshot/create', parameters)
80
+ end
81
+
82
+ # Get information about a screenshot requested previously. See http://browshot.com/api/documentation#screenshot_info for the response format.
83
+ #
84
+ # +id+:: screenshot ID
85
+ def screenshot_info(id=0)
86
+ return return_reply('screenshot/info', { 'id' => id })
87
+ end
88
+
89
+ # Get details about screenshots requested. See http://browshot.com/api/documentation#screenshot_list for the response format.
90
+ def screenshot_list(parameters={})
91
+ return return_reply('screenshot/list', parameters)
92
+ end
93
+
94
+ # Retrieve the screenshot, or a thumbnail. See http://browshot.com/api/documentation#thumbnails for the response format.
95
+ #
96
+ # Return an empty string if the image could not be retrieved.
97
+ # +id+:: screenshot ID
98
+ def screenshot_thumbnail(url='', parameters={})
99
+ begin
100
+ url = URL.new(url)
101
+
102
+ parameters.each_pair do |key, value|
103
+ url.params[key] = value
104
+ end
105
+
106
+ puts "#{url}" if (@debug)
107
+
108
+
109
+ response = url.get
110
+
111
+ if (response.success?)
112
+ return response.response.body
113
+ else
114
+ puts "Error from #{url}: #{response.code}" if (@debug)
115
+ return ''
116
+ end
117
+ rescue Exception => e
118
+ puts "{e.message}" if (@debug)
119
+ raise e
120
+ end
121
+ end
122
+
123
+ # Retrieve the screenshot, or a thumbnail, and save it to a file. See http://browshot.com/api/documentation#thumbnails for the response format.
124
+ #
125
+ # See http://browshot.com/api/documentation#thumbnails for the full list of possible arguments.
126
+ #
127
+ # +url+:: URL of the screenshot (screenshot_url value retrieved from screenshot_create() or screenshot_info()). You will get the full image if no other argument is specified.
128
+ # +file+: Local file name to write to.
129
+ def screenshot_thumbnail_file(url='', file='', parameters={})
130
+ content = screenshot_thumbnail(url, parameters);
131
+
132
+ if ($content != '')
133
+ File.open(file, 'w') {|f| f.write(content) }
134
+ return file
135
+ else
136
+ puts "No thumbnail retrieved\n" if (@debug)
137
+ return ''
138
+ end
139
+ end
140
+
141
+ # Return information about the user account. See http://browshot.com/api/documentation#account_info for the response format.
142
+ def account_info(parameters={})
143
+ return return_reply('account/info', parameters)
144
+ end
145
+
146
+ private
147
+
148
+ def make_url(action='', parameters={})
149
+ url = URL.new("#{@base}#{action}?key=#{@key}")
150
+
151
+
152
+ parameters.each_pair do |key, value|
153
+ url.params[key] = value
154
+ end
155
+
156
+ puts "#{url}" if (@debug)
157
+
158
+ return url
159
+ end
160
+
161
+ def return_reply(action='', parameters={})
162
+ begin
163
+ url = make_url(action, parameters)
164
+
165
+ response = url.get
166
+
167
+ if (response.success?)
168
+ json_decode = JSON.parse(response.response.body)
169
+ return json_decode
170
+ else
171
+ puts "Error from #{url}: #{response.code}" if (@debug)
172
+ return { 'error' => 1, 'message' => response.code }
173
+ end
174
+ rescue Exception => e
175
+ puts "{e.message}" if (@debug)
176
+ raise e
177
+ end
178
+ end
179
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'browshot'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,269 @@
1
+ current_dir = File.expand_path(File.dirname(__FILE__))
2
+ require "#{current_dir}/helper"
3
+
4
+ class TestBrowshot < Test::Unit::TestCase
5
+ # def test_new
6
+ # puts "New client"
7
+ # client = Browshot.new()
8
+ # client = Browshot.new(key='',nil,debug=1)
9
+ # assert_equal(1, 1)
10
+ # end
11
+ context "Browshot client" do
12
+ setup do
13
+ @browshot = Browshot.new('vPTtKKLBtPUNxVwwfEKlVvekuxHyTXyi')
14
+ end
15
+
16
+ should "get the API version" do
17
+ assert_equal '1.2', @browshot.api_version()
18
+ end
19
+
20
+ should "get the list of instances available" do
21
+ # assert_equal 10, @calculator.product(2, 5)
22
+ instances = @browshot.instance_list()
23
+ assert_equal false, instances['free'].nil?, "List of free instances is missing"
24
+ assert_equal true, instances['free'].kind_of?(Array), "List of free instances is incorrect"
25
+ assert_equal true, instances['free'].length > 0, "There should be at least 1 free instance"
26
+
27
+ assert_equal false, instances['shared'].nil?, "List of shared instances is missing"
28
+ assert_equal true, instances['shared'].kind_of?(Array), "List of shared instances is incorrect"
29
+ assert_equal true, instances['shared'].length > 0, "There should be at least 1 shared instance"
30
+
31
+ assert_equal false, instances['private'].nil?, "List of private instances is missing"
32
+ assert_equal true, instances['private'].kind_of?(Array), "List of private instances is incorrect"
33
+ assert_equal true, instances['private'].length == 0, "There should be at least no private instance"
34
+
35
+ free = instances['free'][0]
36
+ assert_equal false, free['id'].nil?, "Missing instance ID"
37
+ assert_equal false, free['width'].nil?, "Missing instance screen width"
38
+ assert_equal false, free['height'].nil?, "Missing instance screen height"
39
+ assert_equal false, free['load'].nil?, "Missing instance load"
40
+ assert_equal false, free['browser'].nil?, "Missing instance browser"
41
+ assert_equal false, free['browser']['id'].nil?, "Missing instance browser ID"
42
+ assert_equal false, free['browser']['name'].nil?, "Missing instance browser name"
43
+ assert_equal false, free['browser']['javascript'].nil?, "Missing instance browser javascript capability"
44
+ assert_equal false, free['browser']['flash'].nil?, "Missing instance browser flash capability"
45
+ assert_equal false, free['browser']['mobile'].nil?, "Missing instance browser mobile capability"
46
+ assert_equal false, free['type'].nil?, "Missing instance type"
47
+ assert_equal false, free['active'].nil?, "Missing instance active"
48
+ assert_equal 1, free['active'].to_i, "Free instance should be active"
49
+ assert_equal false, free['screenshot_cost'].nil?, "Missing instance cost"
50
+ assert_equal 0, free['screenshot_cost'].to_i, "Cost should be 0"
51
+ end
52
+
53
+ should "get an instance information" do
54
+ instances = @browshot.instance_list()
55
+ free = instances['free'][0]
56
+
57
+ instance = @browshot.instance_info(free['id'])
58
+ assert_equal free['id'], instance['id'], "Mismatch instance ID"
59
+ assert_equal free['width'], instance['width'], "Mismatch instance screen width"
60
+ assert_equal free['height'], instance['height'], "Mismatch instance screen height"
61
+ assert_equal free['load'], instance['load'], "Mismatch instance load"
62
+ assert_equal free['browser']['id'], instance['browser']['id'], "Mismatch instance browser ID"
63
+ assert_equal free['browser']['name'], instance['browser']['name'], "Mismatch instance browser name"
64
+ assert_equal free['browser']['javascript'], instance['browser']['javascript'],"Mismatch instance browser javascript capability"
65
+ assert_equal free['browser']['flash'], instance['browser']['flash'], "Mismatch instance browser flash capability"
66
+ assert_equal free['browser']['mobile'], instance['browser']['mobile'], "Mismatch instance browser mobile capability"
67
+ assert_equal free['type'], instance['type'], "Mismatch instance type"
68
+ assert_equal free['active'], instance['active'], "Mismatch instance active"
69
+ assert_equal free['screenshot_cost'], instance['screenshot_cost'], "Mismatch instance cost"
70
+ end
71
+
72
+ should "send an error for the wrong instance ID" do
73
+ instance = @browshot.instance_info(-1)
74
+
75
+ assert_equal false, instance['error'].nil?, "Instance should not be found"
76
+ assert_equal false, instance['status'].nil?, "Instance should not be found"
77
+ end
78
+
79
+ should "send an errror when creating a instanc with ivalid arguments" do
80
+ instance = @browshot.instance_create({'width' => 3000})
81
+ assert_equal false, instance['error'].nil?, "Instance width should be too large"
82
+
83
+ instance = @browshot.instance_create({'height' => 3000})
84
+ assert_equal false, instance['error'].nil?, "Instance width should be too large"
85
+
86
+ instance = @browshot.instance_create({'browser_id' => -1})
87
+ assert_equal false, instance['error'].nil?, "Instance browser ID should be invalid"
88
+ end
89
+
90
+ should "create a new instance (sort of)" do
91
+ # Instance is not actually created for test account, so the reply may not match our parameters
92
+ instance = @browshot.instance_create()
93
+
94
+ assert_equal false, instance['id'].nil?, "Instance ID should be present"
95
+ assert_equal false, instance['width'].nil?, "Instance screen width should be present"
96
+ assert_equal false, instance['height'].nil?, "Instance screen height should be present"
97
+ assert_equal false, instance['active'].nil?, "Instance active should be present"
98
+ assert_equal 1, instance['active'].to_i, "Instance should be active"
99
+ assert_equal false, instance['browser'].nil?, "Instance browser should be present"
100
+ assert_equal false, instance['browser']['id'].nil?, "Instance browser ID should be present"
101
+ end
102
+
103
+ should "get the list of browsers" do
104
+ browsers = @browshot.browser_list()
105
+ assert_equal true, browsers.length > 0, "There should be multiple browsers"
106
+
107
+ browser_id = 0
108
+ browsers.each do |key, browser|
109
+ browser_id = key
110
+ break
111
+ end
112
+
113
+ assert_equal true, browser_id.to_i > 0, "Browser ID should be positive"
114
+ browser = browsers[browser_id]
115
+
116
+ assert_equal false, browser['name'].nil?, "Browser name should be present"
117
+ assert_equal false, browser['user_agent'].nil?, "Browser user_agent should be present"
118
+ assert_equal false, browser['appname'].nil?, "Browser appname should be present"
119
+ assert_equal false, browser['vendorsub'].nil?, "Browser vendorsub should be present"
120
+ assert_equal false, browser['appcodename'].nil?, "Browser appcodename should be present"
121
+ assert_equal false, browser['platform'].nil?, "Browser platform should be present"
122
+ assert_equal false, browser['vendor'].nil?, "Browser vendor should be present"
123
+ assert_equal false, browser['appversion'].nil?, "Browser appversion should be present"
124
+ assert_equal false, browser['javascript'].nil?, "Browser javascript capability should be present"
125
+ assert_equal false, browser['mobile'].nil?, "Browser mobile capability should be present"
126
+ assert_equal false, browser['flash'].nil?, "Browser flash capability should be present"
127
+ end
128
+
129
+ should "create a browser" do
130
+ # browser is not actually created for test account, so the reply may not match our parameters
131
+ browser = @browshot.browser_create({'mobile' => 1, 'flash' => 1, 'user_agent' => 'test'});
132
+
133
+ assert_equal false, browser['name'].nil?, "Browser name should be present"
134
+ assert_equal false, browser['user_agent'].nil?, "Browser user_agent should be present"
135
+ assert_equal false, browser['appname'].nil?, "Browser appname should be present"
136
+ assert_equal false, browser['vendorsub'].nil?, "Browser vendorsub should be present"
137
+ assert_equal false, browser['appcodename'].nil?, "Browser appcodename should be present"
138
+ assert_equal false, browser['platform'].nil?, "Browser platform should be present"
139
+ assert_equal false, browser['vendor'].nil?, "Browser vendor should be present"
140
+ assert_equal false, browser['appversion'].nil?, "Browser appversion should be present"
141
+ assert_equal false, browser['javascript'].nil?, "Browser javascript capability should be present"
142
+ assert_equal false, browser['mobile'].nil?, "Browser mobile capability should be present"
143
+ assert_equal false, browser['flash'].nil?, "Browser flash capability should be present"
144
+ end
145
+
146
+ should "fail to create screenshot" do
147
+ screenshot = @browshot.screenshot_create();
148
+ assert_equal false, screenshot['error'].nil?, "Screenshot should have failed"
149
+
150
+ screenshot = @browshot.screenshot_create('-')
151
+ assert_equal false, screenshot['error'].nil?, "Screenshot should have failed"
152
+ end
153
+
154
+
155
+ should "create screenshot" do
156
+ # screenshot is not actually created for test account, so the reply may not match our parameters
157
+ screenshot = @browshot.screenshot_create('http://browshot.com/');
158
+
159
+ assert_equal false, screenshot['id'].nil?, "Screenshot ID should be present"
160
+ assert_equal false, screenshot['status'].nil?, "Screenshot status should be present"
161
+ assert_equal false, screenshot['priority'].nil?, "Screenshot priority should be present"
162
+
163
+ if (screenshot['status'] == 'finished')
164
+ assert_equal false, screenshot['screenshot_url'].nil?, "Screenshot screenshot_url should be present"
165
+ assert_equal false, screenshot['url'].nil?, "Screenshot url should be present"
166
+ assert_equal false, screenshot['size'].nil?, "Screenshot size should be present"
167
+ assert_equal false, screenshot['width'].nil?, "Screenshot width should be present"
168
+ assert_equal false, screenshot['height'].nil?, "Screenshot height should be present"
169
+ assert_equal false, screenshot['request_time'].nil?, "Screenshot request_time should be present"
170
+ assert_equal false, screenshot['started'].nil?, "Screenshot started should be present"
171
+ assert_equal false, screenshot['load'].nil?, "Screenshot load should be present"
172
+ assert_equal false, screenshot['content'].nil?, "Screenshot content should be present"
173
+ assert_equal false, screenshot['finished'].nil?, "Screenshot finished should be present"
174
+ assert_equal false, screenshot['instance_id'].nil?, "Screenshot instance_id should be present"
175
+ assert_equal false, screenshot['response_code'].nil?, "Screenshot response_code should be present"
176
+ assert_equal false, screenshot['final_url'].nil?, "Screenshot final_url should be present"
177
+ assert_equal false, screenshot['content_type'].nil?, "Screenshot content_type should be present"
178
+ assert_equal false, screenshot['scale'].nil?, "Screenshot scale should be present"
179
+ end
180
+ end
181
+
182
+ should "not be able to retrieve a screenshot" do
183
+ screenshot = @browshot.screenshot_info()
184
+ assert_equal false, screenshot['error'].nil?, "Screenshot should have failed"
185
+ end
186
+
187
+ should "to retrieve a screenshot" do
188
+ screenshot = @browshot.screenshot_create('http://browshot.com/');
189
+ info = @browshot.screenshot_info(screenshot['id'])
190
+
191
+ assert_equal false, info['id'].nil?, "Screenshot ID should be present"
192
+ assert_equal false, info['status'].nil?, "Screenshot status should be present"
193
+ assert_equal false, info['priority'].nil?, "Screenshot priority should be present"
194
+
195
+ if (info['status'] == 'finished')
196
+ assert_equal false, info['screenshot_url'].nil?, "Screenshot screenshot_url should be present"
197
+ assert_equal false, info['url'].nil?, "Screenshot url should be present"
198
+ assert_equal false, info['size'].nil?, "Screenshot size should be present"
199
+ assert_equal false, info['width'].nil?, "Screenshot width should be present"
200
+ assert_equal false, info['height'].nil?, "Screenshot height should be present"
201
+ assert_equal false, info['request_time'].nil?, "Screenshot request_time should be present"
202
+ assert_equal false, info['started'].nil?, "Screenshot started should be present"
203
+ assert_equal false, info['load'].nil?, "Screenshot load should be present"
204
+ assert_equal false, info['content'].nil?, "Screenshot content should be present"
205
+ assert_equal false, info['finished'].nil?, "Screenshot finished should be present"
206
+ assert_equal false, info['instance_id'].nil?, "Screenshot instance_id should be present"
207
+ assert_equal false, info['response_code'].nil?, "Screenshot response_code should be present"
208
+ assert_equal false, info['final_url'].nil?, "Screenshot final_url should be present"
209
+ assert_equal false, info['content_type'].nil?, "Screenshot content_type should be present"
210
+ assert_equal false, info['scale'].nil?, "Screenshot scale should be present"
211
+ end
212
+ end
213
+
214
+ should "retrieve the list of screenshots" do
215
+ screenshots = @browshot.screenshot_list();
216
+ assert_equal true, screenshots.length > 0, "There should be multiple screenshots"
217
+
218
+ screenshot_id = 0
219
+ screenshots.each do |key, screenshot|
220
+ screenshot_id = key
221
+ break
222
+ end
223
+
224
+ assert_equal true, screenshot_id.to_i > 0, "Screesnot ID should be positive"
225
+ screenshot = screenshots[screenshot_id]
226
+
227
+ assert_equal false, screenshot['id'].nil?, "Screenshot ID should be present"
228
+ assert_equal false, screenshot['status'].nil?, "Screenshot status should be present"
229
+ assert_equal false, screenshot['priority'].nil?, "Screenshot priority should be present"
230
+
231
+ if (screenshot['status'] == 'finished')
232
+ assert_equal false, screenshot['screenshot_url'].nil?, "Screenshot screenshot_url should be present"
233
+ assert_equal false, screenshot['url'].nil?, "Screenshot url should be present"
234
+ assert_equal false, screenshot['size'].nil?, "Screenshot size should be present"
235
+ assert_equal false, screenshot['width'].nil?, "Screenshot width should be present"
236
+ assert_equal false, screenshot['height'].nil?, "Screenshot height should be present"
237
+ assert_equal false, screenshot['request_time'].nil?, "Screenshot request_time should be present"
238
+ assert_equal false, screenshot['started'].nil?, "Screenshot started should be present"
239
+ assert_equal false, screenshot['load'].nil?, "Screenshot load should be present"
240
+ assert_equal false, screenshot['content'].nil?, "Screenshot content should be present"
241
+ assert_equal false, screenshot['finished'].nil?, "Screenshot finished should be present"
242
+ assert_equal false, screenshot['instance_id'].nil?, "Screenshot instance_id should be present"
243
+ assert_equal false, screenshot['response_code'].nil?, "Screenshot response_code should be present"
244
+ assert_equal false, screenshot['final_url'].nil?, "Screenshot final_url should be present"
245
+ assert_equal false, screenshot['content_type'].nil?, "Screenshot content_type should be present"
246
+ assert_equal false, screenshot['scale'].nil?, "Screenshot scale should be present"
247
+ end
248
+ end
249
+
250
+ should "retrieve a thrumbnail" do
251
+ # TODO
252
+ end
253
+
254
+ should "retrieve account information" do
255
+ account = @browshot.account_info()
256
+ assert_equal false, account['balance'].nil?, "Account balance should be present"
257
+ assert_equal 0, account['balance'].to_i, "Balance should be empty"
258
+ assert_equal false, account['active'].nil?, "Account active should be present"
259
+ assert_equal 1, account['active'].to_i, "Accountshould be active"
260
+ assert_equal false, account['instances'].nil?, "Account instances should be present"
261
+ end
262
+
263
+ should "refuse invalid key" do
264
+ bad = Browshot.new()
265
+ account = bad.account_info()
266
+ assert_equal false, account['error'].nil?, "Request should be invalid"
267
+ end
268
+ end
269
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: browshot
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Julien Sobrier
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: &165066380 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *165066380
25
+ - !ruby/object:Gem::Dependency
26
+ name: url
27
+ requirement: &165065860 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *165065860
36
+ - !ruby/object:Gem::Dependency
37
+ name: shoulda
38
+ requirement: &165065360 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *165065360
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: &165064880 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *165064880
58
+ - !ruby/object:Gem::Dependency
59
+ name: jeweler
60
+ requirement: &165064380 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 1.6.4
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *165064380
69
+ - !ruby/object:Gem::Dependency
70
+ name: rcov
71
+ requirement: &165063880 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *165063880
80
+ description: ! 'Browshot (http://www.browshot.com/) is a web service to easily make
81
+ screenshots of web pages in any screen size, as any device: iPhone©, iPad©, Android©,
82
+ Nook©, PC, etc. Browshot has full Flash, JavaScript, CSS, & HTML5 support. The latest
83
+ API version is detailed at http://browshot.com/api/documentation. browshot.rb follows
84
+ the API documentation very closely: the function names are similar to the URLs used
85
+ (screenshot/create becomes screenshot_create(), instance/list becomes instance_list(),
86
+ etc.), the request arguments are exactly the same, etc. The library version matches
87
+ closely the API version it handles: browshot 1.0.0 is the first release for the
88
+ API 1.0, browshot 1.1.1 is the second release for the API 1.1, etc. browshot.rb
89
+ can handle most the API updates within the same major version, e.g. browshot.rb
90
+ 1.0.0 should be compatible with the API 1.1 or 1.2.'
91
+ email: julien@sobrier.net
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files:
95
+ - LICENSE.txt
96
+ - README.rdoc
97
+ files:
98
+ - Gemfile
99
+ - Gemfile.lock
100
+ - LICENSE.txt
101
+ - README.rdoc
102
+ - Rakefile
103
+ - VERSION
104
+ - lib/browshot.rb
105
+ - test/helper.rb
106
+ - test/test_browshot.rb
107
+ homepage: http://github.com/juliensobrier/browshot-ruby
108
+ licenses:
109
+ - MIT
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ segments:
121
+ - 0
122
+ hash: 3205083617624134341
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ! '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 1.8.11
132
+ signing_key:
133
+ specification_version: 3
134
+ summary: Ruby library for Browshot (L<http://www.browshot.com/>), a web service to
135
+ create website screenshots.
136
+ test_files: []