lib/wordnik/resource_modules/word.rb in wordnik-4.06.04 vs lib/wordnik/resource_modules/word.rb in wordnik-4.06.05
- old
+ new
@@ -1358,9 +1358,38 @@
body ||= {}
request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
request_only ? request : request.response.body
end
+ # Fetches single audio pronunciation.
+ # The metadata includes a time-expiring fileUrl which allows reading the audio file directly from the API. Currently only audio pronunciations from the American Heritage Dictionary in mp3 format are supported.
+ #
+ def get_pronunciation(word, pronId, *args)
+ http_method = :get
+ path = '/word/{word}/pronunciation/{pronId}'
+ path.sub!('{word}', word.to_s)
+ path.sub!('{pronId}', pronId.to_s)
+
+ # Ruby turns all key-value arguments at the end into a single hash
+ # e.g. Wordnik.word.get_examples('dingo', :limit => 10, :part_of_speech => 'verb')
+ # becomes {:limit => 10, :part_of_speech => 'verb'}
+ last_arg = args.pop if args.last.is_a?(Hash)
+ last_arg = args.pop if args.last.is_a?(Array)
+ last_arg ||= {}
+
+ # Look for a kwarg called :request_only, whose presence indicates
+ # that we want the request itself back, not the response body
+ if last_arg.is_a?(Hash) && last_arg[:request_only].present?
+ request_only = true
+ last_arg.delete(:request_only)
+ end
+
+ params = last_arg
+ body ||= {}
+ request = Wordnik::Request.new(http_method, path, :params => params, :body => body)
+ request_only ? request : request.response.body
+ end
+
# Internal method to update an audio object
#
def update_audio_internal(word, body, *args)
http_method = :put
path = '/word/{word}/audioInternal'
\ No newline at end of file