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.
Files changed (67) hide show
  1. data/README.markdown +3 -3
  2. data/lib/geocaching.rb +9 -10
  3. data/lib/geocaching/cache.rb +16 -25
  4. data/lib/geocaching/http.rb +12 -4
  5. data/lib/geocaching/log.rb +1 -12
  6. data/lib/geocaching/my_logs.rb +3 -12
  7. data/lib/geocaching/user.rb +2 -13
  8. data/lib/geocaching/version.rb +1 -1
  9. data/lib/geocaching/watchlist.rb +1 -14
  10. metadata +3 -75
  11. data/Rakefile +0 -11
  12. data/geocaching.gemspec +0 -24
  13. data/lib/geocaching/pocket_query.rb +0 -213
  14. data/spec/cache/ape.rb +0 -75
  15. data/spec/cache/cito.rb +0 -75
  16. data/spec/cache/earthcache.rb +0 -75
  17. data/spec/cache/event.rb +0 -75
  18. data/spec/cache/letterbox.rb +0 -75
  19. data/spec/cache/lfevent.rb +0 -75
  20. data/spec/cache/locationless.rb +0 -75
  21. data/spec/cache/megaevent.rb +0 -75
  22. data/spec/cache/multi.rb +0 -75
  23. data/spec/cache/mystery.rb +0 -75
  24. data/spec/cache/traditional.rb +0 -75
  25. data/spec/cache/virtual.rb +0 -75
  26. data/spec/cache/webcam.rb +0 -75
  27. data/spec/cache/wherigo.rb +0 -75
  28. data/spec/cache_spec.rb +0 -20
  29. data/spec/helper.rb +0 -16
  30. data/spec/log/announcement.rb +0 -28
  31. data/spec/log/announcement.txt +0 -14
  32. data/spec/log/archive.rb +0 -28
  33. data/spec/log/archive.txt +0 -5
  34. data/spec/log/attended.rb +0 -28
  35. data/spec/log/attended.txt +0 -1
  36. data/spec/log/coords_update.rb +0 -28
  37. data/spec/log/coords_update.txt +0 -9
  38. data/spec/log/disable.rb +0 -28
  39. data/spec/log/disable.txt +0 -5
  40. data/spec/log/dnf.rb +0 -28
  41. data/spec/log/dnf.txt +0 -5
  42. data/spec/log/enable.rb +0 -28
  43. data/spec/log/enable.txt +0 -1
  44. data/spec/log/found.rb +0 -28
  45. data/spec/log/found.txt +0 -5
  46. data/spec/log/needs_archived.rb +0 -28
  47. data/spec/log/needs_archived.txt +0 -1
  48. data/spec/log/needs_maintenance.rb +0 -28
  49. data/spec/log/needs_maintenance.txt +0 -1
  50. data/spec/log/note.rb +0 -28
  51. data/spec/log/note.txt +0 -1
  52. data/spec/log/owner_maintenance.rb +0 -28
  53. data/spec/log/owner_maintenance.txt +0 -1
  54. data/spec/log/publish.rb +0 -28
  55. data/spec/log/publish.txt +0 -1
  56. data/spec/log/retract.rb +0 -28
  57. data/spec/log/retract.txt +0 -4
  58. data/spec/log/reviewer_note.rb +0 -28
  59. data/spec/log/reviewer_note.txt +0 -3
  60. data/spec/log/unarchive.rb +0 -28
  61. data/spec/log/unarchive.txt +0 -1
  62. data/spec/log/webcam_photo_taken.rb +0 -28
  63. data/spec/log/webcam_photo_taken.txt +0 -1
  64. data/spec/log/will_attend.rb +0 -28
  65. data/spec/log/will_attend.txt +0 -1
  66. data/spec/log_spec.rb +0 -21
  67. data/spec/user_spec.rb +0 -48
@@ -58,10 +58,10 @@ Tests
58
58
  -----
59
59
 
