Class: OxfordDictionary::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/oxford_dictionary/request.rb

Overview

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

Constant Summary collapse

BASE_URL =
'https://od-api.oxforddictionaries.com/api/v2'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(app_id:, app_key:) ⇒ Request

Returns a new instance of Request.



9
10
11
12
# File 'lib/oxford_dictionary/request.rb', line 9

def initialize(app_id:, app_key:)
  @app_id = app_id
  @app_key = app_key
end

Instance Method Details

#get(uri:) ⇒ Object



14
15
16
17
18
19
20
# 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