geocaching 0.3.0 → 0.4.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.
Files changed (65) hide show
  1. data/README.markdown +6 -0
  2. data/geocaching.gemspec +3 -1
  3. data/lib/geocaching.rb +4 -1
  4. data/lib/geocaching/cache.rb +65 -21
  5. data/lib/geocaching/cache_type.rb +57 -13
  6. data/lib/geocaching/log.rb +34 -2
  7. data/lib/geocaching/log_type.rb +57 -19
  8. data/lib/geocaching/my_logs.rb +150 -0
  9. data/lib/geocaching/user.rb +251 -0
  10. data/lib/geocaching/version.rb +3 -0
  11. data/spec/cache/ape.rb +69 -0
  12. data/spec/cache/cito.rb +12 -0
  13. data/spec/cache/earthcache.rb +12 -0
  14. data/spec/cache/event.rb +12 -0
  15. data/spec/cache/letterbox.rb +12 -0
  16. data/spec/cache/lfevent.rb +12 -0
  17. data/spec/cache/locationless.rb +12 -0
  18. data/spec/cache/megaevent.rb +12 -0
  19. data/spec/cache/multi.rb +27 -15
  20. data/spec/cache/mystery.rb +12 -0
  21. data/spec/cache/traditional.rb +12 -0
  22. data/spec/cache/virtual.rb +12 -0
  23. data/spec/cache/webcam.rb +12 -0
  24. data/spec/cache/wherigo.rb +12 -0
  25. data/spec/cache_spec.rb +3 -2
  26. data/spec/log/announcement.rb +28 -0
  27. data/spec/log/announcement.txt +14 -0
  28. data/spec/log/archive.rb +28 -0
  29. data/spec/log/archive.txt +5 -0
  30. data/spec/log/attended.rb +28 -0
  31. data/spec/log/attended.txt +1 -0
  32. data/spec/log/coords_update.rb +28 -0
  33. data/spec/log/coords_update.txt +9 -0
  34. data/spec/log/disable.rb +28 -0
  35. data/spec/log/disable.txt +3 -0
  36. data/spec/log/dnf.rb +28 -0
  37. data/spec/log/dnf.txt +5 -0
  38. data/spec/log/enable.rb +28 -0
  39. data/spec/log/enable.txt +1 -0
  40. data/spec/log/found.rb +28 -0
  41. data/spec/{log_message.txt → log/found.txt} +0 -0
  42. data/spec/log/needs_archived.rb +28 -0
  43. data/spec/log/needs_archived.txt +1 -0
  44. data/spec/log/needs_maintenance.rb +28 -0
  45. data/spec/log/needs_maintenance.txt +1 -0
  46. data/spec/log/note.rb +28 -0
  47. data/spec/log/note.txt +1 -0
  48. data/spec/log/owner_maintenance.rb +28 -0
  49. data/spec/log/owner_maintenance.txt +1 -0
  50. data/spec/log/publish.rb +28 -0
  51. data/spec/log/publish.txt +1 -0
  52. data/spec/log/retract.rb +28 -0
  53. data/spec/log/retract.txt +4 -0
  54. data/spec/log/reviewer_note.rb +28 -0
  55. data/spec/log/reviewer_note.txt +3 -0
  56. data/spec/log/unarchive.rb +28 -0
  57. data/spec/log/unarchive.txt +1 -0
  58. data/spec/log/webcam_photo_taken.rb +28 -0
  59. data/spec/log/webcam_photo_taken.txt +1 -0
  60. data/spec/log/will_attend.rb +28 -0
  61. data/spec/log/will_attend.txt +1 -0
  62. data/spec/log_spec.rb +7 -17
  63. data/spec/user_spec.rb +48 -0
  64. metadata +44 -6
  65. data/lib/geocaching/mylogs.rb +0 -63
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+
3
+ describe "Geocaching::Log for b70042d7-1411-4f56-950e-d23303e7ab4e (Unarchive)" do
4
+ before :all do
5
+ @log = Geocaching::Log.fetch(:guid => "b70042d7-1411-4f56-950e-d23303e7ab4e")
6
+ end
7
+
8
+ it "should return the correct username" do
9
+ @log.username.should == "Krypton"
10
+ end
11
+
12
+ it "should return the correct cache GUID" do
13
+ @log.cache.guid.should == "4d56861e-2779-4b2c-b06a-5bbea2ec93d4"
14
+ end
15
+
16
+ it "should return the correct type" do
17
+ @log.type.to_sym.should == :unarchive
18
+ end
19
+
20
+ it "should return the correct date" do
21
+ @log.date.should == Time.mktime(2009, 1, 16)
22
+ end
23
+
24
+ it "should return the correct message" do
25
+ should_message = File.read(__FILE__.gsub(/rb$/, "txt"))
26
+ @log.message.should == should_message.gsub(/\r\n/, "\n")
27
+ end
28
+ end
@@ -0,0 +1 @@
1
+ Unarchiving cache.
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+
3
+ describe "Geocaching::Log for c7f88568-9417-45c2-9906-c4f0210c7837 (Webcam Photo Taken)" do
4
+ before :all do
5
+ @log = Geocaching::Log.fetch(:guid => "c7f88568-9417-45c2-9906-c4f0210c7837")
6
+ end
7
+
8
+ it "should return the correct username" do
9
+ @log.username.should == "123flash"
10
+ end
11
+
12
+ it "should return the correct cache GUID" do
13
+ @log.cache.guid.should == "ed19825b-f94d-450f-a1df-feb274f33ac8"
14
+ end
15
+
16
+ it "should return the correct type" do
17
+ @log.type.to_sym.should == :webcam_photo_taken
18
+ end
19
+
20
+ it "should return the correct date" do
21
+ @log.date.should == Time.mktime(2010, 6, 30)
22
+ end
23
+
24
+ it "should return the correct message" do
25
+ should_message = File.read(__FILE__.gsub(/rb$/, "txt"))
26
+ @log.message.should == should_message.gsub(/\r\n/, "\n")
27
+ end
28
+ end
@@ -0,0 +1 @@
1
+ Thanks KBer for letting me log it as a find,
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+
3
+ describe "Geocaching::Log for 4ef9383c-19b6-41d6-843e-31ada8abbc22 (Will Attend)" do
4
+ before :all do
5
+ @log = Geocaching::Log.fetch(:guid => "4ef9383c-19b6-41d6-843e-31ada8abbc22")
6
+ end
7
+
8
+ it "should return the correct username" do
9
+ @log.username.should == "Dennis the Menace2"
10
+ end
11
+
12
+ it "should return the correct cache GUID" do
13
+ @log.cache.guid.should == "2f067ddb-1999-403a-8f9f-7509b8a68494"
14
+ end
15
+
16
+ it "should return the correct type" do
17
+ @log.type.to_sym.should == :will_attend
18
+ end
19
+
20
+ it "should return the correct date" do
21
+ @log.date.should == Time.mktime(2010, 7, 30)
22
+ end
23
+
24
+ it "should return the correct message" do
25
+ should_message = File.read(__FILE__.gsub(/rb$/, "txt"))
26
+ @log.message.should == should_message.gsub(/\r\n/, "\n")
27
+ end
28
+ end
@@ -0,0 +1 @@
1
+ Sounds like I will be able to make this one. Thanks for having it later in the day, so I can still make church.
@@ -1,25 +1,15 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
4
+ dir = File.dirname(__FILE__)
4
5
 