60
60
  Tests are written using [RSpec](http://relishapp.com/rspec).
61
+ You need [Bundler](http://gembundler.com/) to run the tests.
61
62
 
62
- $ export GC_USERNAME="username"
63
- $ export GC_PASSWORD="password"
64
- $ rake test
63
+ $ bundle update
64
+ $ GC_USERNAME="username" GC_PASSWORD="password" bundle exec rake test
65
65
 
66
66
  Additional environment variables you may specify are:
67
67
 
@@ -79,14 +79,13 @@ module Geocaching
79
79
  class HTTPError < Error
80
80
  end
81
81
 
82
- autoload :HTTP, "geocaching/http"
83
- autoload :Cache, "geocaching/cache"
84
- autoload :CacheType, "geocaching/cache_type"
85
- autoload :Log, "geocaching/log"
86
- autoload :LogType, "geocaching/log_type"
87
- autoload :MyLogs, "geocaching/my_logs"
88
- autoload :User, "geocaching/user"
89
- autoload :Watchlist, "geocaching/watchlist"
90
- autoload :PocketQuery, "geocaching/pocket_query"
91
- autoload :VERSION, "geocaching/version"
82
+ autoload :Cache, "geocaching/cache"
83
+ autoload :CacheType, "geocaching/cache_type"
84
+ autoload :HTTP, "geocaching/http"
85
+ autoload :Log, "geocaching/log"
86
+ autoload :LogType, "geocaching/log_type"
87
+ autoload :MyLogs, "geocaching/my_logs"
88
+ autoload :User, "geocaching/user"
89
+ autoload :VERSION, "geocaching/version"
90
+ autoload :Watchlist, "geocaching/watchlist"
92
91
  end
@@ -21,10 +21,6 @@ module Geocaching
21
21
  # information are available without being logged in, most information
22
22
  # will only be accessible after a successful login.
23
23
  #
24
- # This class does caching. That means that multiple calls of, for example,
25
- # the {#latitude} method only do one HTTP request. To override the cached
26
- # information, call the {#fetch} method manually.
27
- #
28
24
  # == Usage
29
25
  #
30
26
  # cache = Geocaching::Cache.fetch(:code => "GCTEST")
@@ -149,7 +145,8 @@ module Geocaching
149
145
  def fetch
150
146
  raise ArgumentError, "Neither code nor GUID given" unless @code or @guid
151
147
 
152
- resp, @data = HTTP.get(path)
148
+ base_path = "/seek/cache_details.aspx?log=y&"
149
+ resp, @data = HTTP.get(base_path + (@code ? "wp=#{@code}" : "guid=#{@guid}"))
153
150
  @doc = Nokogiri::HTML.parse(@data)
154
151
  end
155
152
 
@@ -207,10 +204,10 @@ module Geocaching
207
204
  elements = @doc.search("div.CacheDetailNavigationWidget li a[href^='/seek/log.aspx']")
208
205
 
209
206
  if elements.size > 0 and elements.first["href"] =~ /ID=(\d+)/
210
- @id = $1.to_i
207
+ id = $1.to_i
211
208
  end
212
209
 
213
- @id || begin
210
+ id || begin
214
211
  raise ParseError, "Could not extract ID from website"
215
212
  end
216
213
  end
@@ -260,9 +257,10 @@ module Geocaching
260
257
  def owner
261
258
  @owner ||= begin
262
259
  raise NotFetchedError unless fetched?
260
+ elements = @doc.search("span.minorCacheDetails a[href*='/profile/?guid=']")
263
261
 
264
- if @data =~ /<strong>\s*?A[(n\s*?Event)]*\s*?cache\s*?<\/strong>\s*?by\s*?<a.*?guid=([a-f0-9-]{36}).*?>(.*?)<\/a>/
265
- @owner_display_name = HTTP.unescape($2)
262
+ if elements.size == 1 and elements.first["href"] =~ /guid=([a-f0-9-]{36})/
263
+ @owner_display_name = HTTP.unescape(elements.first.content)
266
264
  User.new(:guid => $1)
267
265
  else
268
266
  raise ParseError, "Could not extract owner from website"
@@ -284,8 +282,9 @@ module Geocaching
284
282
  def difficulty
285
283
  @difficulty ||= begin
286
284
  raise NotFetchedError unless fetched?
285
+ elements = @doc.search("#ctl00_ContentBody_uxLegendScale img")
287
286
 
288
- if @data =~ /<strong>\s*?Difficulty:<\/strong>\s*?<img.*?alt="([\d\.]{1,3}) out of 5" \/>/
287
+ if elements.size == 1 and elements.first["alt"] =~ /([\d\.]{1,3}) out of 5/
289
288
  $1.to_f
290
289
  else
291
290
  raise ParseError, "Could not extract difficulty rating from website"
@@ -299,8 +298,9 @@ module Geocaching
299
298
  def terrain
300
299
  @terrain ||= begin
301
300
  raise NotFetchedError unless fetched?
301
+ elements = @doc.search("#ctl00_ContentBody_Localize6 img")
302
302
 
303
- if @data =~ /<strong>\s+?Terrain:<\/strong>\s+?<img.*?alt="([\d\.]{1,3}) out of 5" \/>/
303
+ if elements.size == 1 and elements.first["alt"] =~ /([\d\.]{1,3}) out of 5/
304
304
  $1.to_f
305
305
  else
306
306
  raise ParseError, "Could not extract terrain rating from website"
@@ -315,7 +315,7 @@ module Geocaching
315
315
  @hidden_at ||= begin
316
316
  raise NotFetchedError unless fetched?
317
317
 
318
- if @data =~ /<strong>\s*?Hidden\s*?:\s*?<\/strong>\s*?(\d{1,2})\/(\d{1,2})\/(\d{4})/
318
+ if @data =~ /<span class="minorCacheDetails">Hidden\s*?:\s*?(\d{1,2})\/(\d{1,2})\/(\d{4})<\/span>/
319
319
  Time.mktime($3, $1, $2)
320
320
  else
321
321
  raise ParseError, "Could not extract hidden date from website"
@@ -331,7 +331,7 @@ module Geocaching
331
331
  raise NotFetchedError unless fetched?
332
332
  return nil unless [:event, :megaevent, :cito, :lfevent].include?(type.to_sym)
333
333
 
334
- if @data =~ /<strong>\s*?Event Date:\s*?<\/strong>\s*?\w+, (\d+) (\w+) (\d{4})/
334
+ if @data =~ /<span class="minorCacheDetails">\s*?Event Date:\s*?\w+, (\d+) (\w+) (\d{4})<\/span>/
335
335
  Time.parse([$1, $2, $3].join)
336
336
  else
337
337
  raise ParseError, "Could not extract event date from website"
@@ -553,9 +553,9 @@ module Geocaching
553
553
  })
