Class: HotOrNot::UrlResult
- Inherits:
-
Object
- Object
- HotOrNot::UrlResult
- Extended by:
- Forwardable
- Defined in:
- lib/hot_or_not/url_result.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :method => :get }
Instance Attribute Summary collapse
-
#latency ⇒ Object
readonly
Returns the value of attribute latency.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #error? ⇒ Boolean
- #error_message ⇒ Object
-
#initialize(url, response, error, latency) ⇒ UrlResult
constructor
A new instance of UrlResult.
- #success? ⇒ Boolean
Constructor Details
#initialize(url, response, error, latency) ⇒ UrlResult
Returns a new instance of UrlResult.
26 27 28 29 |
# File 'lib/hot_or_not/url_result.rb', line 26 def initialize(url, response, error, latency) @url, @error, @latency = url, error, latency @response = response || error.response end |
Instance Attribute Details
#latency ⇒ Object (readonly)
Returns the value of attribute latency.
23 24 25 |
# File 'lib/hot_or_not/url_result.rb', line 23 def latency @latency end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
23 24 25 |
# File 'lib/hot_or_not/url_result.rb', line 23 def url @url end |
Class Method Details
.retrieve_for(url, options) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/hot_or_not/url_result.rb', line 8 def retrieve_for(url, ) = DEFAULT_OPTIONS.merge [:url] = url response, error = nil, nil start = Time.now begin response = RestClient::Request.execute() rescue RestClient::Exception => e error = e end new url, response, error, Time.now - start end |
Instance Method Details
#error? ⇒ Boolean
35 36 37 |
# File 'lib/hot_or_not/url_result.rb', line 35 def error? !success? end |
#error_message ⇒ Object
39 40 41 |
# File 'lib/hot_or_not/url_result.rb', line 39 def "The url #{@url} received error: #{@error.}" end |
#success? ⇒ Boolean
31 32 33 |
# File 'lib/hot_or_not/url_result.rb', line 31 def success? @error.nil? end |