geocaching 0.6.0 → 0.6.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/README.markdown +3 -3
- data/lib/geocaching.rb +9 -10
- data/lib/geocaching/cache.rb +16 -25
- data/lib/geocaching/http.rb +12 -4
- data/lib/geocaching/log.rb +1 -12
- data/lib/geocaching/my_logs.rb +3 -12
- data/lib/geocaching/user.rb +2 -13
- data/lib/geocaching/version.rb +1 -1
- data/lib/geocaching/watchlist.rb +1 -14
- metadata +3 -75
- data/Rakefile +0 -11
- data/geocaching.gemspec +0 -24
- data/lib/geocaching/pocket_query.rb +0 -213
- data/spec/cache/ape.rb +0 -75
- data/spec/cache/cito.rb +0 -75
- data/spec/cache/earthcache.rb +0 -75
- data/spec/cache/event.rb +0 -75
- data/spec/cache/letterbox.rb +0 -75
- data/spec/cache/lfevent.rb +0 -75
- data/spec/cache/locationless.rb +0 -75
- data/spec/cache/megaevent.rb +0 -75
- data/spec/cache/multi.rb +0 -75
- data/spec/cache/mystery.rb +0 -75
- data/spec/cache/traditional.rb +0 -75
- data/spec/cache/virtual.rb +0 -75
- data/spec/cache/webcam.rb +0 -75
- data/spec/cache/wherigo.rb +0 -75
- data/spec/cache_spec.rb +0 -20
- data/spec/helper.rb +0 -16
- data/spec/log/announcement.rb +0 -28
- data/spec/log/announcement.txt +0 -14
- data/spec/log/archive.rb +0 -28
- data/spec/log/archive.txt +0 -5
- data/spec/log/attended.rb +0 -28
- data/spec/log/attended.txt +0 -1
- data/spec/log/coords_update.rb +0 -28
- data/spec/log/coords_update.txt +0 -9
- data/spec/log/disable.rb +0 -28
- data/spec/log/disable.txt +0 -5
- data/spec/log/dnf.rb +0 -28
- data/spec/log/dnf.txt +0 -5
- data/spec/log/enable.rb +0 -28
- data/spec/log/enable.txt +0 -1
- data/spec/log/found.rb +0 -28
- data/spec/log/found.txt +0 -5
- data/spec/log/needs_archived.rb +0 -28
- data/spec/log/needs_archived.txt +0 -1
- data/spec/log/needs_maintenance.rb +0 -28
- data/spec/log/needs_maintenance.txt +0 -1
- data/spec/log/note.rb +0 -28
- data/spec/log/note.txt +0 -1
- data/spec/log/owner_maintenance.rb +0 -28
- data/spec/log/owner_maintenance.txt +0 -1
- data/spec/log/publish.rb +0 -28
- data/spec/log/publish.txt +0 -1
- data/spec/log/retract.rb +0 -28
- data/spec/log/retract.txt +0 -4
- data/spec/log/reviewer_note.rb +0 -28
- data/spec/log/reviewer_note.txt +0 -3
- data/spec/log/unarchive.rb +0 -28
- data/spec/log/unarchive.txt +0 -1
- data/spec/log/webcam_photo_taken.rb +0 -28
- data/spec/log/webcam_photo_taken.txt +0 -1
- data/spec/log/will_attend.rb +0 -28
- data/spec/log/will_attend.txt +0 -1
- data/spec/log_spec.rb +0 -21
- data/spec/user_spec.rb +0 -48
data/Rakefile
DELETED
data/geocaching.gemspec
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require "#{File.dirname(__FILE__)}/lib/geocaching/version"
|
2
|
-
|
3
|
-
Gem::Specification.new do |s|
|
4
|
-
s.name = "geocaching"
|
5
|
-
s.version = Geocaching::VERSION
|
6
|
-
|
7
|
-
s.summary = "Ruby API for geocaching.com"
|
8
|
-
s.description = "A Ruby library that provides an API for geocaching.com"
|
9
|
-
|
10
|
-
s.author = "Thomas Cyron"
|
11
|
-
s.email = "thomas@thcyron.de"
|
12
|
-
s.homepage = "http://nano.github.com/ruby-geocaching"
|
13
|
-
|
14
|
-
s.files = %w(README.markdown Rakefile geocaching.gemspec)
|
15
|
-
s.files += Dir.glob("lib/**/*")
|
16
|
-
s.files += Dir.glob("spec/**/*")
|
17
|
-
|
18
|
-
s.has_rdoc = false
|
19
|
-
|
20
|
-
s.add_dependency "nokogiri", ">= 1.4.2"
|
21
|
-
s.add_dependency "json", ">= 1.4.6"
|
22
|
-
|
23
|
-
s.add_development_dependency "rspec", ">= 2.0.0"
|
24
|
-
end
|
@@ -1,213 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Geocaching
|
4
|
-
# The {PocketQuery} class represents a Pocket Query.
|
5
|
-
#
|
6
|
-
# == Usage
|
7
|
-
#
|
8
|
-
# === Downloading a Pocket Query
|
9
|
-
#
|
10
|
-
# avail_pqs = Geocaching::PocketQuery.ready_for_download
|
11
|
-
# pq = avail_pqs.first
|
12
|
-
#
|
13
|
-
# pq.download
|
14
|
-
# pq.parse
|
15
|
-
#
|
16
|
-
# puts "The PQ contains #{pq.caches.size} caches."
|
17
|
-
#
|
18
|
-
# === Reading a Pocket Query from file
|
19
|
-
#
|
20
|
-
# pq = Geocaching::PocketQuery.from_file("123456.gpx")
|
21
|
-
# puts "The PQ’s name is #{pq.name}."
|
22
|
-
#
|
23
|
-
class PocketQuery
|
24
|
-
# Reads a Pocket Query from file and parses it. The file may either be a
|
25
|
-
# GPX file or a zip file containing the GPX file.
|
26
|
-
#
|
27
|
-
# @param [String] file File name
|
28
|
-
# @return [Geocaching::PocketQuery] Pocket Query
|
29
|
-
def self.from_file(file)
|
30
|
-
pq = new(:raw => File.read(file))
|
31
|
-
pq.parse
|
32
|
-
pq
|
33
|
-
end
|
34
|
-
|
35
|
-
# Returns an array of Pocket Queries that are ready for download. You
|
36
|
-
# need to be logged in and a Premium Member to use this feature.
|
37
|
-
#
|
38
|
-
# @return [Array<Geocaching::PocketQuery>]
|
39
|
-
# Array of Pocket Queries ready for download
|
40
|
-
def self.ready_for_download
|
41
|
-
raise LoginError unless HTTP.loggedin?
|
42
|
-
|
43
|
-
pqs = []
|
44
|
-
resp, data = HTTP.get("/pocket/default.aspx")
|
45
|
-
doc = Nokogiri::HTML.parse(data)
|
46
|
-
|
47
|
-
elements = doc.search("table#uxOfflinePQTable")
|
48
|
-
raise ParseError unless elements.size == 1
|
49
|
-
|
50
|
-
elements = elements.first.search("tr")[1..-1]
|
51
|
-
|
52
|
-
elements.each do |row|
|
53
|
-
# Name
|
54
|
-
elements = row.search("td:nth-child(3) > a")
|
55
|
-
next unless elements.size == 1
|
56
|
-
name = elements.first.text.strip
|
57
|
-
|
58
|
-
# GUID
|
59
|
-
if elements.first["href"] =~ /g=([a-f0-9-]{36})/
|
60
|
-
guid = $1
|
61
|
-
else
|
62
|
-
next
|
63
|
-
end
|
64
|
-
|
65
|
-
# Number of results
|
66
|
-
elements = row.search("td:nth-child(5)")
|
67
|
-
next unless elements.size == 1
|
68
|
-
results = elements.first.text.to_i
|
69
|
-
|
70
|
-
# Last Generated date
|
71
|
-
elements = row.search("td:nth-child(6)")
|
72
|
-
next unless elements.size == 1
|
73
|
-
if elements.first.text =~ /(\d{2})\/(\d{2})\/(\d{4})/
|
74
|
-
date = Time.mktime($3, $1, $2)
|
75
|
-
end
|
76
|
-
|
77
|
-
if guid and name and results and date
|
78
|
-
pq = PocketQuery.new \
|
79
|
-
:guid => guid,
|
80
|
-
:name => name,
|
81
|
-
:results => results,
|
82
|
-
:last_generated_at => date
|
83
|
-
pqs << pq
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
pqs
|
88
|
-
end
|
89
|
-
|
90
|
-
class << self
|
91
|
-
alias ready ready_for_download
|
92
|
-
end
|
93
|
-
|
94
|
-
# Adds the ”My Finds“ Pocket Query to the Queue.
|
95
|
-
#
|
96
|
-
# @return [void]
|
97
|
-
def self.schedule_my_finds
|
98
|
-
resp, data = HTTP.post("/pocket/default.aspx", {
|
99
|
-
"ctl00$ContentBody$PQListControl1$btnScheduleNow" => "Yes"
|
100
|
-
})
|
101
|
-
|
102
|
-
!!(data =~ /Your 'My Finds' Pocket Query has been scheduled to run./)
|
103
|
-
end
|
104
|
-
|
105
|
-
# Creates a new instance. The following attributes may be specified
|
106
|
-
# as parameters:
|
107
|
-
#
|
108
|
-
# * +:guid+ — The Pocket Query’s GUID
|
109
|
-
#
|
110
|
-
# @param [Hash] attributes A hash of attributes
|
111
|
-
# @raise [ArgumentError] Trying to set an unknown attribute
|
112
|
-
def initialize(attributes = {})
|
113
|
-
attributes.each do |key, value|
|
114
|
-
if [:guid, :name, :results, :last_generated_at, :raw].include?(key)
|
115
|
-
if key == :last_generated_at and not value.kind_of?(Time)
|
116
|
-
raise TypeError, \
|
117
|
-
"Attribute `last_generated_at' must be an instance of Time"
|
118
|
-
end
|
119
|
-
|
120
|
-
if key == :results and not value.kind_of?(Fixnum)
|
121
|
-
raise TypeError, "Attribute `results' must be a number"
|
122
|
-
end
|
123
|
-
|
124
|
-
instance_variable_set("@#{key}", value)
|
125
|
-
else
|
126
|
-
raise ArgumentError, "Trying to set unknown attribute `#{key}'"
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
# Returns the Pocket Query’s GUID.
|
132
|
-
#
|
133
|
-
# @return [String] GUID
|
134
|
-
def guid
|
135
|
-
@guid
|
136
|
-
end
|
137
|
-
|
138
|
-
# Returns the Pocket Query’s name.
|
139
|
-
#
|
140
|
-
# @return [String] Name
|
141
|
-
def name
|
142
|
-
@name ||= begin
|
143
|
-
@gpx.xpath("/xmlns:gpx/xmlns:name").content if @gpx
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
# Returns the date the Pocket Query was last generated at.
|
148
|
-
#
|
149
|
-
# @return [Time] Last generated date
|
150
|
-
def last_generated_at
|
151
|
-
@last_generated_at ||= begin
|
152
|
-
if @gpx
|
153
|
-
# ...
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
# Returns the number of results inside the Pocket Query.
|
159
|
-
#
|
160
|
-
# @return [Fixnum] Number of results
|
161
|
-
def results
|
162
|
-
@results ||= begin
|
163
|
-
@caches.size if @caches
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
# Returns the Pocket Query’s raw data. This may be either zipped data
|
168
|
-
# or a GPX document.
|
169
|
-
#
|
170
|
-
# @return [String] Raw data (zip or gpx)
|
171
|
-
def raw
|
172
|
-
@raw || begin
|
173
|
-
raise NotFetchedError, "You have to download the Pocket Query first"
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
# Returns the Nokogiri XML document object for the GPX tree.
|
178
|
-
#
|
179
|
-
# @return [Nokogiri::XML::Document] Nokogiri XML document
|
180
|
-
def gpx
|
181
|
-
@gpx || begin
|
182
|
-
raise NotFetchedError, "You have to download the Pocket Query first"
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
# Downloads and parses the Pocket Query.
|
187
|
-
#
|
188
|
-
# @return [void]
|
189
|
-
def download
|
190
|
-
raise LoginError unless HTTP.loggedin?
|
191
|
-
|
192
|
-
resp, @raw = HTTP.get("/pocket/downloadpq.ashx?g=#{guid}")
|
193
|
-
parse
|
194
|
-
end
|
195
|
-
|
196
|
-
private
|
197
|
-
|
198
|
-
# Parses the Pocket Query’s GPX document.
|
199
|
-
#
|
200
|
-
# @return [void]
|
201
|
-
def parse
|
202
|
-
unless @raw
|
203
|
-
raise NotFetchedError, "You have to download the Pocket Query first"
|
204
|
-
end
|
205
|
-
|
206
|
-
if @raw[0..2] == "PK"
|
207
|
-
raise "Support for zip Pocket Query isn’t implemented yet"
|
208
|
-
else
|
209
|
-
@gpx = Nokogiri::XML.parse(@raw)
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
data/spec/cache/ape.rb
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
describe "Geocaching::Cache for 7d120ae2-855c-430d-9c14-3d7427de4bdd (Project A.P.E. Cache)" do
|
4
|
-
before :all do
|
5
|
-
@cache = Geocaching::Cache.fetch(:guid => "7d120ae2-855c-430d-9c14-3d7427de4bdd")
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should return the correct GC code" do
|
9
|
-
@cache.code.should == "GC1169"
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should return the correct ID" do
|
13
|
-
@cache.id.should == 4457
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should return the correct name" do
|
17
|
-
@cache.name.should == "Mission 9: Tunnel of Light"
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should return the correct displayed owner name" do
|
21
|
-
@cache.owner_display_name.should == "Project APE (maintained by Moun10Bike)"
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should return the correct owner GUID" do
|
25
|
-
@cache.owner.guid == "47975ebd-efc1-40d6-94c1-b379a6221a8f"
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should return the correct cache type" do
|
29
|
-
@cache.type.to_sym.should == :ape
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should return the correct size" do
|
33
|
-
@cache.size.should == :large
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should return the correct hidden date" do
|
37
|
-
@cache.hidden_at.should == Time.mktime(2001, 7, 18)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should return the correct difficulty rating" do
|
41
|
-
@cache.difficulty.should == 1
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should return the correct terrain rating" do
|
45
|
-
@cache.terrain.should == 3
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should return the correct latitude" do
|
49
|
-
@cache.latitude.should == 47.3919
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should return the correct longitude" do
|
53
|
-
@cache.longitude.should == -121.455083
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should return the correct location" do
|
57
|
-
@cache.location.should == "Washington, United States"
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should return a plausible number of logs" do
|
61
|
-
@cache.logs.size.should >= 3566
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should return cache has not been archived" do
|
65
|
-
@cache.archived?.should == false
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should return cache is not PM-only" do
|
69
|
-
@cache.pmonly?.should == false
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should return cache is not in review" do
|
73
|
-
@cache.in_review?.should == false
|
74
|
-
end
|
75
|
-
end
|
data/spec/cache/cito.rb
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
describe "Geocaching::Cache for c52ff346-4567-4865-a230-c136843049e5 (CITO)" do
|
4
|
-
before :all do
|
5
|
-
@cache = Geocaching::Cache.fetch(:guid => "c52ff346-4567-4865-a230-c136843049e5")
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should return the correct GC code" do
|
9
|
-
@cache.code.should == "GC1W95B"
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should return the correct ID" do
|
13
|
-
@cache.id.should == 1325573
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should return the correct name" do
|
17
|
-
@cache.name.should == "1. Dresdner CITO"
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should return the correct displayed owner name" do
|
21
|
-
@cache.owner_display_name.should == "GPS-Murmel, afrineo, Karrataka"
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should return the correct owner GUID" do
|
25
|
-
@cache.owner.guid == "b2fcf494-ecb8-4862-a279-03a325f6e1a1"
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should return the correct cache type" do
|
29
|
-
@cache.type.to_sym.should == :cito
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should return the correct size" do
|
33
|
-
@cache.size.should == :not_chosen
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should return the correct event date" do
|
37
|
-
@cache.event_date.should == Time.mktime(2010, 4, 17)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should return the correct difficulty rating" do
|
41
|
-
@cache.difficulty.should == 2.5
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should return the correct terrain rating" do
|
45
|
-
@cache.terrain.should == 4.5
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should return the correct latitude" do
|
49
|
-
@cache.latitude.should == 51.066667
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should return the correct longitude" do
|
53
|
-
@cache.longitude.should == 13.728333
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should return the correct location" do
|
57
|
-
@cache.location.should == "Sachsen, Germany"
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should return a plausible number of logs" do
|
61
|
-
@cache.logs.size.should >= 337
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should return cache has been archived" do
|
65
|
-
@cache.archived?.should == true
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should return cache is not PM-only" do
|
69
|
-
@cache.pmonly?.should == false
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should return cache is not in review" do
|
73
|
-
@cache.in_review?.should == false
|
74
|
-
end
|
75
|
-
end
|
data/spec/cache/earthcache.rb
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
describe "Geocaching::Cache for e34a5b69-51a1-4ed4-838d-e3c3cb75a35a (EarthCache)" do
|
4
|
-
before :all do
|
5
|
-
@cache = Geocaching::Cache.fetch(:guid => "e34a5b69-51a1-4ed4-838d-e3c3cb75a35a")
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should return the correct GC code" do
|
9
|
-
@cache.code.should == "GC26Y3T"
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should return the correct ID" do
|
13
|
-
@cache.id.should == 1642655
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should return the correct name" do
|
17
|
-
@cache.name.should == "Kniepsand Amrum (Earthcache)"
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should return the correct displayed owner name" do
|
21
|
-
@cache.owner_display_name.should == "Ifranipop"
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should return the correct owner GUID" do
|
25
|
-
@cache.owner.guid == "4fcca7ab-b4c7-42ee-86d6-c61056a9263e"
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should return the correct cache type" do
|
29
|
-
@cache.type.to_sym.should == :earthcache
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should return the correct size" do
|
33
|
-
@cache.size.should == :not_chosen
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should return the correct hidden date" do
|
37
|
-
@cache.hidden_at.should == Time.mktime(2010, 4, 17)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should return the correct difficulty rating" do
|
41
|
-
@cache.difficulty.should == 2
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should return the correct terrain rating" do
|
45
|
-
@cache.terrain.should == 2
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should return the correct latitude" do
|
49
|
-
@cache.latitude.should == 54.64475
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should return the correct longitude" do
|
53
|
-
@cache.longitude.should == 8.321667
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should return the correct location" do
|
57
|
-
@cache.location.should == "Schleswig-Holstein, Germany"
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should return the correct number of logs" do
|
61
|
-
@cache.logs.size.should >= 57
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should return cache has not been archived" do
|
65
|
-
@cache.archived?.should == false
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should return cache is not PM-only" do
|
69
|
-
@cache.pmonly?.should == false
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should return cache is not in review" do
|
73
|
-
@cache.in_review?.should == false
|
74
|
-
end
|
75
|
-
end
|