browshot 1.14.0 → 1.16.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51442cd950b03b0460cc2688dc05836ee21988a5
4
- data.tar.gz: 8beba4478dc66aa0723ee3a1511dba76d9b51f5c
3
+ metadata.gz: b028681c4d0960152ecc9202204806a51fe50c46
4
+ data.tar.gz: 40fd0ccc8878200afe4f52d56c1d275f8a446d2f
5
5
  SHA512:
6
- metadata.gz: 547ad76a3d2ab3f6d12df58b6fb33c0f4587e8f4d8c9621f347eb699f594b4fbf3bfcece97f10de75360279d606a20ad7058a96ecdce3503fb94710e887a2ffd
7
- data.tar.gz: 008bf622b3d388335f9c4e590264154d1bb3c9e755696c86599c14f564b2fa265535540417edf6da8ee8b6ddab4f4eab9c05784269e12ed63885d61330934e4f
6
+ metadata.gz: c05b5fb8570efe864ec45acb4afb0d9c73aaac3dcfdc5b06ad8241e9e26df40eda540b4d7800748156a478aacfc92b7e0154b2a5715aedfeeb1e78d8a9544326
7
+ data.tar.gz: 19cdc44a170a87d70cbddba7141102ee2c957aca6946506de600a403018626508959d4a77978711a34999fbfab2afff965bf0ac812546fa4c27f8045fc99738a
data/Gemfile CHANGED
@@ -4,3 +4,6 @@ source "http://rubygems.org"
4
4
  gem "json", ">= 0"
5
5
  gem "url", ">= 0"
6
6
 
7
+ group :test do
8
+ gem 'shoulda'
9
+ end
data/Rakefile CHANGED
@@ -5,4 +5,14 @@ Rake::TestTask.new do |t|
5
5
  end
6
6
 
7
7
  desc "Run tests"
8
- task :default => :test
8
+ task :default => :test
9
+
10
+ require 'rdoc/task'
11
+ Rake::RDocTask.new do |rdoc|
12
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
13
+
14
+ rdoc.rdoc_dir = 'rdoc'
15
+ rdoc.title = "browshot #{version}"
16
+ rdoc.rdoc_files.include('README*')
17
+ rdoc.rdoc_files.include('lib/**/*.rb')
18
+ end
@@ -5,7 +5,7 @@
5
5
  # and this library.
6
6
  #
7
7
  # @author Julien Sobrier (mailto:jsobrier@browshot.com)
8
- # Copyright:: Copyright (c) 2013 Browshot
8
+ # Copyright:: Copyright (c) 2016 Browshot
9
9
  # License:: Distributes under the same terms as Ruby
10
10
 
11
11
  require 'rubygems'
@@ -13,6 +13,7 @@ require 'url'
13
13
  require 'json'
14
14
  require 'net/http'
15
15
  require 'net/https'
16
+ require "cgi"
16
17
 
17
18
  class Browshot
18
19
  # @!attribute [r]
@@ -28,17 +29,17 @@ class Browshot
28
29
  # New client
29
30
  #
30
31
  # @param key [String] API key
31
- # @param base [String] 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.
32
32
  # @param debug [Boolean] Set to true to print debug output to the standard output. false (disabled) by default.
33
- def initialize(key='', base='https://api.browshot.com/api/v1/', debug=false)
33
+ # @param base [String] 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.
34
+ def initialize(key='', debug=false, base='https://api.browshot.com/api/v1/')
34
35
  @key = key || ''
35
- @base = base || 'http://127.0.0.1:3000/api/v1/'
36
+ @base = base || 'https://api.browshot.com/api/v1/'
36
37
  @debug = debug || false
37
38
  end
38
39
 
39
40
  # Return the API version handled by the library. Note that this library can usually handle new arguments in requests without requiring an update.
40
41
  def api_version()
41
- return "1.14"
42
+ return "1.16"
42
43
  end
43
44
 
44
45
  # Retrieve a screenshot with one call. See {https://browshot.com/api/documentation#simple} for the full list of possible arguments.
@@ -87,10 +88,6 @@ class Browshot
87
88
  return return_reply('instance/info', { 'id' => id })
88
89
  end
89
90
 
