Class: TestRail::Client

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from Users

#user, #user_by_email, #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

#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

#priorities

Methods included from Cases

#add_case, #case, #cases, #cases_by_title, #cases_ids, #delete_case, #update_case

Methods included from CaseTypes

#case_types

Methods included from CaseFields

#case_fields

Constructor Details

#initialize(server, email, password, secure: true, verbose: false) ⇒ Client

Returns a new instance of Client.

Parameters:

  • server (String)

    TestRail server host

  • email (String)

    TestRail email

  • password (String)

    TestRail password or API key

  • [Boolean] (Hash)

    a customizable set of options



21
22
23
24
25
26
27
28
29
30
# File 'lib/testrail_api/client.rb', line 21

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

#emailObject (readonly)

Returns the value of attribute email.



14
15
16
# File 'lib/testrail_api/client.rb', line 14

def email
  @email
end

#passwordObject (readonly)

Returns the value of attribute password.



14
15
16
# File 'lib/testrail_api/client.rb', line 14

def password
  @password
end

#serverObject (readonly)

Returns the value of attribute server.



14
15
16
# File 'lib/testrail_api/client.rb', line 14

def server
  @server
end

Instance Method Details

#api_endpointObject



44
45
46
# File 'lib/testrail_api/client.rb', line 44

def api_endpoint
  @api_endpoint ||= File.join("#{scheme}://#{@server}", 'index.php?api/v2')
end

#credentialsObject



60
61
62
# File 'lib/testrail_api/client.rb', line 60

def credentials
  "#{@email}:#{@password}"
end

#get(path, opts = {}) ⇒ Object



52
53
54
# File 'lib/testrail_api/client.rb', line 52

def get(path, opts = {})
  request(:get, path, opts)
end

#post(path, opts = {}) ⇒ Object



56
57
58
# File 'lib/testrail_api/client.rb', line 56

def post(path, opts = {})
  request(:post, path, opts)
end

#request(method, path, opts = {}) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/testrail_api/client.rb', line 64

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

#schemeObject



40
41
42
# File 'lib/testrail_api/client.rb', line 40

def scheme
  @scheme ||= @secure ? 'https' : 'http'
end

#user_agentObject



48
49
50
# File 'lib/testrail_api/client.rb', line 48

def user_agent
  @user_agent ||= "TestRail API v2 Gem #{VERSION}"
end

#verboseObject



36
37
38
# File 'lib/testrail_api/client.rb', line 36

def verbose
  Typhoeus::Config.verbose
end

#verbose=(bool) ⇒ Object



32
33
34
# File 'lib/testrail_api/client.rb', line 32

def verbose=(bool)
  Typhoeus::Config.verbose = bool
end