5
6
  require "geocaching"
6
- require "helper"
7
+ require "#{dir}/helper"
7
8
 
8
- describe "Geocaching::Log for a3237dec-6931-4221-8f00-5d62923b411a" do
9
- before :all do
10
- @log = Geocaching::Log.fetch(:guid => "a3237dec-6931-4221-8f00-5d62923b411a")
11
- end
12
-
13
- it "should return the correct username" do
14
- @log.username.should == "CampinCrazy"
15
- end
16
-
17
- it "should return the correct cache GUID" do
18
- @log.cache.guid.should == "66274935-40d5-43d8-8cc3-c819e38f9dcc"
19
- end
20
-
21
- it "should return the correct message" do
22
- should_message = File.read(File.join(File.dirname(__FILE__), "log_message.txt"))
23
- @log.message.should == should_message.gsub(/\r\n/, "\n")
9
+ Geocaching::LogType::TYPES.to_a.map { |a| a[0].to_s }.each do |type|
10
+ begin
11
+ require "#{dir}/log/#{type}"
12
+ rescue LoadError
13
+ $stderr.puts "Missing test for log type #{type}"
24
14
  end
25
15
  end
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
4
+
5
+ require "geocaching"
6
+ require "helper"
7
+
8
+ describe "Geocaching::User for efa09aeb-e2ac-4aad-8779-725a4aa35eac" do
9
+ before :all do
10
+ @user = Geocaching::User.fetch(:guid => "efa09aeb-e2ac-4aad-8779-725a4aa35eac")
11
+ end
12
+
13
+ it "should return the correct GUID" do
14
+ @user.guid.should == "efa09aeb-e2ac-4aad-8779-725a4aa35eac"
15
+ end
16
+
17
+ it "should return the correct user name" do
18
+ @user.name.should == "palmetto"
19
+ end
20
+
21
+ it "should return the correct member since date" do
22
+ @user.member_since.should == Time.mktime(2005, 12, 5)
23
+ end
24
+
25
+ it "should return a plausible last visit date" do
26
+ @user.last_visit.should >= Time.mktime(2010, 8, 12)
27
+ end
28
+
29
+ it "should return the correct occupation" do
30
+ @user.occupation.should == "loafering"
31
+ end
32
+
33
+ it "should return the correct location" do
34
+ @user.location.should == "sunny Florida"
35
+ end
36
+
37
+ it "should return no homepage" do
38
+ @user.homepage.should == nil
39
+ end
40
+
41
+ it "should return user is a premium member" do
42
+ @user.premium_member?.should == true
43
+ end
44
+
45
+ it "should return user is a reviewer" do
46
+ @user.reviewer?.should == true
47
+ end
48
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 3
7
+ - 4
8
8
  - 0
