Class: YandexTranlatorIS::YandexTr
- Inherits:
-
Object
- Object
- YandexTranlatorIS::YandexTr
- Defined in:
- lib/yandex_tranlator_IS.rb
Class Method Summary collapse
- .apikey(api_key) ⇒ Object
- .default_lang(lang) ⇒ Object
- .default_languages ⇒ Object
- .languages ⇒ Object
- .start ⇒ Object
- .translate(text, packet = {}) ⇒ Object
Class Method Details
.apikey(api_key) ⇒ Object
13 14 15 |
# File 'lib/yandex_tranlator_IS.rb', line 13 def apikey(api_key) @api_key = api_key end |
.default_lang(lang) ⇒ Object
17 18 19 |
# File 'lib/yandex_tranlator_IS.rb', line 17 def default_lang(lang) @default_lang = lang end |
.default_languages ⇒ Object
21 22 23 |
# File 'lib/yandex_tranlator_IS.rb', line 21 def default_languages @default_lang end |
.languages ⇒ Object
32 33 34 35 36 |
# 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 ⇒ Object
9 10 11 |
# File 'lib/yandex_tranlator_IS.rb', line 9 def start @api_key end |
.translate(text, packet = {}) ⇒ Object
25 26 27 28 29 30 |
# 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 |