testrail-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/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +50 -0
- data/Rakefile +6 -0
- data/lib/testrail/deprecated/client.rb +169 -0
- data/lib/testrail/deprecated/command_helper.rb +17 -0
- data/lib/testrail/deprecated/config.rb +33 -0
- data/lib/testrail/deprecated/request.rb +55 -0
- data/lib/testrail/deprecated/response.rb +35 -0
- data/lib/testrail/endpoints.rb +120 -0
- data/lib/testrail/testrail-ruby.rb +82 -0
- data/lib/testrail/version.rb +3 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/testrail/ruby_spec.rb +11 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f7a6dc45f35045c16ee5d10d47a5ead48168c998
|
4
|
+
data.tar.gz: 4c507174bf0555a10991dcf707166207cfdcd9c2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3360d16ef79e1318c7e14b95f438bad4d5f7430c92e6d155dbebf6920cee5cebc306251e6b8f14013f5df212be852d00c2bfeebdee76f6f8f8b379c18e191b0b
|
7
|
+
data.tar.gz: b8a6943d6fefc07498ff5cd4ea9f7b294e2b544c9959f9ae4782df4a7c9dd30c4c55992ea71b3d8fb2e0fb95246911945a04f09c6d33ea7f309bc834fc71eb03
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Frances Morales
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# testrail-ruby
|
2
|
+
Ruby bindings and idiomatic interface for testrail v2 API
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'testrail-ruby'
|
10
|
+
```
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install testrail-ruby
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
|
23
|
+
``` ruby
|
24
|
+
#require_relative '../testrail-ruby/lib/testrail/testrail-ruby'
|
25
|
+
require 'testrail-ruby'
|
26
|
+
|
27
|
+
client = TestRail::APIClient.new('https://YourTestrailURL')
|
28
|
+
client.user = 'YourUserName'
|
29
|
+
client.password = 'YourPassword'
|
30
|
+
|
31
|
+
puts client.get_projects
|
32
|
+
puts client.get_project(1)
|
33
|
+
client.get_tests(1)
|
34
|
+
puts client.get_test("1")
|
35
|
+
|
36
|
+
```
|
37
|
+
|
38
|
+
# Development
|
39
|
+
|
40
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
41
|
+
|
42
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/testrail-ruby.
|
47
|
+
|
48
|
+
## License
|
49
|
+
|
50
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
module Testrail
|
2
|
+
class Client
|
3
|
+
|
4
|
+
attr_reader :request
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@request = Testrail::Request
|
8
|
+
end
|
9
|
+
|
10
|
+
# Test Results - see http://docs.gurock.com/testrail-api/reference-results
|
11
|
+
def add_result(test_id, opts = {})
|
12
|
+
request.post('add_result', test_id, opts)
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_result_for_case(run_id, case_id, opts = {})
|
16
|
+
request.post('add_result_for_case', run_id, case_id, opts)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Test - see http://docs.gurock.com/testrail-api/reference-tests
|
20
|
+
def get_test(test_id, opts = {})
|
21
|
+
request.get('get_test', test_id, opts)
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_tests(run_id, opts = {})
|
25
|
+
request.get('get_tests', run_id, opts)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Test Cases - see http://docs.gurock.com/testrail-api/reference-cases
|
29
|
+
def get_case(case_id, opts = {})
|
30
|
+
request.get('get_case', case_id, opts)
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_cases(suite_id, section_id, opts = {})
|
34
|
+
request.get('get_cases', [suite_id, section_id], opts)
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_case(section_id, opts = {})
|
38
|
+
request.post('add_case', section_id, opts)
|
39
|
+
end
|
40
|
+
|
41
|
+
def update_case(case_id, opts = {})
|
42
|
+
request.post('update_case', case_id, opts)
|
43
|
+
end
|
44
|
+
|
45
|
+
def delete_case(case_id, opts = {})
|
46
|
+
request.post('delete_case', case_id, opts)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Suites and Sections - see http://docs.gurock.com/testrail-api/reference-suites
|
50
|
+
def get_suite(suite_id, opts = {})
|
51
|
+
request.get('get_suite', suite_id, opts)
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_suites(project_id, opts = {})
|
55
|
+
request.get('get_suites', project_id, opts)
|
56
|
+
end
|
57
|
+
|
58
|
+
def get_section(section_id, opts = {})
|
59
|
+
request.get('get_section', section_id, opts)
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_sections(suite_id, opts = {})
|
63
|
+
request.get('get_sections', suite_id, opts)
|
64
|
+
end
|
65
|
+
|
66
|
+
def add_suite(project_id, opts = {})
|
67
|
+
request.post('add_suite', project_id, opts)
|
68
|
+
end
|
69
|
+
|
70
|
+
def add_section(suite_id, opts = {})
|
71
|
+
request.post('add_section', suite_id, opts)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Test Runs - see http://docs.gurock.com/testrail-api/reference-runs
|
75
|
+
def get_run(run_id, opts = {})
|
76
|
+
request.get('get_run', run_id, opts)
|
77
|
+
end
|
78
|
+
|
79
|
+
def get_runs(project_id, plan_id, opts = {})
|
80
|
+
request.get('get_runs', project_id, plan_id, opts)
|
81
|
+
end
|
82
|
+
|
83
|
+
def add_run(suite_id, opts = {})
|
84
|
+
request.post('add_run', suite_id, opts)
|
85
|
+
end
|
86
|
+
|
87
|
+
def close_run(run_id, opts = {})
|
88
|
+
request.post('close_run', run_id, opts)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Test Plans - see http://docs.gurock.com/testrail-api/reference-plans
|
92
|
+
def get_plan(plan_id, opts = {})
|
93
|
+
request.get('get_plan', plan_id, opts)
|
94
|
+
end
|
95
|
+
|
96
|
+
def get_plans(project_id, opts = {})
|
97
|
+
request.get('get_plans', project_id, opts)
|
98
|
+
end
|
99
|
+
|
100
|
+
def add_plan(project_id, opts = {})
|
101
|
+
request.post('add_plan', project_id, opts)
|
102
|
+
end
|
103
|
+
|
104
|
+
def add_plan_entries(plan_id, opts = {})
|
105
|
+
request.post('add_plan_entries', plan_id, opts)
|
106
|
+
end
|
107
|
+
|
108
|
+
def close_plan(plan_id, opts = {})
|
109
|
+
request.post('close_plan', plan_id, opts)
|
110
|
+
end
|
111
|
+
|
112
|
+
# Milestones - see http://docs.gurock.com/testrail-api/reference-milestones
|
113
|
+
def get_milestone(milestone_id, opts = {})
|
114
|
+
request.get('get_milestone', milestone_id, opts)
|
115
|
+
end
|
116
|
+
|
117
|
+
def get_milestones(project_id, opts = {})
|
118
|
+
request.get('get_milestones', project_id, opts)
|
119
|
+
end
|
120
|
+
|
121
|
+
def add_milestone(project_id, opts = {})
|
122
|
+
request.post('add_milestone', project_id, opts)
|
123
|
+
end
|
124
|
+
|
125
|
+
# Projects - see http://docs.gurock.com/testrail-api/reference-projects
|
126
|
+
def get_project(project_id, opts = {})
|
127
|
+
request.get('get_project', project_id, opts)
|
128
|
+
end
|
129
|
+
|
130
|
+
def get_projects(opts = {})
|
131
|
+
request.get('get_projects', opts)
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
# COMMANDS.each do |method_name|
|
136
|
+
# define_method method_name
|
137
|
+
# end
|
138
|
+
|
139
|
+
COMMANDS = %w[add_result
|
140
|
+
add_result_for_case
|
141
|
+
get_test
|
142
|
+
get_tests
|
143
|
+
get_case
|
144
|
+
get_cases
|
145
|
+
add_case
|
146
|
+
update_case
|
147
|
+
delete_case
|
148
|
+
get_suite
|
149
|
+
get_suites
|
150
|
+
get_section
|
151
|
+
get_sections
|
152
|
+
add_suite
|
153
|
+
add_section
|
154
|
+
get_run
|
155
|
+
get_runs
|
156
|
+
add_run
|
157
|
+
close_run
|
158
|
+
get_plan
|
159
|
+
get_plans
|
160
|
+
add_plan
|
161
|
+
add_plan_entries
|
162
|
+
close_plan
|
163
|
+
get_milestone
|
164
|
+
get_milestones
|
165
|
+
add_milestone
|
166
|
+
get_project
|
167
|
+
get_projects]
|
168
|
+
end
|
169
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Testrail
|
2
|
+
module CommandHelper
|
3
|
+
def build_url(command, ids = nil)
|
4
|
+
command = Testrail.config.server + Testrail.config.api_path + command
|
5
|
+
unless ids.nil?
|
6
|
+
ids = '/' + [ids].flatten.join('/')
|
7
|
+
command += ids
|
8
|
+
end
|
9
|
+
command + key
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
def key
|
14
|
+
'&key=' + String(Testrail.config.api_key)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'active_support/configurable'
|
3
|
+
|
4
|
+
module Testrail
|
5
|
+
|
6
|
+
def self.configure(&block)
|
7
|
+
@config = Config.new
|
8
|
+
yield @config if block_given?
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.config
|
12
|
+
@config ||= Config.new
|
13
|
+
end
|
14
|
+
|
15
|
+
class Config
|
16
|
+
include ActiveSupport::Configurable
|
17
|
+
config_accessor :headers, :server, :api_path, :api_key, :logger
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
default_config
|
21
|
+
end
|
22
|
+
|
23
|
+
def default_config
|
24
|
+
self.headers = {
|
25
|
+
"Accept" => "application/json"
|
26
|
+
}
|
27
|
+
self.server = "https://example.testrail.com"
|
28
|
+
self.api_path = "/index.php?/miniapi/"
|
29
|
+
self.api_key = nil
|
30
|
+
self.logger = Logger.new STDOUT
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'testrail/command_helper'
|
3
|
+
|
4
|
+
module Testrail
|
5
|
+
class Request
|
6
|
+
extend Testrail::CommandHelper
|
7
|
+
include HTTParty
|
8
|
+
|
9
|
+
base_uri Testrail.config.server
|
10
|
+
format :json
|
11
|
+
|
12
|
+
def self.get(*args)
|
13
|
+
request(:get, *args)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.post(*args)
|
17
|
+
request(:post, *args)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def self.request(method, *args)
|
23
|
+
command, ids, opts = parse_args(*args)
|
24
|
+
url = build_url(command, ids)
|
25
|
+
attempts = 0
|
26
|
+
begin
|
27
|
+
response = Testrail::Response.new(HTTParty.send(method, url, opts))
|
28
|
+
rescue TimeoutError => error
|
29
|
+
attempts += 1
|
30
|
+
retry if attempts < 3
|
31
|
+
log_error error, "Timeout connecting to #{method.to_s.upcase} #{url}"
|
32
|
+
raise error
|
33
|
+
rescue Exception => error
|
34
|
+
log_error error, "Unexpected exception intercepted calling TestRail"
|
35
|
+
raise error
|
36
|
+
end
|
37
|
+
response
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.log_error(error, message)
|
41
|
+
unless Testrail.logger.nil?
|
42
|
+
Testrail.logger.error message
|
43
|
+
Testrail.logger.error error
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.parse_args(*args)
|
48
|
+
opts = args.last.instance_of?(Hash) ? args.pop : {}
|
49
|
+
opts[:headers] = opts[:headers] ? Testrail.config.headers.merge(opts[:headers]) : Testrail.config.headers
|
50
|
+
command = args.shift
|
51
|
+
ids = args.empty? ? nil : args
|
52
|
+
[command, ids, opts]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Testrail
|
5
|
+
class Response
|
6
|
+
attr_reader :http_response
|
7
|
+
attr_accessor :success, :payload, :error
|
8
|
+
|
9
|
+
extend Forwardable
|
10
|
+
|
11
|
+
def_delegators :http_response, :request, :response, :code
|
12
|
+
|
13
|
+
def initialize(http_response = nil)
|
14
|
+
@http_response = http_response
|
15
|
+
parse_payload if http_response.respond_to?(:body) && !http_response.body.nil?
|
16
|
+
parse_error if Integer(http_response.code) >= 400
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def parse_payload
|
21
|
+
result_body = JSON.parse(http_response.body)
|
22
|
+
@success = result_body.key?('result') ? result_body.delete('result') : nil
|
23
|
+
@payload = @success ? result_body : nil
|
24
|
+
@error = result_body.key?('error') ? result_body.delete('error') : nil
|
25
|
+
rescue JSON::ParserError
|
26
|
+
@success = false
|
27
|
+
@error = "Malformed JSON response.\n Received #{http_response.body}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def parse_error
|
31
|
+
@success = false
|
32
|
+
@error = ::Net::HTTPResponse::CODE_TO_OBJ[http_response.code.to_s].name.gsub!(/Net::HTTP/, '')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
|
2
|
+
#
|
3
|
+
# This space left blank intentionally
|
4
|
+
#
|
5
|
+
module Endpoints
|
6
|
+
def add_result(test_id, opts = {})
|
7
|
+
self.send_post("add_result/#{test_id}", opts)
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_result_for_case(run_id, case_id, opts = {})
|
11
|
+
self.send_post("add_result_for_case/#{run_id}/#{case_id}", opts)
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_test(test_id, opts = {})
|
15
|
+
self.send_get("get_test/#{test_id}", opts)
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_tests(run_id, opts = {})
|
19
|
+
self.send_get("get_tests/#{run_id}", opts)
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_case(case_id, opts = {})
|
23
|
+
self.send_get("get_case/#{case_id}", opts)
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_cases(suite_id, section_id, opts = {})
|
27
|
+
self.send_get("get_cases/#{suite_id}/#{section_id}", opts)
|
28
|
+
end
|
29
|
+
|
30
|
+
def add_case(section_id, opts = {})
|
31
|
+
self.send_post("add_case/#{section_id}", opts)
|
32
|
+
end
|
33
|
+
|
34
|
+
def update_case(case_id, opts = {})
|
35
|
+
self.send_post("update_case/#{case_id}", opts)
|
36
|
+
end
|
37
|
+
|
38
|
+
def delete_case(case_id, opts = {})
|
39
|
+
self.send_post("delete_case/#{case_id}", opts)
|
40
|
+
end
|
41
|
+
def get_suite(suite_id, opts = {})
|
42
|
+
self.send_get("get_suite/#{suite_id}", opts)
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_suites(project_id, opts = {})
|
46
|
+
self.send_get("get_suites/#{project_id}", opts)
|
47
|
+
end
|
48
|
+
|
49
|
+
def get_section(section_id, opts = {})
|
50
|
+
self.send_get("get_section/#{section_id}", opts)
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_sections(suite_id, opts = {})
|
54
|
+
self.send_get("get_sections/#{suite_id}", opts)
|
55
|
+
end
|
56
|
+
|
57
|
+
def add_suite(project_id, opts = {})
|
58
|
+
self.send_post("add_suite/#{project_id}", opts)
|
59
|
+
end
|
60
|
+
|
61
|
+
def add_section(suite_id, opts = {})
|
62
|
+
self.send_post("add_section/#{suite_id}", opts)
|
63
|
+
end
|
64
|
+
|
65
|
+
def get_run(run_id, opts = {})
|
66
|
+
self.send_get("get_run/#{run_id}", opts)
|
67
|
+
end
|
68
|
+
|
69
|
+
def get_runs(project_id, plan_id, opts = {})
|
70
|
+
self.send_get("get_runs/#{project_id}/#{plan_id}", opts)
|
71
|
+
end
|
72
|
+
|
73
|
+
def add_run(suite_id, opts = {})
|
74
|
+
self.send_post("add_run/#{suite_id}", opts)
|
75
|
+
end
|
76
|
+
|
77
|
+
def close_run(run_id, opts = {})
|
78
|
+
self.send_post("close_run/#{run_id}", opts)
|
79
|
+
end
|
80
|
+
|
81
|
+
def get_plan(plan_id, opts = {})
|
82
|
+
self.send_get("get_plan/#{plan_id}", opts)
|
83
|
+
end
|
84
|
+
|
85
|
+
def get_plans(project_id, opts = {})
|
86
|
+
self.send_get("get_plans/#{project_id}", opts)
|
87
|
+
end
|
88
|
+
|
89
|
+
def add_plan(project_id, opts = {})
|
90
|
+
self.send_post("add_plan/#{project_id}", opts)
|
91
|
+
end
|
92
|
+
|
93
|
+
def add_plan_entries(plan_id, opts = {})
|
94
|
+
self.send_post("add_plan_entries/#{plan_id}", opts)
|
95
|
+
end
|
96
|
+
|
97
|
+
def close_plan(plan_id, opts = {})
|
98
|
+
self.send_post("close_plan/#{plan_id}", opts)
|
99
|
+
end
|
100
|
+
|
101
|
+
def get_milestone(milestone_id, opts = {})
|
102
|
+
self.send_get("get_milestone/#{milestone_id}", opts)
|
103
|
+
end
|
104
|
+
|
105
|
+
def get_milestones(project_id, opts = {})
|
106
|
+
self.send_get("get_milestones/#{project_id}", opts)
|
107
|
+
end
|
108
|
+
|
109
|
+
def add_milestone(project_id, opts = {})
|
110
|
+
self.send_post("add_milestone/#{project_id}", opts)
|
111
|
+
end
|
112
|
+
|
113
|
+
def get_project(project_id, opts = {})
|
114
|
+
self.send_get("get_project/#{project_id}", opts)
|
115
|
+
end
|
116
|
+
|
117
|
+
def get_projects(opts = {})
|
118
|
+
self.send_get("get_projects", opts)
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require "testrail/version"
|
2
|
+
require_relative 'endpoints'
|
3
|
+
require 'net/http'
|
4
|
+
require 'net/https'
|
5
|
+
require 'uri'
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
# USAGE:
|
9
|
+
# @client = TestRail::APIClient.new('YourBaseURLHere')
|
10
|
+
# @client.user = 'UserName'
|
11
|
+
# @client.password = 'Password'
|
12
|
+
|
13
|
+
|
14
|
+
module TestRail
|
15
|
+
class APIClient
|
16
|
+
@url = ''
|
17
|
+
@user = ''
|
18
|
+
@password = ''
|
19
|
+
|
20
|
+
include Endpoints
|
21
|
+
attr_accessor :user
|
22
|
+
attr_accessor :password
|
23
|
+
|
24
|
+
def initialize(base_url)
|
25
|
+
if !base_url.match(/\/$/)
|
26
|
+
base_url += '/'
|
27
|
+
end
|
28
|
+
@url = base_url + 'index.php?/api/v2/'
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def send_get(uri, data)
|
33
|
+
_send_request('GET', uri, data)
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
def send_post(uri, data)
|
38
|
+
_send_request('POST', uri, data)
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def _send_request(method, uri, data)
|
43
|
+
url = URI.parse(@url + uri)
|
44
|
+
if method == 'POST'
|
45
|
+
request = Net::HTTP::Post.new(url.path + '?' + url.query)
|
46
|
+
request.body = JSON.dump(data)
|
47
|
+
else
|
48
|
+
request = Net::HTTP::Get.new(url.path + '?' + url.query)
|
49
|
+
end
|
50
|
+
request.basic_auth(@user, @password)
|
51
|
+
request.add_field('Content-Type', 'application/json')
|
52
|
+
|
53
|
+
conn = Net::HTTP.new(url.host, url.port)
|
54
|
+
if url.scheme == 'https'
|
55
|
+
conn.use_ssl = true
|
56
|
+
conn.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
57
|
+
end
|
58
|
+
response = conn.request(request)
|
59
|
+
|
60
|
+
if response.body && !response.body.empty?
|
61
|
+
result = JSON.parse(response.body)
|
62
|
+
else
|
63
|
+
result = {}
|
64
|
+
end
|
65
|
+
|
66
|
+
if response.code != '200'
|
67
|
+
if result && result.key?('error')
|
68
|
+
error = '"' + result['error'] + '"'
|
69
|
+
else
|
70
|
+
error = 'No additional error message received'
|
71
|
+
end
|
72
|
+
raise APIError.new('TestRail API returned HTTP %s (%s)' %
|
73
|
+
[response.code, error])
|
74
|
+
end
|
75
|
+
|
76
|
+
result
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
class APIError < StandardError
|
81
|
+
end
|
82
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require "testrail/ruby"
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
# Enable flags like --only-failures and --next-failure
|
6
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
7
|
+
|
8
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
9
|
+
config.disable_monkey_patching!
|
10
|
+
|
11
|
+
config.expect_with :rspec do |c|
|
12
|
+
c.syntax = :expect
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: testrail-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Frances Morales
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-06-07 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: '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: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
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: json
|
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: A Ruby client wrapper for the TestRail API (v2)
|
70
|
+
email: fmorales@francesmoralespec.com
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- Gemfile
|
76
|
+
- LICENSE.txt
|
77
|
+
- README.md
|
78
|
+
- Rakefile
|
79
|
+
- lib/testrail/deprecated/client.rb
|
80
|
+
- lib/testrail/deprecated/command_helper.rb
|
81
|
+
- lib/testrail/deprecated/config.rb
|
82
|
+
- lib/testrail/deprecated/request.rb
|
83
|
+
- lib/testrail/deprecated/response.rb
|
84
|
+
- lib/testrail/endpoints.rb
|
85
|
+
- lib/testrail/testrail-ruby.rb
|
86
|
+
- lib/testrail/version.rb
|
87
|
+
- spec/spec_helper.rb
|
88
|
+
- spec/testrail/ruby_spec.rb
|
89
|
+
homepage: https://github.com/fmorales/TestRail-Ruby
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata:
|
93
|
+
allowed_push_host: https://rubygems.org
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.6.10
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Client wrapper in Ruby for TestRail API (v2)
|
114
|
+
test_files:
|
115
|
+
- spec/spec_helper.rb
|
116
|
+
- spec/testrail/ruby_spec.rb
|