554
554
  end
555
555
 
556
- # Returns a Hash representation of this class.
556
+ # Returns a hash representing this cache.
557
557
  #
558
- # @return [Hash] Hash representing this class
558
+ # @return [Hash] Hash representing this cache
559
559
  def to_hash
560
560
  hash = {
561
561
  :id => id,
@@ -578,7 +578,7 @@ module Geocaching
578
578
  :unpublished? => unpublished?
579
579
  }
580
580
 
581
- if [:event, :megaevent, :lfevent].include?(type)
581
+ if [:event, :megaevent, :lfevent, :cito].include?(type.to_sym)
582
582
  hash[:event_date] = event_date
583
583
  else
584
584
  hash[:hidden_at] = hidden_at
@@ -586,14 +586,5 @@ module Geocaching
586
586
 
587
587
  hash
588
588
  end
589
-
590
- private
591
-
592
- # Returns the HTTP request path.
593
- #
594
- # @return [String] HTTP request path
595
- def path
596
- "/seek/cache_details.aspx?log=y&" + (@code ? "wp=#{@code}" : "guid=#{@guid}")
597
- end
598
589
  end
599
590
  end
@@ -116,7 +116,7 @@ module Geocaching
116
116
  @loggedin = false
117
117
  @cookie = nil
118
118
 
119
- get("/login/default.aspx?RESET=Y")
119
+ get("/login/default.aspx?RESETCOMPLETE=Y")
120
120
  end
121
121
 
122
122
  # Returns whether you‘ve already logged in.
@@ -147,8 +147,12 @@ module Geocaching
147
147
  raise HTTPError
148
148
  end
149
149
 
150
- unless resp.kind_of?(Net::HTTPSuccess) or resp.kind_of?(Net::HTTPRedirection)
151
- raise HTTPError
150
+ unless resp.kind_of?(Net::HTTPSuccess)
151
+ if resp.kind_of?(Net::HTTPRedirection) and resp.response["location"]
152
+ resp, data = get(resp.response["location"])
153
+ else
154
+ raise HTTPError
155
+ end
152
156
  end
153
157
 
154
158
  [resp, data]
@@ -187,7 +191,11 @@ module Geocaching
187
191
  end
188
192
 
189
193
  unless resp.kind_of?(Net::HTTPSuccess)
190
- raise HTTPError
194
+ if resp.kind_of?(Net::HTTPRedirection) and resp.response["location"]
195
+ resp, data = get(resp.response["location"])
196
+ else
197
+ raise HTTPError
198
+ end
191
199
  end
192
200
 
193
201
  [resp, data]
@@ -2,10 +2,6 @@
2
2
 
3
3
  module Geocaching
