testrail-ruby 0.0.25 → 0.0.26

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b4ccea7ce8bd366b7707b13371c2e1aa724aa25c
4
- data.tar.gz: d5d7452a441b044193853ff3e605ff4fb36d5014
3
+ metadata.gz: 904c7cb657f6119209dc39dab2ff4bede4b639c5
4
+ data.tar.gz: 7c42db52877d5de46334bae1ee84e749ddb382b4
5
5
  SHA512:
6
- metadata.gz: 7b41cdc1e02547b0853670b10b132cb5e6f54d59654a0d1e17e982c72fa50734b1c42d6d2e0f22dad0d57baa58a3c45eceb87dd64eea87142e01d78f5562b14f
7
- data.tar.gz: 52a727af3b2390eae510ee7a0fd9b5e5760706eb0f2753b3379bfe8729118ef92fc9dea460f0b513eac8a8f8b4d8e69ee957431ce8372d56330fc6a0968f1fa6
6
+ metadata.gz: a42df30911e8911ab678b8addab502a259220ccf07fd574ae2780667d7795f574ffe5e9bb759ab40917e51ffe61a2f6a27e06980aa6dc77b21458dfd331d9df9
7
+ data.tar.gz: 697a7bb11855a1c67e2da489fff779fcf8aa8b586a6f6180377378bfc36f54813c7f4d5ea19755616b4fd61fd5be9e10717ca3cfd64385f328a6a56b0c7f0a21
@@ -0,0 +1,85 @@
1
+ require_relative '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
+ module TestRail
14
+ class APIClient
15
+ @url = ''
16
+ @user = ''
17
+ @password = ''
18
+
19
+ include Endpoints
20
+ attr_accessor :user
21
+ attr_accessor :password
22
+
23
+ def initialize(base_url)
24
+ base_url += '/' unless base_url =~ /\/$/
25
+ @url = base_url + 'index.php?/api/v2/'
26
+ end
27
+
28
+ def send_get(uri, data)
29
+ puts "Getting: #{uri}"
30
+ puts "Sending Data: #{data}"
31
+ _send_request('GET', uri, data)
32
+ end
33
+
34
+ def send_post(uri, data)
35
+ puts "Posting: #{uri}"
36
+ puts "Sending Data: #{data}"
37
+ _send_request('POST', uri, data)
38
+ end
39
+
40
+ private
41
+
42
+ def _send_request(method, uri, data)
43
+ url = URI.parse(@url + uri)
44
+ puts "URL: #{url}"
45
+ puts "url.query: #{url.query}"
46
+ puts "Data Payload: #{data}"
47
+ if method == 'POST'
48
+ request = Net::HTTP::Post.new(url.path + '?' + url.query)
49
+ request.body = JSON.dump(data)
50
+ else
51
+ request = Net::HTTP::Get.new(url.path + '?' + url.query)
52
+ end
53
+ request.basic_auth(@user, @password)
54
+ request.add_field('Content-Type', 'application/json')
55
+
56
+ conn = Net::HTTP.new(url.host, url.port)
57
+ if url.scheme == 'https'
58
+ conn.use_ssl = true
59
+ conn.verify_mode = OpenSSL::SSL::VERIFY_NONE
60
+ end
61
+ response = conn.request(request)
62
+
63
+ result = if response.body && !response.body.empty?
64
+ JSON.parse(response.body)
65
+ else
66
+ {}
67
+ end
68
+
69
+ if response.code != '200'
70
+ error = if result && result.key?('error')
71
+ '"' + result['error'] + '"'
72
+ else
73
+ 'No additional error message received'
74
+ end
75
+ raise APIError, 'TestRail API returned HTTP %s (%s)' %
76
+ [response.code, error]
77
+ end
78
+
79
+ result
80
+ end
81
+ end
82
+
83
+ class APIError < StandardError
84
+ end
85
+ end
data/lib/testrail-ruby.rb CHANGED
@@ -21,30 +21,47 @@ module TestRail
21
21
  attr_accessor :password
22
22
 
23
23
  def initialize(base_url)
24
- base_url += '/' unless base_url =~ /\/$/
24
+ if !base_url.match(/\/$/)
25
+ base_url += '/'
26
+ end
25
27
  @url = base_url + 'index.php?/api/v2/'
26
28
  end
27
29
 
28
- def send_get(uri, data)
29
- puts "Getting: #{uri}"
30
- puts "Sending Data: #{data}"
31
- _send_request('GET', uri, data)
30
+ #
31
+ # Send Get
32
+ #
33
+ # Issues a GET request (read) against the API and returns the result
34
+ # (as Ruby hash).
35
+ #
36
+ # Arguments:
37
+ #
38
+ # uri The API method to call including parameters
39
+ # (e.g. get_case/1)
40
+ #
41
+ def send_get(uri)
42
+ _send_request('GET', uri, nil)
32
43
  end
33
44
 
45
+ #
46
+ # Send POST
47
+ #
48
+ # Issues a POST request (write) against the API and returns the result
49
+ # (as Ruby hash).
50
+ #
51
+ # Arguments:
52
+ #
53
+ # uri The API method to call including parameters
54
+ # (e.g. add_case/1)
55
+ # data The data to submit as part of the request (as
56
+ # Ruby hash, strings must be UTF-8 encoded)
57
+ #
34
58
  def send_post(uri, data)
35
- puts "Posting: #{uri}"
36
- puts "Sending Data: #{data}"
37
59
  _send_request('POST', uri, data)
38
60
  end
39
61
 
40
62
  private
41
-
42
63
  def _send_request(method, uri, data)
43
64
  url = URI.parse(@url + uri)
44
- puts "Request URL: #{url}"
45
- puts "url.path: #{url.path}"
46
- puts "url.query: #{url.query}"
47
- puts "Data Payload: #{data}"
48
65
  if method == 'POST'
49
66
  request = Net::HTTP::Post.new(url.path + '?' + url.query)
50
67
  request.body = JSON.dump(data)
@@ -61,20 +78,20 @@ module TestRail
61
78
  end
62
79
  response = conn.request(request)
63
80
 
64
- result = if response.body && !response.body.empty?
65
- JSON.parse(response.body)
66
- else
67
- {}
68
- end
81
+ if response.body && !response.body.empty?
82
+ result = JSON.parse(response.body)
83
+ else
84
+ result = {}
85
+ end
69
86
 
70
87
  if response.code != '200'
71
- error = if result && result.key?('error')
72
- '"' + result['error'] + '"'
73
- else
74
- 'No additional error message received'
75
- end
76
- raise APIError, 'TestRail API returned HTTP %s (%s)' %
77
- [response.code, error]
88
+ if result && result.key?('error')
89
+ error = '"' + result['error'] + '"'
90
+ else
91
+ error = 'No additional error message received'
92
+ end
93
+ raise APIError.new('TestRail API returned HTTP %s (%s)' %
94
+ [response.code, error])
78
95
  end
79
96
 
80
97
  result
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Testrail
2
- VERSION = '0.0.25'.freeze
2
+ VERSION = '0.0.26'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: testrail-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.25
4
+ version: 0.0.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frances Morales
@@ -105,6 +105,7 @@ files:
105
105
  - README.md
106
106
  - Rakefile
107
107
  - lib/endpoints.rb
108
+ - lib/testrail-ruby-broken.rb
108
109
  - lib/testrail-ruby.rb
109
110
  - lib/version.rb
110
111
  - spec/spec_helper.rb