Class: IFD_Rest
- Inherits:
-
Object
- Object
- IFD_Rest
- Defined in:
- lib/helper/rest_helper.rb
Class Method Summary collapse
- .get_rest_body ⇒ Object
- .get_rest_result ⇒ Object
- .print_rest_code ⇒ Object
- .send_request(*args) ⇒ Object
- .set_headers(data) ⇒ Object
- .store_json_node_result(json_node, string) ⇒ Object
- .verify_response_at_json_node(json_node, string) ⇒ Object
- .verify_response_body_with_json(json) ⇒ Object
- .verify_rest_response_code(code) ⇒ Object
Class Method Details
.get_rest_body ⇒ Object
32 33 34 |
# File 'lib/helper/rest_helper.rb', line 32 def self.get_rest_body puts "REST RESULT body: #{IFD_Rest.get_rest_result.body}" end |
.get_rest_result ⇒ Object
16 17 18 19 20 21 |
# File 'lib/helper/rest_helper.rb', line 16 def self.get_rest_result if @response.nil? p "WARNING***: MISSING STEPS: Please send a REST request to get response first." end @response end |
.print_rest_code ⇒ Object
28 29 30 |
# File 'lib/helper/rest_helper.rb', line 28 def self.print_rest_code puts "REST RESULT code: #{IFD_Rest.get_rest_result.code}" end |
.send_request(*args) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/helper/rest_helper.rb', line 49 def self.send_request(*args) request_type = args.shift.downcase url = Utils.check_dynamic_value(args.shift) put_log "Request URL: #{url}" json_payload = args.shift if json_payload payload = Hash.new JSON.parse(json_payload).each do |k1, v1| payload[Utils.check_dynamic_value(k1)] = Utils.check_dynamic_value(v1) end payload = payload.to_json end put_log "Data Body from #{request_type} method: #{payload}" if (payload.nil? && request_type == 'get' && @header.nil?) @response = Request.get(url) elsif (payload.nil? && request_type == 'get') @response = Request.get(url, {headers: @header}) elsif (payload.nil? && request_type == 'delete' && @header.nil?) @response = Request.delete(url) elsif (payload.nil? && request_type == 'delete') @response = Request.delete(url, {headers: @header}) elsif (payload && request_type == 'get' && @header.nil?) @response = Request.get(url, {body: payload}) elsif (payload && request_type == 'get') @response = Request.get(url, {body: payload, headers: @header}) elsif (payload && request_type == 'post' && @header.nil?) @response = Request.post(url, {body: payload}) elsif (payload && request_type == 'post') @response = Request.post(url, {body: payload, headers: @header}) elsif (payload && request_type == 'put' && @header.nil?) @response = Request.put(url, {body: payload}) elsif (payload && request_type == 'put') @response = Request.put(url, {body: payload, headers: @header}) end end |
.set_headers(data) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/helper/rest_helper.rb', line 3 def self.set_headers(data) unless data.hashes.empty? data = data.hashes[0] data = JSON.parse(data) unless data.is_a? Hash data.each_pair do |k, v| data[k] = Utils.check_dynamic_value(v) end @header = data end p "HEADER: #{@header}" end |
.store_json_node_result(json_node, string) ⇒ Object
23 24 25 26 |
# File 'lib/helper/rest_helper.rb', line 23 def self.store_json_node_result(json_node,string) $context_value = JsonPath.new(json_node).on(IFD_Rest.get_rest_result.body).to_a.map(&:to_s)[0] Utils.set_var(string, '$context_value') end |
.verify_response_at_json_node(json_node, string) ⇒ Object
44 45 46 47 |
# File 'lib/helper/rest_helper.rb', line 44 def self.verify_response_at_json_node(json_node,string) result = JsonPath.new(json_node).on(IFD_Rest.get_rest_result.body).to_a.map(&:to_s) IFD_Assertion.assert_string_equal(string, result[0]) end |
.verify_response_body_with_json(json) ⇒ Object
40 41 42 |
# File 'lib/helper/rest_helper.rb', line 40 def self.verify_response_body_with_json(json) IFD_Assertion.assert_string_equal(json, IFD_Rest.get_rest_result.body.to_s) end |
.verify_rest_response_code(code) ⇒ Object
36 37 38 |
# File 'lib/helper/rest_helper.rb', line 36 def self.verify_rest_response_code(code) IFD_Assertion.assert_string_equal(code, IFD_Rest.get_rest_result.code.to_s) end |