testrail_client 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ab03375d79ebfa8e03ce85ceaa5b86b2a86779b6
4
+ data.tar.gz: 2c253f1b3f8c4aa228e6dfb656f8895870be21e4
5
+ SHA512:
6
+ metadata.gz: d262bf3611cc7264329e481c8ba652f8d56287d1981dae68168838e40e6ec1ea1be7e246524a91e4650c2a6f9cf576467d5f476681c451c0d6bfcac88de22fab
7
+ data.tar.gz: d0b95a0ad1519020319384d2afcc326e2052a705dfedd80025c94536de97c97e0a523b2ec815653eb990cc67ca306d2fd4585245cd69e1fa88ab99e351f862ee
@@ -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 testrail.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Zach Pendleton
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,25 @@
1
+ # TestRail
2
+
3
+ While the (TestRail)[http://www.gurock.com/testrail/] Ruby client for their
4
+ V2 API _is_ available (on Github)[https://github.com/gurock/testrail-api],
5
+ it isn't available as a gem. Ain't nobody want to be copying and pasting API
6
+ clients into their projects.
7
+
8
+ And thus, zachpendleton/testrail was born. It's a gem wrapped around the
9
+ example Gurock client.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'testrail', git: 'git://github.com/zachpendleton/testrail.git'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ ## Usage
24
+
25
+ Read more about Gurock's client over at (their repo)[https://github.com/gurock/testrail-api].
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,106 @@
1
+ #
2
+ # TestRail API binding for Ruby (API v2, available since TestRail 3.0)
3
+ #
4
+ # Learn more:
5
+ #
6
+ # http://docs.gurock.com/testrail-api2/start
7
+ # http://docs.gurock.com/testrail-api2/accessing
8
+ #
9
+ # Copyright Gurock Software GmbH. See license.md for details.
10
+ #
11
+
12
+ require 'net/http'
13
+ require 'net/https'
14
+ require 'uri'
15
+ require 'json'
16
+
17
+ module TestRail
18
+ class APIClient
19
+ @url = ''
20
+ @user = ''
21
+ @password = ''
22
+
23
+ attr_accessor :user
24
+ attr_accessor :password
25
+
26
+ def initialize(base_url)
27
+ if !base_url.match(/\/$/)
28
+ base_url += '/'
29
+ end
30
+ @url = base_url + 'index.php?/api/v2/'
31
+ end
32
+
33
+ #
34
+ # Send Get
35
+ #
36
+ # Issues a GET request (read) against the API and returns the result
37
+ # (as Ruby hash).
38
+ #
39
+ # Arguments:
40
+ #
41
+ # uri The API method to call including parameters
42
+ # (e.g. get_case/1)
43
+ #
44
+ def send_get(uri)
45
+ _send_request('GET', uri, nil)
46
+ end
47
+
48
+ #
49
+ # Send POST
50
+ #
51
+ # Issues a POST request (write) against the API and returns the result
52
+ # (as Ruby hash).
53
+ #
54
+ # Arguments:
55
+ #
56
+ # uri The API method to call including parameters
57
+ # (e.g. add_case/1)
58
+ # data The data to submit as part of the request (as
59
+ # Ruby hash, strings must be UTF-8 encoded)
60
+ #
61
+ def send_post(uri, data)
62
+ _send_request('POST', uri, data)
63
+ end
64
+
65
+ private
66
+ def _send_request(method, uri, data)
67
+ url = URI.parse(@url + uri)
68
+ if method == 'POST'
69
+ request = Net::HTTP::Post.new(url.path + '?' + url.query)
70
+ request.body = JSON.dump(data)
71
+ else
72
+ request = Net::HTTP::Get.new(url.path + '?' + url.query)
73
+ end
74
+ request.basic_auth(@user, @password)
75
+ request.add_field('Content-Type', 'application/json')
76
+
77
+ conn = Net::HTTP.new(url.host, url.port)
78
+ if url.scheme == 'https'
79
+ conn.use_ssl = true
80
+ conn.verify_mode = OpenSSL::SSL::VERIFY_NONE
81
+ end
82
+ response = conn.request(request)
83
+
84
+ if response.body && !response.body.empty?
85
+ result = JSON.parse(response.body)
86
+ else
87
+ result = {}
88
+ end
89
+
90
+ if response.code != '200'
91
+ if result && result.key?('error')
92
+ error = '"' + result['error'] + '"'
93
+ else
94
+ error = 'No additional error message received'
95
+ end
96
+ raise APIError.new('TestRail API returned HTTP %s (%s)' %
97
+ [response.code, error])
98
+ end
99
+
100
+ result
101
+ end
102
+ end
103
+
104
+ class APIError < StandardError
105
+ end
106
+ end
@@ -0,0 +1,3 @@
1
+ module TestRail
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,4 @@
1
+ require "testrail/version"
2
+ require "testrail/api_client"
3
+
4
+ module TestRail; end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'testrail/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'testrail_client'
8
+ spec.version = TestRail::VERSION
9
+ spec.authors = ['Zach Pendleton']
10
+ spec.email = ['zachpendleton@gmail.com']
11
+ spec.summary = %q{A gem wrapper for the Gurock TestRail client}
12
+ spec.homepage = 'https://github.com/zachpendleton/testrail'
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
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: testrail_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Zach Pendleton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-23 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
+ description:
42
+ email:
43
+ - zachpendleton@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/testrail/api_client.rb
54
+ - lib/testrail/version.rb
55
+ - lib/testrail_client.rb
56
+ - testrail_client.gemspec
57
+ homepage: https://github.com/zachpendleton/testrail
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
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
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.2.2
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: A gem wrapper for the Gurock TestRail client
81
+ test_files: []