90
- # Create a private instance. See http://browshot.com/api/documentation#instance_create for the response format.
91
- def instance_create(parameters={})
92
- return return_reply('instance/create', parameters)
93
- end
94
91
 
95
92
  # Return the list of browsers. See http://browshot.com/api/documentation#browser_list for the response format.
96
93
  def browser_list()
@@ -104,10 +101,6 @@ class Browshot
104
101
  return return_reply('browser/info', { 'id' => id })
105
102
  end
106
103
 
107
- # Create a custom browser. See http://browshot.com/api/documentation#browser_create for the response format.
108
- def browser_create(parameters={})
109
- return return_reply('browser/create', parameters)
110
- end
111
104
 
112
105
  # Request a screenshot. See http://browshot.com/api/documentation#screenshot_create for the response format.
113
106
  #
@@ -221,11 +214,7 @@ class Browshot
221
214
  # Request multiple screenshots. See http://browshot.com/api/documentation#screenshot_multiple for the response format.
222
215
  #
223
216
  # See http://browshot.com/api/documentation#screenshot_multiple for the full list of possible arguments.
224
- #
225
- # @param url [String] URL of the website to create a screenshot of
226
- def screenshot_multiple(url='', parameters={})
227
- parameters[:url] = url
228
-
217
+ def screenshot_multiple(parameters={})
229
218
  return return_reply('screenshot/multiple', parameters)
230
219
  end
231
220
 
@@ -236,7 +225,7 @@ class Browshot
236
225
  # @param id [Integer] Instance ID
237
226
  # @param file [String] Path to the text file which contains the list of URLs
238
227
  def batch_create(id=0, file='', parameters={})
239
- parameters[:id] = id
228
+ parameters[:instance_id] = id
240
229
  parameters[:file] = file
241
230
 
242
231
  return return_post_reply('batch/create', parameters)
@@ -262,11 +251,21 @@ class Browshot
262
251
  private
263
252
 
264
253
  def make_url(action='', parameters={})
265
- url = URL.new("#{@base}#{action}?key=#{@key}")
254
+ url = "#{@base}#{action}?key=#{@key}"
266
255
 
267
256
 
268
257
  parameters.each_pair do |key, value|
269
- url.params[key] = value
258
+ if (key == 'urls')
259
+ value.each { |val|
260
+ url += '&url=' + CGI::escape(val.to_s)
261
+ }
262
+ elsif (key == 'instances')
263
+ value.each { |instance|
264
+ url += '&instance_id=' + CGI::escape(instance.to_s)
265
+ }
266
+ else
267
+ url += "&#{key}=" + CGI::escape(value.to_s)
268
+ end
270
269
  end
271
270
 
272
271
  puts "#{url}" if (@debug)
@@ -302,9 +301,9 @@ class Browshot
302
301
  begin
303
302
  url = make_url(action, parameters)
304
303
 
305
- response = url.get
304
+ response = Net::HTTP.get_response(URI(url))
306
305
 
307
- if (response.success? == false)
306
+ if (response.code == 200)
308
307
  puts "Error from #{url}: #{response.code}" if (@debug)
309
308
  end
310
309
  return response.response.body
@@ -320,7 +319,7 @@ class Browshot
320
319
  parameters.delete(:file)
321
320
  url = make_url(action, parameters)
322
321
 
323
- response = post(url.to_s,file)
322
+ response = post(url,file)
324
323
 
325
324
  case response
326
325
  when Net::HTTPSuccess then
@@ -1,5 +1,7 @@
1
1
  require 'rubygems'
2
+ require 'shoulda'
2
3
  require 'bundler'
4
+
3
5
  begin
4
6
  Bundler.setup(:default, :development)
5
7
  rescue Bundler::BundlerError => e
@@ -7,8 +9,10 @@ rescue Bundler::BundlerError => e
7
9
  $stderr.puts "Run `bundle install` to install missing gems"
8
10
  exit e.status_code
9
11
  end
12
+
13
+ require 'rubygems'
10
14
  require 'test/unit'
11
- require 'shoulda'
15
+ # require 'shoulda'
12
16
 
13
17
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
18
  $LOAD_PATH.unshift(File.dirname(__FILE__))
@@ -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.14', @browshot.api_version()
17
+ assert_equal '1.16', @browshot.api_version()
18
18
  end
