Sha256: e7c64d0f05178218cea7bb002bc889ac818d71eac9e8dc884e92558c06b00853
Contents?: true
Size: 1.6 KB
Versions: 2
Compression:
Stored size: 1.6 KB
Contents
require 'api-tester/definition/response' require 'api-tester/definition/api_method' require 'api-tester/test_helper' require 'rest-client' module ApiTester class Endpoint attr_accessor :name attr_accessor :base_url attr_accessor :path_params attr_accessor :methods attr_accessor :test_helper attr_accessor :bad_request_response attr_accessor :not_allowed_response attr_accessor :not_found_response def initialize name, url self.base_url = url self.name = name self.methods = [] self.path_params = [] self.test_helper = ApiTester::TestHelper.new self.bad_request_response = ApiTester::Response.new 400 self.not_allowed_response = ApiTester::Response.new 415 self.not_found_response = ApiTester::Response.new 404 end def url temp_url = self.base_url self.path_params.each do |param| temp_url.sub! "{#{param}}", self.test_helper.retrieve_param(param) end temp_url end def call method, payload={}, headers={} self.test_helper.before begin response = RestClient::Request.execute(method: method.verb, url: self.url, payload: payload, headers: headers) rescue RestClient::ExceptionWithResponse => e response = e.response end self.test_helper.after response end def add_method verb, response, request=Request.new() self.methods << ApiTester::ApiMethod.new(verb, response, request) self end def add_path_param param self.path_params << param self end def verbs self.methods.map(&:verb) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
api-tester-0.3.0 | lib/api-tester/definition/endpoint.rb |
api-tester-0.2.0 | lib/api-tester/definition/endpoint.rb |