geocaching 0.7.0 → 0.7.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 +1 -1
- data/lib/geocaching/cache.rb +3 -0
- data/lib/geocaching/cache_attribute.rb +29 -0
- data/lib/geocaching/errors.rb +12 -0
- data/lib/geocaching/parsers/cache_attribute.rb +25 -0
- data/lib/geocaching/parsers/cache_gpx.rb +0 -3
- data/lib/geocaching/parsers/cache_simple.rb +0 -3
- data/lib/geocaching/parsers/log.rb +0 -3
- data/lib/geocaching/parsers/trackable.rb +0 -3
- data/lib/geocaching/session/attributes.rb +17 -0
- data/lib/geocaching/session/caches.rb +17 -0
- data/lib/geocaching/session.rb +1 -0
- data/lib/geocaching.rb +4 -1
- metadata +4 -1
data/README.markdown
CHANGED
@@ -5,7 +5,7 @@ Ruby API for Geocaching.com
|
|
5
5
|
It doesn’t scrape their website but rather uses the same API the
|
6
6
|
iPhone and Android geocaching apps use.
|
7
7
|
|
8
|
-
See the [website](
|
8
|
+
See the [website](http://nano.github.com/ruby-geocaching) for more information.
|
9
9
|
|
10
10
|
|
11
11
|
Tests
|
data/lib/geocaching/cache.rb
CHANGED
@@ -26,6 +26,7 @@ module Geocaching
|
|
26
26
|
attr_accessor :long_description
|
27
27
|
attr_accessor :hint
|
28
28
|
attr_accessor :waypoints
|
29
|
+
attr_accessor :attributes
|
29
30
|
|
30
31
|
def self.from_xml(doc)
|
31
32
|
Parsers::CacheSimple.new(doc).parse
|
@@ -37,6 +38,7 @@ module Geocaching
|
|
37
38
|
|
38
39
|
def initialize(attributes = {})
|
39
40
|
@waypoints = []
|
41
|
+
@attributes = []
|
40
42
|
|
41
43
|
attributes.each do |key, value|
|
42
44
|
if respond_to?("#{key}=")
|
@@ -103,6 +105,7 @@ module Geocaching
|
|
103
105
|
:is_archived => is_archived,
|
104
106
|
:is_premium => is_premium,
|
105
107
|
:waypoints => waypoints,
|
108
|
+
:attributes => attributes,
|
106
109
|
:short_description => short_description,
|
107
110
|
:long_description => long_description,
|
108
111
|
:hint => hint
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "geocaching/parsers/cache_attribute"
|
4
|
+
|
5
|
+
module Geocaching
|
6
|
+
class CacheAttribute
|
7
|
+
attr_accessor :name
|
8
|
+
|
9
|
+
def self.from_xml(doc)
|
10
|
+
Parsers::CacheAttribute.new(doc).parse
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(attributes = {})
|
14
|
+
attributes.each do |key, value|
|
15
|
+
if respond_to?("#{key}=")
|
16
|
+
send("#{key}=", value)
|
17
|
+
else
|
18
|
+
raise ArgumentError, "Unknown attribute `#{key}'"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
alias :to_s :name
|
24
|
+
|
25
|
+
def ==(name)
|
26
|
+
@name == name
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/geocaching/errors.rb
CHANGED
@@ -4,4 +4,16 @@ module Geocaching
|
|
4
4
|
class Error < Exception; end
|
5
5
|
class HTTPError < Error; end
|
6
6
|
class ParseError < Error; end
|
7
|
+
|
8
|
+
class GeocacheNotPublished < Error
|
9
|
+
def initialize
|
10
|
+
super "The geocache hasn't been published yet"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class GeocacheNotAvailable < Error
|
15
|
+
def initialize
|
16
|
+
super "The geocache is currently unavailable for viewing"
|
17
|
+
end
|
18
|
+
end
|
7
19
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Geocaching
|
4
|
+
module Parsers
|
5
|
+
class CacheAttribute
|
6
|
+
def initialize(doc)
|
7
|
+
@doc = doc
|
8
|
+
end
|
9
|
+
|
10
|
+
def parse
|
11
|
+
attributes = []
|
12
|
+
|
13
|
+
@doc.xpath("//xmlns:AttributeSimpleDataSet/xmlns:Attribute").each do |attribute_node|
|
14
|
+
if node = attribute_node.xpath("./xmlns:Name").first
|
15
|
+
attributes << Geocaching::CacheAttribute.new(:name => node.text)
|
16
|
+
else
|
17
|
+
raise ParseError, "Could not parse cache attribute from XML"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
attributes
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Geocaching
|
4
|
+
class Session
|
5
|
+
module Attributes
|
6
|
+
def get_attributes_for_cache_by_cache_code(cache_code)
|
7
|
+
response = request("GetAttributesByWptCode", {
|
8
|
+
"sessionToken" => session_token,
|
9
|
+
"wptCode" => cache_code,
|
10
|
+
"schemaName" => "AttributeSimpleDataSet.xsd"
|
11
|
+
})
|
12
|
+
|
13
|
+
CacheAttribute.from_xml(response.doc)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -19,6 +19,13 @@ module Geocaching
|
|
19
19
|
"cacheCode" => code
|
20
20
|
})
|
21
21
|
|
22
|
+
case response.status
|
23
|
+
when "GeocacheNotAvailable"
|
24
|
+
raise GeocacheNotAvailable
|
25
|
+
when "GeocacheNotPublished"
|
26
|
+
raise GeocacheNotPublished
|
27
|
+
end
|
28
|
+
|
22
29
|
case schema
|
23
30
|
when "CacheSimpleDataSet.xsd"
|
24
31
|
caches = Cache.from_xml(response.doc)
|
@@ -56,6 +63,16 @@ module Geocaching
|
|
56
63
|
|
57
64
|
Cache.from_xml(response.doc)
|
58
65
|
end
|
66
|
+
|
67
|
+
def get_attributes_for_cache_by_cache_code(cache_code)
|
68
|
+
response = request("GetAttributesByWptCode", {
|
69
|
+
"sessionToken" => session_token,
|
70
|
+
"wptCode" => cache_code,
|
71
|
+
"schemaName" => "AttributeSimpleDataSet.xsd"
|
72
|
+
})
|
73
|
+
|
74
|
+
CacheAttribute.from_xml(response.doc)
|
75
|
+
end
|
59
76
|
end
|
60
77
|
end
|
61
78
|
end
|
data/lib/geocaching/session.rb
CHANGED
data/lib/geocaching.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
+
require "time"
|
4
|
+
|
3
5
|
require "geocaching/cache"
|
6
|
+
require "geocaching/cache_attribute"
|
4
7
|
require "geocaching/cache_type"
|
5
8
|
require "geocaching/container_type"
|
6
9
|
require "geocaching/errors"
|
@@ -14,5 +17,5 @@ require "geocaching/waypoint"
|
|
14
17
|
require "geocaching/waypoint_type"
|
15
18
|
|
16
19
|
module Geocaching
|
17
|
-
VERSION = "0.7.
|
20
|
+
VERSION = "0.7.1"
|
18
21
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: geocaching
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.7.
|
5
|
+
version: 0.7.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Thomas Cyron
|
@@ -46,17 +46,20 @@ extra_rdoc_files: []
|
|
46
46
|
files:
|
47
47
|
- README.markdown
|
48
48
|
- lib/geocaching/cache.rb
|
49
|
+
- lib/geocaching/cache_attribute.rb
|
49
50
|
- lib/geocaching/cache_type.rb
|
50
51
|
- lib/geocaching/container_type.rb
|
51
52
|
- lib/geocaching/errors.rb
|
52
53
|
- lib/geocaching/log.rb
|
53
54
|
- lib/geocaching/log_type.rb
|
55
|
+
- lib/geocaching/parsers/cache_attribute.rb
|
54
56
|
- lib/geocaching/parsers/cache_gpx.rb
|
55
57
|
- lib/geocaching/parsers/cache_gpx_additional_waypoint.rb
|
56
58
|
- lib/geocaching/parsers/cache_gpx_cache_waypoint.rb
|
57
59
|
- lib/geocaching/parsers/cache_simple.rb
|
58
60
|
- lib/geocaching/parsers/log.rb
|
59
61
|
- lib/geocaching/parsers/trackable.rb
|
62
|
+
- lib/geocaching/session/attributes.rb
|
60
63
|
- lib/geocaching/session/caches.rb
|
61
64
|
- lib/geocaching/session/logs.rb
|
62
65
|
- lib/geocaching/session/trackables.rb
|