19
19
 
20
20
  should "get a screenshot with the simple method" do
@@ -32,17 +32,17 @@ class TestBrowshot < Test::Unit::TestCase
32
32
  should "get the list of instances available" do
33
33
  # assert_equal 10, @calculator.product(2, 5)
34
34
  instances = @browshot.instance_list()
35
- assert_equal false, instances['free'].nil?, "List of free instances is missing"
36
- assert_equal true, instances['free'].kind_of?(Array), "List of free instances is incorrect"
37
- assert_equal true, instances['free'].length > 0, "There should be at least 1 free instance"
35
+ assert_equal false, instances['free'].nil?, "List of free instances is missing"
36
+ assert_equal true, instances['free'].kind_of?(Array), "List of free instances is incorrect"
37
+ assert_equal true, instances['free'].length > 0, "There should be at least 1 free instance"
38
38
 
39
- assert_equal false, instances['shared'].nil?, "List of shared instances is missing"
40
- assert_equal true, instances['shared'].kind_of?(Array), "List of shared instances is incorrect"
41
- assert_equal true, instances['shared'].length > 0, "There should be at least 1 shared instance"
39
+ assert_equal false, instances['shared'].nil?, "List of shared instances is missing"
40
+ assert_equal true, instances['shared'].kind_of?(Array), "List of shared instances is incorrect"
41
+ assert_equal true, instances['shared'].length > 0, "There should be at least 1 shared instance"
42
42
 
43
- assert_equal false, instances['private'].nil?, "List of private instances is missing"
44
- assert_equal true, instances['private'].kind_of?(Array), "List of private instances is incorrect"
45
- assert_equal true, instances['private'].length == 0, "There should be at least no private instance"
43
+ assert_equal false, instances['private'].nil?, "List of private instances is missing"
44
+ assert_equal true, instances['private'].kind_of?(Array), "List of private instances is incorrect"
45
+ assert_equal true, instances['private'].length == 1, "There should be at least no private instance"
46
46
 
47
47
  free = instances['free'][0]
48
48
  assert_equal false, free['id'].nil?, "Missing instance ID"
@@ -50,14 +50,14 @@ class TestBrowshot < Test::Unit::TestCase
50
50
  assert_equal false, free['height'].nil?, "Missing instance screen height"
51
51
  assert_equal false, free['load'].nil?, "Missing instance load"
52
52
  assert_equal false, free['browser'].nil?, "Missing instance browser"
53
- assert_equal false, free['browser']['id'].nil?, "Missing instance browser ID"
54
- assert_equal false, free['browser']['name'].nil?, "Missing instance browser name"
55
- assert_equal false, free['browser']['javascript'].nil?, "Missing instance browser javascript capability"
56
- assert_equal false, free['browser']['flash'].nil?, "Missing instance browser flash capability"
57
- assert_equal false, free['browser']['mobile'].nil?, "Missing instance browser mobile capability"
53
+ assert_equal false, free['browser']['id'].nil?, "Missing instance browser ID"
54
+ assert_equal false, free['browser']['name'].nil?, "Missing instance browser name"
55
+ assert_equal false, free['browser']['javascript'].nil?, "Missing instance browser javascript capability"
56
+ assert_equal false, free['browser']['flash'].nil?, "Missing instance browser flash capability"
57
+ assert_equal false, free['browser']['mobile'].nil?, "Missing instance browser mobile capability"
58
58
  assert_equal false, free['type'].nil?, "Missing instance type"
59
- assert_equal false, free['screenshot_cost'].nil?, "Missing instance cost"
60
- assert_equal 0, free['screenshot_cost'].to_i, "Cost should be 0"
59
+ assert_equal false, free['screenshot_cost'].nil?, "Missing instance cost"
60
+ assert_equal 0, free['screenshot_cost'].to_i, "Cost should be 0"
61
61
  end
62
62
 
63
63
  should "get an instance information" do
@@ -65,17 +65,17 @@ class TestBrowshot < Test::Unit::TestCase
65
65
  free = instances['free'][0]
66
66
 
67
67
  instance = @browshot.instance_info(free['id'])