4
4
  # The {Log} class represents a log on geocaching.com.
5
- #
6
- # This class does caching. That means that multiple calls of, for example,
7
- # the {#date} method only do one HTTP request. If you want to override the
8
- # cached information, call the {#fetch} method manually.
9
5
  class Log
10
6
  # Creates a new instance and calls the {#fetch} method afterwards.
11
7
  # +:guid+ must be specified as an attribute.
@@ -58,7 +54,7 @@ module Geocaching
58
54
  raise ArgumentError, "No GUID given" unless @guid
59
55
  raise LoginError unless HTTP.loggedin?
60
56
 
61
- resp, @data = HTTP.get(path)
57
+ resp, @data = HTTP.get("/seek/log.aspx?LUID=#{@guid}")
62
58
  @doc = Nokogiri::HTML.parse(@data)
63
59
  end
64
60
 
@@ -212,12 +208,5 @@ module Geocaching
212
208
  info
213
209
  end
214
210
  end
215
-
216
- # Returns the HTTP request path.
217
- #
218
- # @return [String] HTTP request path
219
- def path
220
- "/seek/log.aspx?LUID=#{@guid}"
221
- end
222
211
  end
223
212
  end
@@ -4,13 +4,11 @@ module Geocaching
4
4
  # The {MyLogs} class provides access to the logs the user
5
5
  # you’re logged in with has written.
6
6
  #
7
- # This class does caching. If you want to override the cached information,
8
- # call the {#fetch} method manually.
9
- #
10
7
  # == Usage
11
8
  #
12
9
  # mylogs = Geocaching::MyLogs.fetch
13
- # puts "I've written #{mylogs.size} logs."
10
+ # puts "I've written #{mylogs.logs.size} logs."
11
+ #
14
12
  class MyLogs
15
13
  # Creates a new instance and calls {#fetch} afterwards.
16
14
  #
@@ -27,7 +25,7 @@ module Geocaching
27
25
  def fetch
28
26
  raise LoginError unless HTTP.loggedin?
29
27
 
30
- resp, @data = HTTP.get(path)
28
+ resp, @data = HTTP.get("/my/logs.aspx?s=1")
31
29
  @doc = Nokogiri::HTML.parse(@data)
32
30
  end
33
31
 
@@ -72,13 +70,6 @@ module Geocaching
72
70
 
73
71
  private
74
72
 
75
- # Returns the HTTP request path.
76
- #
77
- # @return [String] HTTP request path
78
- def path
79
- "/my/logs.aspx?s=1"
80
- end
81
-
82
73
  # Extracts information from a HTML table row node.
83
74
  #
84
75
  # @return [Hash] Extracted information
@@ -5,13 +5,11 @@ require "time"
5
5
  module Geocaching
6
6
  # The {User} class represents a user on geocaching.com.
7
7
  #
8
- # This class does caching. If you want to override the cached information,
9
- # call the {#fetch} method manually.
10
- #
11
8
  # == Usage
12
9
  #
13
10
  # user = Geocaching::User.fetch(:guid => "...")
14
11
  # puts user.name #=> "Jack"
12
+ #
15
13
  class User
16
14
  # Creates a new instance and calls the {fetch} method afterwards.
17
15
  # +:guid+ must be given as an attribute.
@@ -52,7 +50,7 @@ module Geocaching
52
50
  def fetch
53
51
  raise ArgumentError, "No GUID given" unless @guid
54
52
 
55
- resp, @data = HTTP.get(path)
53
+ resp, @data = HTTP.get("/profile/?guid=#{guid}")
56
54
  @doc = Nokogiri::HTML.parse(@data)
57
55
  end
58
56
 
@@ -215,14 +213,5 @@ module Geocaching
215
213
  def premium_member?
216
214
  status.include?("Premium Member")
217
215
  end
218
-
219
- private
220
-
221
- # Returns the HTTP request path.
222
- #
223
- # @return [String] HTTP request path
224
- def path
225
- "/profile/?guid=#{guid}"
226
- end
227
216
  end
228
217
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Geocaching
4
- VERSION = "0.6.0"
4
+ VERSION = "0.6.1"
5
5
  end
@@ -2,12 +2,6 @@
2
2
 
3
3
  module Geocaching
4
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
5
  class Watchlist
12
6
  # Creates a new instance of this class and calls the {#caches} method.
13
7
  #
@@ -47,7 +41,7 @@ module Geocaching
47
41
  raise LoginError, "You need to be logged in to access your watchlist"
