Sha256: 1f4896bda75a17f7e06d982702fcabde2a5defbaafb555cfb267e23fedde359a

Contents?: true

Size: 1.59 KB

Versions: 2

Compression:

Stored size: 1.59 KB

Contents

require 'oxford_dictionary/deprecated_request'
require 'oxford_dictionary/api_objects/entry_response'

module OxfordDictionary
  module Endpoints
    # Interface to '/entries' endpoint
    module EntryEndpoint
      include OxfordDictionary::DeprecatedRequest
      ENDPOINT = 'entries'.freeze

      def entry(query, params = {})
        entry_request(query, params)
      end

      def entry_definitions(query, params = {})
        params[:end] = 'definitions'
        entry_request(query, params)
      end

      def entry_examples(query, params = {})
        params[:end] = 'examples'
        entry_request(query, params)
      end

      def entry_pronunciations(query, params = {})
        params[:end] = 'pronunciations'
        entry_request(query, params)
      end

      def entry_sentences(query, params = {})
        params[:end] = 'sentences'
        entry_request(query, params)
      end

      def entry_antonyms(query, params = {})
        params[:end] = 'antonyms'
        entry_request(query, params)
      end

      def entry_synonyms(query, params = {})
        params[:end] = 'synonyms'
        entry_request(query, params)
      end

      def entry_antonyms_synonyms(query, params = {})
        params[:end] = 'synonyms;antonyms'
        entry_request(query, params)
      end

      def entry_translations(query, params = {})
        params.key?(:translations) || params[:translations] = 'es'
        entry_request(query, params)
      end

      private

      def entry_request(query, params)
        EntryResponse.new(request(ENDPOINT, query, params)['results'][0])
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
oxford_dictionary-1.2.0 lib/oxford_dictionary/endpoints/entry_endpoint.rb
oxford_dictionary-1.1.0 lib/oxford_dictionary/endpoints/entry_endpoint.rb