zgen_client 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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/zgen_client.rb +85 -0
  3. metadata +77 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 221a72ebc9e46b8dbbc1541c0db356f7ce5c0eaca31cce44f79fa9349d45b5b9
4
+ data.tar.gz: 95ceb308e1705c49f5c91113a8386871f58ecd2c7a2b1fda255598e08cf33f3a
5
+ SHA512:
6
+ metadata.gz: 59ceaa64ae5763155d058b762fc7755e58ef403ece1e632dc394393109ec43a6a29c61dc44f7d18f5173b568a8b758726dbe16ca75320cb4c4bb5dfa6a14735d
7
+ data.tar.gz: 594a2ec36f7ac2bdabab0bd18d9364bc701643654d330ead12553bd75c09c66e5f0302c4c6e9764606c6af85cbe3f4de67fecad12e15f42cf18fa19f19ab0eb1
@@ -0,0 +1,85 @@
1
+ require "rest-client"
2
+ require "jwt"
3
+ require "uri"
4
+ require "json"
5
+ require "time"
6
+
7
+ # The Zgen Client main class
8
+ class ZgenClient
9
+ @@users_login_endpoint = "users/login"
10
+ @@test_execution_endpoint = "v1/Incident/TestCaseExecution"
11
+ @@attachment_endpoint = "v1/Incident/attachment"
12
+
13
+ def initialize(api_host:, api_port:, user_email:, user_password:, user_customer_name:, proxy_host: nil, proxy_port: nil, timeout: 30, is_https: false)
14
+ @api_host = api_host
15
+ @api_port = api_port
16
+ @user_email = user_email
17
+ @user_password = user_password
18
+ @user_customer_name = user_customer_name
19
+ @proxy_host = proxy_host
20
+ @proxy_port = proxy_port
21
+ @timeout = timeout
22
+ @is_https = is_https
23
+ @token = nil
24
+ @user_id = nil
25
+ end
26
+
27
+ # Create a test case result with the information passed from a test case.
28
+ # @param project_id [Integer] the project id
29
+ # @param execution_code [String] the execution code
30
+ # @param cycle_start_date [String] The initial date of the project cycle
31
+ # @param test_result_ok [true, false] true if the test passed
32
+ # @param date [String] Date of test execution. Format: 2022-02-09 00:00:00
33
+ # @param test_result_comments [String] Comments to assign to test result
34
+ # @param tags [Array<String>] List of tags
35
+ # @param incident_id [Integer] Incident id
36
+ # @param status [String] Status
37
+ # @param status_date [String] Status date
38
+ # @return [String] Test result id
39
+ def post_test_execution(project_id:, execution_code:, cycle_start_date:, test_result_ok:, date:, test_result_comments: "", tags: [], incident_id: nil, status: nil, status_date: nil)
40
+ url = "#{build_base_url()}/#{@@test_execution_endpoint}"
41
+ headers = { :Authorization => "Bearer #{get_token()}", content_type: "application/json" }
42
+ body = { projectID: project_id, executionCode: execution_code, cycleStartDate: cycle_start_date, testResultOK: test_result_ok, testerUserID: @user_id, testResultComments: test_result_comments, date: date, tags: tags, incidentID: incident_id, status: status, statusDate: status_date }.to_json
43
+ response = RestClient.post(url, body, headers)
44
+ JSON.parse(response.body)["testResultID"]
45
+ end
46
+
47
+ # An attachment is persisted to the result of a test case.
48
+ # @param test_result_id [String] Test result id
49
+ # @param evidence [File] Evidence file
50
+ # @return OpenStruct
51
+ def post_attachment(test_result_id:, evidence:)
52
+ url = "#{build_base_url()}/#{@@attachment_endpoint}"
53
+ headers = { :Authorization => "Bearer #{get_token()}" }
54
+ body = { :file => evidence, :TestResultID => test_result_id }
55
+ response = RestClient.post(url, body, headers)
56
+ JSON.parse(response.body, object_class: OpenStruct)
57
+ end
58
+
59
+ private
60
+
61
+ def build_base_url()
62
+ if @is_https
63
+ base_url = URI::HTTPS.build(:host => @api_host, :port => @api_port).to_s
64
+ elsif base_url = URI::HTTP.build(:host => @api_host, :port => @api_port).to_s
65
+ end
66
+ "#{base_url}/api"
67
+ end
68
+
69
+ def get_token()
70
+ if @token == nil || is_token_expired()
71
+ url = "#{build_base_url()}/#{@@users_login_endpoint}"
72
+ body = { email: @user_email, password: @user_password }.to_json
73
+ response = RestClient.post(url, body, params: { customerName: @user_customer_name }, content_type: "application/json")
74
+ @user_id = JSON.parse(response.body)["userID"]
75
+ @token = JSON.parse(response.body)["token"]
76
+ else
77
+ @token
78
+ end
79
+ end
80
+
81
+ def is_token_expired()
82
+ payload, header = JWT.decode @token, nil, false
83
+ Time.at(payload["exp"]) < Time.now
84
+ end
85
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zgen_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Guilherme Silva Sousa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-02-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.7.0
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: '2.1'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 1.7.0
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.1'
33
+ - !ruby/object:Gem::Dependency
34
+ name: jwt
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.3'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.3'
47
+ description: The REST Client for ZGen/Knooly
48
+ email: guilherme.sousa@keeggo.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - lib/zgen_client.rb
54
+ homepage: https://rubygems.org/gems/zgen_client
55
+ licenses:
56
+ - MIT
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 2.0.0
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubygems_version: 3.2.32
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: ZGen Client
77
+ test_files: []