sauce 0.1.0
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.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/lib/rest.rb +37 -0
- data/lib/sauce.rb +2 -0
- data/lib/tunnel.rb +39 -0
- data/test/debug.rb +7 -0
- data/test/helper.rb +10 -0
- data/test/test_sauce.rb +57 -0
- metadata +87 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Sauce Labs Inc
|
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,17 @@
|
|
1
|
+
= sauce
|
2
|
+
|
3
|
+
Ruby access to SauceLab's features
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Sauce Labs Inc. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "sauce"
|
8
|
+
gem.summary = "Ruby access to Sauce Labs' features"
|
9
|
+
gem.description = "A ruby interface to Sauce Labs' services. Start/stop tunnels, retrieve Selenium logs, access video replays, etc."
|
10
|
+
gem.email = "sean@saucelabs.com"
|
11
|
+
gem.homepage = "http://github.com/sgrove/sauce"
|
12
|
+
gem.authors = ["Sean Grove"]
|
13
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
+
gem.add_development_dependency "rest-client", ">= 0"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
Rake::TestTask.new(:test) do |test|
|
24
|
+
test.libs << 'lib' << 'test'
|
25
|
+
test.pattern = 'test/**/test_*.rb'
|
26
|
+
test.verbose = true
|
27
|
+
end
|
28
|
+
|
29
|
+
begin
|
30
|
+
require 'rcov/rcovtask'
|
31
|
+
Rcov::RcovTask.new do |test|
|
32
|
+
test.libs << 'test'
|
33
|
+
test.pattern = 'test/**/test_*.rb'
|
34
|
+
test.verbose = true
|
35
|
+
end
|
36
|
+
rescue LoadError
|
37
|
+
task :rcov do
|
38
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
task :test => :check_dependencies
|
43
|
+
|
44
|
+
task :default => :test
|
45
|
+
|
46
|
+
require 'rake/rdoctask'
|
47
|
+
Rake::RDocTask.new do |rdoc|
|
48
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
49
|
+
|
50
|
+
rdoc.rdoc_dir = 'rdoc'
|
51
|
+
rdoc.title = "sauce #{version}"
|
52
|
+
rdoc.rdoc_files.include('README*')
|
53
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
54
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/rest.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Sauce
|
5
|
+
class Client
|
6
|
+
class BadAccessError < StandardError; end #nodoc
|
7
|
+
class MisconfiguredError < StandardError; end #nodoc
|
8
|
+
|
9
|
+
attr_accessor :username, :access_key, :client, :api_url
|
10
|
+
|
11
|
+
def initialize(options)
|
12
|
+
@username = options[:username]
|
13
|
+
@access_key = options[:access_key]
|
14
|
+
|
15
|
+
raise MisconfiguredError if @username.nil? or @access_key.nil?
|
16
|
+
@api_url = "https://#{@username}:#{@access_key}@saucelabs.com/rest/#{@username}/"
|
17
|
+
@client = RestClient::Resource.new @api_url
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_tunnel(options)
|
21
|
+
response = JSON.parse @client[:tunnels].post(options.to_json, :content_type => 'application/json')
|
22
|
+
raise Sauce::Client::BadAccessError unless response["error"].nil?
|
23
|
+
Sauce::Tunnel.new(@client, response)
|
24
|
+
end
|
25
|
+
|
26
|
+
def tunnels(options = {})
|
27
|
+
response = JSON.parse @client[:tunnels].get
|
28
|
+
return response.collect{|r| Sauce::Tunnel.new(@client, r)}
|
29
|
+
end
|
30
|
+
|
31
|
+
def destroy_all_tunnels(options={})
|
32
|
+
tunnels.each do |t|
|
33
|
+
t.destroy
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/sauce.rb
ADDED
data/lib/tunnel.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
module Sauce
|
2
|
+
# Interact with a Sauce Labs tunnel as if it were a ruby object
|
3
|
+
class Tunnel
|
4
|
+
class NoIDError < StandardError; end #nodoc
|
5
|
+
|
6
|
+
attr_accessor :client, :application_address, :username, :access_key, :timeout
|
7
|
+
attr_accessor :status, :owner, :creation_time, :id, :host
|
8
|
+
|
9
|
+
def initialize(client, options)
|
10
|
+
@client = client
|
11
|
+
build!(options)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Hits the destroy url for this tunnel, and then refreshes. Keep in mind it takes some time to completely teardown a tunnel.
|
15
|
+
def destroy
|
16
|
+
response = @client["tunnels/#{@id}"].delete
|
17
|
+
refresh!
|
18
|
+
end
|
19
|
+
|
20
|
+
# Retrieves the latest information on this tunnel from the Sauce Labs' server
|
21
|
+
def refresh!
|
22
|
+
response = JSON.parse @client["tunnels/#{@id}"].get
|
23
|
+
build! response
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
# Sets all internal variables from a hash
|
29
|
+
def build!(options)
|
30
|
+
@status = options["Status"]
|
31
|
+
@owner = options["Owner"]
|
32
|
+
@id = options["_id"]
|
33
|
+
@id = options["id"] if @id.nil? or @id.empty?
|
34
|
+
@host = options["Host"]
|
35
|
+
|
36
|
+
raise NoIDError if @id.nil? or @id.empty?
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/test/debug.rb
ADDED
data/test/helper.rb
ADDED
data/test/test_sauce.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSauce < Test::Unit::TestCase
|
4
|
+
context "A Client instance" do
|
5
|
+
setup do
|
6
|
+
# Create this file and put in your details to run the tests
|
7
|
+
account = YAML.load_file "live_account.yml"
|
8
|
+
@client = Sauce::Client.new(:username => account["username"],
|
9
|
+
:access_key => account["access_key"])
|
10
|
+
@client.destroy_all_tunnels
|
11
|
+
end
|
12
|
+
|
13
|
+
should "initialize with passed variables" do
|
14
|
+
client = Sauce::Client.new(:username => "test_user",
|
15
|
+
:access_key => "abc123")
|
16
|
+
assert_equal client.api_url, "https://test_user:abc123@saucelabs.com/rest/test_user/"
|
17
|
+
end
|
18
|
+
|
19
|
+
should "create a tunnel with the current user" do
|
20
|
+
tunnel = @client.create_tunnel('DomainNames' => ["123.456.789.123"])
|
21
|
+
tunnel.refresh!
|
22
|
+
assert_not_nil tunnel
|
23
|
+
assert_equal "sgrove", tunnel.owner
|
24
|
+
end
|
25
|
+
|
26
|
+
should "list current tunnels" do
|
27
|
+
@client.create_tunnel('DomainNames' => ["111.111.111.111"])
|
28
|
+
@client.create_tunnel('DomainNames' => ["111.111.111.112"])
|
29
|
+
@client.create_tunnel('DomainNames' => ["111.111.111.113"])
|
30
|
+
|
31
|
+
tunnels = @client.tunnels
|
32
|
+
assert_equal 3, tunnels.select{|t| t.status != "halting"}.count
|
33
|
+
end
|
34
|
+
|
35
|
+
should "destroy a tunnel" do
|
36
|
+
tunnel = @client.create_tunnel('DomainNames' => ["111.111.111.114"])
|
37
|
+
tunnel.destroy
|
38
|
+
assert_equal "halting", tunnel.status
|
39
|
+
end
|
40
|
+
|
41
|
+
should "destroy all tunnels" do
|
42
|
+
@client.create_tunnel('DomainNames' => ["111.111.111.115"])
|
43
|
+
@client.create_tunnel('DomainNames' => ["111.111.111.116"])
|
44
|
+
@client.create_tunnel('DomainNames' => ["111.111.111.117"])
|
45
|
+
|
46
|
+
@client.destroy_all_tunnels
|
47
|
+
|
48
|
+
@client.tunnels.each do |tunnel|
|
49
|
+
assert_equal "halting", tunnel.status
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def teardown
|
54
|
+
@client.destroy_all_tunnels
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sauce
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sean Grove
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-02-16 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: thoughtbot-shoulda
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rest-client
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
description: A ruby interface to Sauce Labs' services. Start/stop tunnels, retrieve Selenium logs, access video replays, etc.
|
36
|
+
email: sean@saucelabs.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- .document
|
46
|
+
- .gitignore
|
47
|
+
- LICENSE
|
48
|
+
- README.rdoc
|
49
|
+
- Rakefile
|
50
|
+
- VERSION
|
51
|
+
- lib/rest.rb
|
52
|
+
- lib/sauce.rb
|
53
|
+
- lib/tunnel.rb
|
54
|
+
- test/helper.rb
|
55
|
+
- test/test_sauce.rb
|
56
|
+
has_rdoc: true
|
57
|
+
homepage: http://github.com/sgrove/sauce
|
58
|
+
licenses: []
|
59
|
+
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options:
|
62
|
+
- --charset=UTF-8
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: "0"
|
70
|
+
version:
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: "0"
|
76
|
+
version:
|
77
|
+
requirements: []
|
78
|
+
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 1.3.5
|
81
|
+
signing_key:
|
82
|
+
specification_version: 3
|
83
|
+
summary: Ruby access to Sauce Labs' features
|
84
|
+
test_files:
|
85
|
+
- test/debug.rb
|
86
|
+
- test/helper.rb
|
87
|
+
- test/test_sauce.rb
|