geocaching 0.5.0 → 0.6.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 +47 -21
- data/geocaching.gemspec +3 -0
- data/lib/geocaching.rb +20 -6
- data/lib/geocaching/cache.rb +237 -94
- data/lib/geocaching/cache_type.rb +17 -13
- data/lib/geocaching/http.rb +12 -16
- data/lib/geocaching/log.rb +67 -46
- data/lib/geocaching/log_type.rb +17 -13
- data/lib/geocaching/my_logs.rb +22 -16
- data/lib/geocaching/pocket_query.rb +213 -0
- data/lib/geocaching/user.rb +46 -69
- data/lib/geocaching/version.rb +3 -1
- data/lib/geocaching/watchlist.rb +106 -0
- data/spec/cache/ape.rb +4 -0
- data/spec/cache/cito.rb +4 -0
- data/spec/cache/earthcache.rb +4 -0
- data/spec/cache/event.rb +4 -0
- data/spec/cache/letterbox.rb +4 -0
- data/spec/cache/lfevent.rb +4 -0
- data/spec/cache/locationless.rb +4 -0
- data/spec/cache/megaevent.rb +4 -0
- data/spec/cache/multi.rb +4 -0
- data/spec/cache/mystery.rb +4 -0
- data/spec/cache/traditional.rb +4 -0
- data/spec/cache/virtual.rb +4 -0
- data/spec/cache/webcam.rb +4 -0
- data/spec/cache/wherigo.rb +4 -0
- data/spec/cache_spec.rb +7 -1
- data/spec/log/announcement.rb +1 -1
- data/spec/log/archive.rb +1 -1
- data/spec/log/attended.rb +1 -1
- data/spec/log/coords_update.rb +1 -1
- data/spec/log/disable.rb +1 -1
- data/spec/log/dnf.rb +1 -1
- data/spec/log/enable.rb +1 -1
- data/spec/log/found.rb +1 -1
- data/spec/log/needs_archived.rb +1 -1
- data/spec/log/needs_maintenance.rb +1 -1
- data/spec/log/note.rb +1 -1
- data/spec/log/owner_maintenance.rb +1 -1
- data/spec/log/publish.rb +1 -1
- data/spec/log/retract.rb +1 -1
- data/spec/log/reviewer_note.rb +1 -1
- data/spec/log/unarchive.rb +1 -1
- data/spec/log/webcam_photo_taken.rb +1 -1
- data/spec/log/will_attend.rb +1 -1
- data/spec/log_spec.rb +7 -1
- metadata +22 -6
- data/lib/geocaching/pq.rb +0 -72
data/lib/geocaching/version.rb
CHANGED
@@ -0,0 +1,106 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Geocaching
|
4
|
+
# The {Watchlist} class provides access to the user’s watchlist.
|
5
|
+
#
|
6
|
+
# This method does caching. That means that multiple calls to, for example,
|
7
|
+
# the {#caches} method do only one HTTP request. If you want to override
|
8
|
+
# the cached information, call the {#fetch} method manually. Note that this
|
9
|
+
# only applies to instances of this class, so a HTTP request is made for
|
10
|
+
# every call of the {caches} class method.
|
11
|
+
class Watchlist
|
12
|
+
# Creates a new instance of this class and calls the {#caches} method.
|
13
|
+
#
|
14
|
+
# @return [Array<Geocaching::Cache>]
|
15
|
+
def self.caches
|
16
|
+
new.caches
|
17
|
+
end
|
18
|
+
|
19
|
+
# Returns an array of caches the user has on its watchlist.
|
20
|
+
#
|
21
|
+
# @return [Array<Geocaching::Cache>]
|
22
|
+
def caches
|
23
|
+
@caches ||= begin
|
24
|
+
caches = []
|
25
|
+
fetch unless fetched?
|
26
|
+
|
27
|
+
@doc.search("table.Table > tbody > tr").each do |row|
|
28
|
+
if info = extract_info_from_row(row) and info.size == 3
|
29
|
+
cache = Cache.new \
|
30
|
+
:guid => info[:cache_guid],
|
31
|
+
:name => info[:cache_name],
|
32
|
+
:type => info[:cache_type]
|
33
|
+
caches << cache
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
caches
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Fetches information from geocaching.com. Usually, you only call this
|
42
|
+
# method manually if you want to override the cached information.
|
43
|
+
#
|
44
|
+
# @return [void]
|
45
|
+
def fetch
|
46
|
+
unless HTTP.loggedin?
|
47
|
+
raise LoginError, "You need to be logged in to access your watchlist"
|
48
|
+
end
|
49
|
+
|
50
|
+
resp, @data = HTTP.get(path)
|
51
|
+
@doc = Nokogiri::HTML.parse(@data)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Returns whether watchlist information have successfully been fetched
|
55
|
+
# from geocaching.com.
|
56
|
+
#
|
57
|
+
# @return [Boolean] Have watchlist information been fetched?
|
58
|
+
def fetched?
|
59
|
+
@data and @doc
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
# Returns the HTTP request path.
|
65
|
+
#
|
66
|
+
# @return [String] HTTP request path
|
67
|
+
def path
|
68
|
+
"/my/watchlist.aspx"
|
69
|
+
end
|
70
|
+
|
71
|
+
# Returns the information from a HTML table row node.
|
72
|
+
#
|
73
|
+
# @return [Hash] Extracted information
|
74
|
+
def extract_info_from_row(row)
|
75
|
+
info = {}
|
76
|
+
|
77
|
+
# Cache GUID
|
78
|
+
elements = row.search("td:nth-child(3) a")
|
79
|
+
if elements.size == 1
|
80
|
+
url = elements.first["href"]
|
81
|
+
if url and url =~ /guid=([a-f0-9-]{36})/
|
82
|
+
info[:cache_guid] = $1
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# Cache type
|
87
|
+
elements = row.search("td:nth-child(2) > img")
|
88
|
+
if elements.size == 1
|
89
|
+
if title = elements.first["alt"]
|
90
|
+
if type = CacheType.for_title(title)
|
91
|
+
info[:cache_type] = type
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# Cache name
|
97
|
+
elements = row.search("td:nth-child(3) a")
|
98
|
+
if elements.size == 1
|
99
|
+
name = elements.first.text
|
100
|
+
info[:cache_name] = name.strip if name
|
101
|
+
end
|
102
|
+
|
103
|
+
info
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
data/spec/cache/ape.rb
CHANGED
@@ -9,6 +9,10 @@ describe "Geocaching::Cache for 7d120ae2-855c-430d-9c14-3d7427de4bdd (Project A.
|
|
9
9
|
@cache.code.should == "GC1169"
|
10
10
|
end
|
11
11
|
|
12
|
+
it "should return the correct ID" do
|
13
|
+
@cache.id.should == 4457
|
14
|
+
end
|
15
|
+
|
12
16
|
it "should return the correct name" do
|
13
17
|
@cache.name.should == "Mission 9: Tunnel of Light"
|
14
18
|
end
|
data/spec/cache/cito.rb
CHANGED
@@ -9,6 +9,10 @@ describe "Geocaching::Cache for c52ff346-4567-4865-a230-c136843049e5 (CITO)" do
|
|
9
9
|
@cache.code.should == "GC1W95B"
|
10
10
|
end
|
11
11
|
|
12
|
+
it "should return the correct ID" do
|
13
|
+
@cache.id.should == 1325573
|
14
|
+
end
|
15
|
+
|
12
16
|
it "should return the correct name" do
|
13
17
|
@cache.name.should == "1. Dresdner CITO"
|
14
18
|
end
|
data/spec/cache/earthcache.rb
CHANGED
@@ -9,6 +9,10 @@ describe "Geocaching::Cache for e34a5b69-51a1-4ed4-838d-e3c3cb75a35a (EarthCache
|
|
9
9
|
@cache.code.should == "GC26Y3T"
|
10
10
|
end
|
11
11
|
|
12
|
+
it "should return the correct ID" do
|
13
|
+
@cache.id.should == 1642655
|
14
|
+
end
|
15
|
+
|
12
16
|
it "should return the correct name" do
|
13
17
|
@cache.name.should == "Kniepsand Amrum (Earthcache)"
|
14
18
|
end
|
data/spec/cache/event.rb
CHANGED
@@ -9,6 +9,10 @@ describe "Geocaching::Cache for 6cea30b1-7279-43ac-86a8-cdfd1daeb348 (Event)" do
|
|
9
9
|
@cache.code.should == "GC211KT"
|
10
10
|
end
|
11
11
|
|
12
|
+
it "should return the correct ID" do
|
13
|
+
@cache.id.should == 1467288
|
14
|
+
end
|
15
|
+
|
12
16
|
it "should return the correct name" do
|
13
17
|
@cache.name.should == "Weihnachtliches Vorglühen"
|
14
18
|
end
|
data/spec/cache/letterbox.rb
CHANGED
@@ -9,6 +9,10 @@ describe "Geocaching::Cache for 01328a57-5a04-4e69-a1cc-ce0eeaa452f5 (Letterbox)
|
|
9
9
|
@cache.code.should == "GC1KBJD"
|
10
10
|
end
|
11
11
|
|
12
|
+
it "should return the correct ID" do
|
13
|
+
@cache.id.should == 1089572
|
14
|
+
end
|
15
|
+
|
12
16
|
it "should return the correct name" do
|
13
17
|
@cache.name.should == "Worzeldorfer Gebirge (Letterbox)"
|
14
18
|
end
|
data/spec/cache/lfevent.rb
CHANGED
@@ -9,6 +9,10 @@ describe "Geocaching::Cache for 32512f3a-0fc2-45df-943b-af0a6f17f1fa (Lost and F
|
|
9
9
|
@cache.code.should == "GC2546Y"
|
10
10
|
end
|
11
11
|
|
12
|
+
it "should return the correct ID" do
|
13
|
+
@cache.id.should == 1588936
|
14
|
+
end
|
15
|
+
|
12
16
|
it "should return the correct name" do
|
13
17
|
@cache.name.should == "10 Jahre! Nürnberg, Germany"
|
14
18
|
end
|
data/spec/cache/locationless.rb
CHANGED
@@ -9,6 +9,10 @@ describe "Geocaching::Cache for 9ce22167-5a8d-451c-a69b-b19d5ec4f578 (Locationle
|
|
9
9
|
@cache.code.should == "GCB48F"
|
10
10
|
end
|
11
11
|
|
12
|
+
it "should return the correct ID" do
|
13
|
+
@cache.id.should == 46223
|
14
|
+
end
|
15
|
+
|
12
16
|
it "should return the correct name" do
|
13
17
|
@cache.name.should == "die letzte ihrer art?"
|
14
18
|
end
|
data/spec/cache/megaevent.rb
CHANGED
@@ -9,6 +9,10 @@ describe "Geocaching::Cache for b60781d0-0933-426d-9a67-80eb855e87ef (Mega Event
|
|
9
9
|
@cache.code.should == "GC1XEDZ"
|
10
10
|
end
|
11
11
|
|
12
|
+
it "should return the correct ID" do
|
13
|
+
@cache.id.should == 1360436
|
14
|
+
end
|
15
|
+
|
12
16
|
it "should return the correct name" do
|
13
17
|
@cache.name.should == "Pinzgau 2010"
|
14
18
|
end
|
data/spec/cache/multi.rb
CHANGED
@@ -9,6 +9,10 @@ describe "Geocaching::Cache for 07cfab08-dadb-4a8f-a187-2a63404b4d3c (Multi)" do
|
|
9
9
|
@cache.code.should == "GC1V1RH"
|
10
10
|
end
|
11
11
|
|
12
|
+
it "should return the correct ID" do
|
13
|
+
@cache.id.should == 1288689
|
14
|
+
end
|
15
|
+
|
12
16
|
it "should return the correct name" do
|
13
17
|
@cache.name.should == "D1 - Plan-les-Ouates - le défi"
|
14
18
|
end
|
data/spec/cache/mystery.rb
CHANGED
@@ -9,6 +9,10 @@ describe "Geocaching::Cache for 1d86cace-bada-435a-817a-f841718d7754 (Mystery)"
|
|
9
9
|
@cache.code.should == "GC21BBB"
|
10
10
|
end
|
11
11
|
|
12
|
+
it "should return the correct ID" do
|
13
|
+
@cache.id.should == 1476636
|
14
|
+
end
|
15
|
+
|
12
16
|
it "should return the correct name" do
|
13
17
|
@cache.name.should == "Nordstadt-Matrix"
|
14
18
|
end
|
data/spec/cache/traditional.rb
CHANGED
@@ -9,6 +9,10 @@ describe "Geocaching::Cache for 66274935-40d5-43d8-8cc3-c819e38f9dcc (Traditiona
|
|
9
9
|
@cache.code.should == "GCF00"
|
10
10
|
end
|
11
11
|
|
12
|
+
it "should return the correct ID" do
|
13
|
+
@cache.id.should == 3840
|
14
|
+
end
|
15
|
+
|
12
16
|
it "should return the correct name" do
|
13
17
|
@cache.name.should == "Bridge Over Troubled Waters"
|
14
18
|
end
|
data/spec/cache/virtual.rb
CHANGED
@@ -9,6 +9,10 @@ describe "Geocaching::Cache for 4e8b79e1-ffb2-4845-9c24-5ef54137a9b9 (Virtual)"
|
|
9
9
|
@cache.code.should == "GCEB74"
|
10
10
|
end
|
11
11
|
|
12
|
+
it "should return the correct ID" do
|
13
|
+
@cache.id.should == 60276
|
14
|
+
end
|
15
|
+
|
12
16
|
it "should return the correct name" do
|
13
17
|
@cache.name.should == "Buecherturm"
|
14
18
|
end
|
data/spec/cache/webcam.rb
CHANGED
@@ -9,6 +9,10 @@ describe "Geocaching::Cache for 8cd0976c-42cf-40a2-ae02-ed87ad52d5b1 (Webcam)" d
|
|
9
9
|
@cache.code.should == "GCQG38"
|
10
10
|
end
|
11
11
|
|
12
|
+
it "should return the correct ID" do
|
13
|
+
@cache.id.should == 289550
|
14
|
+
end
|
15
|
+
|
12
16
|
it "should return the correct name" do
|
13
17
|
@cache.name.should == "Versteckte Kamera"
|
14
18
|
end
|
data/spec/cache/wherigo.rb
CHANGED
@@ -9,6 +9,10 @@ describe "Geocaching::Cache for 6128b8a1-2ed3-48f0-9e05-a7117c5faffc (Wherigo)"
|
|
9
9
|
@cache.code.should == "GC19RVP"
|
10
10
|
end
|
11
11
|
|
12
|
+
it "should return the correct ID" do
|
13
|
+
@cache.id.should == 804412
|
14
|
+
end
|
15
|
+
|
12
16
|
it "should return the correct name" do
|
13
17
|
@cache.name.should == "Pegnitztal"
|
14
18
|
end
|
data/spec/cache_spec.rb
CHANGED
@@ -6,7 +6,13 @@ dir = File.dirname(__FILE__)
|
|
6
6
|
require "geocaching"
|
7
7
|
require "#{dir}/helper"
|
8
8
|
|
9
|
-
|
9
|
+
if ENV["GC_CACHE_TYPES"]
|
10
|
+
types = ENV["GC_CACHE_TYPES"].split
|
11
|
+
else
|
12
|
+
types = Geocaching::CacheType::TYPES.to_a.map { |a| a[0].to_s }
|
13
|
+
end
|
14
|
+
|
15
|
+
types.each do |type|
|
10
16
|
# Locationless caches have completely been disabled on geocaching.com
|
11
17
|
next if type == "locationless"
|
12
18
|
|
data/spec/log/announcement.rb
CHANGED
@@ -6,7 +6,7 @@ describe "Geocaching::Log for 37ef1827-17a6-436c-b8a1-01f1573186f3 (Announcement
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it "should return the correct username" do
|
9
|
-
@log.
|
9
|
+
@log.user.name.should == "Frank Frank"
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should return the correct cache GUID" do
|
data/spec/log/archive.rb
CHANGED
data/spec/log/attended.rb
CHANGED
@@ -6,7 +6,7 @@ describe "Geocaching::Log for 9bf458db-6dc9-4e02-b7ea-9cf056c40ade (Attended)" d
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it "should return the correct username" do
|
9
|
-
@log.
|
9
|
+
@log.user.name.should == "Snooking Good"
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should return the correct cache GUID" do
|
data/spec/log/coords_update.rb
CHANGED
@@ -6,7 +6,7 @@ describe "Geocaching::Log for 6802b623-f02c-4268-8fb3-7194ea60a686 (Update Coord
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it "should return the correct username" do
|
9
|
-
@log.
|
9
|
+
@log.user.name.should == "Rudisucht"
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should return the correct cache GUID" do
|
data/spec/log/disable.rb
CHANGED
@@ -6,7 +6,7 @@ describe "Geocaching::Log for 83a3f4f4-7faf-414a-8145-8f334622d20f (Disable List
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it "should return the correct username" do
|
9
|
-
@log.
|
9
|
+
@log.user.name.should == "CacheHasen"
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should return the correct cache GUID" do
|
data/spec/log/dnf.rb
CHANGED
data/spec/log/enable.rb
CHANGED
data/spec/log/found.rb
CHANGED
@@ -6,7 +6,7 @@ describe "Geocaching::Log for a3237dec-6931-4221-8f00-5d62923b411a (Found it)" d
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it "should return the correct username" do
|
9
|
-
@log.
|
9
|
+
@log.user.name.should == "CampinCrazy"
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should return the correct cache GUID" do
|
data/spec/log/needs_archived.rb
CHANGED
@@ -6,7 +6,7 @@ describe "Geocaching::Log for d235f46e-cd16-49af-a520-fa52f6c8abf8 (Needs Archiv
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it "should return the correct username" do
|
9
|
-
@log.
|
9
|
+
@log.user.name.should == "Kent_Allard"
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should return the correct cache GUID" do
|
data/spec/log/note.rb
CHANGED
@@ -6,7 +6,7 @@ describe "Geocaching::Log for 1eb67c1f-610d-4d1d-9703-10b3e47416e2 (Write Note)"
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it "should return the correct username" do
|
9
|
-
@log.
|
9
|
+
@log.user.name.should == "cache-strapped"
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should return the correct cache GUID" do
|
data/spec/log/publish.rb
CHANGED
@@ -6,7 +6,7 @@ describe "Geocaching::Log for d7ae038b-cb26-4b8e-bcca-5effd05870d0 (Publish)" do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it "should return the correct username" do
|
9
|
-
@log.
|
9
|
+
@log.user.name.should == "geoawareCA"
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should return the correct cache GUID" do
|
data/spec/log/retract.rb
CHANGED
data/spec/log/reviewer_note.rb
CHANGED
@@ -6,7 +6,7 @@ describe "Geocaching::Log for 876d4e85-ebe9-4098-8552-151f34d3b4de (Post Reviewe
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it "should return the correct username" do
|
9
|
-
@log.
|
9
|
+
@log.user.name.should == "Prime Reviewer"
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should return the correct cache GUID" do
|
data/spec/log/unarchive.rb
CHANGED