Sha256: a851b6bdb70460592bcbee3daded60228a9ff38120ef538bf1bff116c303421e

Contents?: true

Size: 884 Bytes

Versions: 1

Compression:

Stored size: 884 Bytes

Contents

require 'oxford_dictionary/endpoints/endpoint'

module OxfordDictionary
  module Endpoints
    class Search < Endpoint
      ENDPOINT = 'search'.freeze

      def search(language:, params: {})
        query_string = "#{ENDPOINT}/#{language}"
        uri = URI(query_string)

        unless params.empty?
          uri.query = URI.encode_www_form(params)
        end

        response = @request_client.get(uri: uri)
        deserialize.call(response.body)
      end

      def search_translation(source_language:, target_language:, params: {})
        query_string =
          "#{ENDPOINT}/translations/#{source_language}/#{target_language}"
        uri = URI(query_string)

        unless params.empty?
          uri.query = URI.encode_www_form(params)
        end

        response = @request_client.get(uri: uri)
        deserialize.call(response.body)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
oxford_dictionary-1.3.0 lib/oxford_dictionary/endpoints/search.rb