class HttpClient

Public Class Methods

new(api_key) click to toggle source
# File lib/oxford/face/http_client.rb, line 7
def initialize(api_key)
  uris = URI.parse("https://api.projectoxford.ai")
  @http = Net::HTTP.new(uris.host, uris.port)
  @http.use_ssl = true
  @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  @api_key = api_key
end

Public Instance Methods

delete(path, params = {}) click to toggle source
# File lib/oxford/face/http_client.rb, line 75
def delete(path, params = {})
  request = Net::HTTP::Delete.new("/face/v1.0#{path}")
  request.content_type = "application/json"
  request['Ocp-Apim-Subscription-Key'] = @api_key

  if params.is_a?(Hash)
    request.set_form_data(params)
  else
    request.body = params
  end

  response = @http.request(request)
  response
end
get(path, params = {}) click to toggle source
# File lib/oxford/face/http_client.rb, line 15
def get(path, params = {})
  request = Net::HTTP::Get.new("/face/v1.0#{path}")
  request.content_type = "application/json"
  request['Ocp-Apim-Subscription-Key'] = @api_key

  if params.is_a?(Hash)
    request.set_form_data(params)
  else
    request.body = params
  end

  response = @http.request(request)
  response
end
patch(path, params = {}) click to toggle source
# File lib/oxford/face/http_client.rb, line 60
def patch(path, params = {})
  request = Net::HTTP::Patch.new("/face/v1.0#{path}")
  request.content_type = "application/json"
  request['Ocp-Apim-Subscription-Key'] = @api_key

  if params.is_a?(Hash)
    request.body = params.to_json
  else
    request.body = params
  end

  response = @http.request(request)
  response
end
post(path, params = {}) click to toggle source
# File lib/oxford/face/http_client.rb, line 30
def post(path, params = {})
  request = Net::HTTP::Post.new("/face/v1.0#{path}")
  request.content_type = "application/json"
  request['Ocp-Apim-Subscription-Key'] = @api_key

  if params.is_a?(Hash)
    request.body = params.to_json
  else
    request.body = params
  end

  response = @http.request(request)
  response
end
put(path, params = {}) click to toggle source
# File lib/oxford/face/http_client.rb, line 45
def put(path, params = {})
  request = Net::HTTP::Put.new("/face/v1.0#{path}")
  request.content_type = "application/json"
  request['Ocp-Apim-Subscription-Key'] = @api_key

  if params.is_a?(Hash)
    request.body = params.to_json
  else
    request.body = params
  end

  response = @http.request(request)
  response
end