geocaching 0.2.1 → 0.2.3
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.rb +2 -0
- data/lib/geocaching/cache.rb +8 -4
- data/lib/geocaching/cache_type.rb +46 -0
- data/lib/geocaching/log_type.rb +72 -0
- data/lib/geocaching/mylogs.rb +63 -0
- data/spec/cache_spec.rb +5 -1
- metadata +6 -3
data/geocaching.gemspec
CHANGED
data/lib/geocaching.rb
CHANGED
data/lib/geocaching/cache.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require "time"
|
4
|
-
|
5
3
|
module Geocaching
|
6
4
|
# This class is subclass of Array and is used to store all logs
|
7
5
|
# that belong to a cache. It implements the {#fetch_all} method to
|
@@ -140,6 +138,10 @@ module Geocaching
|
|
140
138
|
end
|
141
139
|
end
|
142
140
|
|
141
|
+
def type
|
142
|
+
CacheType.for_id(type_id)
|
143
|
+
end
|
144
|
+
|
143
145
|
# The cache’s name.
|
144
146
|
#
|
145
147
|
# @return [String] Name
|
@@ -202,7 +204,7 @@ module Geocaching
|
|
202
204
|
raise NotFetchedError unless fetched?
|
203
205
|
|
204
206
|
if @data =~ /<strong>\s*?Hidden\s*?:\s*?<\/strong>\s*?(\d{1,2})\/(\d{1,2})\/(\d{4})/
|
205
|
-
Time.
|
207
|
+
Time.mktime($3, $1, $2)
|
206
208
|
else
|
207
209
|
raise ExtractError, "Could not extract hidden date from website"
|
208
210
|
end
|
@@ -314,7 +316,9 @@ module Geocaching
|
|
314
316
|
def pmonly?
|
315
317
|
@is_pmonly ||= begin
|
316
318
|
raise NotFetchedError unless fetched?
|
317
|
-
|
319
|
+
|
320
|
+
@doc.search("#ctl00_ContentBody_basicMemberMsg").size == 1 ||
|
321
|
+
!!(@data =~ /<p class="Warning">This is a Premium Member Only cache\.<\/p>/)
|
318
322
|
end
|
319
323
|
end
|
320
324
|
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Geocaching
|
2
|
+
class CacheType
|
3
|
+
MAPPING = {
|
4
|
+
:traditional => [2, "Traditional Cache"],
|
5
|
+
:multi => [3, "Multi Cache"],
|
6
|
+
:mystery => [8, "Mystery Cache"],
|
7
|
+
:letterbox => [5, "Letterbox Hybrid"],
|
8
|
+
:wherigo => [1858, "Wherigo"],
|
9
|
+
:event => [6, "Event Cache"],
|
10
|
+
:megaevent => [453, "Mega Event Cache"],
|
11
|
+
:cito => [13, "Cache in Trash out Event"],
|
12
|
+
:earthcache => [137, "EarthCache"],
|
13
|
+
:lfevent => [3653, "Lost and Found Event Cache"],
|
14
|
+
:locationless => [12, "Locationless Reverse Cache"],
|
15
|
+
:webcam => [11, "Webcam Cache"],
|
16
|
+
:virtual => [4, "Virtual Cache"],
|
17
|
+
:ape => [32, "Project A.P.E. Cache"] # TODO
|
18
|
+
}
|
19
|
+
|
20
|
+
def self.for_id(id)
|
21
|
+
if info = MAPPING.to_a.select { |(k,v)| v[0] == id } and info.size == 1
|
22
|
+
new(info.first)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize(info)
|
27
|
+
@info = info
|
28
|
+
end
|
29
|
+
|
30
|
+
def id
|
31
|
+
@info[1][0]
|
32
|
+
end
|
33
|
+
|
34
|
+
def name
|
35
|
+
@info[1][1]
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_sym
|
39
|
+
@info[0]
|
40
|
+
end
|
41
|
+
|
42
|
+
def ==(s)
|
43
|
+
to_sym == s
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Geocaching
|
2
|
+
class LogType
|
3
|
+
MAPPING = {
|
4
|
+
:cache_published => ["icon_greenlight", "Published"],
|
5
|
+
CACHE_RETRACTED = 0x02
|
6
|
+
:dnf => ["icon_sad", "Didn't find it"],
|
7
|
+
:found => ["icon_smile", "Found it"],
|
8
|
+
WEBCAM_PHOTO_TAKEN = 0x05
|
9
|
+
WILL_ATTEND = 0x06
|
10
|
+
ANNOUNCEMENT = 0x07
|
11
|
+
:attended => ["icon_attended", "Attended"],
|
12
|
+
NEEDS_MAINTENANCE = 0x09
|
13
|
+
:PERFORMED_MAINTENANCE = 0x0a
|
14
|
+
:cache_disabled => ["icon_disabled", "Temporarily Disable Listing"],
|
15
|
+
CACHE_ENABLED = 0x0c
|
16
|
+
NOTE = 0x0d
|
17
|
+
NEEDS_ARCHIVED = 0x0e
|
18
|
+
:cache_archived => ["traffic_cone", "Archive"],
|
19
|
+
:cache_unarchived => ["traffic_cone", "Unarchive"],
|
20
|
+
COORDS_UPDATED = 0x11
|
21
|
+
REVIEWER_NOTE = 0x12
|
22
|
+
}
|
23
|
+
|
24
|
+
def self.for_icon(icon)
|
25
|
+
case icon
|
26
|
+
when "" then CACHE_PUBLISHED
|
27
|
+
when "" then CACHE_RETRACTED # TODO
|
28
|
+
when "" then DID_NOT_FOUND
|
29
|
+
when "" then FOUND
|
30
|
+
when "" then WEBCAM_PHOTO_TAKEN # TODO
|
31
|
+
when "icon_rsvp" then WILL_ATTEND
|
32
|
+
when "icon_announcement" then ANNOUNCEMENT
|
33
|
+
when "" then ATTENDED
|
34
|
+
when "icon_needsmaint" then NEEDS_MAINTENANCE
|
35
|
+
when "icon_maint" then PERFORMED_MAINTENANCE
|
36
|
+
when "icon_disabled" then CACHE_DISABLED
|
37
|
+
when "icon_enabled" then CACHE_ENABLED
|
38
|
+
when "icon_note" then NOTE
|
39
|
+
when "icon_remove" then NEEDS_ARCHIVED
|
40
|
+
when "traffic_cone" then CACHE_ARCHIVED
|
41
|
+
when "traffic_cone" then CACHE_UNARCHIVED
|
42
|
+
when "coord_update" then COORDS_UPDATED
|
43
|
+
when "big_smile" then REVIEWER_NOTE
|
44
|
+
else nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.for_title(title)
|
49
|
+
case title
|
50
|
+
when "Publish Listing" then CACHE_PUBLISHED
|
51
|
+
when "" then CACHE_RETRACTED # TODO
|
52
|
+
when "Didn't find it" then DID_NOT_FOUND
|
53
|
+
when "Found it" then FOUND # TODO
|
54
|
+
when "" then WEBCAM_PHOTO_TAKEN
|
55
|
+
when "Will Attend" then WILL_ATTEND
|
56
|
+
when "Announcement" then ANNOUNCEMENT
|
57
|
+
when "Attended" then ATTENDED
|
58
|
+
when "Needs Maintenance" then NEEDS_MAINTENANCE
|
59
|
+
when "Owner Maintenance" then PERFORMED_MAINTENANCE
|
60
|
+
when "Temporarily Disable Listing" then CACHE_DISABLED
|
61
|
+
when "Enable Listing" then CACHE_ENABLE
|
62
|
+
when "Write note" then NOTE
|
63
|
+
when "Needs Archived" then NEEDS_ARCHIVED
|
64
|
+
when "Archive" then CACHE_ARCHIVED
|
65
|
+
when "Unarchive" then CACHE_UNARCHIVE
|
66
|
+
when "Update Coordinates" then COORDS_UPDATED
|
67
|
+
when "Post Reviewer Note" then REVIEWER_NOTE
|
68
|
+
else nil
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Geocaching
|
2
|
+
class MyLogs
|
3
|
+
def self.fetch
|
4
|
+
mylogs = new
|
5
|
+
mylogs.fetch
|
6
|
+
mylogs
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
end
|
11
|
+
|
12
|
+
def fetch
|
13
|
+
raise LoginError, "Need to be logged in to fetch log information" unless HTTP.loggedin?
|
14
|
+
|
15
|
+
resp, @data = HTTP.get(path)
|
16
|
+
@doc = Nokogiri::HTML.parse(@data)
|
17
|
+
end
|
18
|
+
|
19
|
+
def logs
|
20
|
+
@logs ||= begin
|
21
|
+
rows = @doc.search("table.Table tr")
|
22
|
+
logs = []
|
23
|
+
|
24
|
+
rows.each do |row|
|
25
|
+
info = {}
|
26
|
+
|
27
|
+
# Cache GUID
|
28
|
+
elements = row.search("td:nth-child(3) a")
|
29
|
+
if elements.size == 1
|
30
|
+
url = elements.first["href"]
|
31
|
+
if url and url =~ /guid=([a-f0-9-]{36})/
|
32
|
+
info[:cache_guid] = $1
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Log GUID
|
37
|
+
elements = row.search("td:nth-child(5) a")
|
38
|
+
if elements.size == 1
|
39
|
+
url = elements.first["href"]
|
40
|
+
if url and url =~ /LUID=([a-f0-9-]{36})/
|
41
|
+
info[:log_guid] = $1
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
if info.size == 2
|
46
|
+
cache = Cache.new(:guid => info[:cache_guid])
|
47
|
+
log = Log.new(:guid => info[:log_guid], :cache => cache)
|
48
|
+
|
49
|
+
logs << log
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
logs
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def path
|
60
|
+
"/my/logs.aspx?s=1"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/spec/cache_spec.rb
CHANGED
@@ -39,7 +39,7 @@ share_as :GCF00 do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should return the correct hidden at date" do
|
42
|
-
@cache.hidden_at.should == Time.
|
42
|
+
@cache.hidden_at.should == Time.mktime(2001, 07, 05)
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should return the correct location" do
|
@@ -57,6 +57,10 @@ share_as :GCF00 do
|
|
57
57
|
it "should return a plausible number of total logs" do
|
58
58
|
@cache.logs.size.should >= 230
|
59
59
|
end
|
60
|
+
|
61
|
+
it "should return the correct type" do
|
62
|
+
@cache.type.to_sym.should == :traditional
|
63
|
+
end
|
60
64
|
end
|
61
65
|
|
62
66
|
describe "Geocaching::Cache for GCF00" do
|
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
|
+
- 3
|
9
|
+
version: 0.2.3
|
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-
|
17
|
+
date: 2010-08-06 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -58,8 +58,11 @@ files:
|
|
58
58
|
- Rakefile
|
59
59
|
- geocaching.gemspec
|
60
60
|
- lib/geocaching/cache.rb
|
61
|
+
- lib/geocaching/cache_type.rb
|
61
62
|
- lib/geocaching/http.rb
|
62
63
|
- lib/geocaching/log.rb
|
64
|
+
- lib/geocaching/log_type.rb
|
65
|
+
- lib/geocaching/mylogs.rb
|
63
66
|
- lib/geocaching.rb
|
64
67
|
- spec/cache_spec.rb
|
65
68
|
- spec/helper.rb
|