cbt_ruby 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/cbt_ruby/browser.rb +25 -0
- data/lib/cbt_ruby/browsers.rb +16 -0
- data/lib/cbt_ruby/screenshot_info.rb +30 -0
- data/lib/cbt_ruby/screenshot_test.rb +48 -0
- data/lib/cbt_ruby.rb +58 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c626a155980f1c81b339bef8f541bee9a2a3aef1
|
4
|
+
data.tar.gz: 80f5758e79797a9f5a2cff286f389d4a1257e37f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '0388cf3ab5ebaf16e2743b7a1d05d2e2e7ad6968c1ba641661d46cd15fe99a3243211be81b5145fcc2a15f672a88084e1fc77b9c3c75b747f25e43adb7bde762'
|
7
|
+
data.tar.gz: 07a0c1e860377e5fb705318838df6879e1a28522a6094df26e01ae5acde38366b3566ffb1cfdfe201311647f7bba754d01bc695d81888500f3773eb270bea2e0
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module CBTRUBY
|
2
|
+
class CbtClient::Browser
|
3
|
+
def initialize(browser:, version:, platform: nil, resolution: nil)
|
4
|
+
@browser = browser
|
5
|
+
@version = version
|
6
|
+
@platform = platform
|
7
|
+
@resolution = resolution
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
string = "#{@browser}#{@version}"
|
12
|
+
if @platform.nil?
|
13
|
+
return string
|
14
|
+
else
|
15
|
+
string += "|#{@platform}"
|
16
|
+
if @resolution.nil?
|
17
|
+
return string
|
18
|
+
else
|
19
|
+
string += "|#{@resolution}"
|
20
|
+
return string
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module CBTRUBY
|
2
|
+
class CbtClient::Browsers
|
3
|
+
def initialize
|
4
|
+
@browsers = []
|
5
|
+
end
|
6
|
+
|
7
|
+
# takes a CbtClient::Browser object as input and adds it to the list of browsers
|
8
|
+
def add(browser)
|
9
|
+
@browsers.push(browser)
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
@browsers.map(&:to_s).join(',')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module CBTRUBY
|
2
|
+
class CbtClient::ScreenshotInfo
|
3
|
+
def initialize(client:, session:)
|
4
|
+
@client = client
|
5
|
+
@session = session
|
6
|
+
end
|
7
|
+
|
8
|
+
def request
|
9
|
+
@client.basic_request(url: "screenshots/#{@session}")
|
10
|
+
end
|
11
|
+
|
12
|
+
def running
|
13
|
+
status = request
|
14
|
+
#puts status
|
15
|
+
status['versions'][0]['active']
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class CbtClient::ScreenshotVersionInfo < CbtClient::ScreenshotInfo
|
20
|
+
def initialize(client:, session:, version:)
|
21
|
+
@client = client
|
22
|
+
@session = session
|
23
|
+
@version = version
|
24
|
+
end
|
25
|
+
|
26
|
+
def request
|
27
|
+
@client.basic_request(url: "screenshots/#{@session}/#{@version}")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module CBTRUBY
|
4
|
+
# Provides a simple interface to the CBT API for performing screenshot tests
|
5
|
+
class CbtClient::ScreenshotTest
|
6
|
+
# Set up the screenshot test
|
7
|
+
|
8
|
+
def initialize(client:, params:, block: true)
|
9
|
+
@input_params = params
|
10
|
+
# puts @input_params[:url]
|
11
|
+
@params = @input_params
|
12
|
+
format_params
|
13
|
+
# puts @params[:browsers]
|
14
|
+
@client = client
|
15
|
+
@block = block
|
16
|
+
|
17
|
+
self.begin
|
18
|
+
end
|
19
|
+
|
20
|
+
def format_params
|
21
|
+
@params[:browsers] = @params[:browsers].to_s if @params[:browsers]
|
22
|
+
|
23
|
+
if @params[:email_list]
|
24
|
+
@params[:email_list] = @params[:email_list].join(',')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def begin
|
29
|
+
@test = @client.basic_request(url: 'screenshots', reqMethod: POST, data: @params)
|
30
|
+
puts @test
|
31
|
+
@info = CBTRUBY::CbtClient::ScreenshotInfo.new(client: @client, session: @test['screenshot_test_id'])
|
32
|
+
if @block
|
33
|
+
@running = true
|
34
|
+
wait_for_finish
|
35
|
+
end
|
36
|
+
return @info.request
|
37
|
+
end
|
38
|
+
|
39
|
+
def wait_for_finish
|
40
|
+
while @running
|
41
|
+
sleep 15
|
42
|
+
@running = @info.running
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
require_relative 'screenshot_info'
|
data/lib/cbt_ruby.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module CBTRUBY
|
6
|
+
CBT_API = 'https://crossbrowsertesting.com/api/v3/'.freeze
|
7
|
+
POST = 'post'.freeze
|
8
|
+
GET = 'get'.freeze
|
9
|
+
|
10
|
+
# Core class for the gem.
|
11
|
+
class CbtClient
|
12
|
+
# Initialize the CBT client object using username and authkey
|
13
|
+
def initialize(username, authkey)
|
14
|
+
@username = username
|
15
|
+
@authkey = authkey
|
16
|
+
end
|
17
|
+
|
18
|
+
# Base for making API requests
|
19
|
+
# Returns a hash table
|
20
|
+
def basic_request(url:, reqMethod: 'get', data: nil)
|
21
|
+
uri = URI.parse(CBT_API + url)
|
22
|
+
|
23
|
+
# Set request method
|
24
|
+
case reqMethod
|
25
|
+
when 'post'
|
26
|
+
request = Net::HTTP::Post.new(uri)
|
27
|
+
request.set_form_data(data)
|
28
|
+
when 'get'
|
29
|
+
uri.query = URI.encode_www_form(data) unless data.nil?
|
30
|
+
request = Net::HTTP::Get.new(uri)
|
31
|
+
end
|
32
|
+
|
33
|
+
request.basic_auth(@username, @authkey)
|
34
|
+
|
35
|
+
req_options = {
|
36
|
+
use_ssl: uri.scheme == 'https'
|
37
|
+
}
|
38
|
+
|
39
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
40
|
+
http.request(request)
|
41
|
+
end
|
42
|
+
|
43
|
+
if response.code == '200'
|
44
|
+
return JSON.parse(response.body)
|
45
|
+
else
|
46
|
+
puts response.code
|
47
|
+
puts response.body
|
48
|
+
return JSON.parse(response.body)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
require_relative 'cbt_ruby/browser'
|
56
|
+
require_relative 'cbt_ruby/browsers'
|
57
|
+
require_relative 'cbt_ruby/screenshot_info'
|
58
|
+
require_relative 'cbt_ruby/screenshot_test'
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cbt_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Harold Schreckengost
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-30 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- harolds@crossbrowsertesting.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/cbt_ruby.rb
|
21
|
+
- lib/cbt_ruby/browser.rb
|
22
|
+
- lib/cbt_ruby/browsers.rb
|
23
|
+
- lib/cbt_ruby/screenshot_info.rb
|
24
|
+
- lib/cbt_ruby/screenshot_test.rb
|
25
|
+
homepage: https://github.com/crossbrowsertesting/cbt_ruby
|
26
|
+
licenses: []
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 2.6.13
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: A gem for interactiong with the CrossBrowserTesting.com API
|
48
|
+
test_files: []
|