fatigue 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/Gemfile.lock +23 -0
- data/fatigue.gemspec +4 -2
- data/lib/fatigue.rb +1 -1
- data/lib/fatigue/garmin.rb +56 -27
- data/readme.markdown +5 -0
- metadata +8 -6
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
fatigue (0.0.3)
|
5
|
+
mechanize (= 1.0.0)
|
6
|
+
nokogiri (>= 1.4.0)
|
7
|
+
ruby-progressbar (= 0.0.9)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: http://rubygems.org/
|
11
|
+
specs:
|
12
|
+
mechanize (1.0.0)
|
13
|
+
nokogiri (>= 1.2.1)
|
14
|
+
nokogiri (1.4.4)
|
15
|
+
rr (0.10.11)
|
16
|
+
ruby-progressbar (0.0.9)
|
17
|
+
|
18
|
+
PLATFORMS
|
19
|
+
ruby
|
20
|
+
|
21
|
+
DEPENDENCIES
|
22
|
+
fatigue!
|
23
|
+
rr (= 0.10.11)
|
data/fatigue.gemspec
CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
|
|
13
13
|
## If your rubyforge_project name is different, then edit it and comment out
|
14
14
|
## the sub! line in the Rakefile
|
15
15
|
s.name = 'fatigue'
|
16
|
-
s.version = '0.0.
|
17
|
-
s.date = '
|
16
|
+
s.version = '0.0.4'
|
17
|
+
s.date = '2011-10-12'
|
18
18
|
s.rubyforge_project = 'fatigue'
|
19
19
|
|
20
20
|
## Make sure your summary is short. The description may be as long
|
@@ -62,6 +62,8 @@ Gem::Specification.new do |s|
|
|
62
62
|
## THE MANIFEST COMMENTS, they are used as delimiters by the task.
|
63
63
|
# = MANIFEST =
|
64
64
|
s.files = %w[
|
65
|
+
Gemfile
|
66
|
+
Gemfile.lock
|
65
67
|
Rakefile
|
66
68
|
bin/fatigue
|
67
69
|
fatigue.gemspec
|
data/lib/fatigue.rb
CHANGED
data/lib/fatigue/garmin.rb
CHANGED
@@ -39,6 +39,25 @@ module Fatigue
|
|
39
39
|
page.inspect =~ /aren't signed in/ ? true : false
|
40
40
|
end
|
41
41
|
|
42
|
+
# Public: gets the number, time and date formats from the settings page
|
43
|
+
#
|
44
|
+
# IF the user has different settings from the default, the form may return
|
45
|
+
# errors when trying to post runs
|
46
|
+
#
|
47
|
+
def get_formats
|
48
|
+
page = @agent.get('http://connect.garmin.com/settings')
|
49
|
+
html = Nokogiri::HTML(page.body)
|
50
|
+
scr = html.css("script").select { |s| s.text =~ /(DATE_FORMAT)/ }.first.text
|
51
|
+
|
52
|
+
date_value = scr.match(/DATE_FORMAT = '(.+)'/)[1]
|
53
|
+
time_value = scr.match(/TIME_FORMAT = '(.+)'/)[1]
|
54
|
+
number_value = scr.match(/NUMBER_FORMAT = '(.+)'/)[1]
|
55
|
+
|
56
|
+
@date_format = date_value.gsub('yyyy', '%Y').gsub('dd', '%d').gsub('MM', '%m')
|
57
|
+
@time_format = (time_value == 'twenty_four' ? '%H:%M' : '%I:%M %p' )
|
58
|
+
@decimal_format = (number_value == 'decimal_comma' ? ',' : '.')
|
59
|
+
end
|
60
|
+
|
42
61
|
# Public: posts a new Run to your logged-in Garmin account.
|
43
62
|
#
|
44
63
|
# run - A Fatigue::Run instance.
|
@@ -46,34 +65,43 @@ module Fatigue
|
|
46
65
|
# Returns true if success, false if failure. Requires #login to be called
|
47
66
|
# prior to execution.
|
48
67
|
def post_run(run)
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
68
|
+
begin
|
69
|
+
manual_run = @agent.get('http://connect.garmin.com/activity/manual')
|
70
|
+
form = manual_run.form('manualActivityForm')
|
71
|
+
form.activityBeginDate = run.started_at.strftime(@date_format)
|
72
|
+
form.activityBeginTime = run.started_at.strftime(@time_format)
|
73
|
+
form.field_with(:name => 'activityTimeZoneDecoration:activityTimeZone').
|
74
|
+
options.select { |option|
|
75
|
+
# select option where our timezones are equal (-07:00, etc)
|
76
|
+
zone = run.started_at.getlocal.strftime('%z').gsub('+','\+').gsub('0000', '\(GMT\)')
|
77
|
+
option.text.gsub(':','') =~ /#{zone}/
|
78
|
+
}.first.select
|
79
|
+
form['activityNameDecoration:activityName'] = run.formatted_name
|
80
|
+
form.field_with(:name => 'activityTypeDecoration:activityType').
|
81
|
+
options.select { |option| option.value == 'running' }.
|
82
|
+
first.select
|
83
|
+
form['speedPaceContainer:activitySummarySumDuration'] = run.hours
|
84
|
+
form['speedPaceContainer:activitySummarySumDurationMinute'] = run.minutes
|
85
|
+
form['speedPaceContainer:activitySummarySumDurationSecond'] = run.seconds
|
86
|
+
form['speedPaceContainer:activitySummarySumDistanceDecoration:activitySummarySumDistance'] = run.distance.to_s.gsub('.', @decimal_format)
|
87
|
+
form.field_with(:name => 'speedPaceContainer:activitySummarySumDistanceDecoration:distanceUnit').
|
88
|
+
options.select { |option| option.text == run.unit }.first.select
|
89
|
+
form['descriptionDecoration:description'] = run.description
|
90
|
+
form['calories'] = run.calories
|
91
|
+
form['AJAXREQUEST'] = '_viewRoot'
|
92
|
+
form['saveButton'] = 'saveButton'
|
73
93
|
|
74
|
-
|
75
|
-
|
76
|
-
|
94
|
+
resp = @agent.submit(form, form.buttons_with(:name => 'saveButton').first)
|
95
|
+
verify_response(resp.body)
|
96
|
+
rescue NoMethodError => e
|
97
|
+
puts "Darn!\nGarmin logged us out while attempting to post a run on #{run.started_at.strftime(@date_format)}. Logging back in!"
|
98
|
+
if login
|
99
|
+
post_run(run)
|
100
|
+
else
|
101
|
+
puts "Couldn't log back in. Aborting."
|
102
|
+
exit
|
103
|
+
end
|
104
|
+
end
|
77
105
|
end
|
78
106
|
|
79
107
|
# Public: Posts a collection of Runs to your logged-in Garmin account.
|
@@ -83,6 +111,7 @@ module Fatigue
|
|
83
111
|
# Returns the number of runs successfully posted to the Garmin account.
|
84
112
|
# Requires #login to be called prior to execution.
|
85
113
|
def post_runs(runs)
|
114
|
+
get_formats
|
86
115
|
progress = ProgressBar.new(" status", runs.size)
|
87
116
|
runs.each do |run|
|
88
117
|
post_run(run)
|
data/readme.markdown
CHANGED
@@ -51,6 +51,11 @@ enter your Mac password when prompted. This will download the code to your
|
|
51
51
|
machine. When it tells you "3 gems installed", type `fatigue` and enjoy the
|
52
52
|
show.
|
53
53
|
|
54
|
+
NOTE: If you run into a problem during installation where it spits out `ERROR:
|
55
|
+
Failed to build gem native extension`, that means you need to install XCode.
|
56
|
+
It's available on your OS X install DVD or through the Mac App Store. We're
|
57
|
+
working on fixing this so you don't need to install XCode in the future.
|
58
|
+
|
54
59
|
**For Windows Users**
|
55
60
|
|
56
61
|
Microsoft makes everything harder since you'll have to install Ruby yourself.
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fatigue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Zach Holman
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-10-12 00:00:00 -07:00
|
19
19
|
default_executable: fatigue
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -93,6 +93,8 @@ extensions: []
|
|
93
93
|
extra_rdoc_files:
|
94
94
|
- readme.markdown
|
95
95
|
files:
|
96
|
+
- Gemfile
|
97
|
+
- Gemfile.lock
|
96
98
|
- Rakefile
|
97
99
|
- bin/fatigue
|
98
100
|
- fatigue.gemspec
|
@@ -137,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
139
|
requirements: []
|
138
140
|
|
139
141
|
rubyforge_project: fatigue
|
140
|
-
rubygems_version: 1.
|
142
|
+
rubygems_version: 1.6.2
|
141
143
|
signing_key:
|
142
144
|
specification_version: 2
|
143
145
|
summary: Import your Nike+ runs into Garmin Connect.
|