Module: ApiSpec::Helpers

Extended by:
Helpers
Included in:
Helpers
Defined in:
lib/api_spec/helpers.rb

Instance Method Summary collapse

Instance Method Details

#http_clientObject



50
51
52
# File 'lib/api_spec/helpers.rb', line 50

def http_client
  ApiSpec.configuration.http_client
end

#make_request(method, path, table) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/api_spec/helpers.rb', line 19

def make_request(method, path, table)
  parameters = ApiSpec::Parameters.new(method, path, table)
  headers = parameters.headers.merge(test_headers)

  begin
    case method
    when :get
      @response = http_client.get parameters.url,
        headers.merge(params: parameters.query)
    when :post
      @response = http_client.post parameters.url, parameters.body,
        headers
    when :put
      @response = http_client.put parameters.url, parameters.body,
        headers
    when :delete
      @response = http_client.delete parameters.url,
        headers
    else
      fail "Unsupported method: #{method}"
    end

    if ENV["API_SPEC_DEBUG"]
      puts "@response = #{@response.body}"
    end
  rescue RestClient::Exception => e
    @response = ErrorResponse.new(e.http_code, e.http_body)
    puts "Error response body: #{ @response.body }"
  end
end

#test_headersObject



15
16
17
# File 'lib/api_spec/helpers.rb', line 15

def test_headers
  {"X-Test-Name" => $test_name}
end