Module: OnlyofficeTestrailWrapper::RequestsHelper
- Included in:
- Testrail2
- Defined in:
- lib/onlyoffice_testrail_wrapper/testrail/requests_helper.rb
Overview
Module for working with requests
Instance Method Summary collapse
-
#http_get(request_url) ⇒ Hash
Perform http get on address.
-
#http_post(request_url, data_hash = {}) ⇒ Hash
Perform http post on address.
-
#send_request(uri, request) ⇒ Net::HTTPResponse
Send request to Testrail.
Instance Method Details
#http_get(request_url) ⇒ Hash
Perform http get on address
31 32 33 34 35 36 |
# File 'lib/onlyoffice_testrail_wrapper/testrail/requests_helper.rb', line 31 def http_get(request_url) uri = URI get_testrail_address + request_url request = Net::HTTP::Get.new uri.request_uri response = send_request(uri, request) JSON.parse response.body end |
#http_post(request_url, data_hash = {}) ⇒ Hash
Perform http post on address
42 43 44 45 46 47 48 49 50 |
# File 'lib/onlyoffice_testrail_wrapper/testrail/requests_helper.rb', line 42 def http_post(request_url, data_hash = {}) uri = URI get_testrail_address + request_url request = Net::HTTP::Post.new uri.request_uri request.body = data_hash.to_json response = send_request(uri, request) return if response.body == '' JSON.parse response.body end |
#send_request(uri, request) ⇒ Net::HTTPResponse
Send request to Testrail
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/onlyoffice_testrail_wrapper/testrail/requests_helper.rb', line 10 def send_request(uri, request) request.basic_auth admin_user, admin_pass request.delete 'content-type' request.add_field 'content-type', 'application/json' is_ssl = (uri.scheme == 'https') @connection ||= Net::HTTP.start(uri.host, uri.port, use_ssl: is_ssl) @connection.start unless @connection.started? attempts = 0 begin response = @connection.request(request) rescue Timeout::Error attempts += 1 retry if attempts < 3 raise 'Timeout error after 3 attempts' end response end |