Class: MorpherInflecter::Inflection

Inherits:
Object
  • Object
show all
Defined in:
lib/morpher_inflecter.rb

Overview

Класс для получения данных с веб-сервиса Морфера.

Instance Method Summary collapse

Instance Method Details

#get(text, token = nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/morpher_inflecter.rb', line 29

def get(text, token = nil)
  params = { s: text }
  params[:token] = token if token

  uri = URI(MorpherInflecter::URL)
  uri.query = URI.encode_www_form(params)

  JSON.parse( open(uri, 'Accept' => 'application/json').read )

rescue OpenURI::HTTPError => ex
  error = { error: ex.message.strip }
  if MorpherInflecter::ERROR_CODES.map{|c| c[1][0]}.include?(error[:error])
    error.update JSON.parse(ex.io.string)
  end
  error
end