browserstack-screenshot 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.DS_Store +0 -0
- data/.gitignore +17 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +103 -0
- data/Rakefile +1 -0
- data/browserstack-screenshot.gemspec +23 -0
- data/lib/screenshot/client.rb +98 -0
- data/lib/screenshot/version.rb +3 -0
- data/lib/screenshot.rb +5 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZTUyYmVmYzE5MDJmZDA5YjY4MGRhOGVkNzBlZmEyMWZmYTcyNmU2MQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
N2E2YzM4YzM3Yjk3ODg5NWJiYjY0YzdkYWYxNzk5YTNlZTRhZjk3YQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MTRkODZlN2UwZmFmZjA4ZDRlMjIzN2U2NWU2ZTYwOTQwMzkzMDBmMTY4NzQy
|
10
|
+
MGJlMTU0ZWM3Yzg1MzgyM2IzOGNjYTM4ZTFiMzk0N2RkNWQwNDU0Y2U3Nzcw
|
11
|
+
NmU5M2NkMmVmOGExNzA0OGY5MjdkMzBjZmRkZmI4MzQ5MWVjNDE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZWQyMzBiMTY3YjNhYzY0N2M0NWNjZWMwNzc0ODMxMGZmYTc4OWEwZWZkZWMx
|
14
|
+
NDZmODRmOGUxMjIzYzU0NjdkZjI1OGUwMTI2NDQwYzk4OWMxY2Q0MWJmYjk1
|
15
|
+
YWFjNTljNWI3NGU3MWJiMjc3MTNlYzk1N2JhNWE5YThkODgzMmU=
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
screenshots
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-1.8.7
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 ahmed1490
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
# BrowserStack Screenshots
|
2
|
+
|
3
|
+
A ruby gem for [BrowserStack](http://browserstack.com)'s [Screenshot](http://browserstack.com/screenshots) [API](http://www.browserstack.com/screenshots/api).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'browserstack-screenshot'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
gem install browserstack-screenshot
|
18
|
+
|
19
|
+
## Example of Use
|
20
|
+
|
21
|
+
First, you need to require the screenshot gem:
|
22
|
+
|
23
|
+
``` ruby
|
24
|
+
require 'screenshot'
|
25
|
+
```
|
26
|
+
|
27
|
+
### Creating Client
|
28
|
+
Creates a new client instance.
|
29
|
+
|
30
|
+
* `settings`: A hash of settings that apply to all requests for the new client.
|
31
|
+
* `:username`: The username for the BrowserStack account.
|
32
|
+
* `:password`: The password for the BrowserStack account.
|
33
|
+
|
34
|
+
``` ruby
|
35
|
+
settings = {:username => "foo", :password => "foobar"}
|
36
|
+
client = Screenshot::Client.new(settings)
|
37
|
+
```
|
38
|
+
|
39
|
+
###API
|
40
|
+
|
41
|
+
####Getting available os and browsers
|
42
|
+
Fetches all available browsers. [API info](http://www.browserstack.com/screenshots/api#browser-list)
|
43
|
+
|
44
|
+
``` ruby
|
45
|
+
client.get_os_and_browsers #returns a hash
|
46
|
+
```
|
47
|
+
|
48
|
+
####Generating Screenshots
|
49
|
+
Frame the config object according to the format given. [Format info](http://www.browserstack.com/screenshots/api#job-ids)
|
50
|
+
|
51
|
+
Eg settings object:
|
52
|
+
``` ruby
|
53
|
+
params = {
|
54
|
+
:url => "www.google.com",
|
55
|
+
:callback_url => "http://example.com/pingback_url",
|
56
|
+
:win_res => "1024x768", #Options : "1024x768", "1280x1024"
|
57
|
+
:mac_res => "1920x1080", #Options : "1024x768", "1280x960", "1280x1024", "1600x1200", "1920x1080"
|
58
|
+
:quality => "compressed", #Options : "compressed", "original"
|
59
|
+
:tunnel => false,
|
60
|
+
:browsers => [
|
61
|
+
{:os=>"Windows",:os_version=>"7",:browser=>"ie",:browser_version=>"8.0"},
|
62
|
+
{:os=>"Windows",:os_version=>"XP",:browser=>"ie",:browser_version=>"7.0"}
|
63
|
+
]
|
64
|
+
}
|
65
|
+
```
|
66
|
+
`callback_url`, `win_res`, `mac_res`, `quality` and `tunnel` being optional parameters.
|
67
|
+
|
68
|
+
#####For testing Local/Internal Server setup
|
69
|
+
* First setup local tunnel using the command line method as mentioned [here](http://www.browserstack.com/local-testing#setup)
|
70
|
+
* Pass `:tunnel => true` in the params object
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
A request id is returned when a valid request is made.
|
75
|
+
|
76
|
+
``` ruby
|
77
|
+
request_id = client.generate_screenshots params
|
78
|
+
```
|
79
|
+
|
80
|
+
####Checking/Polling the status of the request
|
81
|
+
Use this method to check if the requested screenshots are complete.
|
82
|
+
``` ruby
|
83
|
+
client.screenshots_done? request_id #returns `true` or `false`
|
84
|
+
```
|
85
|
+
|
86
|
+
Or you can fetch the request state
|
87
|
+
``` ruby
|
88
|
+
client.screenshots_status request_id #returns `queue` or `processing` or `done`
|
89
|
+
```
|
90
|
+
|
91
|
+
####Fetching the response of the requested screenshots
|
92
|
+
``` ruby
|
93
|
+
client.screenshots request_id
|
94
|
+
```
|
95
|
+
|
96
|
+
|
97
|
+
## Contributing
|
98
|
+
|
99
|
+
1. Fork it
|
100
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
101
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
102
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
103
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'screenshot/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "browserstack-screenshot"
|
8
|
+
spec.version = Screenshot::VERSION
|
9
|
+
spec.authors = ["ahmed1490"]
|
10
|
+
spec.email = ["ahmed1490@gmail.com"]
|
11
|
+
spec.description = %q{Ruby wrapper for Browserstack screenshots API}
|
12
|
+
spec.summary = %q{Get screenshots from live browsers using this gem}
|
13
|
+
spec.homepage = "https://github.com/browserstack/ruby-screenshots"
|
14
|
+
spec.license = ""
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_dependency("yajl-ruby", "1.1.0")
|
23
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
module Screenshot
|
2
|
+
class Client
|
3
|
+
|
4
|
+
API = "http://www.browserstack.com/screenshots"
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
options = symbolize_keys options
|
8
|
+
unless options[:username] && options[:password]
|
9
|
+
raise "Expecting Parameters: username and password in the options Hash!"
|
10
|
+
end
|
11
|
+
@authentication = "Basic " + Base64.encode64("#{options[:username]}:#{options[:password]}").strip
|
12
|
+
#authenticate options, AUTH_URI
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_os_and_browsers
|
17
|
+
res = http_get_request :extend_uri => "browsers.json"
|
18
|
+
parse res
|
19
|
+
end
|
20
|
+
|
21
|
+
def generate_screenshots configHash={}
|
22
|
+
res = http_post_request :data => Yajl::Encoder.encode(configHash)
|
23
|
+
responseJson = parse res
|
24
|
+
request = responseJson[:job_id]
|
25
|
+
end
|
26
|
+
|
27
|
+
def screenshots_done? job_id
|
28
|
+
(screenshots_status job_id) == "done" ? true : false
|
29
|
+
end
|
30
|
+
|
31
|
+
def screenshots_status job_id
|
32
|
+
res = http_get_request :extend_uri => "#{job_id}.json"
|
33
|
+
responseJson = parse res
|
34
|
+
responseJson[:state]
|
35
|
+
end
|
36
|
+
|
37
|
+
def screenshots job_id
|
38
|
+
res = http_get_request :extend_uri => "#{job_id}.json"
|
39
|
+
responseJson = parse res
|
40
|
+
responseJson[:screenshots]
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def authenticate options, uri=API
|
45
|
+
http_get_request options, uri
|
46
|
+
end
|
47
|
+
|
48
|
+
def http_get_request options={}, uri=API
|
49
|
+
uri = URI.parse uri if uri
|
50
|
+
uri.path = uri.path + "/#{options[:extend_uri].to_s}" if options[:extend_uri]
|
51
|
+
req = Net::HTTP::Get.new uri.request_uri
|
52
|
+
make_request req, options, uri
|
53
|
+
end
|
54
|
+
|
55
|
+
def http_post_request options={}, uri=API
|
56
|
+
uri = URI.parse uri if uri
|
57
|
+
req = Net::HTTP::Post.new uri.request_uri, initheader = {'Content-Type' =>'application/json'}
|
58
|
+
req.body = options[:data] if options[:data]
|
59
|
+
make_request req, options, uri
|
60
|
+
end
|
61
|
+
|
62
|
+
def make_request req, options={}, uri=API
|
63
|
+
conn = Net::HTTP.new uri.host, uri.port
|
64
|
+
add_authentication options, req
|
65
|
+
res = conn.request req
|
66
|
+
http_response_code_check res
|
67
|
+
res
|
68
|
+
end
|
69
|
+
|
70
|
+
def add_authentication options, req
|
71
|
+
req["Authorization"] = @authentication
|
72
|
+
req
|
73
|
+
end
|
74
|
+
|
75
|
+
def http_response_code_check res
|
76
|
+
case res.code.to_i
|
77
|
+
when 200
|
78
|
+
res
|
79
|
+
when 401
|
80
|
+
raise "401 Unauthorized : Authentication Failed!"
|
81
|
+
when 422
|
82
|
+
raise "Unprocessable entity."+"\n Response Body: "+res.body
|
83
|
+
else
|
84
|
+
raise "Unexpected Response Code : "+res.code+"\n Response Body: "+res.body
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def parse(response)
|
89
|
+
parser = Yajl::Parser.new(:symbolize_keys => true)
|
90
|
+
parser.parse(response.body)
|
91
|
+
end
|
92
|
+
|
93
|
+
def symbolize_keys hash
|
94
|
+
hash.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
95
|
+
end
|
96
|
+
|
97
|
+
end #Client
|
98
|
+
end #Screenshots
|
data/lib/screenshot.rb
ADDED
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: browserstack-screenshot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ahmed1490
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: yajl-ruby
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.1.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.1.0
|
41
|
+
description: Ruby wrapper for Browserstack screenshots API
|
42
|
+
email:
|
43
|
+
- ahmed1490@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- !binary |-
|
49
|
+
LkRTX1N0b3Jl
|
50
|
+
- !binary |-
|
51
|
+
LmdpdGlnbm9yZQ==
|
52
|
+
- !binary |-
|
53
|
+
LnJ1YnktZ2Vtc2V0
|
54
|
+
- !binary |-
|
55
|
+
LnJ1YnktdmVyc2lvbg==
|
56
|
+
- !binary |-
|
57
|
+
R2VtZmlsZQ==
|
58
|
+
- !binary |-
|
59
|
+
TElDRU5TRS50eHQ=
|
60
|
+
- !binary |-
|
61
|
+
UkVBRE1FLm1k
|
62
|
+
- !binary |-
|
63
|
+
UmFrZWZpbGU=
|
64
|
+
- !binary |-
|
65
|
+
YnJvd3NlcnN0YWNrLXNjcmVlbnNob3QuZ2Vtc3BlYw==
|
66
|
+
- !binary |-
|
67
|
+
bGliL3NjcmVlbnNob3QucmI=
|
68
|
+
- !binary |-
|
69
|
+
bGliL3NjcmVlbnNob3QvY2xpZW50LnJi
|
70
|
+
- !binary |-
|
71
|
+
bGliL3NjcmVlbnNob3QvdmVyc2lvbi5yYg==
|
72
|
+
homepage: https://github.com/browserstack/ruby-screenshots
|
73
|
+
licenses:
|
74
|
+
- ''
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.0.3
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Get screenshots from live browsers using this gem
|
96
|
+
test_files: []
|