geocaching 0.2.0 → 0.2.1
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/geocaching.gemspec +1 -1
- data/lib/geocaching/cache.rb +1 -1
- data/lib/geocaching/http.rb +23 -2
- metadata +4 -4
data/geocaching.gemspec
CHANGED
data/lib/geocaching/cache.rb
CHANGED
@@ -201,7 +201,7 @@ module Geocaching
|
|
201
201
|
@hidden_at ||= begin
|
202
202
|
raise NotFetchedError unless fetched?
|
203
203
|
|
204
|
-
if @data =~ /<strong>\s
|
204
|
+
if @data =~ /<strong>\s*?Hidden\s*?:\s*?<\/strong>\s*?(\d{1,2})\/(\d{1,2})\/(\d{4})/
|
205
205
|
Time.parse([$3, $1, $2].join("-"))
|
206
206
|
else
|
207
207
|
raise ExtractError, "Could not extract hidden date from website"
|
data/lib/geocaching/http.rb
CHANGED
@@ -6,8 +6,21 @@ require "timeout"
|
|
6
6
|
|
7
7
|
module Geocaching
|
8
8
|
class HTTP
|
9
|
+
# An array of user agent strings. A random one is chosen.
|
10
|
+
USER_AGENTS = [
|
11
|
+
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",
|
12
|
+
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)",
|
13
|
+
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)",
|
14
|
+
"Mozilla/5.0 (compatible; Konqueror/3.2; Linux 2.6.2) (KHTML, like Gecko)",
|
15
|
+
"Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/125.2 (KHTML, like Gecko) Safari/125.8",
|
16
|
+
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13",
|
17
|
+
"Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10",
|
18
|
+
"Mozilla/5.0 (X11; U; Linux i586; en-US; rv:1.7.3) Gecko/20040924 Epiphany/1.4.4 (Ubuntu)",
|
19
|
+
"Opera/9.80 (Macintosh; Intel Mac OS X; U; en) Presto/2.2.15 Version/10.00"
|
20
|
+
]
|
21
|
+
|
9
22
|
# The user agent sent with each request.
|
10
|
-
@user_agent =
|
23
|
+
@user_agent = nil
|
11
24
|
|
12
25
|
# Timeout for sending and receiving HTTP data.
|
13
26
|
@timeout = 8
|
@@ -201,12 +214,20 @@ module Geocaching
|
|
201
214
|
meta
|
202
215
|
end
|
203
216
|
|
217
|
+
# Returns the user agent string to use for the HTTP requests. If no
|
218
|
+
# user agent is set explicitly, a random one is chosen.
|
219
|
+
#
|
220
|
+
# @return [String] User agent
|
221
|
+
def user_agent
|
222
|
+
self.class.user_agent ||= USER_AGENTS.shuffle.first
|
223
|
+
end
|
224
|
+
|
204
225
|
# Returns an hash with the HTTP headers sent with each request.
|
205
226
|
#
|
206
227
|
# @return [Hash] Default HTTP headers
|
207
228
|
def default_header
|
208
229
|
{
|
209
|
-
"User-Agent" =>
|
230
|
+
"User-Agent" => user_agent
|
210
231
|
}
|
211
232
|
end
|
212
233
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 1
|
9
|
+
version: 0.2.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Thomas Cyron
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-07-
|
17
|
+
date: 2010-07-29 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -65,7 +65,7 @@ files:
|
|
65
65
|
- spec/helper.rb
|
66
66
|
- spec/log_message.txt
|
67
67
|
- spec/log_spec.rb
|
68
|
-
has_rdoc:
|
68
|
+
has_rdoc: true
|
69
69
|
homepage: http://nano.github.com/ruby-geocaching
|
70
70
|
licenses: []
|
71
71
|
|