class YandexTranslator::Api
Constants
- DEFAULT_LANG
- METHOD_DETECT
- METHOD_GET_LANGS
- METHOD_TRASLATE
Attributes
api_key[RW]
default_lang[RW]
Public Class Methods
check_lang(lang)
click to toggle source
# File lib/ps_yandex_translator.rb, line 26 def self.check_lang(lang) lang || @default_lang end
check_text(text)
click to toggle source
# File lib/ps_yandex_translator.rb, line 22 def self.check_text(text) text || '' end
conf() { |yandex_translator ||= api| ... }
click to toggle source
# File lib/ps_yandex_translator.rb, line 15 def self.conf yield(@yandex_translator ||= YandexTranslator::Api.new) @api_key = @yandex_translator.api_key @default_lang = @yandex_translator.default_lang || DEFAULT_LANG @connect = ApiYandexTranslatorConnect.new(api_key: @api_key) end
default_lang()
click to toggle source
# File lib/ps_yandex_translator.rb, line 34 def self.default_lang @default_lang end
define_language(params = {})
click to toggle source
# File lib/ps_yandex_translator.rb, line 38 def self.define_language(params = {}) request_params = { text: check_text(params[:text]) } @connect.post(request_params, METHOD_DETECT, 'lang') end
key()
click to toggle source
# File lib/ps_yandex_translator.rb, line 30 def self.key @api_key end
languages(params = {})
click to toggle source
# File lib/ps_yandex_translator.rb, line 54 def self.languages(params = {}) request_params = { ui: check_lang(params[:lang]) } @connect.post(request_params, METHOD_GET_LANGS, 'langs') end
translate(params = {})
click to toggle source
# File lib/ps_yandex_translator.rb, line 45 def self.translate(params = {}) request_params = { lang: check_lang(params[:lang]), text: check_text(params[:text]), options: 1 } @connect.post(request_params, METHOD_TRASLATE, 'text') end