class YandexTranlatorIS::YandexTr
Public Class Methods
apikey(api_key)
click to toggle source
# File lib/yandex_tranlator_IS.rb, line 13 def apikey(api_key) @api_key = api_key end
default_lang(lang)
click to toggle source
# File lib/yandex_tranlator_IS.rb, line 17 def default_lang(lang) @default_lang = lang end
default_languages()
click to toggle source
# File lib/yandex_tranlator_IS.rb, line 21 def default_languages @default_lang end
languages()
click to toggle source
# File lib/yandex_tranlator_IS.rb, line 32 def languages uri = URI.parse("https://translate.yandex.net/api/v1.5/tr.json/getLangs?key=#{@api_key}&ui=en") result = Net::HTTP.get(uri) JSON.parse(result)['langs'] end
start()
click to toggle source
# File lib/yandex_tranlator_IS.rb, line 9 def start @api_key end
translate(text, packet = {})
click to toggle source
# File lib/yandex_tranlator_IS.rb, line 25 def translate(text, packet = {}) lang = packet[:lang] || @default_lang || 'ru' uri = URI.parse("https://translate.yandex.net/api/v1.5/tr.json/translate?key=#{@api_key}&text=#{URI.encode(text)}&lang=#{lang}") result = Net::HTTP.get(uri) JSON.parse(result)['text'] end