class Net::HTTPResponse
Public Instance Methods
from_json()
click to toggle source
Converts the result from JSON if okay?
returns true; otherwise returns nil.
Can be combined with or_raise!
to get a JSON result or raise an exception:
Okay::HTTP.get("https://example.org/blah.json").or_raise!.from_json
# File lib/okay/http.rb, line 34 def from_json return nil unless okay? require "json" JSON.parse(body) end
okay?()
click to toggle source
Returns false if the server encountered an error, true otherwise.
# File lib/okay/http.rb, line 14 def okay? self.value true rescue Net::HTTPExceptions false end
or_raise!()
click to toggle source
Raises an exception if the request failed. (A fatal equivalent of okay?
)
# File lib/okay/http.rb, line 22 def or_raise! self.value self end