testrail_api 0.1.1 → 1.0.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.
@@ -1,4 +1,7 @@
1
- require 'testrail_api/endpoints'
1
+ require 'core_ext/array'
2
+
3
+ require 'testrail_api/api'
4
+ require 'testrail_api/default'
2
5
  require 'testrail_api/version'
3
6
 
4
7
  require 'typhoeus'
@@ -6,26 +9,32 @@ require 'json'
6
9
 
7
10
  module TestRail
8
11
  class Client
9
- attr_accessor :server
10
- attr_accessor :username, :password
11
- attr_accessor :verbose
12
+ include API
13
+
14
+ attr_reader :server, :email, :password
12
15
 
13
16
  # @param server [String] TestRail server host
14
17
  # @param email [String] TestRail email
15
18
  # @param password [String] TestRail password or API key
16
- # @param opts [Hash] Optional parameters
17
- # @option opts [Boolean] :verbose Print libcurl debug output to the console (STDERR) if true (default : false)
18
- # @option opts [Boolean] :secure Use HTTPS if true (default: true)
19
- def initialize(server, email, password, opts = {})
19
+ # @option [Boolean] :secure Use HTTPS if true (default: true)
20
+ # @option [Boolean] :verbose Print libcurl debug output to the console (STDERR) if true (default : false)
21
+ def initialize(server, email, password, secure: true, verbose: false)
20
22
  # required
21
- @server = server
22
- @username = email
23
- @password = password
23
+ @server = server
24
+ @email = email
25
+ @password = password
24
26
 
25
27
  # optional
26
- @verbose = opts.fetch(:verbose, false)
27
- @secure = opts.fetch(:secure, true)
28
- Typhoeus::Config.verbose = verbose
28
+ @secure = secure
29
+ self.verbose = verbose
30
+ end
31
+
32
+ def verbose=(bool)
33
+ Typhoeus::Config.verbose = bool
34
+ end
35
+
36
+ def verbose
37
+ Typhoeus::Config.verbose
29
38
  end
30
39
 
31
40
  def scheme
@@ -33,21 +42,13 @@ module TestRail
33
42
  end
34
43
 
35
44
  def api_endpoint
36
- @api_endpoint ||= File.join("#{scheme}://#{@server}", 'index.php?api/v2') if @server
45
+ @api_endpoint ||= File.join("#{scheme}://#{@server}", 'index.php?api/v2')
37
46
  end
38
47
 
39
48
  def user_agent
40
49
  @user_agent ||= "TestRail API v2 Gem #{VERSION}"
41
50
  end
42
51
 
43
- def default_headers
44
- @default_headers ||= {
45
- 'Accept' => 'application/json',
46
- 'Content-Type' => 'application/json',
47
- 'User-Agent' => user_agent
48
- }
49
- end
50
-
51
52
  def get(path, opts = {})
52
53
  request(:get, path, opts)
53
54
  end
@@ -56,12 +57,17 @@ module TestRail
56
57
  request(:post, path, opts)
57
58
  end
58
59
 
60
+ def credentials
61
+ "#{@email}:#{@password}"
62
+ end
63
+
59
64
  def request(method, path, opts = {})
60
65
  body = Typhoeus::Request.new(
61
66
  File.join(api_endpoint, path),
62
67
  { method: method,
63
- headers: default_headers,
64
- userpwd: "#{@username}:#{@password}" }.merge(opts)
68
+ headers: Default::HEADERS,
69
+ userpwd: credentials
70
+ }.merge(opts)
65
71
  ).run.body
66
72
  JSON.parse(body)
67
73
  rescue JSON::ParserError
@@ -0,0 +1,16 @@
1
+ module TestRail
2
+ module Default
3
+ # Default User-Agent header
4
+ USER_AGENT ||= "TestRail API Ruby Gem #{TestRail::VERSION}".freeze
5
+
6
+ # Default media type
7
+ MEDIA_TYPE ||= 'application/json'.freeze
8
+
9
+ # Default headers
10
+ HEADERS ||= {
11
+ 'Content-Type' => MEDIA_TYPE,
12
+ # 'Accept' => MEDIA_TYPE,
13
+ 'User-Agent' => USER_AGENT
14
+ }.freeze
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module TestRail
2
- VERSION = '0.1.1'.freeze
2
+ VERSION ||= '1.0.0'.freeze
3
3
  end
data/testrail_api.gemspec CHANGED
@@ -10,10 +10,9 @@ Gem::Specification.new do |spec|
10
10
  spec.platform = Gem::Platform::RUBY
11
11
 
12
12
  spec.authors = ['Kirill Zhukov']
13
- spec.email = ['zhukov.kirill.96@gmail.com']
14
13
 
15
- spec.summary = 'Client for TestRail API v2'
16
- spec.description = 'Wrapper for TestRail API v2'
14
+ spec.summary = 'Ruby client for TestRail API v2'
15
+ spec.description = spec.summary
17
16
  spec.homepage = 'https://github.com/kirillzh/testrail_api'
18
17
  spec.license = 'MIT'
19
18
 
@@ -24,7 +23,7 @@ Gem::Specification.new do |spec|
24
23
  spec.add_development_dependency('bundler', '~> 1.10')
25
24
  spec.add_development_dependency('rake', '~> 10.0')
26
25
 
27
- spec.add_dependency('typhoeus', '~> 0.7.2')
26
+ spec.add_dependency('typhoeus', '~> 0.7.0')
28
27
 
29
28
  spec.required_ruby_version = '>= 1.9.2'
30
29
  spec.required_rubygems_version = '>= 1.3.5'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: testrail_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kirill Zhukov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-15 00:00:00.000000000 Z
11
+ date: 2016-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,17 +44,16 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.7.2
47
+ version: 0.7.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.7.2
55
- description: Wrapper for TestRail API v2
56
- email:
57
- - zhukov.kirill.96@gmail.com
54
+ version: 0.7.0
55
+ description: Ruby client for TestRail API v2
56
+ email:
58
57
  executables: []
59
58
  extensions: []
60
59
  extra_rdoc_files: []
@@ -65,7 +64,10 @@ files:
65
64
  - LICENSE
66
65
  - README.md
67
66
  - Rakefile
67
+ - lib/core_ext/array.rb
68
+ - lib/core_ext/array/to_list.rb
68
69
  - lib/testrail_api.rb
70
+ - lib/testrail_api/api.rb
69
71
  - lib/testrail_api/client.rb
70
72
  - lib/testrail_api/client/case_fields.rb
71
73
  - lib/testrail_api/client/case_types.rb
@@ -82,7 +84,7 @@ files:
82
84
  - lib/testrail_api/client/suites.rb
83
85
  - lib/testrail_api/client/tests.rb
84
86
  - lib/testrail_api/client/users.rb
85
- - lib/testrail_api/endpoints.rb
87
+ - lib/testrail_api/default.rb
86
88
  - lib/testrail_api/version.rb
87
89
  - testrail_api.gemspec
88
90
  homepage: https://github.com/kirillzh/testrail_api
@@ -105,9 +107,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
107
  version: 1.3.5
106
108
  requirements: []
107
109
  rubyforge_project:
108
- rubygems_version: 2.4.7
110
+ rubygems_version: 2.5.1
109
111
  signing_key:
110
112
  specification_version: 4
111
- summary: Client for TestRail API v2
113
+ summary: Ruby client for TestRail API v2
112
114
  test_files: []
113
115
  has_rdoc:
@@ -1,15 +0,0 @@
1
- require 'testrail_api/client/case_fields'
2
- require 'testrail_api/client/case_types'
3
- require 'testrail_api/client/cases'
4
- require 'testrail_api/client/milestones'
5
- require 'testrail_api/client/plans'
6
- require 'testrail_api/client/priorities'
7
- require 'testrail_api/client/projects'
8
- require 'testrail_api/client/result_fields'
9
- require 'testrail_api/client/runs'
10
- require 'testrail_api/client/sections'
11
- require 'testrail_api/client/statuses'
12
- require 'testrail_api/client/suites'
13
- require 'testrail_api/client/suites'
14
- require 'testrail_api/client/tests'
15
- require 'testrail_api/client/users'