Class: Glosbe::HTTP
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#ok ⇒ Object
(also: #ok?)
readonly
Returns the value of attribute ok.
Instance Method Summary collapse
-
#initialize(from:, to:, phrase:) ⇒ HTTP
constructor
A new instance of HTTP.
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
#body ⇒ Object (readonly)
Returns the value of attribute body.
3 4 5 |
# File 'lib/glosbe/http.rb', line 3 def body @body end |
#ok ⇒ Object (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 |