barge-sdk 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0045713fbacbcb13ba122623b3421ca4012eb41b
4
+ data.tar.gz: 99d1b8df3a9796e5b15d9b85633846bf991d0948
5
+ SHA512:
6
+ metadata.gz: 1f9e1aa9fb99412b8b4810e038e1b05741d9c07884f0a92a666ac762c76044d025b1a66581ae1adacf1e56ff7bc8be352dcd3f4bdcf534ac20c14c3d06d55c46
7
+ data.tar.gz: d68f617eb3b9e2ddbc259cecb60a4c90d7514ad28e711eebe6edf675723fff79c3a7bca5c4a0df2851748928532e8cd3c86c13006e02118dbc9cc395e8a317c3
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sdk-ruby.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Noah Blumenthal
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.
@@ -0,0 +1 @@
1
+ ## See http://meta.bargeapp.com/docs for usage information
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.pattern = "test/*_test.rb"
7
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'barge/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "barge-sdk"
8
+ spec.version = Barge::VERSION
9
+ spec.authors = ["Noah Blumenthal"]
10
+ spec.email = ["noah@bargeapp.com"]
11
+ spec.summary = %q{SDK for Barge}
12
+ spec.homepage = "http://www.bargeapp.com"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "minitest"
23
+ spec.add_development_dependency "webmock"
24
+ end
@@ -0,0 +1,104 @@
1
+ require "barge/version"
2
+ require 'net/http'
3
+ require 'json'
4
+
5
+ module Barge
6
+ class BargeException < Exception ; end
7
+ class WebdriverTimeout < BargeException ; end
8
+ class UnauthorizedException < BargeException ; end
9
+ class NotFoundException < BargeException ; end
10
+
11
+ class Client
12
+ def initialize(opts = {})
13
+ @api_key = opts[:api_key] or raise ArgumentError, 'api_key is required'
14
+ @endpoint = opts[:endpoint] || 'https://www.bargeapp.com/api'
15
+ @ssl = opts.has_key?(:ssl) ? !!opts[:ssl] : true
16
+ @verify_mode = opts[:verify_mode] || OpenSSL::SSL::VERIFY_PEER
17
+ end
18
+
19
+ def create_webdriver_session(sync = true)
20
+ puts "IN create_webdriver_session"
21
+ session = execute :post, 'webdriver_sessions'
22
+
23
+ if !sync
24
+ return session
25
+ end
26
+
27
+ loops = 0
28
+ loop do
29
+ session = describe_webdriver_sessions(session['id'])
30
+ break unless session['status'] == 'pending'
31
+ if ((loops += 1) > 10)
32
+ raise WebdriverTimeout
33
+ else
34
+ sleep 3
35
+ end
36
+ end
37
+
38
+ Capybara.default_driver = :selenium
39
+ Capybara::Selenium::Remote.use(session['ip'], url: "http://#{session['ip']}:#{session['port']}/", desired_capabilities: { browser: 'chrome'})
40
+
41
+ session
42
+ end
43
+
44
+ def describe_webdriver_sessions(id = nil)
45
+ execute :get, "webdriver_sessions/#{id}"
46
+ end
47
+
48
+ def create_webdriver_test(opts = {})
49
+ execute :post, "tests/create_webdriver", {
50
+ webdriver_session_id: opts[:webdriver_session_id],
51
+ users: opts[:users],
52
+ minutes: opts[:minutes]
53
+ }
54
+ end
55
+
56
+ def describe_tests(id = nil)
57
+ execute :get, "tests/#{id}"
58
+ end
59
+
60
+ private
61
+ def execute(verb, path, params = {})
62
+ # Titleize verb name and initialize that class by name
63
+ klass_name = verb.slice(0,1).capitalize + verb.slice(1..-1).downcase
64
+ klass = Net::HTTP.const_get(klass_name)
65
+
66
+ uri = URI("#{@endpoint}/#{path}")
67
+ http = Net::HTTP.new(uri.host, uri.port)
68
+
69
+ if @ssl
70
+ http.use_ssl = true
71
+ http.verify_mode = @verify_mode
72
+ end
73
+
74
+ req = klass.new(uri.request_uri, { 'Content-Type' =>'application/json', 'API-KEY' => @api_key })
75
+
76
+
77
+ if params.keys.count > 0
78
+ req.body = params.to_json
79
+ end
80
+
81
+ res = http.request(req)
82
+
83
+ case res.code
84
+ when '200', '201', '422'
85
+ if res.body && res.body.length > 2
86
+ JSON.parse(res.body)
87
+ else
88
+ {}
89
+ end
90
+ when '401'
91
+ # unauthorized
92
+ raise UnauthorizedException
93
+ when '404'
94
+ # not found
95
+ raise NotFoundException
96
+ when '422'
97
+ # bad params
98
+ JSON.parse(res.body)
99
+ else
100
+ raise BargeException, "#{res.code}: #{res.body}"
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,3 @@
1
+ module Barge
2
+ VERSION = "0.0.7"
3
+ end
@@ -0,0 +1,48 @@
1
+ require 'test_helper'
2
+
3
+ class BargeTest < MiniTest::Test
4
+ def setup
5
+ @client = Barge::Client.new api_key: '123456789'
6
+ @base_url = "https://www.bargeapp.com"
7
+ @success_body = '{"success": true}'
8
+ end
9
+
10
+ def test_throws_if_no_api_key
11
+ assert_raises ArgumentError do
12
+ @client = Barge::Client.new
13
+ end
14
+ end
15
+
16
+ def test_create_webdriver_session_success
17
+ stub_request(:post, "#{@base_url}/api/webdriver_sessions").to_return(status: 200, body: @success_body)
18
+ resp = @client.create_webdriver_session(false)
19
+ assert_equal JSON.parse(@success_body), resp
20
+ end
21
+
22
+ def test_create_webdriver_unauthorized
23
+ stub_request(:post, "#{@base_url}/api/webdriver_sessions").to_return(status: 401)
24
+ assert_raises Barge::UnauthorizedException do
25
+ @client.create_webdriver_session(false)
26
+ end
27
+ end
28
+
29
+ def test_describe_webdriver_sessions_success
30
+ stub_request(:get, "#{@base_url}/api/webdriver_sessions/").to_return(status: 200, body: @success_body)
31
+ resp = @client.describe_webdriver_sessions
32
+ assert_equal JSON.parse(@success_body), resp
33
+ end
34
+
35
+ def test_describe_webdriver_sessions_not_found
36
+ stub_request(:get, "#{@base_url}/api/webdriver_sessions/").to_return(status: 404)
37
+
38
+ assert_raises Barge::NotFoundException do
39
+ @client.describe_webdriver_sessions
40
+ end
41
+ end
42
+
43
+ def test_create_webdriver_test_success
44
+ stub_request(:post, "#{@base_url}/api/tests/create_webdriver").to_return(status: 201)
45
+ resp = @client.create_webdriver_test
46
+ assert_equal({}, resp)
47
+ end
48
+ end
@@ -0,0 +1,3 @@
1
+ require 'barge'
2
+ require 'minitest/autorun'
3
+ require 'webmock/minitest'
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: barge-sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.7
5
+ platform: ruby
6
+ authors:
7
+ - Noah Blumenthal
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - noah@bargeapp.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - barge-sdk.gemspec
82
+ - lib/barge.rb
83
+ - lib/barge/version.rb
84
+ - test/barge_test.rb
85
+ - test/test_helper.rb
86
+ homepage: http://www.bargeapp.com
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.2.0
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: SDK for Barge
110
+ test_files:
111
+ - test/barge_test.rb
112
+ - test/test_helper.rb