lib/blekko-search/blekko.rb in blekko-search-0.0.2 vs lib/blekko-search/blekko.rb in blekko-search-0.0.3
- old
+ new
@@ -1,13 +1,19 @@
class Blekko
HOST = "blekko.com"
DEFAULT_MAX_FREQUENCY_PER_SECOND = 1
SECURE_PROTOCOL = "https://"
NON_SECURE_PROTOCOL = "http://"
+
+ class << self
+ attr_accessor :last_request_at
+ def last_request_at
+ @last_request_at ||= {}
+ end
+ end
- attr_accessor :protocol, :api_key, :max_frequency_per_second, :username, :password, :login_cookie,
- :last_request_at
+ attr_accessor :protocol, :api_key, :max_frequency_per_second, :username, :password, :login_cookie
def initialize(args={})
@api_key = args[:api_key]
@protocol = args[:secure] ? SECURE_PROTOCOL : NON_SECURE_PROTOCOL
@username = args[:username]
@@ -55,15 +61,22 @@
def delay_between_requests
1 / max_frequency_per_second.to_f
end
+ def last_request_at
+ self.class.last_request_at[api_key]
+ end
+
+ def last_request_at=(value)
+ self.class.last_request_at[api_key] = value
+ end
+
def earliest_next_request
last_request_at ? last_request_at + delay_between_requests : Time.now
end
def seconds_until_next_request
[earliest_next_request - Time.now, 0].max
end
-
-
+
end