class MorpherInflecter::Inflection

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

Public Instance Methods

get(text, token = nil) click to toggle source
# File lib/morpher_inflecter.rb, line 28
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