48
42
  end
49
43
 
50
- resp, @data = HTTP.get(path)
44
+ resp, @data = HTTP.get("/my/watchlist.aspx")
51
45
  @doc = Nokogiri::HTML.parse(@data)
52
46
  end
53
47
 
@@ -61,13 +55,6 @@ module Geocaching
61
55
 
62
56
  private
63
57
 
64
- # Returns the HTTP request path.
65
- #
66
- # @return [String] HTTP request path
67
- def path
68
- "/my/watchlist.aspx"
69
- end
70
-
71
58
  # Returns the information from a HTML table row node.
72
59
  #
73
60
  # @return [Hash] Extracted information
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 6
8
- - 0
9
- version: 0.6.0
8
+ - 1
9
+ version: 0.6.1
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-11-28 00:00:00 +01:00
17
+ date: 2011-02-02 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -47,21 +47,6 @@ dependencies:
47
47
  version: 1.4.6
48
48
  type: :runtime
49
49
  version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- name: rspec
52
- prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
54
- none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- segments:
59
- - 2
60
- - 0
61
- - 0
62
- version: 2.0.0
63
- type: :development
64
- version_requirements: *id003
65
50
  description: A Ruby library that provides an API for geocaching.com
66
51
  email: thomas@thcyron.de
67
52
  executables: []
@@ -72,73 +57,16 @@ extra_rdoc_files: []
72
57
 
73
58
  files:
74
59
  - README.markdown
75
- - Rakefile
76
- - geocaching.gemspec
77
60
  - lib/geocaching/cache.rb
78
61
  - lib/geocaching/cache_type.rb
79
62
  - lib/geocaching/http.rb
80
63
  - lib/geocaching/log.rb
81
64
  - lib/geocaching/log_type.rb
82
65
  - lib/geocaching/my_logs.rb
83
- - lib/geocaching/pocket_query.rb
84
66
  - lib/geocaching/user.rb
85
67
  - lib/geocaching/version.rb
86
68
  - lib/geocaching/watchlist.rb
87
69
  - lib/geocaching.rb
88
- - spec/cache/ape.rb
89
- - spec/cache/cito.rb
90
- - spec/cache/earthcache.rb
91
- - spec/cache/event.rb
92
- - spec/cache/letterbox.rb
93
- - spec/cache/lfevent.rb
94
- - spec/cache/locationless.rb
95
- - spec/cache/megaevent.rb
96
- - spec/cache/multi.rb
97
- - spec/cache/mystery.rb
98
- - spec/cache/traditional.rb
99
- - spec/cache/virtual.rb
100
- - spec/cache/webcam.rb
101
- - spec/cache/wherigo.rb
102
- - spec/cache_spec.rb
103
- - spec/helper.rb
104
- - spec/log/announcement.rb
105
- - spec/log/announcement.txt
106
- - spec/log/archive.rb
107
- - spec/log/archive.txt
108
- - spec/log/attended.rb
109
- - spec/log/attended.txt
110
- - spec/log/coords_update.rb
111
- - spec/log/coords_update.txt
112
- - spec/log/disable.rb
113
- - spec/log/disable.txt
114
- - spec/log/dnf.rb
115
- - spec/log/dnf.txt
116
- - spec/log/enable.rb
117
- - spec/log/enable.txt
118
- - spec/log/found.rb
119
- - spec/log/found.txt
120
- - spec/log/needs_archived.rb
121
- - spec/log/needs_archived.txt
122
- - spec/log/needs_maintenance.rb
123
- - spec/log/needs_maintenance.txt
124
- - spec/log/note.rb
125
- - spec/log/note.txt
126
- - spec/log/owner_maintenance.rb
127
- - spec/log/owner_maintenance.txt
128
- - spec/log/publish.rb
129
- - spec/log/publish.txt
130
- - spec/log/retract.rb
131
- - spec/log/retract.txt
132
- - spec/log/reviewer_note.rb
133
- - spec/log/reviewer_note.txt
134
- - spec/log/unarchive.rb
135
- - spec/log/unarchive.txt
136
- - spec/log/webcam_photo_taken.rb
137
- - spec/log/webcam_photo_taken.txt
138
- - spec/log/will_attend.rb
139
- - spec/log/will_attend.txt
140
- - spec/log_spec.rb
141
- - spec/user_spec.rb
142
70
  has_rdoc: false
143
71
  homepage: http://nano.github.com/ruby-geocaching
144
72
  licenses: []