Class: Glosbe::HTTP

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/glosbe/http.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from:, to:, phrase:) ⇒ HTTP

Returns a new instance of HTTP.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



3
4
5
# File 'lib/glosbe/http.rb', line 3

def body
  @body
end

#okObject (readonly) Also known as: ok?

Returns the value of attribute ok.



3
4
5
# File 'lib/glosbe/http.rb', line 3

def ok
  @ok
end