Class: Object

Inherits:
BasicObject
Defined in:
lib/cucumber/rest_api/http_client.rb

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/cucumber/rest_api/http_client.rb', line 9

def blank?
  respond_to?(:empty?) ? empty? : !self
end

#header(key, value) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/cucumber/rest_api/http_client.rb', line 17

def header key, value
  if @headers == nil
    @headers = Hash.new(0)
  end

  @headers[key] = value
end

#last_responseObject



53
54
55
# File 'lib/cucumber/rest_api/http_client.rb', line 53

def last_response
  return @response
end

#present?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/cucumber/rest_api/http_client.rb', line 13

def present?
  !blank?
end

#request(path, request_opts) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/cucumber/rest_api/http_client.rb', line 25

def request path,request_opts
  req = "#{$SERVER_PATH}" + path
  
  uri = URI.parse(req)
  http = Net::HTTP.new(uri.host, uri.port)

  if request_opts[:method] == :post
    request = Net::HTTP::Post.new(uri.request_uri)

    body = nil
    if request_opts[:params]
      body = request_opts[:params].to_json
    else
      body = request_opts[:input]
    end
  else 
    request = Net::HTTP::Get.new(uri.request_uri)
  end

  #do we have any headers to add?
  if @headers != nil
    @headers.each { |k,v| request.add_field(k, v) }
    @headers = nil
  end

  @response = http.request(request,body)
end