blekko-search 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +1 -1
- data/lib/blekko-search/blekko.rb +17 -4
- data/lib/blekko-search/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -44,7 +44,7 @@ Blekko allows for a maximum of 100 results per search, but if you'd like more, y
|
|
44
44
|
|
45
45
|
By default, the searches will be made 100 results at a time, but you can reduce the page size using the ``:page_size`` argument too.
|
46
46
|
|
47
|
-
Blekko
|
47
|
+
Blekko requests that users of its API throttle searches to one per second. Use one ``Blekko`` instance with the default settings for all searching and slashtag management and that throttling will be taken care of for you.
|
48
48
|
|
49
49
|
#### Results
|
50
50
|
Each result includes the attributes that blekko provides, plus a couple more:
|
data/lib/blekko-search/blekko.rb
CHANGED
@@ -3,9 +3,15 @@ class Blekko
|
|
3
3
|
DEFAULT_MAX_FREQUENCY_PER_SECOND = 1
|
4
4
|
SECURE_PROTOCOL = "https://"
|
5
5
|
NON_SECURE_PROTOCOL = "http://"
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_accessor :last_request_at
|
9
|
+
def last_request_at
|
10
|
+
@last_request_at ||= {}
|
11
|
+
end
|
12
|
+
end
|
6
13
|
|
7
|
-
attr_accessor :protocol, :api_key, :max_frequency_per_second, :username, :password, :login_cookie
|
8
|
-
:last_request_at
|
14
|
+
attr_accessor :protocol, :api_key, :max_frequency_per_second, :username, :password, :login_cookie
|
9
15
|
|
10
16
|
def initialize(args={})
|
11
17
|
@api_key = args[:api_key]
|
@@ -57,6 +63,14 @@ class Blekko
|
|
57
63
|
1 / max_frequency_per_second.to_f
|
58
64
|
end
|
59
65
|
|
66
|
+
def last_request_at
|
67
|
+
self.class.last_request_at[api_key]
|
68
|
+
end
|
69
|
+
|
70
|
+
def last_request_at=(value)
|
71
|
+
self.class.last_request_at[api_key] = value
|
72
|
+
end
|
73
|
+
|
60
74
|
def earliest_next_request
|
61
75
|
last_request_at ? last_request_at + delay_between_requests : Time.now
|
62
76
|
end
|
@@ -64,6 +78,5 @@ class Blekko
|
|
64
78
|
def seconds_until_next_request
|
65
79
|
[earliest_next_request - Time.now, 0].max
|
66
80
|
end
|
67
|
-
|
68
|
-
|
81
|
+
|
69
82
|
end
|