68
- assert_equal free['id'], instance['id'], "Mismatch instance ID"
69
- assert_equal free['width'], instance['width'], "Mismatch instance screen width"
70
- assert_equal free['height'], instance['height'], "Mismatch instance screen height"
71
- # assert_equal free['load'], instance['load'], "Mismatch instance load"
72
- assert_equal free['browser']['id'], instance['browser']['id'], "Mismatch instance browser ID"
73
- assert_equal free['browser']['name'], instance['browser']['name'], "Mismatch instance browser name"
68
+ assert_equal free['id'], instance['id'], "Mismatch instance ID"
69
+ assert_equal free['width'], instance['width'], "Mismatch instance screen width"
70
+ assert_equal free['height'], instance['height'], "Mismatch instance screen height"
71
+ # assert_equal free['load'], instance['load'], "Mismatch instance load"
72
+ assert_equal free['browser']['id'], instance['browser']['id'], "Mismatch instance browser ID"
73
+ assert_equal free['browser']['name'], instance['browser']['name'], "Mismatch instance browser name"
74
74
  assert_equal free['browser']['javascript'], instance['browser']['javascript'],"Mismatch instance browser javascript capability"
75
- assert_equal free['browser']['flash'], instance['browser']['flash'], "Mismatch instance browser flash capability"
76
- assert_equal free['browser']['mobile'], instance['browser']['mobile'], "Mismatch instance browser mobile capability"
77
- assert_equal free['type'], instance['type'], "Mismatch instance type"
78
- assert_equal free['screenshot_cost'], instance['screenshot_cost'], "Mismatch instance cost"
75
+ assert_equal free['browser']['flash'], instance['browser']['flash'], "Mismatch instance browser flash capability"
76
+ assert_equal free['browser']['mobile'].to_i, instance['browser']['mobile'].to_i, "Mismatch instance browser mobile capability"
77
+ assert_equal free['type'], instance['type'], "Mismatch instance type"
78
+ assert_equal free['screenshot_cost'].to_i, instance['screenshot_cost'].to_i, "Mismatch instance cost"
79
79
  end
80
80
 
81
81
  should "send an error for the wrong instance ID" do
@@ -85,29 +85,29 @@ 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 instance with ivalid arguments" do
89
- instance = @browshot.instance_create({'width' => 3000})
90
- assert_equal false, instance['error'].nil?, "Instance width should be too large"
91
-
92
- instance = @browshot.instance_create({'height' => 3000})
93
- assert_equal false, instance['error'].nil?, "Instance width should be too large"
94
-
95
- instance = @browshot.instance_create({'browser_id' => -1})
96
- assert_equal false, instance['error'].nil?, "Instance browser ID should be invalid"
97
- end
88
+ # should "send an errror when creating a instance with ivalid arguments" do
89
+ # instance = @browshot.instance_create({'width' => 3000})
90
+ # assert_equal false, instance['error'].nil?, "Instance width should be too large"
91
+ #
92
+ # instance = @browshot.instance_create({'height' => 3000})
93
+ # assert_equal false, instance['error'].nil?, "Instance width should be too large"
94
+ #
95
+ # instance = @browshot.instance_create({'browser_id' => -1})
96
+ # assert_equal false, instance['error'].nil?, "Instance browser ID should be invalid"
97
+ # end
98
98
 
99
- should "create a new instance" do
100
- # Option disabled for most accounts
101
- instance = @browshot.instance_create()
102
-
103
- assert_equal false, instance['error'].nil?, "Instance cannot be created for this account"
104
- # assert_equal false, instance['id'].nil?, "Instance ID should be present"
105
- # assert_equal false, instance['width'].nil?, "Instance screen width should be present"
106
- # assert_equal false, instance['height'].nil?, "Instance screen height should be present"
107
- # assert_equal 1, instance['active'].to_i, "Instance should be active"
108
- # assert_equal false, instance['browser'].nil?, "Instance browser should be present"
109
- # assert_equal false, instance['browser']['id'].nil?, "Instance browser ID should be present"
110
- end
99
+ # should "create a new instance" do
100
+ # # Option disabled for most accounts
101
+ # instance = @browshot.instance_create()
102
+ #
103
+ # assert_equal false, instance['error'].nil?, "Instance cannot be created for this account"
104
+ # # assert_equal false, instance['id'].nil?, "Instance ID should be present"
105
+ # # assert_equal false, instance['width'].nil?, "Instance screen width should be present"
106
+ # # assert_equal false, instance['height'].nil?, "Instance screen height should be present"
107
+ # # assert_equal 1, instance['active'].to_i, "Instance should be active"
108
+ # # assert_equal false, instance['browser'].nil?, "Instance browser should be present"
109
+ # # assert_equal false, instance['browser']['id'].nil?, "Instance browser ID should be present"
110
+ # end
111
111
 
