Class: TestRail::Client
- Inherits:
-
Object
- Object
- TestRail::Client
- Includes:
- API
- Defined in:
- lib/testrail_api/api.rb,
lib/testrail_api/client.rb,
lib/testrail_api/client/runs.rb,
lib/testrail_api/client/cases.rb,
lib/testrail_api/client/plans.rb,
lib/testrail_api/client/tests.rb,
lib/testrail_api/client/users.rb,
lib/testrail_api/client/suites.rb,
lib/testrail_api/client/results.rb,
lib/testrail_api/client/projects.rb,
lib/testrail_api/client/sections.rb,
lib/testrail_api/client/statuses.rb,
lib/testrail_api/client/case_types.rb,
lib/testrail_api/client/milestones.rb,
lib/testrail_api/client/priorities.rb,
lib/testrail_api/client/case_fields.rb,
lib/testrail_api/client/result_fields.rb
Defined Under Namespace
Modules: API, CaseFields, CaseTypes, Cases, Milestones, Plans, Priorities, Projects, ResultFields, Results, Runs, Sections, Statuses, Suites, Tests, Users
Instance Attribute Summary collapse
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Instance Method Summary collapse
- #api_endpoint ⇒ Object
- #credentials ⇒ Object
- #get(path, opts = {}) ⇒ Object
-
#initialize(server, email, password, secure: true, verbose: false) ⇒ Client
constructor
A new instance of Client.
- #post(path, opts = {}) ⇒ Object
- #request(method, path, opts = {}) ⇒ Object
- #scheme ⇒ Object
- #user_agent ⇒ Object
- #verbose ⇒ Object
- #verbose=(bool) ⇒ Object
Methods included from Users
Methods included from Tests
#test, #test_by_title, #test_id_by_title, #tests
Methods included from Suites
#add_suite, #suite, #suite_by_name, #suites, #suites_by_project_name
Methods included from Statuses
Methods included from Sections
#add_section, #delete_section, #section, #section_by_name, #sections, #update_section
Methods included from Runs
#add_run, #close_run, #delete_run, #run, #runs, #update_run
Methods included from Results
#add_result, #add_result_for_case, #add_results, #add_results_for_cases, #results, #results_for_case, #results_for_run
Methods included from Projects
#project, #project_by_name, #projects, #projects_ids
Methods included from Priorities
Methods included from Cases
#add_case, #case, #cases, #cases_by_title, #cases_ids, #delete_case, #update_case
Methods included from CaseTypes
Methods included from CaseFields
Constructor Details
#initialize(server, email, password, secure: true, verbose: false) ⇒ Client
Returns a new instance of Client.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/testrail_api/client.rb', line 16 def initialize(server, email, password, secure: true, verbose: false) # required @server = server @email = email @password = password # optional @secure = secure self.verbose = verbose end |
Instance Attribute Details
#email ⇒ Object (readonly)
Returns the value of attribute email.
9 10 11 |
# File 'lib/testrail_api/client.rb', line 9 def email @email end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
9 10 11 |
# File 'lib/testrail_api/client.rb', line 9 def password @password end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
9 10 11 |
# File 'lib/testrail_api/client.rb', line 9 def server @server end |
Instance Method Details
#api_endpoint ⇒ Object
39 40 41 |
# File 'lib/testrail_api/client.rb', line 39 def api_endpoint @api_endpoint ||= File.join("#{scheme}://#{@server}", 'index.php?api/v2') end |
#credentials ⇒ Object
55 56 57 |
# File 'lib/testrail_api/client.rb', line 55 def credentials "#{@email}:#{@password}" end |
#get(path, opts = {}) ⇒ Object
47 48 49 |
# File 'lib/testrail_api/client.rb', line 47 def get(path, opts = {}) request(:get, path, opts) end |
#post(path, opts = {}) ⇒ Object
51 52 53 |
# File 'lib/testrail_api/client.rb', line 51 def post(path, opts = {}) request(:post, path, opts) end |
#request(method, path, opts = {}) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/testrail_api/client.rb', line 59 def request(method, path, opts = {}) body = Typhoeus::Request.new( File.join(api_endpoint, path), { method: method, headers: Default::HEADERS, userpwd: credentials }.merge(opts) ).run.body JSON.parse(body) rescue JSON::ParserError body end |
#scheme ⇒ Object
35 36 37 |
# File 'lib/testrail_api/client.rb', line 35 def scheme @scheme ||= @secure ? 'https' : 'http' end |
#user_agent ⇒ Object
43 44 45 |
# File 'lib/testrail_api/client.rb', line 43 def user_agent @user_agent ||= "TestRail API v2 Gem #{VERSION}" end |
#verbose ⇒ Object
31 32 33 |
# File 'lib/testrail_api/client.rb', line 31 def verbose Typhoeus::Config.verbose end |
#verbose=(bool) ⇒ Object
27 28 29 |
# File 'lib/testrail_api/client.rb', line 27 def verbose=(bool) Typhoeus::Config.verbose = bool end |