module HTTPHelpers

Public Instance Methods

delete(url, headers = {}) click to toggle source
# File spec/support/http_helpers.rb, line 37
def delete(url, headers = {})
  request(Net::HTTP::Delete, url, headers)
end
get(url, headers = {}) click to toggle source
# File spec/support/http_helpers.rb, line 19
def get(url, headers = {})
  request(Net::HTTP::Get, url, headers)
end
patch(url, payload, headers = {}) click to toggle source
# File spec/support/http_helpers.rb, line 30
def patch(url, payload, headers = {})
  request(Net::HTTP::Patch, url, headers) do |req|
    req['Content-Type'] = 'application/vnd.api+json'
    req.body = payload.to_json
  end
end
post(url, payload, headers = {}) click to toggle source
# File spec/support/http_helpers.rb, line 23
def post(url, payload, headers = {})
  request(Net::HTTP::Post, url, headers) do |req|
    req['Content-Type'] = 'application/vnd.api+json'
    req.body = payload.to_json
  end
end
request(klass, url, headers) { |req| ... } click to toggle source
# File spec/support/http_helpers.rb, line 5
def request(klass, url, headers)
  uri = URI(ENV['HOST'] + url)
  req = klass.new(uri)
  req['Accept'] = 'application/vnd.api+json'

  yield(req) if block_given?

  headers.each { |k, v| req[k.to_s] = v }

  @_response = Net::HTTP.start(uri.hostname, uri.port) do |http|
    http.request(req)
  end
end
response() click to toggle source
# File spec/support/http_helpers.rb, line 41
def response
  @_response
end
response_body() click to toggle source
# File spec/support/http_helpers.rb, line 45
def response_body
  JSON.parse(response.body)
end
response_status() click to toggle source
# File spec/support/http_helpers.rb, line 49
def response_status
  response.code.to_i
end