ruby-fitbit 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,327 @@
1
+ HTTP/1.1 200 OK
2
+ Server: Apache-Coyote/1.1
3
+ Expires: Thu, 01 Jan 1970 00:00:00 GMT
4
+ Cache-control: no-store, no-cache, must-revalidate
5
+ Pragma: no-cache
6
+ Content-Type: text/html;charset=UTF-8
7
+ Content-Language: en-US
8
+ Transfer-Encoding: chunked
9
+ Date: Mon, 19 Jul 2010 01:06:57 GMT
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
18
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
19
+ <head>
20
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
21
+ <title>Login</title>
22
+ <meta name="keywords" content="keywords" />
23
+ <meta name="description" content="description" />
24
+ <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
25
+
26
+
27
+ <link rel="stylesheet" type="text/css" href="/pack?h=3f18725800c7f1b86b3af8be68c89e9e&item=%2Fyui%2F2.7.0%2Fbuild%2Ffonts%2Ffonts-min.css&item=%2Fyui%2F2.7.0%2Fbuild%2Freset%2Freset-min.css&item=%2Fyui%2F2.7.0%2Fbuild%2Fcontainer%2Fassets%2Fskins%2Fsam%2Fcontainer.css&item=%2Fyui%2F2.7.0%2Fbuild%2Fcalendar%2Fassets%2Fskins%2Fsam%2Fcalendar.css&item=%2Fyui%2F2.7.0%2Fbuild%2Fautocomplete%2Fassets%2Fskins%2Fsam%2Fautocomplete.css&item=%2Fdesign%2F2009-07%2Fcss%2Fcommon.css&item=%2Fdesign%2F2009-07%2Fcss%2Fapp.css"/>
28
+
29
+
30
+
31
+ <script type="text/javascript">
32
+ document.documentElement.className += ' js';
33
+
34
+ function setTextLimits() {
35
+ for (var nodes = document.getElementsByTagName('*'), i = 0, l = nodes.length; i < l; i++) {
36
+ var m = nodes[i].className.match(/(?:^|\s)textLimit(?:(\d+)(?:-(\d+))?)?(?=\s|$)/i);
37
+ if (!m || !nodes[i].lastChild) {
38
+ continue;
39
+ }
40
+
41
+ var el = nodes[i];
42
+ var lines = m[1] || 1;
43
+ var maxWidth = m[2] || Number.MAX_VALUE;
44
+ var clone = el.cloneNode(false);
45
+ var ellipsis = clone.appendChild(document.createTextNode('\u2026'));
46
+ el.parentNode.replaceChild(clone, el);
47
+ var maxHeight = (clone.scrollHeight - clone.clientHeight) + ((clone.clientHeight + 3) * lines);
48
+ clone.parentNode.replaceChild(el, clone);
49
+ if (el.scrollHeight > maxHeight || el.scrollWidth > maxWidth) {
50
+ el.title = (el.textContent || el.innerText || '').replace(/^\s+|\s+$/g, '');
51
+ for (var root = el, node = root.lastChild;; node = root.lastChild) {
52
+ if (node && node.nodeType == 1) {
53
+ root = node;
54
+ } else {
55
+ if (!node) {
56
+ if (root == el) {
57
+ break;
58
+ }
59
+ node = root;
60
+ root = root.parentNode;
61
+ root.removeChild(node);
62
+ } else if (node.nodeType == 3) {
63
+ node.nodeValue = node.nodeValue.slice(0, -1);
64
+ if (!node.nodeValue) {
65
+ root = node.parentNode;
66
+ root.removeChild(node);
67
+ }
68
+ } else {
69
+ root.removeChild(node);
70
+ }
71
+ root.appendChild(ellipsis);
72
+ if (el.scrollHeight <= maxHeight && el.scrollWidth <= maxWidth) {
73
+ break;
74
+ }
75
+ root.removeChild(ellipsis);
76
+ }
77
+ }
78
+ }
79
+ }
80
+ }
81
+ </script>
82
+
83
+
84
+
85
+ <link rel="stylesheet" type="text/css" href="/pack?h=691d2300ae3a7f208eaab331a1432ef8&item=%2Fdesign%2F2009-07%2Fcss%2Fapp.css&item=%2Fdesign%2F2009-07%2Fcss%2Flogin.css"/>
86
+
87
+ </head>
88
+
89
+ <body>
90
+
91
+ <div id="main">
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+ <div id="header">
103
+ <div class="logo"><a href="http://www.fitbit.com/"><img src="/images/layout/logo.gif" alt=""/></a></div>
104
+ <div class="accountLinks">
105
+
106
+
107
+ <ul>
108
+ <li><a href="http://www.fitbit.com/help" rel="nofollow">Help</a></li>
109
+ <li><a href="https://www.fitbit.com/login" rel="nofollow">Log In</a></li>
110
+ <li class="last"><a href="https://www.fitbit.com/signup" rel="nofollow">Sign Up</a></li>
111
+ </ul>
112
+
113
+ </div>
114
+
115
+ <div id="menu">
116
+
117
+
118
+ <ul>
119
+ <li><a href="http://www.fitbit.com/">Home</a></li>
120
+ <li><a href="http://www.fitbit.com/product" rel="nofollow">Features</a></li>
121
+ <li><a href="http://blog.fitbit.com" rel="nofollow">Blog</a></li>
122
+ <li><a href="http://www.fitbit.com/company" rel="nofollow">About</a></li>
123
+ <li><a href="http://www.fitbit.com/product" rel="nofollow">Store</a></li>
124
+ <li><a href="https://www.fitbit.com/forums" rel="nofollow">Community</a></li>
125
+ </ul>
126
+
127
+ </div>
128
+
129
+ </div>
130
+
131
+
132
+
133
+ <div id="content">
134
+ <div class="rail clearfix">
135
+ <div class="header clearfix"><a href="/order/"><img src="/images/login/purchase_fitbit.gif" alt="Purchase Fitbit" border="0" width="255" height="39"/></a></div>
136
+ <div class="content clearfix">
137
+ <img class="screenshots" src="/images/login/web_screenshots.png" alt="Fitbit Screens" width="284" height="222"/>
138
+ <h2>Not just activity, but calories too!</h2>
139
+ <p>The Fitbit Tracker contains a motion sensor like the ones found in the Nintendo Wii. The Tracker senses your motion in three dimensions and converts this into useful information about your daily activities. The Tracker measures the intensity and duration of your physical activities.</p>
140
+ </div>
141
+ </div>
142
+ <div class="primary clearfix">
143
+ <div class="header clearfix"><h1>Login &amp; Setup</h1></div>
144
+
145
+
146
+
147
+
148
+ <div style="padding: 20px 30px;"></div>
149
+
150
+
151
+
152
+
153
+
154
+ <div class="column1 form clearfix">
155
+ <h2>Log in</h2>
156
+
157
+
158
+ <form name="login" action="https://www.fitbit.com/login" method="post">
159
+ <h3>Email:</h3>
160
+ <input name="email" class="text" type="text" />
161
+ <h3>Password: <span class="formHint">(<a tabindex="-1" href="/login/forgotPassword" onclick="viewForgotPassword(); return false;">Forgot your password?</a>)</span></h3>
162
+ <input name="password" class="text" type="password" />
163
+ <p><label><input name="rememberMe" value="true" tabindex="-1" type="checkbox" checked="checked" /> Remember Me</label></p>
164
+ <input name="login" value="Log In" class="button" type="submit" />
165
+
166
+ <input name="redirect" value="" type="hidden" />
167
+ <div style="display: none;"><input type="hidden" name="_sourcePage" value="xoym83lTc7LGrJMFkFsv6XbX0f6OV1Ndj1zeGcz7OKzA3gkNXMXGnj27D-H9WXS-" /><input type="hidden" name="__fp" value="QVL1QbgbuJVztQ7FkK21Ry2MI7JbqWTf" /></div></form>
168
+ </div>
169
+ <div class="column1 form clearfix">
170
+ <h2>Set up your account</h2>
171
+ <form name="signup" action="https://www.fitbit.com/setup" method="post">
172
+ <h3>Email:</h3>
173
+ <input name="email" class="text" type="text" />
174
+ <h3>Password:</h3>
175
+ <input name="password" class="text" type="password" />
176
+
177
+ <p id="terms">By signing up, I agree to the <a href="/terms" onclick="window.open('http://www.fitbit.com/terms'); return false;" tabindex="-1">Terms and Conditions</a></p>
178
+ <input name="signup" value="Create My Account" class="button" type="submit" />
179
+ <input name="sessId" value="" type="hidden" />
180
+ <input name="timezone" value="" type="hidden" />
181
+
182
+ <input name="redirect" value="" type="hidden" />
183
+ <div style="display: none;"><input type="hidden" name="_sourcePage" value="etZudjc2X5fGrJMFkFsv6XbX0f6OV1Ndj1zeGcz7OKzA3gkNXMXGnj27D-H9WXS-" /><input type="hidden" name="__fp" value="z_rMAQuc79U=" /></div></form>
184
+ <form name="forgotPassword" action="https://www.fitbit.com/login/forgotPassword" method="post">
185
+ <input name="email" value="" type="hidden" />
186
+ <div style="display: none;"><input type="hidden" name="_sourcePage" value="noMY3z2iN9vGrJMFkFsv6XbX0f6OV1Ndj1zeGcz7OKzA3gkNXMXGnj27D-H9WXS-" /><input type="hidden" name="__fp" value="KLf5fEQNreQ=" /></div></form>
187
+ </div>
188
+ </div>
189
+ </div>
190
+
191
+
192
+
193
+
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+ <div id="footer">
207
+ <div id="columns">
208
+ <div class="column">
209
+ <h4>Help</h4>
210
+ <ul>
211
+
212
+ <li><a href="http://www.fitbit.com/faq" rel="nofollow">FAQ</a></li>
213
+ <li><a href="http://www.fitbit.com/manual" rel="nofollow">Product Manual</a></li>
214
+ <li><a href="http://www.fitbit.com/returns" rel="nofollow">Returns and Warranty</a></li>
215
+ <li><a href="http://www.fitbit.com/contact" rel="nofollow">Contact</a></li>
216
+ </ul>
217
+ </div>
218
+ <div class="column">
219
+ <h4>Downloads</h4>
220
+ <ul>
221
+ <li><a href="http://www.fitbit.com/start" rel="nofollow">Windows XP, Vista and 7</a></li>
222
+ <li><a href="http://www.fitbit.com/start" rel="nofollow">Mac OS X</a></li>
223
+ </ul>
224
+ </div>
225
+ <div class="column">
226
+ <h4>Explore</h4>
227
+ <ul>
228
+ <li><a href="http://www.fitbit.com/premium/about" rel="nofollow">Premium Membership</a></li>
229
+ <li><a href="http://www.fitbit.com/foods/categories" rel="nofollow">Calories in Foods</a></li>
230
+ <li><a href="http://www.fitbit.com/foods/restaurants" rel="nofollow">Foods by Restaurant</a></li>
231
+ <li><a href="http://www.fitbit.com/foods/brands" rel="nofollow">Foods By Brand</a></li>
232
+ <li><a href="http://www.fitbit.com/foods/search" rel="nofollow">Search Foods</a></li>
233
+
234
+ <li><a href="http://www.fitbit.com/users/index" rel="nofollow">All Users</a></li>
235
+
236
+ </ul>
237
+ </div>
238
+ <div class="column">
239
+ <h4>Company</h4>
240
+ <ul>
241
+ <li><a href="http://blog.fitbit.com">Fitbit Blog</a></li>
242
+ <li><a href="http://www.fitbit.com/company" rel="nofollow">About Fitbit</a></li>
243
+ <li><a href="http://www.fitbit.com/privacy" rel="nofollow">Privacy Policy</a></li>
244
+ <li><a href="http://www.fitbit.com/terms" rel="nofollow">Terms of Use</a></li>
245
+ </ul>
246
+ </div>
247
+ <div class="column last">
248
+ <h4>Purchase Fitbit</h4>
249
+ <p>Includes Fitbit Tracker, Base Station & Software</p>
250
+ <h5><a href="http://www.fitbit.com/product">Buy Now &raquo;</a></h5>
251
+ </div>
252
+ <img src="/images/layout/product.jpg" alt="product" />
253
+ </div>
254
+ <div id="copyright">&copy; 2010 Fitbit, Inc. All rights reserved.</div>
255
+ </div>
256
+
257
+ </div>
258
+
259
+
260
+
261
+ <script type="text/javascript" src="/pack?h=ace4c3c76cb4305cbad3160322007103&item=%2Fyui%2F2.7.0%2Fbuild%2Fyahoo-dom-event%2Fyahoo-dom-event.js&item=%2Fyui%2F2.7.0%2Fbuild%2Fconnection%2Fconnection-min.js&item=%2Fyui%2F2.7.0%2Fbuild%2Felement%2Felement-min.js&item=%2Fyui%2F2.7.0%2Fbuild%2Fjson%2Fjson-min.js&item=%2Fyui%2F2.7.0%2Fbuild%2Fcontainer%2Fcontainer-min.js&item=%2Fyui%2F2.7.0%2Fbuild%2Fcalendar%2Fcalendar-min.js&item=%2Fyui%2F2.7.0%2Fbuild%2Fanimation%2Fanimation-min.js&item=%2Fyui%2F2.7.0%2Fbuild%2Fdatasource%2Fdatasource-min.js&item=%2Fyui%2F2.7.0%2Fbuild%2Fautocomplete%2Fautocomplete-min.js&item=%2Fyui%2F2.7.0%2Fbuild%2Fcookie%2Fcookie-min.js&item=%2Fjs%2Fantlr3-all-min.js&item=%2Fjs%2Fswfobject-1.5.js&item=%2Fjs%2Ffitbit.js&item=%2Fjs%2Fapp.js&item=%2Fjs%2Futil.js&item=%2Fjs%2Fpremium.js"></script>
262
+
263
+ <!--[if IE 6]>
264
+ <script type="text/javascript">document.execCommand("BackgroundImageCache", false, true);</script>
265
+ <![endif]-->
266
+ <!--[if lt IE 9]>
267
+ <script type="text/javascript" src="/pack?h=4db94e3559545453a61eca38533ab82c&item=%2Fjs%2Flib%2Fcurvycorners%2Fcurvycorners.src.js"></script>
268
+ <![endif]-->
269
+
270
+ <script type="text/javascript">
271
+ document.forms['signup'].elements['timezone'].value = (new Date().getTimezoneOffset() / 60) * -1;
272
+
273
+ setTimeout(function(){try{document.forms['login'].elements['email'].focus();}catch(e){}},1);
274
+
275
+ function viewForgotPassword() {
276
+ document.forms['forgotPassword'].elements['email'].value = document.forms['login'].elements['email'].value;
277
+ document.forms['forgotPassword'].submit();
278
+ }
279
+ </script>
280
+
281
+
282
+
283
+
284
+ <script type="text/javascript">
285
+ /*
286
+ Inserts GA using DOM insertion of <script> tag and "script onload" method to
287
+ initialize the pageTracker object. Prevents GA insertion from blocking I/O!
288
+
289
+ As suggested in Steve Souder's talk. See:
290
+ http://google-code-updates.blogspot.com/2009/03/steve-souders-lifes-too-short-write.html
291
+ */
292
+
293
+ /* acct is GA account number, i.e. "UA-5555555-1" */
294
+ function gaSSDSLoad (acct) {
295
+ var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."),
296
+ pageTracker,
297
+ s;
298
+ s = document.createElement('script');
299
+ s.src = gaJsHost + 'google-analytics.com/ga.js';
300
+ s.type = 'text/javascript';
301
+ s.onloadDone = false;
302
+ function init () {
303
+ pageTracker = _gat._getTracker(acct);
304
+
305
+ pageTracker._setCustomVar(1, "visitorType", "notloggedin", 1);
306
+
307
+
308
+ pageTracker._trackPageview();
309
+ }
310
+ s.onload = function () {
311
+ s.onloadDone = true;
312
+ init();
313
+ };
314
+ s.onreadystatechange = function() {
315
+ if (('loaded' === s.readyState || 'complete' === s.readyState) && !s.onloadDone) {
316
+ s.onloadDone = true;
317
+ init();
318
+ }
319
+ };
320
+ document.getElementsByTagName('head')[0].appendChild(s);
321
+ }
322
+
323
+ /* and run it */
324
+ gaSSDSLoad("UA-2595270-1");
325
+ </script>
326
+ </body>
327
+ </html>
@@ -1,7 +1,84 @@
1
- require 'helper'
1
+ require File.expand_path('./helper', File.dirname(__FILE__))
2
+ require 'webmock/test_unit'
3
+ #require 'vcr'
4
+ require 'ruby-fitbit'
5
+ require 'mocha'
2
6
 
