geocaching 0.1.0 → 0.2.0
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/Rakefile +2 -0
- data/geocaching.gemspec +13 -15
- data/lib/geocaching/cache.rb +8 -6
- data/lib/geocaching/http.rb +5 -1
- data/lib/geocaching/log.rb +4 -2
- data/lib/geocaching.rb +13 -6
- data/spec/cache_spec.rb +2 -0
- data/spec/helper.rb +2 -0
- data/spec/log_spec.rb +2 -0
- metadata +37 -13
data/Rakefile
CHANGED
data/geocaching.gemspec
CHANGED
@@ -1,21 +1,19 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
|
-
s.name
|
3
|
-
s.version
|
2
|
+
s.name = "geocaching"
|
3
|
+
s.version = "0.2.0"
|
4
4
|
|
5
|
-
s.summary
|
6
|
-
s.description =
|
7
|
-
A Ruby library that allows to access information on geocaching.com
|
8
|
-
in an object-oriented manner.
|
9
|
-
EOD
|
5
|
+
s.summary = "API for geocaching.com"
|
6
|
+
s.description = "A Ruby library that provides an API for information on geocaching.com"
|
10
7
|
|
11
|
-
s.author
|
12
|
-
s.email
|
13
|
-
s.homepage
|
8
|
+
s.author = "Thomas Cyron"
|
9
|
+
s.email = "nano@fooo.org"
|
10
|
+
s.homepage = "http://nano.github.com/ruby-geocaching"
|
14
11
|
|
15
|
-
s.
|
16
|
-
s.
|
12
|
+
s.files = %w(README.markdown Rakefile geocaching.gemspec)
|
13
|
+
s.files += Dir.glob("lib/**/*")
|
14
|
+
s.files += Dir.glob("spec/**/*")
|
17
15
|
|
18
|
-
s.
|
19
|
-
s.
|
20
|
-
s.
|
16
|
+
s.has_rdoc = false
|
17
|
+
s.add_dependency "nokogiri", ">= 1.4.2"
|
18
|
+
s.add_development_dependency "rspec"
|
21
19
|
end
|
data/lib/geocaching/cache.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require "time"
|
2
4
|
|
3
5
|
module Geocaching
|
@@ -70,7 +72,7 @@ module Geocaching
|
|
70
72
|
raise ArgumentError, "Neither code nor GUID given" unless @code or @guid
|
71
73
|
|
72
74
|
resp, @data = HTTP.get(path)
|
73
|
-
@doc =
|
75
|
+
@doc = Nokogiri::HTML.parse(@data)
|
74
76
|
end
|
75
77
|
|
76
78
|
# Whether information have successfully been fetched
|
@@ -91,7 +93,7 @@ module Geocaching
|
|
91
93
|
raise NotFetchedError unless fetched?
|
92
94
|
elements = @doc.search("#ctl00_uxWaypointName.GCCode")
|
93
95
|
|
94
|
-
if elements.size == 1 and elements.first.
|
96
|
+
if elements.size == 1 and elements.first.content =~ /(GC[A-Z0-9]+)/
|
95
97
|
HTTP.unescape($1)
|
96
98
|
else
|
97
99
|
raise ExtractError, "Could not extract code from website"
|
@@ -111,7 +113,7 @@ module Geocaching
|
|
111
113
|
elements = @doc.search("#ctl00_ContentBody_lnkPrintFriendly")
|
112
114
|
guid = nil
|
113
115
|
|
114
|
-
if elements.size == 1 and href = elements.first
|
116
|
+
if elements.size == 1 and href = elements.first["href"]
|
115
117
|
guid = $1 if href =~ /guid=([0-9a-f-]{36})/
|
116
118
|
end
|
117
119
|
|
@@ -149,7 +151,7 @@ module Geocaching
|
|
149
151
|
elements = @doc.search("span#ctl00_ContentBody_CacheName")
|
150
152
|
|
151
153
|
if elements.size == 1
|
152
|
-
HTTP.unescape(elements.first.
|
154
|
+
HTTP.unescape(elements.first.content)
|
153
155
|
else
|
154
156
|
raise ExtractError, "Could not extract name from website"
|
155
157
|
end
|
@@ -239,7 +241,7 @@ module Geocaching
|
|
239
241
|
latitude = nil
|
240
242
|
elements = @doc.search("a#ctl00_ContentBody_lnkConversions")
|
241
243
|
|
242
|
-
if elements.size == 1 and href = elements.first
|
244
|
+
if elements.size == 1 and href = elements.first["href"]
|
243
245
|
latitude = $1.to_f if href =~ /lat=(-?[0-9\.]+)/
|
244
246
|
end
|
245
247
|
|
@@ -261,7 +263,7 @@ module Geocaching
|
|
261
263
|
longitude = nil
|
262
264
|
elements = @doc.search("a#ctl00_ContentBody_lnkConversions")
|
263
265
|
|
264
|
-
if elements.size == 1 and href = elements.first
|
266
|
+
if elements.size == 1 and href = elements.first["href"]
|
265
267
|
longitude = $1.to_f if href =~ /lon=(-?[0-9\.]+)/
|
266
268
|
end
|
267
269
|
|
data/lib/geocaching/http.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require "cgi"
|
2
4
|
require "net/http"
|
3
5
|
require "timeout"
|
@@ -54,7 +56,9 @@ module Geocaching
|
|
54
56
|
#
|
55
57
|
# @return [String] The converted string
|
56
58
|
def unescape(str)
|
57
|
-
|
59
|
+
str = str.force_encoding("UTF-8")
|
60
|
+
str = str.gsub(/&#(\d{3});/) { [$1.to_i].pack("U") }
|
61
|
+
CGI.unescapeHTML(str)
|
58
62
|
end
|
59
63
|
end
|
60
64
|
|
data/lib/geocaching/log.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
module Geocaching
|
2
4
|
# This class represents a log on geocaching.com.
|
3
5
|
class Log
|
@@ -52,7 +54,7 @@ module Geocaching
|
|
52
54
|
raise LoginError, "Need to be logged in to fetch log information" unless HTTP.loggedin?
|
53
55
|
|
54
56
|
resp, @data = HTTP.get(path)
|
55
|
-
@doc =
|
57
|
+
@doc = Nokogiri::HTML.parse(@data)
|
56
58
|
end
|
57
59
|
|
58
60
|
# Whether information have successfully been fetched
|
@@ -150,7 +152,7 @@ module Geocaching
|
|
150
152
|
|
151
153
|
def meta
|
152
154
|
@meta ||= begin
|
153
|
-
elements = @doc.search("meta").select { |e| e
|
155
|
+
elements = @doc.search("meta").select { |e| e["name"] =~ /^og:/ }.flatten
|
154
156
|
info = {}
|
155
157
|
|
156
158
|
elements.each do |element|
|
data/lib/geocaching.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "nokogiri"
|
2
4
|
|
3
5
|
# This is a Ruby library to access information on geocaching.com. As
|
4
6
|
# Groundspeak does not provide a public API yet, one needs to parse the
|
@@ -33,18 +35,23 @@ require "hpricot"
|
|
33
35
|
# p log.username #=> Foobar
|
34
36
|
#
|
35
37
|
module Geocaching
|
38
|
+
# All exceptions raised by this library are subclasses of this class. It
|
39
|
+
# easily allows to rescue from all exceptions by catching Geocaching::Error.
|
40
|
+
class Error < Exception
|
41
|
+
end
|
42
|
+
|
36
43
|
# This exception is raised when a method that requires being
|
37
44
|
# logged in is called when not logged in.
|
38
|
-
class LoginError <
|
45
|
+
class LoginError < Error
|
39
46
|
end
|
40
47
|
|
41
48
|
# This exception is raised when a timeout is hit.
|
42
|
-
class TimeoutError <
|
49
|
+
class TimeoutError < Error
|
43
50
|
end
|
44
51
|
|
45
52
|
# This exception is raised when a method is called that requires
|
46
53
|
# the +#fetch+ method to be called first.
|
47
|
-
class NotFetchedError <
|
54
|
+
class NotFetchedError < Error
|
48
55
|
def initialize
|
49
56
|
super "Need to call the #fetch method first"
|
50
57
|
end
|
@@ -53,11 +60,11 @@ module Geocaching
|
|
53
60
|
# This exception is raised when information could not be
|
54
61
|
# extracted out of the website’s HTML code. For example,
|
55
62
|
# this may happen if Groundspeak changed their website.
|
56
|
-
class ExtractError <
|
63
|
+
class ExtractError < Error
|
57
64
|
end
|
58
65
|
|
59
66
|
# This exception is raised when a HTTP request fails.
|
60
|
-
class HTTPError <
|
67
|
+
class HTTPError < Error
|
61
68
|
end
|
62
69
|
|
63
70
|
autoload :HTTP, "geocaching/http"
|
data/spec/cache_spec.rb
CHANGED
data/spec/helper.rb
CHANGED
data/spec/log_spec.rb
CHANGED
metadata
CHANGED
@@ -4,24 +4,48 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 2
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
|
-
-
|
12
|
+
- Thomas Cyron
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-07-
|
17
|
+
date: 2010-07-27 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
|
-
dependencies:
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: nokogiri
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 1
|
30
|
+
- 4
|
31
|
+
- 2
|
32
|
+
version: 1.4.2
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
description: A Ruby library that provides an API for information on geocaching.com
|
25
49
|
email: nano@fooo.org
|
26
50
|
executables: []
|
27
51
|
|
@@ -41,8 +65,8 @@ files:
|
|
41
65
|
- spec/helper.rb
|
42
66
|
- spec/log_message.txt
|
43
67
|
- spec/log_spec.rb
|
44
|
-
has_rdoc:
|
45
|
-
homepage: http://nano.github.com/geocaching
|
68
|
+
has_rdoc: false
|
69
|
+
homepage: http://nano.github.com/ruby-geocaching
|
46
70
|
licenses: []
|
47
71
|
|
48
72
|
post_install_message:
|
@@ -72,6 +96,6 @@ rubyforge_project:
|
|
72
96
|
rubygems_version: 1.3.7
|
73
97
|
signing_key:
|
74
98
|
specification_version: 3
|
75
|
-
summary:
|
99
|
+
summary: API for geocaching.com
|
76
100
|
test_files: []
|
77
101
|
|