Module: Bahtera
- Defined in:
- lib/bahtera.rb,
lib/bahtera/kata.rb,
lib/bahtera/version.rb
Defined Under Namespace
Classes: BaseKata, Kata, LemmaNotFound, RequestError
Constant Summary collapse
- BASE_URL =
"http://kateglo.bahtera.org/api.php"
- BASE_PARAMS =
{ format: 'json' }
- VERSION =
"0.1.0"
Class Method Summary collapse
Class Method Details
.lookup(lemma) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/bahtera.rb', line 14 def lookup(lemma) @lemma = lemma if @lemma =~ /\s/ @lemma.split(' ').map do |l| begin lookup(l) rescue MultiJson::LoadError end end else @uri = Addressable::URI.parse BASE_URL @uri.query_values = BASE_PARAMS.merge(phrase: @lemma) response = Net::HTTP.get_response(@uri) unless response.kind_of? Net::HTTPSuccess raise Bahtera::RequestError, "HTTP Response: #{response.code} #{response.}" end parse_response(response.body) end end |