3
7
  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"
8
+ include WebMock
9
+
10
+ #VCR.config do |c|
11
+ # c.cassette_library_dir = 'fixtures/vcr_cassettes'
12
+ # c.http_stubbing_library = :webmock
13
+ #end
14
+
15
+ #TODO this is a mess it took awhile to figure out a way to make the tests work at all clean this up
16
+
17
+ HEADERS = <<END
18
+ HTTP/1.1 200 OK
19
+ Server: Apache-Coyote/1.1
20
+ Expires: Thu, 01 Jan 1970 00:00:00 GMT
21
+ Cache-control: no-store, no-cache, must-revalidate
22
+ Pragma: no-cache
23
+ Content-Type: text/html;charset=UTF-8
24
+ Content-Language: en-US
25
+ Transfer-Encoding: chunked
26
+ Date: Mon, 19 Jul 2010 00:49:32 GMT
27
+ END
28
+
29
+ def fake_login
30
+ # Created a response via
31
+ #`curl -is https://www.fitbit.com/login > ./test/responses/loginpage.txt`
32
+ raw_response_file = File.new("./test/responses/loginpage.txt")
33
+ stub_request(:get, "https://www.fitbit.com/login").to_return(raw_response_file)
6
34
  end
35
+
36
+ should "initialize" do
37
+ fake_login
38
+
39
+ response = <<END
40
+ #{HEADERS}
41
+ <div class="accountLinks">
42
+
43
+ <ul>
44
+ <li>Hi <a href="/user/22FAKE" style="border: 0; padding: 0;">dan@fake.com</a></li>
45
+ </ul></div>
46
+ END
47
+
48
+ stub_request(:post, "https://www.fitbit.com/login").to_return(response)
49
+ RubyFitbit.any_instance.stubs(:get_data)
50
+ fitbit = RubyFitbit.new("not@fake.com","pass")
51
+ fitbit.login
52
+ assert fitbit.logged_in
53
+
54
+ def fitbit.userId
55
+ @userId
56
+ end
57
+ assert_equal "22FAKE", fitbit.userId
58
+ end
59
+
60
+ should "get data" do
61
+ fake_login
62
+ data = File.read("./test/responses/data.txt")
63
+ response = "#{HEADERS} #{data}"
64
+
65
+ stub_request(:get, "https://www.fitbit.com/2010/07/18").to_return(response)
66
+
67
+ RubyFitbit.any_instance.stubs(:login)
68
+ fitbit = RubyFitbit.new("fake@fake.com","pass")
69
+ def fitbit.set_logged_in(val)
70
+ @logged_in = val
71
+ end
72
+ fitbit.set_logged_in(true)
73
+
74
+ assert_equal "1928", fitbit.calories, "wrong calories"
75
+ assert_equal "7821", fitbit.steps, "wrong steps"
76
+ assert_equal "3.38", fitbit.miles_walked, "wrong miles"
77
+ assert_equal "16hrs 58min", fitbit.sedentary_active, "wrong sedentary"
78
+ assert_equal "1hr 42min", fitbit.lightly_active, "wrong lightly"
79
+ assert_equal "1hr 51min", fitbit.fairly_active, "wrong fairly"
80
+ assert_equal "17min", fitbit.very_active, "wrong very"
81
+
82
+ end
83
+
7
84
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 1
9
- version: 0.2.1
8
+ - 2
9
+ version: 0.2.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Dan Mayer
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-07-10 00:00:00 -04:00
17
+ date: 2010-07-20 00:00:00 -04:00
18
18
  default_executable: ruby-fitbit
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -91,6 +91,8 @@ files:
91
91
  - lib/ruby-fitbit.rb
92
92
  - ruby-fitbit.gemspec
93
93
  - test/helper.rb
94
+ - test/responses/data.txt
95
+ - test/responses/loginpage.txt
94
96
  - test/test_ruby-fitbit.rb
95
97
  has_rdoc: true
96
98
  homepage: http://github.com/danmayer/ruby-fitbit