simplificator-withings 0.3.4 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +26 -1
- data/lib/withings/measurement_group.rb +7 -3
- data/lib/withings/user.rb +19 -3
- data/simplificator-withings.gemspec +1 -1
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -2,6 +2,28 @@
|
|
2
2
|
|
3
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
4
|
|
5
|
+
== Versions ==
|
6
|
+
|
7
|
+
Note that this release (0.4.0) breaks the API of previous releases:
|
8
|
+
|
9
|
+
=== User.authenticate ===
|
10
|
+
|
11
|
+
User.authenticate() has been replaced by User.userlist
|
12
|
+
|
13
|
+
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)
|
14
|
+
so it seems best to leave the decision to the users of the API.
|
15
|
+
|
16
|
+
The old method is still there but please update your code. It will be removed in the next release.
|
17
|
+
|
18
|
+
=== MeasurementGroup ===
|
19
|
+
|
20
|
+
MeasurementGroup#createt_at has been replaced by MeasurementGroup#taken_on
|
21
|
+
|
22
|
+
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
|
23
|
+
was taken on 2 weeks ago.
|
24
|
+
|
25
|
+
The old method is still there but please update your code. It will be removed in the next release.
|
26
|
+
|
5
27
|
== Installation
|
6
28
|
|
7
29
|
gem install simplificator-withings
|
@@ -56,7 +78,7 @@ All classes are name-spaced, if your other code allows you can include Withings
|
|
56
78
|
include Withings
|
57
79
|
|
58
80
|
A user can be authenticated with email address and password
|
59
|
-
user = User.
|
81
|
+
user = User.userlist('<YOUR EMAIL ADDRESS>', '<YOUR PASSWORD>').first # or any other user which is returned
|
60
82
|
|
61
83
|
Or you can fetch details if you have the user id and public key
|
62
84
|
user = User.info('<YOUR USER ID>', '<YOUR PUBLIC KEY>')
|
@@ -65,6 +87,7 @@ If you already have user id and public key and you do not need further informati
|
|
65
87
|
user = User.new(:user_id => '<YOUR USER ID>', :public_key => '<YOUR PUBLIC_KEY>')
|
66
88
|
|
67
89
|
enable/disable sharing, disabling it will reset the public key
|
90
|
+
user.share() # share all
|
68
91
|
user.share(Withings::SCALE, Withings::BLOOD_PRESSURE_MONITOR)
|
69
92
|
user.share(0)
|
70
93
|
|
@@ -79,6 +102,8 @@ And finally you can get measurements, after all this is what it's for
|
|
79
102
|
user.measurement_groups(:last_updated_at => Time.at(12345))
|
80
103
|
user.measurement_groups(:start_at => Time.at(12345), :end_at => Time.at(67890))
|
81
104
|
user.measurement_groups(:measurement_type => MeasurementGroup::TYPE_FAT)
|
105
|
+
user.measurement_groups(:device => Withings::SCALE)
|
106
|
+
|
82
107
|
|
83
108
|
== Note on keys in hashes
|
84
109
|
|
@@ -19,13 +19,13 @@ class Withings::MeasurementGroup
|
|
19
19
|
BLOOD_PRESSURE_MONITOR_TYPES = [TYPE_DIASTOLIC_BLOOD_PRESSURE, TYPE_SYSTOLIC_BLOOD_PRESSURE, TYPE_HEART_PULSE]
|
20
20
|
SCALE_TYPES = [TYPE_WEIGHT, TYPE_SIZE, TYPE_FAT_FREE_MASS_WEIGHT, TYPE_FAT_RATIO, TYPE_FAT_MASS_WEIGHT]
|
21
21
|
|
22
|
-
attr_reader :group_id, :attribution, :
|
22
|
+
attr_reader :group_id, :attribution, :taken_at, :category
|
23
23
|
attr_reader :weight, :size, :fat, :ratio, :fat_free, :diastolic_blood_pressure, :systolic_blood_pressure, :heart_pulse
|
24
24
|
def initialize(params)
|
25
25
|
params = params.stringify_keys
|
26
26
|
@group_id = params['grpid']
|
27
27
|
@attribution = params['attrib']
|
28
|
-
@
|
28
|
+
@taken_at = Time.at(params['date'])
|
29
29
|
@category = params['category']
|
30
30
|
params['measures'].each do |measure|
|
31
31
|
value = (measure['value'] * 10 ** measure['unit']).to_f
|
@@ -43,6 +43,10 @@ class Withings::MeasurementGroup
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
+
def created_at
|
47
|
+
$stderr.puts "created_at has been deprecated in favour of taken_at. Please updated your code."
|
48
|
+
end
|
49
|
+
|
46
50
|
def measure?
|
47
51
|
self.category == CATEGORY_MEASURE
|
48
52
|
end
|
@@ -52,7 +56,7 @@ class Withings::MeasurementGroup
|
|
52
56
|
end
|
53
57
|
|
54
58
|
def to_s
|
55
|
-
"[ Weight: #{self.weight}, Fat: #{self.fat}, Size: #{self.size}, Ratio: #{self.ratio}, Free: #{self.fat_free}, Blood Pressure: #{self.diastolic_blood_pressure}/#{self.systolic_blood_pressure} @ #{self.heart_pulse}, ID: #{self.group_id} (created at: #{self.
|
59
|
+
"[ Weight: #{self.weight}, Fat: #{self.fat}, Size: #{self.size}, Ratio: #{self.ratio}, Free: #{self.fat_free}, Blood Pressure: #{self.diastolic_blood_pressure}/#{self.systolic_blood_pressure} @ #{self.heart_pulse}, ID: #{self.group_id} (created at: #{self.taken_at.strftime("%d.%m.%Y")})]"
|
56
60
|
end
|
57
61
|
|
58
62
|
def inspect
|
data/lib/withings/user.rb
CHANGED
@@ -1,9 +1,25 @@
|
|
1
1
|
class Withings::User
|
2
2
|
attr_reader :short_name, :public_key, :user_id, :birthdate, :fat_method, :first_name, :last_name, :gender
|
3
3
|
|
4
|
+
|
5
|
+
# Listing the users for this account
|
6
|
+
#
|
7
|
+
def self.userlist(email, password)
|
8
|
+
response = Withings::Connection.get_request('/account', :action => :getuserslist, :email => email, :hash => auth_hash(email, password))
|
9
|
+
response['users'].map do |item|
|
10
|
+
Withings::User.new(item)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
|
4
15
|
# Authenticate a user by email/password
|
5
16
|
#
|
6
17
|
def self.authenticate(email, password)
|
18
|
+
$stderr.puts <<-EOS
|
19
|
+
User.authenticate(email, pwd) has been deprecated in favour of User.userlist(email, pwd) as there is no description or guarantee
|
20
|
+
about the order the users are returned.
|
21
|
+
If you need the same behaviour as before: User.userlist(email, pwd).first
|
22
|
+
EOS
|
7
23
|
response = Withings::Connection.get_request('/account', :action => :getuserslist, :email => email, :hash => auth_hash(email, password))
|
8
24
|
Withings::User.new(response['users'].first)
|
9
25
|
end
|
@@ -53,7 +69,7 @@ class Withings::User
|
|
53
69
|
# - :start_at (default: empty)
|
54
70
|
# - :end_at (default: empty)
|
55
71
|
# - :last_udpated_at (default: empty)
|
56
|
-
#
|
72
|
+
# - :device (default: empty)
|
57
73
|
# Parameters are described in WBS api
|
58
74
|
def measurement_groups(params = {})
|
59
75
|
params = params.stringify_keys
|
@@ -65,7 +81,7 @@ class Withings::User
|
|
65
81
|
options[:startdate] = params['start_at'].to_i if params['start_at']
|
66
82
|
options[:enddate] = params['end_at'].to_i if params['end_at']
|
67
83
|
options[:lastupdate] = params['last_updated_at'].to_i if params['last_updated_at']
|
68
|
-
|
84
|
+
options[:devtype] = params['device'] if params['device']
|
69
85
|
response = connection.get_request('/measure', options.merge(:action => :getmeas))
|
70
86
|
response['measuregrps'].map do |group|
|
71
87
|
Withings::MeasurementGroup.new(group)
|
@@ -86,7 +102,7 @@ class Withings::User
|
|
86
102
|
def to_s
|
87
103
|
"[User #{short_name} / #{:user_id} / #{share?}]"
|
88
104
|
end
|
89
|
-
|
105
|
+
|
90
106
|
|
91
107
|
protected
|
92
108
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simplificator-withings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 3
|
9
8
|
- 4
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- pascalbetz
|