garmin_connectr 0.0.4 → 0.0.5
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.rdoc +6 -1
- data/VERSION +1 -1
- data/examples/activity.rb +7 -2
- data/garmin_connectr.gemspec +2 -2
- data/lib/garmin_connectr.rb +54 -2
- metadata +2 -2
data/README.rdoc
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
= garmin_connectr
|
|
2
2
|
|
|
3
|
-
GarminConnectr is a simple Ruby library for accessing data from Garmin Connect. As of 12/2009, Garmin's own Connect API has yet to be released.
|
|
3
|
+
GarminConnectr is a simple Ruby library for accessing data from Garmin Connect. As of 12/2009, Garmin's own Connect API has yet to be released. Until then, this screen scraping lib does the job.
|
|
4
4
|
|
|
5
5
|
Install:
|
|
6
6
|
|
|
@@ -22,6 +22,11 @@ Usage:
|
|
|
22
22
|
puts "#{ activity.name } / #{ activity.start_time }"
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
+
# Review activity split/lap data
|
|
26
|
+
activity.splits.each do |split|
|
|
27
|
+
puts "#{ split['split'] }: Distance: #{ split['distance'] }"
|
|
28
|
+
end
|
|
29
|
+
|
|
25
30
|
See examples/*
|
|
26
31
|
|
|
27
32
|
== Copyright
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.0.
|
|
1
|
+
0.0.5
|
data/examples/activity.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require '../lib/garmin_connectr.rb'
|
|
2
2
|
|
|
3
|
-
activity_id =
|
|
3
|
+
activity_id = 21450277
|
|
4
4
|
|
|
5
5
|
gc = GarminConnectr.new
|
|
6
6
|
activity = gc.load( activity_id )
|
|
@@ -9,4 +9,9 @@ puts activity.name
|
|
|
9
9
|
puts " Activity : #{ activity.activity }"
|
|
10
10
|
puts " Distance : #{ activity.distance }"
|
|
11
11
|
puts " Start : #{ activity.start_time }"
|
|
12
|
-
puts " Avg HR : #{ activity.avg_hr }"
|
|
12
|
+
puts " Avg HR : #{ activity.avg_hr }"
|
|
13
|
+
puts " Splits : #{ activity.splits.count }"
|
|
14
|
+
|
|
15
|
+
activity.splits.each do |split|
|
|
16
|
+
puts "\t#{ split['split'] } : Distance = #{ split['distance'] }"
|
|
17
|
+
end
|
data/garmin_connectr.gemspec
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = %q{garmin_connectr}
|
|
8
|
-
s.version = "0.0.
|
|
8
|
+
s.version = "0.0.5"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["aroth"]
|
|
12
|
-
s.date = %q{
|
|
12
|
+
s.date = %q{2010-01-01}
|
|
13
13
|
s.description = %q{GarminConnectr is a simple Ruby library for accessing data from Garmin Connect.}
|
|
14
14
|
s.email = %q{adamjroth@gmail.com}
|
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/garmin_connectr.rb
CHANGED
|
@@ -2,6 +2,7 @@ require 'rubygems'
|
|
|
2
2
|
require 'nokogiri'
|
|
3
3
|
require 'open-uri'
|
|
4
4
|
require 'mechanize'
|
|
5
|
+
require 'fastercsv'
|
|
5
6
|
|
|
6
7
|
class GarminConnectr
|
|
7
8
|
|
|
@@ -55,7 +56,7 @@ class GarminConnectActivity
|
|
|
55
56
|
|
|
56
57
|
attr_reader :activity_id, :loaded, :name, :url, :device, :start_time, :activity, :event, :time, :distance, :calories
|
|
57
58
|
attr_reader :avg_speed, :max_speed, :avg_power, :max_power, :elevation_gain, :elevation_loss, :min_elevation, :max_elevation, :avg_hr, :max_hr, :avg_bike_cadence, :max_bike_cadence, :avg_temperature, :min_temperature, :max_temperature, :avg_pace, :best_pace
|
|
58
|
-
|
|
59
|
+
|
|
59
60
|
FIELDS = ['Avg Speed', 'Max Speed', 'Avg Power', 'Max Power', 'Elevation Gain', 'Elevation Loss', 'Min Elevation', 'Max Elevation', 'Avg HR', 'Max HR', 'Avg Bike Cadence', 'Max Bike Cadence', 'Avg Temperature', 'Min Temperature', 'Max Temperature', 'Avg Pace', 'Best Pace']
|
|
60
61
|
|
|
61
62
|
def initialize( activity_id, name=nil )
|
|
@@ -63,6 +64,8 @@ class GarminConnectActivity
|
|
|
63
64
|
@name = name unless name.nil?
|
|
64
65
|
@loaded = false
|
|
65
66
|
@fields = ['name', 'url', 'device', 'start_time']
|
|
67
|
+
@splits = []
|
|
68
|
+
@split_summary = {}
|
|
66
69
|
end
|
|
67
70
|
|
|
68
71
|
## Fetch activity details. This will happen automatically if using GarminConnect#load. You will have
|
|
@@ -88,10 +91,59 @@ class GarminConnectActivity
|
|
|
88
91
|
self.instance_variable_set("@#{ name }", self.send( :tab_data, field ) )
|
|
89
92
|
end
|
|
90
93
|
|
|
94
|
+
# Splits - parse CSV
|
|
95
|
+
@doc = open("http://connect.garmin.com/csvExporter/#{ @activity_id }.csv")
|
|
96
|
+
@splits = []
|
|
97
|
+
@split_summary = {}
|
|
98
|
+
|
|
99
|
+
@keys = []
|
|
100
|
+
@csv = FasterCSV.parse( @doc.read )
|
|
101
|
+
@csv[0].each do |key|
|
|
102
|
+
@keys.push key.downcase.gsub(' ','_') if key.is_a?(String)
|
|
103
|
+
end
|
|
104
|
+
## Data Rows
|
|
105
|
+
@csv[1, @csv.length - 2].each_with_index do |row, index|
|
|
106
|
+
split = {}
|
|
107
|
+
@keys.each_with_index do |key, key_index|
|
|
108
|
+
split[ key ] = row[ key_index ]
|
|
109
|
+
end
|
|
110
|
+
@splits << split
|
|
111
|
+
end
|
|
112
|
+
## Summary Row
|
|
113
|
+
@keys.each_with_index do |key, key_index|
|
|
114
|
+
@split_summary[ key ] = @csv.last[ key_index ]
|
|
115
|
+
end
|
|
116
|
+
|
|
91
117
|
self
|
|
92
118
|
end
|
|
93
119
|
|
|
94
|
-
|
|
120
|
+
## Returns an array of hashes detailing activity splits (laps). Attributes may include:
|
|
121
|
+
##
|
|
122
|
+
## split
|
|
123
|
+
## time
|
|
124
|
+
## distance
|
|
125
|
+
## elevation_gain
|
|
126
|
+
## elevation_loss
|
|
127
|
+
## avg_speed
|
|
128
|
+
## max_speed
|
|
129
|
+
## avg_hr
|
|
130
|
+
## max_hr
|
|
131
|
+
## avg_bike_cadence
|
|
132
|
+
## max_bike_cadence
|
|
133
|
+
## calories
|
|
134
|
+
## avg_temp
|
|
135
|
+
## max_power
|
|
136
|
+
## avg_power
|
|
137
|
+
def splits
|
|
138
|
+
@splits
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
## Returns a hash of activity splits/laps summary. See splits rdoc for possible attributes.
|
|
142
|
+
def split_summary
|
|
143
|
+
@split_summary
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
private
|
|
95
147
|
|
|
96
148
|
def tab_data( label )
|
|
97
149
|
label += ":" unless label.match(/:$/)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: garmin_connectr
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- aroth
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date:
|
|
12
|
+
date: 2010-01-01 00:00:00 -05:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies: []
|
|
15
15
|
|