geocaching 0.6.1 → 0.7.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/README.markdown +11 -57
- data/lib/geocaching.rb +13 -86
- data/lib/geocaching/cache.rb +79 -557
- data/lib/geocaching/cache_type.rb +39 -78
- data/lib/geocaching/container_type.rb +45 -0
- data/lib/geocaching/errors.rb +7 -0
- data/lib/geocaching/log.rb +49 -180
- data/lib/geocaching/log_type.rb +51 -81
- data/lib/geocaching/parsers/cache_gpx.rb +42 -0
- data/lib/geocaching/parsers/cache_gpx_additional_waypoint.rb +100 -0
- data/lib/geocaching/parsers/cache_gpx_cache_waypoint.rb +234 -0
- data/lib/geocaching/parsers/cache_simple.rb +219 -0
- data/lib/geocaching/parsers/log.rb +100 -0
- data/lib/geocaching/parsers/trackable.rb +107 -0
- data/lib/geocaching/session.rb +119 -0
- data/lib/geocaching/session/caches.rb +61 -0
- data/lib/geocaching/session/logs.rb +17 -0
- data/lib/geocaching/session/trackables.rb +26 -0
- data/lib/geocaching/trackable.rb +77 -0
- data/lib/geocaching/trackable_type.rb +17 -0
- data/lib/geocaching/user.rb +10 -202
- data/lib/geocaching/waypoint.rb +51 -0
- data/lib/geocaching/waypoint_type.rb +41 -0
- metadata +21 -25
- data/lib/geocaching/http.rb +0 -248
- data/lib/geocaching/my_logs.rb +0 -147
- data/lib/geocaching/version.rb +0 -5
- data/lib/geocaching/watchlist.rb +0 -93
data/lib/geocaching/my_logs.rb
DELETED
@@ -1,147 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Geocaching
|
4
|
-
# The {MyLogs} class provides access to the logs the user
|
5
|
-
# you’re logged in with has written.
|
6
|
-
#
|
7
|
-
# == Usage
|
8
|
-
#
|
9
|
-
# mylogs = Geocaching::MyLogs.fetch
|
10
|
-
# puts "I've written #{mylogs.logs.size} logs."
|
11
|
-
#
|
12
|
-
class MyLogs
|
13
|
-
# Creates a new instance and calls {#fetch} afterwards.
|
14
|
-
#
|
15
|
-
# @return [Geocaching::MyLogs]
|
16
|
-
def self.fetch
|
17
|
-
mylogs = new
|
18
|
-
mylogs.fetch
|
19
|
-
mylogs
|
20
|
-
end
|
21
|
-
|
22
|
-
# Fetches logs from geocaching.com.
|
23
|
-
#
|
24
|
-
# @return [void]
|
25
|
-
def fetch
|
26
|
-
raise LoginError unless HTTP.loggedin?
|
27
|
-
|
28
|
-
resp, @data = HTTP.get("/my/logs.aspx?s=1")
|
29
|
-
@doc = Nokogiri::HTML.parse(@data)
|
30
|
-
end
|
31
|
-
|
32
|
-
# Returns whether logs have successfully been fetched
|
33
|
-
# from geocaching.com.
|
34
|
-
#
|
35
|
-
# @return [Boolean] Have logs been fetched?
|
36
|
-
def fetched?
|
37
|
-
@data and @doc
|
38
|
-
end
|
39
|
-
|
40
|
-
# Returns an array of logs the user you’re logged in with has
|
41
|
-
# written.
|
42
|
-
#
|
43
|
-
# @return [Array<Geocaching::Log>]
|
44
|
-
def logs
|
45
|
-
@logs ||= begin
|
46
|
-
raise NotFetchedError unless fetched?
|
47
|
-
|
48
|
-
rows = @doc.search("table.Table tr")
|
49
|
-
logs = []
|
50
|
-
|
51
|
-
rows.each do |row|
|
52
|
-
if info = extract_info_from_row(row) and info.size == 6
|
53
|
-
cache = Cache.new \
|
54
|
-
:guid => info[:cache_guid],
|
55
|
-
:name => info[:cache_name],
|
56
|
-
:type => info[:cache_type]
|
57
|
-
log = Log.new \
|
58
|
-
:guid => info[:log_guid],
|
59
|
-
:title => info[:log_title],
|
60
|
-
:date => info[:log_date],
|
61
|
-
:cache => cache
|
62
|
-
|
63
|
-
logs << log
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
logs
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
private
|
72
|
-
|
73
|
-
# Extracts information from a HTML table row node.
|
74
|
-
#
|
75
|
-
# @return [Hash] Extracted information
|
76
|
-
def extract_info_from_row(row)
|
77
|
-
info = {}
|
78
|
-
|
79
|
-
# Cache GUID
|
80
|
-
elements = row.search("td:nth-child(3) a")
|
81
|
-
if elements.size == 1
|
82
|
-
url = elements.first["href"]
|
83
|
-
if url and url =~ /guid=([a-f0-9-]{36})/
|
84
|
-
info[:cache_guid] = $1
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
# Cache type
|
89
|
-
elements = row.search("td:nth-child(3) a > img")
|
90
|
-
if elements.size == 1
|
91
|
-
if title = elements.first["title"]
|
92
|
-
if type = CacheType.for_title(title)
|
93
|
-
info[:cache_type] = type
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
# Cache name
|
99
|
-
elements = row.search("td:nth-child(3)")
|
100
|
-
if elements.size == 1
|
101
|
-
archived = elements.first.search("span.Strike.Warning > a > span > strike > font")
|
102
|
-
if archived.size == 1
|
103
|
-
name = archived.first.content
|
104
|
-
info[:cache_name] = name if name
|
105
|
-
else
|
106
|
-
disabled = elements.first.search("strike > a > span > strike")
|
107
|
-
if disabled.size == 1
|
108
|
-
name = disabled.first.content
|
109
|
-
info[:cache_name] = name if name
|
110
|
-
else
|
111
|
-
enabled = elements.first.search("a > span")
|
112
|
-
if enabled.size == 1
|
113
|
-
name = enabled.first.content
|
114
|
-
info[:cache_name] = name if name
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
# Log GUID
|
121
|
-
elements = row.search("td:nth-child(5) a")
|
122
|
-
if elements.size == 1
|
123
|
-
url = elements.first["href"]
|
124
|
-
if url and url =~ /LUID=([a-f0-9-]{36})/
|
125
|
-
info[:log_guid] = $1
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
# Log title
|
130
|
-
elements = row.search("td:first-child img")
|
131
|
-
if elements.size == 1
|
132
|
-
title = elements.first["alt"]
|
133
|
-
info[:log_title] = title if title
|
134
|
-
end
|
135
|
-
|
136
|
-
# Log date
|
137
|
-
elements = row.search("td:nth-child(2)")
|
138
|
-
if elements.size == 1
|
139
|
-
if elements.first.content =~ /(\d{2})\/(\d{2})\/(\d{4})/
|
140
|
-
info[:log_date] = Time.mktime($3, $1, $2)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
info
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
data/lib/geocaching/version.rb
DELETED
data/lib/geocaching/watchlist.rb
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Geocaching
|
4
|
-
# The {Watchlist} class provides access to the user’s watchlist.
|
5
|
-
class Watchlist
|
6
|
-
# Creates a new instance of this class and calls the {#caches} method.
|
7
|
-
#
|
8
|
-
# @return [Array<Geocaching::Cache>]
|
9
|
-
def self.caches
|
10
|
-
new.caches
|
11
|
-
end
|
12
|
-
|
13
|
-
# Returns an array of caches the user has on its watchlist.
|
14
|
-
#
|
15
|
-
# @return [Array<Geocaching::Cache>]
|
16
|
-
def caches
|
17
|
-
@caches ||= begin
|
18
|
-
caches = []
|
19
|
-
fetch unless fetched?
|
20
|
-
|
21
|
-
@doc.search("table.Table > tbody > tr").each do |row|
|
22
|
-
if info = extract_info_from_row(row) and info.size == 3
|
23
|
-
cache = Cache.new \
|
24
|
-
:guid => info[:cache_guid],
|
25
|
-
:name => info[:cache_name],
|
26
|
-
:type => info[:cache_type]
|
27
|
-
caches << cache
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
caches
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
# Fetches information from geocaching.com. Usually, you only call this
|
36
|
-
# method manually if you want to override the cached information.
|
37
|
-
#
|
38
|
-
# @return [void]
|
39
|
-
def fetch
|
40
|
-
unless HTTP.loggedin?
|
41
|
-
raise LoginError, "You need to be logged in to access your watchlist"
|
42
|
-
end
|
43
|
-
|
44
|
-
resp, @data = HTTP.get("/my/watchlist.aspx")
|
45
|
-
@doc = Nokogiri::HTML.parse(@data)
|
46
|
-
end
|
47
|
-
|
48
|
-
# Returns whether watchlist information have successfully been fetched
|
49
|
-
# from geocaching.com.
|
50
|
-
#
|
51
|
-
# @return [Boolean] Have watchlist information been fetched?
|
52
|
-
def fetched?
|
53
|
-
@data and @doc
|
54
|
-
end
|
55
|
-
|
56
|
-
private
|
57
|
-
|
58
|
-
# Returns the information from a HTML table row node.
|
59
|
-
#
|
60
|
-
# @return [Hash] Extracted information
|
61
|
-
def extract_info_from_row(row)
|
62
|
-
info = {}
|
63
|
-
|
64
|
-
# Cache GUID
|
65
|
-
elements = row.search("td:nth-child(3) a")
|
66
|
-
if elements.size == 1
|
67
|
-
url = elements.first["href"]
|
68
|
-
if url and url =~ /guid=([a-f0-9-]{36})/
|
69
|
-
info[:cache_guid] = $1
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
# Cache type
|
74
|
-
elements = row.search("td:nth-child(2) > img")
|
75
|
-
if elements.size == 1
|
76
|
-
if title = elements.first["alt"]
|
77
|
-
if type = CacheType.for_title(title)
|
78
|
-
info[:cache_type] = type
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
# Cache name
|
84
|
-
elements = row.search("td:nth-child(3) a")
|
85
|
-
if elements.size == 1
|
86
|
-
name = elements.first.text
|
87
|
-
info[:cache_name] = name.strip if name
|
88
|
-
end
|
89
|
-
|
90
|
-
info
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|