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



18
19
20
21
22
23
24
25
26
27
# File 'lib/testrail_api/client.rb', line 18

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.



11
12
13
# File 'lib/testrail_api/client.rb', line 11

def email
  @email
end

#passwordObject (readonly)

Returns the value of attribute password.



11
12
13
# File 'lib/testrail_api/client.rb', line 11

def password
  @password
end

#serverObject (readonly)

Returns the value of attribute server.



11
12
13
# File 'lib/testrail_api/client.rb', line 11

def server
  @server
end

Instance Method Details

#api_endpointObject



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

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

#credentialsObject



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

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

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



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

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

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



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

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

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



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/testrail_api/client.rb', line 61

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



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

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

#user_agentObject



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

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

#verboseObject



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

def verbose
  Typhoeus::Config.verbose
end

#verbose=(bool) ⇒ Object



29
30
31
# File 'lib/testrail_api/client.rb', line 29

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