112
112
  should "get the list of browsers" do
113
113
  browsers = @browshot.browser_list()
@@ -135,23 +135,23 @@ class TestBrowshot < Test::Unit::TestCase
135
135
  assert_equal false, browser['flash'].nil?, "Browser flash capability should be present"
136
136
  end
137
137
 
138
- should "create a browser" do
139
- # Option disabled for most accounts
140
- browser = @browshot.browser_create({'mobile' => 1, 'flash' => 1, 'user_agent' => 'test'})
141
-
142
- assert_equal false, browser['error'].nil?, "Browser cannot be created for this account"
143
- # assert_equal false, browser['name'].nil?, "Browser name should be present"
144
- # assert_equal false, browser['user_agent'].nil?, "Browser user_agent should be present"
145
- # assert_equal false, browser['appname'].nil?, "Browser appname should be present"
146
- # assert_equal false, browser['vendorsub'].nil?, "Browser vendorsub should be present"
147
- # assert_equal false, browser['appcodename'].nil?, "Browser appcodename should be present"
148
- # assert_equal false, browser['platform'].nil?, "Browser platform should be present"
149
- # assert_equal false, browser['vendor'].nil?, "Browser vendor should be present"
150
- # assert_equal false, browser['appversion'].nil?, "Browser appversion should be present"
151
- # assert_equal false, browser['javascript'].nil?, "Browser javascript capability should be present"
152
- # assert_equal false, browser['mobile'].nil?, "Browser mobile capability should be present"
153
- # assert_equal false, browser['flash'].nil?, "Browser flash capability should be present"
154
- end
138
+ # should "create a browser" do
139
+ # # Option disabled for most accounts
140
+ # browser = @browshot.browser_create({'mobile' => 1, 'flash' => 1, 'user_agent' => 'test'})
141
+ #
142
+ # assert_equal false, browser['error'].nil?, "Browser cannot be created for this account"
143
+ # # assert_equal false, browser['name'].nil?, "Browser name should be present"
144
+ # # assert_equal false, browser['user_agent'].nil?, "Browser user_agent should be present"
145
+ # # assert_equal false, browser['appname'].nil?, "Browser appname should be present"
146
+ # # assert_equal false, browser['vendorsub'].nil?, "Browser vendorsub should be present"
147
+ # # assert_equal false, browser['appcodename'].nil?, "Browser appcodename should be present"
148
+ # # assert_equal false, browser['platform'].nil?, "Browser platform should be present"
149
+ # # assert_equal false, browser['vendor'].nil?, "Browser vendor should be present"
150
+ # # assert_equal false, browser['appversion'].nil?, "Browser appversion should be present"
151
+ # # assert_equal false, browser['javascript'].nil?, "Browser javascript capability should be present"
152
+ # # assert_equal false, browser['mobile'].nil?, "Browser mobile capability should be present"
153
+ # # assert_equal false, browser['flash'].nil?, "Browser flash capability should be present"
154
+ # end
155
155
 
156
156
  should "fail to create screenshot" do
157
157
  screenshot = @browshot.screenshot_create()
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browshot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.14.0
4
+ version: 1.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julien Sobrier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-20 00:00:00.000000000 Z
11
+ date: 2016-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -125,11 +125,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  version: '0'
126
126
  requirements: []
127
127
  rubyforge_project:
128
- rubygems_version: 2.2.1
128
+ rubygems_version: 2.4.5
129
129
  signing_key:
130
130
  specification_version: 4
131
- summary: Take website screenshtos with Browshot
131
+ summary: Take website screenshots with Browshot
132
132
  test_files:
133
133
  - test/helper.rb
134
134
  - test/test_browshot.rb
135
- has_rdoc: