geocaching 0.7.1 → 0.8.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.
- data/lib/geocaching/cache.rb +4 -4
- data/lib/geocaching/cache_attribute.rb +2 -2
- data/lib/geocaching/log.rb +2 -2
- data/lib/geocaching/parsers/{cache_attribute.rb → cache_attribute_parser.rb} +1 -1
- data/lib/geocaching/parsers/cache_gpx_parser.rb +30 -0
- data/lib/geocaching/parsers/{cache_simple.rb → cache_simple_parser.rb} +4 -19
- data/lib/geocaching/parsers/{cache_gpx_additional_waypoint.rb → gpx_additional_waypoint_parser.rb} +3 -5
- data/lib/geocaching/parsers/{cache_gpx_cache_waypoint.rb → gpx_cache_parser.rb} +8 -69
- data/lib/geocaching/parsers/gpx_cache_waypoint_parser.rb +84 -0
- data/lib/geocaching/parsers/{log.rb → log_parser.rb} +1 -1
- data/lib/geocaching/parsers/pocket_query_data_set_parser.rb +88 -0
- data/lib/geocaching/parsers/pocket_query_parser.rb +94 -0
- data/lib/geocaching/parsers/{trackable.rb → trackable_parser.rb} +1 -1
- data/lib/geocaching/pocket_query.rb +50 -0
- data/lib/geocaching/session/pocket_queries.rb +32 -0
- data/lib/geocaching/session.rb +2 -0
- data/lib/geocaching/trackable.rb +2 -2
- data/lib/geocaching.rb +2 -1
- metadata +14 -9
- data/lib/geocaching/parsers/cache_gpx.rb +0 -39
data/lib/geocaching/cache.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require "geocaching/parsers/
|
4
|
-
require "geocaching/parsers/
|
3
|
+
require "geocaching/parsers/cache_simple_parser"
|
4
|
+
require "geocaching/parsers/cache_gpx_parser"
|
5
5
|
|
6
6
|
module Geocaching
|
7
7
|
class Cache
|
@@ -29,11 +29,11 @@ module Geocaching
|
|
29
29
|
attr_accessor :attributes
|
30
30
|
|
31
31
|
def self.from_xml(doc)
|
32
|
-
Parsers::
|
32
|
+
Parsers::CacheSimpleParser.new(doc).parse
|
33
33
|
end
|
34
34
|
|
35
35
|
def self.from_gpx(doc)
|
36
|
-
Parsers::
|
36
|
+
Parsers::CacheGPXParser.new(doc).parse
|
37
37
|
end
|
38
38
|
|
39
39
|
def initialize(attributes = {})
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require "geocaching/parsers/
|
3
|
+
require "geocaching/parsers/cache_attribute_parser"
|
4
4
|
|
5
5
|
module Geocaching
|
6
6
|
class CacheAttribute
|
7
7
|
attr_accessor :name
|
8
8
|
|
9
9
|
def self.from_xml(doc)
|
10
|
-
Parsers::
|
10
|
+
Parsers::CacheAttributeParser.new(doc).parse
|
11
11
|
end
|
12
12
|
|
13
13
|
def initialize(attributes = {})
|
data/lib/geocaching/log.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require "geocaching/parsers/
|
3
|
+
require "geocaching/parsers/log_parser"
|
4
4
|
|
5
5
|
module Geocaching
|
6
6
|
class Log
|
@@ -13,7 +13,7 @@ module Geocaching
|
|
13
13
|
attr_reader :type
|
14
14
|
|
15
15
|
def self.from_xml(doc)
|
16
|
-
Parsers::
|
16
|
+
Parsers::LogParser.new(doc).parse
|
17
17
|
end
|
18
18
|
|
19
19
|
def initialize(attributes = {})
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "geocaching/parsers/gpx_cache_waypoint_parser"
|
4
|
+
require "geocaching/parsers/gpx_additional_waypoint_parser"
|
5
|
+
|
6
|
+
module Geocaching
|
7
|
+
module Parsers
|
8
|
+
class CacheGPXParser
|
9
|
+
def initialize(doc)
|
10
|
+
@doc = doc
|
11
|
+
end
|
12
|
+
|
13
|
+
def parse
|
14
|
+
cache = nil
|
15
|
+
is_first_wpt = true
|
16
|
+
|
17
|
+
@doc.xpath("//xmlns:gpx/xmlns:wpt").each do |wpt_node|
|
18
|
+
if is_first_wpt
|
19
|
+
cache = GPXCacheWaypointParser.new(wpt_node).parse
|
20
|
+
is_first_wpt = false
|
21
|
+
else
|
22
|
+
cache.waypoints << GPXAdditionalWaypointParser.new(wpt_node).parse
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
cache
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -2,10 +2,7 @@
|
|
2
2
|
|
3
3
|
module Geocaching
|
4
4
|
module Parsers
|
5
|
-
class
|
6
|
-
CACHE_CODE_REGEXP = /^GC[A-Z0-9]+$/
|
7
|
-
COORDINATE_REGEXP = /^-?[0-9]{1,3}\.[0-9]{1,}$/
|
8
|
-
|
5
|
+
class CacheSimpleParser
|
9
6
|
def initialize(doc)
|
10
7
|
@doc = doc
|
11
8
|
end
|
@@ -33,11 +30,7 @@ module Geocaching
|
|
33
30
|
|
34
31
|
def parse_code(cache_node)
|
35
32
|
if node = cache_node.xpath("./xmlns:CacheCode").first
|
36
|
-
|
37
|
-
node.text
|
38
|
-
else
|
39
|
-
raise ParseError, "Got an invalid value for cache code from API"
|
40
|
-
end
|
33
|
+
node.text
|
41
34
|
else
|
42
35
|
raise ParseError, "Could not parse cache code from XML"
|
43
36
|
end
|
@@ -53,11 +46,7 @@ module Geocaching
|
|
53
46
|
|
54
47
|
def parse_latitude(cache_node)
|
55
48
|
if node = cache_node.xpath("./xmlns:Latitude").first
|
56
|
-
|
57
|
-
node.text.to_f
|
58
|
-
else
|
59
|
-
raise ParseError, "Got a non-numeric value for latitude from API"
|
60
|
-
end
|
49
|
+
node.text.to_f
|
61
50
|
else
|
62
51
|
raise ParseError, "Could not parse latitude from XML"
|
63
52
|
end
|
@@ -65,11 +54,7 @@ module Geocaching
|
|
65
54
|
|
66
55
|
def parse_longitude(cache_node)
|
67
56
|
if node = cache_node.xpath("./xmlns:Longitude").first
|
68
|
-
|
69
|
-
node.text.to_f
|
70
|
-
else
|
71
|
-
raise ParseError, "Got a non-numeric value for longitude from API"
|
72
|
-
end
|
57
|
+
node.text.to_f
|
73
58
|
else
|
74
59
|
raise ParseError, "Could not parse longitude from XML"
|
75
60
|
end
|
data/lib/geocaching/parsers/{cache_gpx_additional_waypoint.rb → gpx_additional_waypoint_parser.rb}
RENAMED
@@ -2,9 +2,7 @@
|
|
2
2
|
|
3
3
|
module Geocaching
|
4
4
|
module Parsers
|
5
|
-
class
|
6
|
-
COORDINATE_REGEXP = /^-?[0-9]{1,3}\.[0-9]{1,}$/
|
7
|
-
|
5
|
+
class GPXAdditionalWaypointParser
|
8
6
|
def initialize(wpt_node)
|
9
7
|
@wpt_node = wpt_node
|
10
8
|
end
|
@@ -33,7 +31,7 @@ module Geocaching
|
|
33
31
|
end
|
34
32
|
|
35
33
|
def parse_latitude(wpt_node)
|
36
|
-
if wpt_node["lat"]
|
34
|
+
if wpt_node["lat"]
|
37
35
|
wpt_node["lat"].to_f
|
38
36
|
else
|
39
37
|
raise ParseError, "Invalid waypoint latitude in GPX"
|
@@ -41,7 +39,7 @@ module Geocaching
|
|
41
39
|
end
|
42
40
|
|
43
41
|
def parse_longitude(wpt_node)
|
44
|
-
if wpt_node["lon"]
|
42
|
+
if wpt_node["lon"]
|
45
43
|
wpt_node["lon"].to_f
|
46
44
|
else
|
47
45
|
raise ParseError, "Invalid waypoint longitude in GPX"
|
@@ -2,35 +2,19 @@
|
|
2
2
|
|
3
3
|
module Geocaching
|
4
4
|
module Parsers
|
5
|
-
class
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
WPT_NODE_ATTRIBUTES = %w(guid code latitude longitude hidden_at)
|
10
|
-
|
11
|
-
def initialize(wpt_node)
|
12
|
-
@wpt_node = wpt_node
|
5
|
+
class GPXCacheParser
|
6
|
+
def initialize(cache_node)
|
7
|
+
@cache_node = cache_node
|
13
8
|
end
|
14
9
|
|
15
10
|
def parse
|
16
11
|
cache = Cache.new
|
17
12
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
if cache_node = @wpt_node.xpath("./gpx:extensions/cache:cache", ns).first
|
24
|
-
private_methods.each do |method|
|
25
|
-
if method.to_s =~ /^parse_([a-z_]+)$/
|
26
|
-
unless WPT_NODE_ATTRIBUTES.include?($1)
|
27
|
-
value = send(method, cache_node)
|
28
|
-
cache.send("#{$1}=", value) unless value.nil?
|
29
|
-
end
|
30
|
-
end
|
13
|
+
private_methods.each do |method|
|
14
|
+
if method.to_s =~ /^parse_([a-z_]+)$/
|
15
|
+
value = send(method, @cache_node)
|
16
|
+
cache.send("#{$1}=", value) unless value.nil?
|
31
17
|
end
|
32
|
-
else
|
33
|
-
raise ParseError, "Could not parse GPX"
|
34
18
|
end
|
35
19
|
|
36
20
|
cache
|
@@ -38,51 +22,6 @@ module Geocaching
|
|
38
22
|
|
39
23
|
private
|
40
24
|
|
41
|
-
def parse_code(wpt_node)
|
42
|
-
if node = wpt_node.xpath("./gpx:name", ns).first
|
43
|
-
node.text
|
44
|
-
else
|
45
|
-
raise ParseError, "Could not parse cache code from GPX"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def parse_guid(wpt_node)
|
50
|
-
if node = wpt_node.xpath("./gpx:link", ns).first and node["href"] =~ /guid=([a-f0-9-]{36})/
|
51
|
-
$1
|
52
|
-
else
|
53
|
-
raise ParseError, "Could not parse cache GUID from GPX"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def parse_latitude(wpt_node)
|
58
|
-
if wpt_node["lat"] =~ COORDINATE_REGEXP
|
59
|
-
wpt_node["lat"].to_f
|
60
|
-
else
|
61
|
-
raise ParseError, "Invalid latitude in GPX"
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def parse_longitude(wpt_node)
|
66
|
-
if wpt_node["lon"] =~ COORDINATE_REGEXP
|
67
|
-
wpt_node["lon"].to_f
|
68
|
-
else
|
69
|
-
raise ParseError, "Invalid longitude in GPX"
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def parse_hidden_at(wpt_node)
|
74
|
-
if node = wpt_node.xpath("./gpx:time", ns).first
|
75
|
-
begin
|
76
|
-
time = Time.parse(node.text)
|
77
|
-
Time.mktime(time.year, time.month, time.day)
|
78
|
-
rescue ArgumentError
|
79
|
-
raise ParseError, "Invalid hidden date in GPX"
|
80
|
-
end
|
81
|
-
else
|
82
|
-
raise ParseError, "Could not parse hidden date from GPX"
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
25
|
def parse_name(cache_node)
|
87
26
|
if node = cache_node.xpath("./cache:name", ns).first
|
88
27
|
node.text
|
@@ -225,7 +164,7 @@ module Geocaching
|
|
225
164
|
|
226
165
|
def ns
|
227
166
|
{
|
228
|
-
"gpx" => "http://www.topografix.com/GPX/1/
|
167
|
+
"gpx" => "http://www.topografix.com/GPX/1/0",
|
229
168
|
"cache" => "http://www.groundspeak.com/cache/1/0"
|
230
169
|
}
|
231
170
|
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "geocaching/parsers/gpx_cache_parser"
|
4
|
+
|
5
|
+
module Geocaching
|
6
|
+
module Parsers
|
7
|
+
class GPXCacheWaypointParser
|
8
|
+
def initialize(wpt_node)
|
9
|
+
@wpt_node = wpt_node
|
10
|
+
end
|
11
|
+
|
12
|
+
def parse
|
13
|
+
cache = Cache.new
|
14
|
+
|
15
|
+
if cache_node = @wpt_node.xpath("./gpx:extensions/cache:cache", ns).first
|
16
|
+
cache = GPXCacheParser.new(cache_node).parse
|
17
|
+
else
|
18
|
+
cache = Cache.new
|
19
|
+
end
|
20
|
+
|
21
|
+
%w(guid code latitude longitude hidden_at).each do |attribute|
|
22
|
+
value = send("parse_#{attribute}", @wpt_node)
|
23
|
+
cache.send("#{attribute}=", value) unless value.nil?
|
24
|
+
end
|
25
|
+
|
26
|
+
cache
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def parse_code(wpt_node)
|
32
|
+
if node = wpt_node.xpath("./gpx:name", ns).first
|
33
|
+
node.text
|
34
|
+
else
|
35
|
+
raise ParseError, "Could not parse cache code from GPX"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def parse_guid(wpt_node)
|
40
|
+
if node = wpt_node.xpath("./gpx:link", ns).first and node["href"] =~ /guid=([a-f0-9-]{36})/
|
41
|
+
$1
|
42
|
+
else
|
43
|
+
raise ParseError, "Could not parse cache GUID from GPX"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def parse_latitude(wpt_node)
|
48
|
+
if wpt_node["lat"]
|
49
|
+
wpt_node["lat"].to_f
|
50
|
+
else
|
51
|
+
raise ParseError, "Could not parse latitude from GPX"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def parse_longitude(wpt_node)
|
56
|
+
if wpt_node["lon"]
|
57
|
+
wpt_node["lon"].to_f
|
58
|
+
else
|
59
|
+
raise ParseError, "Could not parse longitude from GPX"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def parse_hidden_at(wpt_node)
|
64
|
+
if node = wpt_node.xpath("./gpx:time", ns).first
|
65
|
+
begin
|
66
|
+
time = Time.parse(node.text)
|
67
|
+
Time.mktime(time.year, time.month, time.day)
|
68
|
+
rescue ArgumentError
|
69
|
+
raise ParseError, "Invalid hidden date in GPX"
|
70
|
+
end
|
71
|
+
else
|
72
|
+
raise ParseError, "Could not parse hidden date from GPX"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def ns
|
77
|
+
{
|
78
|
+
"gpx" => "http://www.topografix.com/GPX/1/1",
|
79
|
+
"cache" => "http://www.groundspeak.com/cache/1/0"
|
80
|
+
}
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Geocaching
|
4
|
+
module Parsers
|
5
|
+
class PocketQueryDataSetParser
|
6
|
+
def initialize(doc)
|
7
|
+
@doc = doc
|
8
|
+
end
|
9
|
+
|
10
|
+
def parse
|
11
|
+
pocket_queries = []
|
12
|
+
|
13
|
+
@doc.xpath("//xmlns:PocketQueryDataSet/xmlns:PocketQuery").each do |pocket_query_node|
|
14
|
+
pocket_query = PocketQuery.new
|
15
|
+
|
16
|
+
private_methods.each do |method|
|
17
|
+
if method.to_s =~ /^parse_([a-z_]+)$/
|
18
|
+
value = send(method, pocket_query_node)
|
19
|
+
pocket_query.send("#{$1}=", value) unless value.nil?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
pocket_queries << pocket_query
|
24
|
+
end
|
25
|
+
|
26
|
+
pocket_queries
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def parse_guid(pocket_query_node)
|
32
|
+
if node = pocket_query_node.xpath("./xmlns:PQGuid").first
|
33
|
+
node.text
|
34
|
+
else
|
35
|
+
raise ParseError, "Could not parse Pocket Query GUID"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def parse_name(pocket_query_node)
|
40
|
+
if node = pocket_query_node.xpath("./xmlns:Name").first
|
41
|
+
node.text
|
42
|
+
else
|
43
|
+
raise ParseError, "Could not parse Pocket Query name"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def parse_generated_at(pocket_query_node)
|
48
|
+
if node = pocket_query_node.xpath("./xmlns:LastGenerated").first
|
49
|
+
begin
|
50
|
+
Time.parse(node.text)
|
51
|
+
rescue ArgumentError
|
52
|
+
raise ParseError, "Invalid Pocket Query generation date"
|
53
|
+
end
|
54
|
+
else
|
55
|
+
raise ParseError, "Could not parse Pocket Query generation date"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def parse_is_download_available(pocket_query_node)
|
60
|
+
if node = pocket_query_node.xpath("./xmlns:DownloadAvailable").first
|
61
|
+
if %w(true false).include?(node.text)
|
62
|
+
node.text == "true"
|
63
|
+
else
|
64
|
+
raise ParseError, "Invalid Pocket Query download availability"
|
65
|
+
end
|
66
|
+
else
|
67
|
+
raise ParseError, "Could not parse Pocket Query download availability"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def parse_filesize(pocket_query_node)
|
72
|
+
if node = pocket_query_node.xpath("./xmlns:FileSizeInBytes").first
|
73
|
+
node.text.to_i unless node.text.to_i == -1
|
74
|
+
else
|
75
|
+
raise ParseError, "Could not parse Pocket Query file size"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def parse_results_count(pocket_query_node)
|
80
|
+
if node = pocket_query_node.xpath("./xmlns:LastRunCount").first
|
81
|
+
node.text.to_i unless node.text.to_i == -1
|
82
|
+
else
|
83
|
+
raise ParseError, "Could not parse Pocket Query results count"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "geocaching/parsers/gpx_cache_parser"
|
4
|
+
|
5
|
+
module Geocaching
|
6
|
+
module Parsers
|
7
|
+
class PocketQueryParser
|
8
|
+
def initialize(xml)
|
9
|
+
@doc = Nokogiri::XML.parse(xml)
|
10
|
+
rescue
|
11
|
+
raise ParseError, "Could not parse Pocket Query XML"
|
12
|
+
end
|
13
|
+
|
14
|
+
def parse
|
15
|
+
pocket_query = PocketQuery.new
|
16
|
+
|
17
|
+
pocket_query.name = parse_name(@doc)
|
18
|
+
pocket_query.generated_at = parse_generated_at(@doc)
|
19
|
+
|
20
|
+
@doc.xpath("//gpx:gpx/gpx:wpt", ns).each do |wpt_node|
|
21
|
+
cache = nil
|
22
|
+
|
23
|
+
if cache_node = wpt_node.xpath("./cache:cache", ns).first
|
24
|
+
cache = GPXCacheParser.new(cache_node).parse
|
25
|
+
else
|
26
|
+
cache = Cache.new
|
27
|
+
end
|
28
|
+
|
29
|
+
%w(latitude longitude code).each do |attribute|
|
30
|
+
value = send("parse_#{attribute}", wpt_node)
|
31
|
+
cache.send("#{attribute}=", value) unless value.nil?
|
32
|
+
end
|
33
|
+
|
34
|
+
pocket_query.caches << cache
|
35
|
+
end
|
36
|
+
|
37
|
+
pocket_query
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def parse_name(doc)
|
43
|
+
if node = doc.xpath("//gpx:name", ns).first
|
44
|
+
node.text
|
45
|
+
else
|
46
|
+
raise ParseError, "Could not parse Pocket Query name from XML"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def parse_generated_at(doc)
|
51
|
+
if node = doc.xpath("//gpx:time", ns).first
|
52
|
+
begin
|
53
|
+
Time.parse(node.text)
|
54
|
+
rescue ArgumentError
|
55
|
+
raise ParseError, "Invalid generation date in Pocket Query XML"
|
56
|
+
end
|
57
|
+
else
|
58
|
+
raise ParseError, "Could not parse Pocket Query generation date from XML"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def parse_code(wpt_node)
|
63
|
+
if node = wpt_node.xpath("./gpx:name", ns).first
|
64
|
+
node.text
|
65
|
+
else
|
66
|
+
raise ParseError, "Could not parse cache code from Pocket Query XML"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def parse_latitude(wpt_node)
|
71
|
+
if wpt_node["lat"]
|
72
|
+
wpt_node["lat"].to_f
|
73
|
+
else
|
74
|
+
raise ParseError, "Invalid latitude in GPX"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def parse_longitude(wpt_node)
|
79
|
+
if wpt_node["lon"]
|
80
|
+
wpt_node["lon"].to_f
|
81
|
+
else
|
82
|
+
raise ParseError, "Invalid longitude in GPX"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def ns
|
87
|
+
{
|
88
|
+
"gpx" => "http://www.topografix.com/GPX/1/0",
|
89
|
+
"cache" => "http://www.groundspeak.com/cache/1/0"
|
90
|
+
}
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "geocaching/parsers/pocket_query_parser"
|
4
|
+
require "geocaching/parsers/pocket_query_data_set_parser"
|
5
|
+
|
6
|
+
module Geocaching
|
7
|
+
class PocketQuery
|
8
|
+
attr_accessor :guid
|
9
|
+
attr_accessor :name
|
10
|
+
attr_accessor :caches
|
11
|
+
attr_reader :generated_at
|
12
|
+
attr_accessor :is_download_available
|
13
|
+
attr_accessor :filesize
|
14
|
+
attr_accessor :results_count
|
15
|
+
|
16
|
+
def self.from_file(file)
|
17
|
+
from_gpx(File.read(file))
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.from_gpx(xml)
|
21
|
+
Parsers::PocketQueryParser.new(xml).parse
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.from_xml(doc)
|
25
|
+
Parsers::PocketQueryDataSetParser.new(doc).parse
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize(attributes = {})
|
29
|
+
@caches = []
|
30
|
+
|
31
|
+
attributes.each do |key, value|
|
32
|
+
if respond_to?("#{key}=")
|
33
|
+
send("#{key}=", value)
|
34
|
+
else
|
35
|
+
raise ArgumentError, "Unknown attribute `#{key}'"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
alias :download_available? :is_download_available
|
41
|
+
|
42
|
+
def generated_at=(time)
|
43
|
+
if time.kind_of?(Time)
|
44
|
+
@generated_at = time
|
45
|
+
else
|
46
|
+
raise TypeError, "`generated_at' must be an instance of Time"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "base64"
|
4
|
+
|
5
|
+
module Geocaching
|
6
|
+
class Session
|
7
|
+
module PocketQueries
|
8
|
+
def get_pocket_queries
|
9
|
+
response = request("GetPocketQueryList", {
|
10
|
+
"sessionToken" => session_token
|
11
|
+
})
|
12
|
+
|
13
|
+
if response.status and response.status == "NoResults"
|
14
|
+
[]
|
15
|
+
else
|
16
|
+
PocketQuery.from_xml(response.doc)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def download_pocket_query_by_guid(pocket_query_guid)
|
21
|
+
response = request("GetPocketQueryZippedFile", {
|
22
|
+
"sessionToken" => session_token,
|
23
|
+
"PocketQueryGuid" => pocket_query_guid
|
24
|
+
})
|
25
|
+
|
26
|
+
if node = response.doc.xpath("//xmlns:PocketQueryZippedFileDataSet/xmlns:PocketQueryZippedFile/xmlns:FileData").first
|
27
|
+
Base64.decode64(node.text)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/geocaching/session.rb
CHANGED
@@ -6,6 +6,7 @@ require "nokogiri"
|
|
6
6
|
|
7
7
|
require "geocaching/session/caches"
|
8
8
|
require "geocaching/session/logs"
|
9
|
+
require "geocaching/session/pocket_queries"
|
9
10
|
require "geocaching/session/trackables"
|
10
11
|
|
11
12
|
module Geocaching
|
@@ -115,6 +116,7 @@ module Geocaching
|
|
115
116
|
|
116
117
|
include Geocaching::Session::Caches
|
117
118
|
include Geocaching::Session::Logs
|
119
|
+
include Geocaching::Session::PocketQueries
|
118
120
|
include Geocaching::Session::Trackables
|
119
121
|
end
|
120
122
|
end
|
data/lib/geocaching/trackable.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require "geocaching/parsers/
|
3
|
+
require "geocaching/parsers/trackable_parser"
|
4
4
|
|
5
5
|
module Geocaching
|
6
6
|
class Trackable
|
@@ -15,7 +15,7 @@ module Geocaching
|
|
15
15
|
attr_reader :current_user
|
16
16
|
|
17
17
|
def self.from_xml(doc)
|
18
|
-
Parsers::
|
18
|
+
Parsers::TrackableParser.new(doc).parse
|
19
19
|
end
|
20
20
|
|
21
21
|
def initialize(attributes = {})
|
data/lib/geocaching.rb
CHANGED
@@ -9,6 +9,7 @@ require "geocaching/container_type"
|
|
9
9
|
require "geocaching/errors"
|
10
10
|
require "geocaching/log"
|
11
11
|
require "geocaching/log_type"
|
12
|
+
require "geocaching/pocket_query"
|
12
13
|
require "geocaching/session"
|
13
14
|
require "geocaching/user"
|
14
15
|
require "geocaching/trackable"
|
@@ -17,5 +18,5 @@ require "geocaching/waypoint"
|
|
17
18
|
require "geocaching/waypoint_type"
|
18
19
|
|
19
20
|
module Geocaching
|
20
|
-
VERSION = "0.
|
21
|
+
VERSION = "0.8.0"
|
21
22
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: geocaching
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.8.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Thomas Cyron
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-04-
|
13
|
+
date: 2011-04-30 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -52,16 +52,21 @@ files:
|
|
52
52
|
- lib/geocaching/errors.rb
|
53
53
|
- lib/geocaching/log.rb
|
54
54
|
- lib/geocaching/log_type.rb
|
55
|
-
- lib/geocaching/parsers/
|
56
|
-
- lib/geocaching/parsers/
|
57
|
-
- lib/geocaching/parsers/
|
58
|
-
- lib/geocaching/parsers/
|
59
|
-
- lib/geocaching/parsers/
|
60
|
-
- lib/geocaching/parsers/
|
61
|
-
- lib/geocaching/parsers/
|
55
|
+
- lib/geocaching/parsers/cache_attribute_parser.rb
|
56
|
+
- lib/geocaching/parsers/cache_gpx_parser.rb
|
57
|
+
- lib/geocaching/parsers/cache_simple_parser.rb
|
58
|
+
- lib/geocaching/parsers/gpx_additional_waypoint_parser.rb
|
59
|
+
- lib/geocaching/parsers/gpx_cache_parser.rb
|
60
|
+
- lib/geocaching/parsers/gpx_cache_waypoint_parser.rb
|
61
|
+
- lib/geocaching/parsers/log_parser.rb
|
62
|
+
- lib/geocaching/parsers/pocket_query_data_set_parser.rb
|
63
|
+
- lib/geocaching/parsers/pocket_query_parser.rb
|
64
|
+
- lib/geocaching/parsers/trackable_parser.rb
|
65
|
+
- lib/geocaching/pocket_query.rb
|
62
66
|
- lib/geocaching/session/attributes.rb
|
63
67
|
- lib/geocaching/session/caches.rb
|
64
68
|
- lib/geocaching/session/logs.rb
|
69
|
+
- lib/geocaching/session/pocket_queries.rb
|
65
70
|
- lib/geocaching/session/trackables.rb
|
66
71
|
- lib/geocaching/session.rb
|
67
72
|
- lib/geocaching/trackable.rb
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require "geocaching/parsers/cache_gpx_cache_waypoint"
|
4
|
-
require "geocaching/parsers/cache_gpx_additional_waypoint"
|
5
|
-
|
6
|
-
module Geocaching
|
7
|
-
module Parsers
|
8
|
-
class CacheGPX
|
9
|
-
def initialize(doc)
|
10
|
-
@doc = doc
|
11
|
-
end
|
12
|
-
|
13
|
-
def parse
|
14
|
-
cache = nil
|
15
|
-
is_first_wpt = true
|
16
|
-
|
17
|
-
@doc.xpath("//gpx:gpx/gpx:wpt", ns).each do |wpt_node|
|
18
|
-
if is_first_wpt
|
19
|
-
cache = CacheGPXCacheWaypoint.new(wpt_node).parse
|
20
|
-
is_first_wpt = false
|
21
|
-
else
|
22
|
-
cache.waypoints << CacheGPXAdditionalWaypoint.new(wpt_node).parse
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
cache
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def ns
|
32
|
-
{
|
33
|
-
"gpx" => "http://www.topografix.com/GPX/1/1",
|
34
|
-
"cache" => "http://www.groundspeak.com/cache/1/0"
|
35
|
-
}
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|