class Glosbe::HTTP

Attributes

body[R]
ok[R]
ok?[R]

Public Class Methods

new(from:, to:, phrase:) click to toggle source
# File lib/glosbe/http.rb, line 10
def initialize(from:, to:, phrase:)
  Glosbe.logger.debug("[Glosbe::HTTP] request from=#{from} to=#{to} phrase=#{phrase}")

  response = self.class.get("/translate",
    query: {
      from: from,
      dest: to,
      phrase: phrase,
      format: "json",
      pretty: "true",
    }
  )

  Glosbe.logger.debug("[Glosbe::HTTP] response code=#{response.code}")
  Glosbe.logger.debug("[Glosbe::HTTP] response body=#{response.body}")

  @ok = response.ok?
  @body = response.ok? || response.too_many_requests? ? response.parsed_response : nil
end