9
- version: 0.3.0
9
+ version: 0.4.0
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-08-11 00:00:00 +02:00
17
+ date: 2010-08-23 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -62,7 +62,9 @@ files:
62
62
  - lib/geocaching/http.rb
63
63
  - lib/geocaching/log.rb
64
64
  - lib/geocaching/log_type.rb
65
- - lib/geocaching/mylogs.rb
65
+ - lib/geocaching/my_logs.rb
66
+ - lib/geocaching/user.rb
67
+ - lib/geocaching/version.rb
66
68
  - lib/geocaching.rb
67
69
  - spec/cache/ape.rb
68
70
  - spec/cache/cito.rb
@@ -80,9 +82,45 @@ files:
80
82
  - spec/cache/wherigo.rb
81
83
  - spec/cache_spec.rb
82
84
  - spec/helper.rb
83
- - spec/log_message.txt
85
+ - spec/log/announcement.rb
86
+ - spec/log/announcement.txt
87
+ - spec/log/archive.rb
88
+ - spec/log/archive.txt
89
+ - spec/log/attended.rb
90
+ - spec/log/attended.txt
91
+ - spec/log/coords_update.rb
92
+ - spec/log/coords_update.txt
93
+ - spec/log/disable.rb
94
+ - spec/log/disable.txt
95
+ - spec/log/dnf.rb
96
+ - spec/log/dnf.txt
97
+ - spec/log/enable.rb
98
+ - spec/log/enable.txt
99
+ - spec/log/found.rb
100
+ - spec/log/found.txt
101
+ - spec/log/needs_archived.rb
102
+ - spec/log/needs_archived.txt
103
+ - spec/log/needs_maintenance.rb
104
+ - spec/log/needs_maintenance.txt
105
+ - spec/log/note.rb
106
+ - spec/log/note.txt
107
+ - spec/log/owner_maintenance.rb
108
+ - spec/log/owner_maintenance.txt
109
+ - spec/log/publish.rb
110
+ - spec/log/publish.txt
111
+ - spec/log/retract.rb
112
+ - spec/log/retract.txt
113
+ - spec/log/reviewer_note.rb
114
+ - spec/log/reviewer_note.txt
115
+ - spec/log/unarchive.rb
116
+ - spec/log/unarchive.txt
117
+ - spec/log/webcam_photo_taken.rb
118
+ - spec/log/webcam_photo_taken.txt
119
+ - spec/log/will_attend.rb
120
+ - spec/log/will_attend.txt
84
121
  - spec/log_spec.rb
85
- has_rdoc: true
122
+ - spec/user_spec.rb
123
+ has_rdoc: false
86
124
  homepage: http://nano.github.com/ruby-geocaching
87
125
  licenses: []
88
126
 
@@ -1,63 +0,0 @@
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