ruby-fitbit 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Dan Mayer
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,62 @@
1
+ = ruby-fitbit
2
+
3
+ This is a Ruby API for the fitbit and the data at fitbit.com
4
+
5
+ Currently the gem uses screen scraping to get the data, but it will switch over to use the official API once available. The current set of data it retrieves is pretty limited, but it should grow over time. Originally built just to display a dashboard of my current fitbit stats on my blog.
6
+
7
+ == Usage
8
+
9
+ install
10
+ `gem install ruby-fitbit`
11
+
12
+ run
13
+ `ruby-fitbit your@email.com YourPassword`
14
+
15
+ ruby usage
16
+ require 'ruby-fitbit'
17
+ fitbit = RubyFitbit.new(EMAIL,PASSWORD)
18
+
19
+ puts "Calories Burned #{fitbit.calories}"
20
+ puts "Steps Taken #{fitbit.steps}"
21
+ puts "Milkes Walked #{fitbit.miles_walked}"
22
+ puts "Activity Levels Durations:"
23
+ puts "Sedentary #{fitbit.sedentary_active}"
24
+ puts "Lightly #{fitbit.lightly_active}"
25
+ puts "Fairly #{fitbit.fairly_active}"
26
+ puts "Very #{fitbit.very_active}"
27
+
28
+ output
29
+ ~/projects/ruby-fitbit(master) > ruby bin/ruby-fitbit my@email.com MYPASS
30
+ Calories Burned 803
31
+ Steps Taken 552
32
+ Milkes Walked .23
33
+ Activity Levels Durations:
34
+ Sedentary 11hrs 1min
35
+ Lightly 18min
36
+ Fairly 16min
37
+ Very 0min
38
+
39
+ done
40
+
41
+
42
+ == TODOs
43
+
44
+ * Get data from any date not just current data
45
+ * get the minute by minute calorie chart breakdowns
46
+ * get food intake tracked etc
47
+ * add ability for gem to write data to fitbit, such as log and food entries
48
+ * build everything needed for a nice fitbit IPhone app to use this API.
49
+
50
+ == Note on Patches/Pull Requests
51
+
52
+ * Fork the project.
53
+ * Make your feature addition or bug fix.
54
+ * Add tests for it. This is important so I don't break it in a
55
+ future version unintentionally.
56
+ * Commit, do not mess with rakefile, version, or history.
57
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
58
+ * Send me a pull request. Bonus points for topic branches.
59
+
60
+ == Copyright
61
+
62
+ Copyright (c) 2010 Dan Mayer. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,67 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "ruby-fitbit"
8
+ gem.summary = %Q{This is a Ruby API for Fitbit.com}
9
+ gem.description = %Q{This is a Ruby API for Fitbit.com, currently scraping, but soon will use the officail API (when released)}
10
+ gem.email = "Danmayer@gmail.com"
11
+ gem.homepage = "http://github.com/danmayer/ruby-fitbit"
12
+ gem.authors = ["Dan Mayer"]
13
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ gem.add_dependency "mechanize", ">= 0.9.3"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/test_*.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+ task :test => :check_dependencies
43
+
44
+ begin
45
+ require 'reek/adapters/rake_task'
46
+ Reek::RakeTask.new do |t|
47
+ t.fail_on_error = true
48
+ t.verbose = false
49
+ t.source_files = 'lib/**/*.rb'
50
+ end
51
+ rescue LoadError
52
+ task :reek do
53
+ abort "Reek is not available. In order to run reek, you must: sudo gem install reek"
54
+ end
55
+ end
56
+
57
+ task :default => :test
58
+
59
+ require 'rake/rdoctask'
60
+ Rake::RDocTask.new do |rdoc|
61
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
62
+
63
+ rdoc.rdoc_dir = 'rdoc'
64
+ rdoc.title = "ruby-fitbit #{version}"
65
+ rdoc.rdoc_files.include('README*')
66
+ rdoc.rdoc_files.include('lib/**/*.rb')
67
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/bin/ruby-fitbit ADDED
@@ -0,0 +1,16 @@
1
+ #! /usr/bin/env ruby
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ruby-fitbit')
3
+
4
+ fitbit = RubyFitbit.new(ARGV[0],ARGV[1])
5
+
6
+ puts "Calories Burned #{fitbit.calories}"
7
+ puts "Steps Taken #{fitbit.steps}"
8
+ puts "Milkes Walked #{fitbit.miles_walked}"
9
+ puts "Activity Levels Durations:"
10
+ puts "Sedentary #{fitbit.sedentary_active}"
11
+ puts "Lightly #{fitbit.lightly_active}"
12
+ puts "Fairly #{fitbit.fairly_active}"
13
+ puts "Very #{fitbit.very_active}"
14
+
15
+ puts ''
16
+ puts "done"
@@ -0,0 +1,33 @@
1
+ require 'rubygems'
2
+ require 'mechanize'
3
+
4
+ class RubyFitbit
5
+
6
+ attr_reader :calories, :steps, :miles_walked, :sedentary_active, :lightly_active, :fairly_active, :very_active
7
+
8
+ def initialize(email, pass)
9
+ @email = email
10
+ @pass = pass
11
+ get_data
12
+ end
13
+
14
+ def get_data
15
+ agent = WWW::Mechanize.new #{|a| a.log = Logger.new(STDERR) } #turn on if debugging
16
+ page = agent.get 'https://www.fitbit.com/login'
17
+
18
+ form = page.forms.first
19
+ form.email = @email
20
+ form.password = @pass
21
+
22
+ page = agent.submit(form, form.buttons.first)
23
+
24
+ @calories = page.search("//div[@class='data']").search("span").children[0].text
25
+ @steps = page.search("//div[@class='data']").search("span").children[2].text.strip
26
+ @miles_walked = page.search("//div[@class='data']").search("span").children[3].text.strip
27
+ @sedentary_active = page.search("//div[@class='sedentary caption']/div[@class='number']").text.strip
28
+ @lightly_active = page.search("//div[@class='lightly caption']/div[@class='number']").text.strip
29
+ @fairly_active = page.search("//div[@class='caption fairly']/div[@class='number']").text.strip
30
+ @very_active = page.search("//div[@class='caption very']/div[@class='number']").text.strip
31
+ end
32
+
33
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'ruby-fitbit'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestRubyFitbit < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-fitbit
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Dan Mayer
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-26 00:00:00 -04:00
18
+ default_executable: ruby-fitbit
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: thoughtbot-shoulda
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: mechanize
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ - 9
42
+ - 3
43
+ version: 0.9.3
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ description: This is a Ruby API for Fitbit.com, currently scraping, but soon will use the officail API (when released)
47
+ email: Danmayer@gmail.com
48
+ executables:
49
+ - ruby-fitbit
50
+ extensions: []
51
+
52
+ extra_rdoc_files:
53
+ - LICENSE
54
+ - README.rdoc
55
+ files:
56
+ - .document
57
+ - .gitignore
58
+ - LICENSE
59
+ - README.rdoc
60
+ - Rakefile
61
+ - VERSION
62
+ - bin/ruby-fitbit
63
+ - lib/ruby-fitbit.rb
64
+ - test/helper.rb
65
+ - test/test_ruby-fitbit.rb
66
+ has_rdoc: true
67
+ homepage: http://github.com/danmayer/ruby-fitbit
68
+ licenses: []
69
+
70
+ post_install_message:
71
+ rdoc_options:
72
+ - --charset=UTF-8
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ requirements: []
90
+
91
+ rubyforge_project:
92
+ rubygems_version: 1.3.6
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: This is a Ruby API for Fitbit.com
96
+ test_files:
97
+ - test/helper.rb
98
+ - test/test_ruby-fitbit.rb