fitbit 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -48,11 +48,17 @@ After running this and successfully connecting with verifier string that is disp
48
48
 
49
49
  You can use this script to learn about the data structures that are returned from different API calls. Since this library always retrieves JSON responses and then parses it into Ruby structures, you can interrogate the response data with simple calls to hashes.
50
50
 
51
+ ## Usage in a Rails Application ##
52
+
53
+ We've started to develop an example app using the this fitbit client. See [https://github.com/whazzmaster/fitbit-client](https://github.com/whazzmaster/fitbit-client fitbit-client rails app) for more information.
54
+
51
55
  # Subscriptions #
52
56
 
53
- The Fitbit API allows for you to set up notification subscription so that when values change (via automatic syncs with the fitbit device) your applications can be notified automatically. You can set up subscriptions via the [Fitbit dev site](https://dev.fitbit.com/ 'Fitbit Developer Site') or via the API itself.
57
+ The Fitbit API allows for you to set up notification subscription so that when values change (via automatic syncs with the fitbit device) your applications can be notified automatically. You can set up a default subscription callback URL via the [Fitbit dev site](https://dev.fitbit.com/ 'Fitbit Developer Site') and then use the Subscriptions API to add or remove subscriptions for individual users.
58
+
59
+ __Currently, notification management is experimental in this gem__. We've built up code to add and remove specific types of subscriptions (foods, activities, sleep, body) but there seems to be some server-side issues with creating general, all-purpose subscriptions.
54
60
 
55
- __Currently, notification management is not supported in this gem__. We'll be moving to support that once we finish support for reading and writing the existing resources.
61
+ The docs are very fuzzy on subscription support at the moment; we definitely plan on extending this support once the backend has matured (or the online docs have improved).
56
62
 
57
63
  # FAQs #
58
64
 
@@ -71,6 +77,9 @@ I wouldn't have been able to spin up so fast without the example of twitter_oaut
71
77
 
72
78
  # Changelog #
73
79
 
80
+ * 11 April, 2011:
81
+ * Fixed an issue where blank user id's are used and an error is thrown.
82
+ * Added support for creating/removing subscriptions (this support is experimental for now, more tests coming)
74
83
  * 24 March, 2011:
75
84
  * Added logging of activities and foods
76
85
  * Added ability to add favorite activities and foods
@@ -4,5 +4,5 @@ require 'oauth'
4
4
  require 'fitbit/client'
5
5
 
6
6
  module Fitbit
7
- VERSION = "0.1.1"
7
+ VERSION = "0.2.0"
8
8
  end
@@ -81,6 +81,8 @@ module Fitbit
81
81
  end
82
82
 
83
83
  def delete(path, headers={})
84
+ p path
85
+ p headers
84
86
  headers.merge!("User-Agent" => "fitbit gem v#{Fitbit::VERSION}", "Accept-Language" => @api_unit_system)
85
87
  oauth_response = access_token.delete("/#{@api_version}#{path}", headers)
86
88
  JSON.parse(oauth_response.body)
@@ -1,8 +1,37 @@
1
1
  module Fitbit
2
2
  class Client
3
3
 
4
- def create_general_subscription(options={})
5
- url = "/user/#{@user_id}/apiSubscriptions"
4
+ def create_subscription(options={})
5
+ unless options[:type] && [:sleep,:body,:activities,:foods].include?(options[:type])
6
+ raise Error, 'Must include options[:type] (values are :activities, :foods, :sleep, and :body)'
7
+ end
8
+ base_url = "/user/#{@user_id}/#{options[:type].to_s}/apiSubscriptions"
9
+ post_subscription(base_url, options)
10
+ end
11
+
12
+ def remove_subscription(options={})
13
+ unless options[:type] && [:sleep,:body,:activities,:foods].include?(options[:type])
14
+ raise Error, 'Must include options[:type] (values are :activities, :foods, :sleep, and :body)'
15
+ end
16
+ unless options[:subscription_id]
17
+ raise Error, "Must include options[:subscription_id] to delete a subscription"
18
+ end
19
+ base_url = "/user/#{@user_id}/#{options[:type].to_s}/apiSubscriptions"
20
+ url = finalize_subscription_url(base_url, options)
21
+ headers = {}
22
+ headers['X-Fitbit-Subscriber-Id'] = options[:subscriber_id] if options[:subscriber_id]
23
+ begin
24
+ delete(url, headers)
25
+ rescue TypeError
26
+ # Deleting a subscription returns a nil response, which causes a TypeError
27
+ # when the oauth library tries to parse it.
28
+ end
29
+ end
30
+
31
+ protected
32
+
33
+ def finalize_subscription_url(base_url, options={})
34
+ url = base_url
6
35
  if options[:subscription_id]
7
36
  url += "/#{options[:subscription_id]}"
8
37
  end
@@ -11,29 +40,12 @@ module Fitbit
11
40
  else
12
41
  url += ".json"
13
42
  end
14
- # puts "Url: #{url}"
15
- # resp = post(url)
16
- # p resp
17
- end
18
-
19
- def create_food_subscription
20
-
21
- end
22
-
23
- def create_activity_subscription
24
-
25
- end
26
-
27
- def create_sleep_subscription
28
-
29
- end
30
-
31
- def create_body_subscription
32
-
43
+ url
33
44
  end
34
45
 
35
- def remove_subscription
36
-
46
+ def post_subscription(base_url, options)
47
+ url = finalize_subscription_url(base_url, options)
48
+ post(url, options)
37
49
  end
38
50
 
39
51
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: fitbit
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Zachery Moneypenny