Skip to content
This repository
Browse code

added fetching eaten calorie data

  • Loading branch information...
commit 6f81e5dfa0d581a552583bde6d32d681c19e521d 1 parent 152d260
Dan Mayer authored October 14, 2010
1  README.rdoc
Source Rendered
@@ -89,6 +89,7 @@ Currently the gem uses screen scraping to get the data, but it will switch over
89 89
 * Commit, do not mess with rakefile, version, or history.
90 90
   (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)
91 91
 * Send me a pull request. Bonus points for topic branches.
  92
+* user dailyTotals id to scrape the current food log from http://www.fitbit.com/foods/log/2010/10/07 for display
92 93
 
93 94
 == Copyright
94 95
 
2  VERSION
... ...
@@ -1 +1 @@
1  
-0.4.0
  1
+0.3.1
1  bin/ruby-fitbit
@@ -9,6 +9,7 @@ if(ARGV[0]!=nil && ARGV[1]!=nil)
9 9
   #testing some in progress API methods
10 10
   #fitbit.submit_food_log({:food => 'coffee', :unit => '8 oz'})
11 11
   #fitbit.get_food_items
  12
+  #puts fitbit.get_eaten_calories[:calories_xml]
12 13
   #exit 1
13 14
 
14 15
   begin
56  lib/ruby-fitbit.rb
@@ -77,28 +77,29 @@ def submit_food_log(options = {})
77 77
   def get_unit_id_for_unit(unit)
78 78
     unit_id   = nil
79 79
     unit_type = unit.match(/\d+ (.*)/)[1]
80  
-    unit_id   = case unit_type
81  
-                when 'oz' then '226'
82  
-                when 'lb' then '180'
83  
-                when 'gram' then '147'
84  
-                when 'kilogram' then '389'
85  
-                when 'roll' then '290'
86  
-                when 'serving' then '304'
87  
-                when 'link' then '188'
88  
-                when 'piece' then '251'
89  
-                when 'fl oz' then '128'
90  
-                when 'ml' then '209'
91  
-                when 'tsp' then '364'
92  
-                when 'tbsp' then '349'
93  
-                when 'cup' then '91'
94  
-                when 'pint' then '256'
95  
-                when 'slice' then '311'
96  
-                when 'liter' then '189'
97  
-                when 'quart' then '279'
98  
-                when 'entree' then '117'
99  
-                when 'portion' then '270'
100  
-                else nil
101  
-                end
  80
+
  81
+    type_map = {'oz' => '226',
  82
+                'lb' => '180',
  83
+                'gram' => '147',
  84
+                'kilogram' => '389',
  85
+                'roll' => '290',
  86
+                'serving' => '304',
  87
+                'link' => '188',
  88
+                'piece' => '251',
  89
+                'fl oz' => '128',
  90
+                'ml' => '209',
  91
+                'tsp' => '364',
  92
+                'tbsp' => '349',
  93
+                'cup' => '91',
  94
+                'pint' => '256',
  95
+                'slice' => '311',
  96
+                'liter' => '189',
  97
+                'quart' => '279',
  98
+                'entree' => '117',
  99
+                'portion' => '270'
  100
+    }
  101
+
  102
+    unit_id   = type_map[unit_type]
102 103
     unit_id
103 104
   end
104 105
 
@@ -109,6 +110,17 @@ def get_food_items(food="Coffe")
109 110
     foods
110 111
   end
111 112
 
  113
+  def get_eaten_calories(date = Time.now)
  114
+    login
  115
+
  116
+    date = get_fitbit_date_format(date).gsub('-','/')
  117
+    page = @agent.get "https://www.fitbit.com/foods/log/#{date}"
  118
+    calories_data = page.search("//div[@id='dailyTotals']").first
  119
+    calories_xml = calories_data.to_xml
  120
+    calories_text = calories_data.text
  121
+    {:calories_xml => calories_xml, :calories_text => calories_text}
  122
+  end
  123
+
112 124
   def get_data(date = Time.now)
113 125
     login
114 126
 
5  ruby-fitbit.gemspec
@@ -5,11 +5,11 @@
5 5
 
6 6
 Gem::Specification.new do |s|
7 7
   s.name = %q{ruby-fitbit}
8  
-  s.version = "0.2.3"
  8
+  s.version = "0.3.1"
9 9
 
10 10
   s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11 11
   s.authors = ["Dan Mayer"]
12  
-  s.date = %q{2010-07-24}
  12
+  s.date = %q{2010-10-14}
13 13
   s.default_executable = %q{ruby-fitbit}
14 14
   s.description = %q{This is a Ruby API for Fitbit.com, currently scraping, but soon will use the officail API (when released)}
15 15
   s.email = %q{Danmayer@gmail.com}
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26 26
      "Rakefile",
27 27
      "VERSION",
28 28
      "bin/ruby-fitbit",
  29
+     "fixtures/vcr_cassettes/fitbit_get_data.yml",
29 30
      "lib/ruby-fitbit.rb",
30 31
      "ruby-fitbit.gemspec",
31 32
      "test/helper.rb",

0 notes on commit 6f81e5d

Please sign in to comment.
Something went wrong with that request. Please try again.