class Y::Translate::API
Constants
- BASE_URI
- METHOD_DETECT
- METHOD_GET_LANGS
- METHOD_TRANSLATE
Attributes
api[RW]
key[RW]
Public Class Methods
key()
click to toggle source
# File lib/y/translate/api.rb, line 27 def self.key api.key end
key=(key)
click to toggle source
# File lib/y/translate/api.rb, line 23 def self.key=(key) @api = new(key) end
new(key)
click to toggle source
# File lib/y/translate/api.rb, line 15 def initialize(key) @key = key end
request(type, method, params = {})
click to toggle source
# File lib/y/translate/api.rb, line 31 def self.request(type, method, params = {}) url = URI.parse("#{BASE_URI}/#{method}") params[:key] = key begin response = HTTP.send(type, url, params: params) rescue raise Error.new end code = response.code.to_i raise Error.new(code) if Error::ERROR_CODES.key?(code) response.parse end