class MwDictionary::Api
Attributes
api_domain[RW]
api_version[RW]
api_key[RW]
dictionary[RW]
Public Class Methods
new(api_key, dictionary = :elementary)
click to toggle source
# File lib/mw-dictionary-api.rb, line 25 def initialize(api_key, dictionary = :elementary) @api_key = api_key @dictionary = dictionary end
Public Instance Methods
lookup(word)
click to toggle source
# File lib/mw-dictionary-api.rb, line 30 def lookup(word) lookup_url = lookup_url(word) response = RestClient::Request.new( :method => :get, :url => lookup_url, :headers => { :accept => :json, :content_type => :json } ).execute results = JSON.parse(response.to_str) end
lookup_url(word)
click to toggle source
# File lib/mw-dictionary-api.rb, line 42 def lookup_url(word) "https://#{self.class.api_domain}/#{self.class.api_version}/#{API_SERVICES[@dictionary]}". gsub!('{api_key}', "#{@api_key}"). gsub!('{word}', "#{word}") end