Sha256: 47fde8ed64434b8b030045c93452931f709bece4153283c03e1eb37cc0941b00

Contents?: true

Size: 649 Bytes

Versions: 6

Compression:

Stored size: 649 Bytes

Contents

require 'net/http'

module OxfordDictionary
  class Request
    BASE_URL = 'https://od-api.oxforddictionaries.com/api/v2'.freeze

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

    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

    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
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
oxford_dictionary-2.0.1 lib/oxford_dictionary/request.rb
oxford_dictionary-2.0.0 lib/oxford_dictionary/request.rb
oxford_dictionary-1.3.1 lib/oxford_dictionary/request.rb
oxford_dictionary-1.3.0 lib/oxford_dictionary/request.rb
oxford_dictionary-1.2.0 lib/oxford_dictionary/request.rb
oxford_dictionary-1.1.0 lib/oxford_dictionary/request.rb