class YatranslateAPI::Gateway

Public Class Methods

new() click to toggle source
# File lib/yatranslateAPI/gateway.rb, line 9
def initialize
  @client = HTTPClient.new
  @error = YatranslateAPI::Errors.new
  @base_url = "https://translate.yandex.net/api/v1.5/tr.json/"
  @body = {
    "Host": "translate.yandex.net",
    "Accept": "*/*",
    "Content-Length": "17",
    "Content-Type": "application/x-www-form-urlencoded"
}
end

Public Instance Methods

generate_request(method, params = {}) click to toggle source
# File lib/yatranslateAPI/gateway.rb, line 21
def generate_request(method, params = {})
  @url = @base_url + method + hash_to_param(params)
end
send_request() click to toggle source
# File lib/yatranslateAPI/gateway.rb, line 25
def send_request
  uri = URI.escape(@url)
  res = @client.post(uri, @body)
  @error.status_check(res)
end

Private Instance Methods

hash_to_param(hash) click to toggle source
# File lib/yatranslateAPI/gateway.rb, line 33
def hash_to_param(hash)
  hash.to_a.map { |x| "#{x[0]}=#{x[1]}" }.join("&")
end