simplificator-withings 0.6.10 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +24 -0
- data/Gemfile +4 -0
- data/LICENSE +1 -1
- data/README.rdoc +186 -179
- data/lib/withings/base.rb +36 -34
- data/lib/withings/connection.rb +83 -86
- data/lib/withings/user.rb +111 -103
- data/simplificator-withings.gemspec +24 -55
- data/test/helper.rb +2 -6
- data/test/users_test.rb +31 -28
- metadata +52 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93725a1f1eaa8d6b32a039d4d5fa36131fbfaa8d
|
4
|
+
data.tar.gz: d3dbf54ac59121fb3b11282fbcbb54f0edaab04c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ada238f3bb8506df0af1bffec2a7f7ca7806a4b2027c6a3636b096d78280239f24ab716c5646db50b01169936fac4dace7f62940c520e48c26790bcf6d446910
|
7
|
+
data.tar.gz: 213d827e296db6820e6125bd4c7a995becf365813667d533625def10b9ff98647aa6f3ef81438dffa146c2d5eef08448790a8fde057adf9dacccc1f398ac9f64
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -1,179 +1,186 @@
|
|
1
|
-
= simplificator-withings
|
2
|
-
|
3
|
-
This is a ruby implementation for the Withings API. Description of the API can be found here: http://www.withings.com/en/api
|
4
|
-
|
5
|
-
== Versions
|
6
|
-
|
7
|
-
=== 0.
|
8
|
-
|
9
|
-
*
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
user.
|
138
|
-
user.
|
139
|
-
|
140
|
-
|
141
|
-
user.
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
user.
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
1
|
+
= simplificator-withings
|
2
|
+
|
3
|
+
This is a ruby implementation for the Withings API. Description of the API can be found here: http://www.withings.com/en/api
|
4
|
+
|
5
|
+
== Versions
|
6
|
+
|
7
|
+
=== 0.7.0
|
8
|
+
|
9
|
+
* Removed shoulda
|
10
|
+
* Fixed failing tests
|
11
|
+
* Refactored Gemspec
|
12
|
+
* Closed PR from github
|
13
|
+
|
14
|
+
=== 0.6.10
|
15
|
+
|
16
|
+
* Do not raise an exception on unknown types of measurement groups.
|
17
|
+
|
18
|
+
=== 0.6.9
|
19
|
+
|
20
|
+
* Added support for activities (thanks to invernizzi)
|
21
|
+
|
22
|
+
=== 0.6.8
|
23
|
+
|
24
|
+
* updated README (thanks to jmaddi)
|
25
|
+
|
26
|
+
=== 0.6.7
|
27
|
+
|
28
|
+
* Swap ruby-hmac for openssl
|
29
|
+
* Allow string userid in User.authenticate
|
30
|
+
|
31
|
+
=== 0.6.6
|
32
|
+
|
33
|
+
Added list_notifications method to user.
|
34
|
+
|
35
|
+
=== 0.6.3
|
36
|
+
|
37
|
+
Fixed escaping for parameters.
|
38
|
+
|
39
|
+
=== 0.6.2
|
40
|
+
|
41
|
+
Updated Readme and Gemspec
|
42
|
+
|
43
|
+
=== 0.6.0
|
44
|
+
|
45
|
+
OAuth implemented. This version is not compatible to previous releases.
|
46
|
+
Authentication via userid/publickey is not supported anymore.
|
47
|
+
|
48
|
+
=== 0.4.5
|
49
|
+
E-Mail Address is downcased before hashing it (authentication)
|
50
|
+
|
51
|
+
=== 0.4.4
|
52
|
+
Various fixes for the support of Blood Pressure Monitor
|
53
|
+
|
54
|
+
=== 0.4.0
|
55
|
+
Note that this release breaks the API of previous releases:
|
56
|
+
|
57
|
+
=== User.authenticate
|
58
|
+
|
59
|
+
User.authenticate() has been replaced by User.userlist
|
60
|
+
|
61
|
+
There is no description available and no guarantee on the order that users are returned by the API (and yes, there can be many users for a single Account)
|
62
|
+
so it seems best to leave the decision to the users of the API.
|
63
|
+
|
64
|
+
The old method is still there but please update your code. It will be removed in the next release.
|
65
|
+
|
66
|
+
=== MeasurementGroup
|
67
|
+
|
68
|
+
MeasurementGroup#created_at has been replaced by MeasurementGroup#taken_at
|
69
|
+
|
70
|
+
Created at is usually the timestamp at which a record was created. But MeasurementGroup#created_at was the timestamp when you actually took the measurement. You can also take measurements (via the Web UI on withings.com) which are for a past date. The record is created today, but the measurement
|
71
|
+
was taken on 2 weeks ago.
|
72
|
+
|
73
|
+
The old method is still there but please update your code. It will be removed in the next release.
|
74
|
+
|
75
|
+
== Installation
|
76
|
+
|
77
|
+
gem install simplificator-withings
|
78
|
+
gem install ruby-hmac
|
79
|
+
|
80
|
+
== Authentication
|
81
|
+
|
82
|
+
The WBS API now uses OAuth. See the API documentation for details.
|
83
|
+
|
84
|
+
== TODO
|
85
|
+
|
86
|
+
* Integration Test? But i don't want to share my credentials... Perhaps with a test account on withings? Solution from Withings support:
|
87
|
+
Hi,
|
88
|
+
|
89
|
+
The easiest is that you just create a regular account
|
90
|
+
(http://start.withings.com), associate it with one scale, then create a user
|
91
|
+
(like any regular customer).
|
92
|
+
|
93
|
+
Once this is done, the account is activated. You may then go to My
|
94
|
+
account/My scale and dissociate the scale, the account will stay opened.
|
95
|
+
That account may be used by who ever you think it should for test purposes
|
96
|
+
and will not be associated to a specific scale.
|
97
|
+
|
98
|
+
Thanks for your enquiry !
|
99
|
+
|
100
|
+
fred
|
101
|
+
|
102
|
+
== Remarks
|
103
|
+
|
104
|
+
* The gem is still under development and the API might change a bit.
|
105
|
+
* Authentication by user_id/public_key is only supported when the user has activated sharing.
|
106
|
+
He can do this either in the sharing overlay on my.withings.com or
|
107
|
+
through the api (user.share <LIST OF DEVICES>) after authentication by email/password
|
108
|
+
* As soon as the user sets sharing to false (user.share = false) the public_key is reset
|
109
|
+
and upon next activation of sharing a new public_key is assigned.
|
110
|
+
* All the methods making remote calls can throw Withing::ApiError if something goes wrong
|
111
|
+
(wrong public_key, missing parameters, ...).
|
112
|
+
You can find more details on the error by looking at the status code in the error.
|
113
|
+
|
114
|
+
== How To
|
115
|
+
|
116
|
+
Require the API implementation
|
117
|
+
require 'rubygems'
|
118
|
+
require 'withings'
|
119
|
+
|
120
|
+
All classes are name-spaced, if your other code allows you can include Withings
|
121
|
+
include Withings
|
122
|
+
|
123
|
+
Setup
|
124
|
+
Withings.consumer_secret = '1234'
|
125
|
+
Withings.consumer_key = 'abcd'
|
126
|
+
|
127
|
+
|
128
|
+
A user can be authenticated using user id and oauth token/secret
|
129
|
+
user = User.authenticate('<YOUR USER ID>', '<YOUR OAUTH TOKEN>', '<YOUR OAUTH TOKEN SECRET>')
|
130
|
+
|
131
|
+
|
132
|
+
You can handle subscriptions through the API (all devices currently known => Scale + Blood Pressure Monitor)
|
133
|
+
user.subscribe_notification('http://foo.bar.com', 'test subscription')
|
134
|
+
Specify what devices you are interested
|
135
|
+
user.subscribe_notification('http://foo.bar.com', 'test subscription', Withings::SCALE, Withings::BLOOD_PRESSURE_MONITOR)
|
136
|
+
|
137
|
+
user.describe_notification('http://foo.bar.com')
|
138
|
+
user.revoke_notification('http://foo.bar.com')
|
139
|
+
|
140
|
+
List notifications is now possible
|
141
|
+
user.list_notifications
|
142
|
+
|
143
|
+
And finally you can get measurements, after all this is what it's for
|
144
|
+
user.measurement_groups(:per_page => 10, :page => 1, :end_at => Time.now)
|
145
|
+
user.measurement_groups(:category => MeasurementGroup::CATEGORY_TARGET)
|
146
|
+
user.measurement_groups(:last_updated_at => Time.at(12345))
|
147
|
+
user.measurement_groups(:start_at => Time.at(12345), :end_at => Time.at(67890))
|
148
|
+
user.measurement_groups(:measurement_type => MeasurementGroup::TYPE_FAT)
|
149
|
+
user.measurement_groups(:device => Withings::SCALE)
|
150
|
+
|
151
|
+
Since 0.6.9 you can also get activities
|
152
|
+
user.get_activities
|
153
|
+
|
154
|
+
|
155
|
+
== Note on keys in hashes
|
156
|
+
|
157
|
+
Keys to constructors (User, MeasurementGroup and NotificationDescription) and methods (User.measurement_groups)
|
158
|
+
can be either String or Symbol
|
159
|
+
|
160
|
+
== Note on naming convention
|
161
|
+
|
162
|
+
The WBS API has parameter with shortened names (e.g. 'grpid') or names not following a consistent naming pattern. While this
|
163
|
+
API implementation tries to stick as close to the API as possible it also tries to unify and simplify the parameter names.
|
164
|
+
The constructors for User, MeasurementGroup and NotificationDescription accept the names provided by the API but convert the names then
|
165
|
+
to a more "ruby" way.
|
166
|
+
An exception to this are the "id" and "publickey" parameters for User.new, they are accepted as "user_id" and "public_key" as well.
|
167
|
+
|
168
|
+
== Note on Patches/Pull Requests
|
169
|
+
|
170
|
+
* Fork the project.
|
171
|
+
* Make your feature addition or bug fix.
|
172
|
+
* Add tests for it. This is important so I don't break it in a
|
173
|
+
future version unintentionally.
|
174
|
+
* Commit, do not mess with rakefile, version, or history.
|
175
|
+
(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)
|
176
|
+
* Send me a pull request. Bonus points for topic branches.
|
177
|
+
|
178
|
+
== Dependencies
|
179
|
+
|
180
|
+
HTTParty is used for making the HTTP requests and Shoulda and Mocha are used for testing.
|
181
|
+
Thanks for these Gems.
|
182
|
+
|
183
|
+
|
184
|
+
== Copyright
|
185
|
+
|
186
|
+
Copyright (c) 2012 simplificator. See LICENSE for details.
|
data/lib/withings/base.rb
CHANGED
@@ -1,34 +1,36 @@
|
|
1
|
-
module Withings
|
2
|
-
SCALE = 1
|
3
|
-
BLOOD_PRESSURE_MONITOR = 4
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
1
|
+
module Withings
|
2
|
+
SCALE = 1
|
3
|
+
BLOOD_PRESSURE_MONITOR = 4
|
4
|
+
PULSE = 16
|
5
|
+
SLEEP_MONITOR = 32
|
6
|
+
|
7
|
+
def self.consumer_secret=(value)
|
8
|
+
@consumer_secret = value
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.consumer_secret
|
12
|
+
raise 'Please specify consumer_secret' unless @consumer_secret
|
13
|
+
@consumer_secret
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.consumer_key=(value)
|
17
|
+
@consumer_key = value
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.consumer_key
|
21
|
+
raise 'Please specify consumer_key' unless @consumer_key
|
22
|
+
@consumer_key
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Copied over from ActiveSupport
|
27
|
+
unless Hash.new.respond_to?(:stringify_keys)
|
28
|
+
class Hash
|
29
|
+
def stringify_keys
|
30
|
+
inject({}) do |options, (key, value)|
|
31
|
+
options[key.to_s] = value
|
32
|
+
options
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|