class OxfordDictionary::Request

A lightweight request class for use by the endpoints All endpoints implement only the GET action

Constants

BASE_URL

Public Class Methods

new(app_id:, app_key:) click to toggle source
# File lib/oxford_dictionary/request.rb, line 9
def initialize(app_id:, app_key:)
  @app_id = app_id
  @app_key = app_key
end

Public Instance Methods

get(uri:) click to toggle source
# File lib/oxford_dictionary/request.rb, line 14
def get(uri:)
  uri = URI("#{BASE_URL}/#{uri}")

  Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |https|
    https.request(request_object(uri))
  end
end

Private Instance Methods

request_object(uri) click to toggle source
# File lib/oxford_dictionary/request.rb, line 24
def request_object(uri)
  Net::HTTP::Get.new(uri).tap do |request|
    request['Accept'] = 'application/json'
    request['app_id'] = @app_id
    request['app_key'] = @app_key
  end
end