simplificator-withings 0.2.8 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +5 -4
- data/lib/withings/base.rb +2 -0
- data/lib/withings/measurement_group.rb +17 -11
- data/lib/withings/user.rb +8 -14
- data/simplificator-withings.gemspec +2 -2
- metadata +7 -7
data/README.rdoc
CHANGED
@@ -39,9 +39,9 @@ will make an API call to populate the attributes, User.new just requires user_id
|
|
39
39
|
* The gem is still under development and the API might change a bit.
|
40
40
|
* Authentication by user_id/public_key is only supported when the user has activated sharing.
|
41
41
|
He can do this either in the sharing overlay on my.withings.com or
|
42
|
-
through the api (user.share
|
42
|
+
through the api (user.share <LIST OF DEVICES>) after authentication by email/password
|
43
43
|
* As soon as the user sets sharing to false (user.share = false) the public_key is reset
|
44
|
-
and upon next activation of sharing
|
44
|
+
and upon next activation of sharing a new public_key is assigned.
|
45
45
|
* All the methods making remote calls can throw Withing::ApiError if something goes wrong
|
46
46
|
(wrong public_key, missing parameters, ...).
|
47
47
|
You can find more details on the error by looking at the status code in the error.
|
@@ -65,14 +65,15 @@ If you already have user id and public key and you do not need further informati
|
|
65
65
|
user = User.new(:user_id => '<YOUR USER ID>', :public_key => '<YOUR PUBLIC_KEY>')
|
66
66
|
|
67
67
|
enable/disable sharing, disabling it will reset the public key
|
68
|
-
user.share
|
68
|
+
user.share(Withings::SCALE, Withings::BLOOD_PRESSURE_MONITOR)
|
69
|
+
user.share(0)
|
69
70
|
|
70
71
|
You can handle subscriptions through the API
|
71
72
|
user.subscribe_notification('http://foo.bar.com', 'test subscription')
|
72
73
|
user.describe_notification('http://foo.bar.com')
|
73
74
|
user.revoke_notification('http://foo.bar.com')
|
74
75
|
|
75
|
-
And finally you can get measurements, after all it's
|
76
|
+
And finally you can get measurements, after all this is what it's for
|
76
77
|
user.measurement_groups(:per_page => 10, :page => 1, :end_at => Time.now)
|
77
78
|
user.measurement_groups(:category => MeasurementGroup::CATEGORY_TARGET)
|
78
79
|
user.measurement_groups(:last_updated_at => Time.at(12345))
|
data/lib/withings/base.rb
CHANGED
@@ -1,20 +1,23 @@
|
|
1
1
|
class Withings::MeasurementGroup
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
ATTRIBUTION_DEVICE = 0
|
3
|
+
ATTRIBUTION_DEVICE_AMBIGUOUS = 1
|
4
|
+
ATTRIBUTION_DEVICE_MANUALLY = 2
|
5
|
+
ATTRIBUTION_DEVICE_MANUALLY_DURING_CREATION = 4
|
6
6
|
|
7
7
|
CATEGORY_MEASURE = 1
|
8
8
|
CATEGORY_TARGET = 2
|
9
9
|
|
10
|
-
TYPE_WEIGHT = 1
|
11
|
-
TYPE_SIZE = 4
|
12
|
-
TYPE_FAT_FREE_MASS_WEIGHT = 5
|
13
|
-
TYPE_FAT_RATIO = 6
|
14
|
-
TYPE_FAT_MASS_WEIGHT = 8
|
10
|
+
TYPE_WEIGHT = 1 # kg
|
11
|
+
TYPE_SIZE = 4 # m
|
12
|
+
TYPE_FAT_FREE_MASS_WEIGHT = 5 # kg
|
13
|
+
TYPE_FAT_RATIO = 6 # % (unitless)
|
14
|
+
TYPE_FAT_MASS_WEIGHT = 8 # kg
|
15
|
+
TYPE_DIASTOLIC_BLOOD_PRESSURE = 9 # mmHg (min, lower)
|
16
|
+
TYPE_SYSTOLIC_BLOOD_PRESSURE = 10 # mmHg (max, upper)
|
17
|
+
TYPE_HEART_PULSE = 11 # bpm
|
15
18
|
|
16
19
|
attr_reader :group_id, :attribution, :created_at, :category
|
17
|
-
attr_reader :weight, :size, :fat, :ratio, :fat_free
|
20
|
+
attr_reader :weight, :size, :fat, :ratio, :fat_free, :diastolic_blood_pressure, :systolic_blood_pressure, :heart_pulse
|
18
21
|
def initialize(params)
|
19
22
|
params = params.stringify_keys
|
20
23
|
@group_id = params['grpid']
|
@@ -29,6 +32,9 @@ class Withings::MeasurementGroup
|
|
29
32
|
when TYPE_FAT_MASS_WEIGHT then @fat = value
|
30
33
|
when TYPE_FAT_RATIO then @ratio = value
|
31
34
|
when TYPE_FAT_FREE_MASS_WEIGHT then @fat_free = value
|
35
|
+
when TYPE_DIASTOLIC_BLOOD_PRESSURE then @diastolic_blood_pressure = value
|
36
|
+
when TYPE_SYSTOLIC_BLOOD_PRESSURE then @systolic_blood_pressure = value
|
37
|
+
when TYPE_HEART_PULSE then @heart_pulse = value
|
32
38
|
else raise "Unknown #{measure.inspect}"
|
33
39
|
end
|
34
40
|
end
|
@@ -43,7 +49,7 @@ class Withings::MeasurementGroup
|
|
43
49
|
end
|
44
50
|
|
45
51
|
def to_s
|
46
|
-
"[ Weight: #{self.weight}, Fat: #{self.fat}, Size: #{self.size}, Ratio: #{self.ratio}, Free: #{self.fat_free}, ID: #{self.group_id}]"
|
52
|
+
"[ 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.created_at.strftime("%d.%m.%Y")})]"
|
47
53
|
end
|
48
54
|
|
49
55
|
def inspect
|
data/lib/withings/user.rb
CHANGED
@@ -17,7 +17,6 @@ class Withings::User
|
|
17
17
|
#
|
18
18
|
# If you create a user yourself, then the only attributes of interest (required for calls to the API) are 'user_id' and 'public_key'
|
19
19
|
#
|
20
|
-
|
21
20
|
def initialize(params)
|
22
21
|
params = params.stringify_keys
|
23
22
|
@short_name = params['shortname']
|
@@ -25,7 +24,7 @@ class Withings::User
|
|
25
24
|
@last_name = params['lastname']
|
26
25
|
@public_key = params['publickey'] || params['public_key']
|
27
26
|
@user_id = params['id'] || params['user_id']
|
28
|
-
@share = params['ispublic']
|
27
|
+
@share = params['ispublic']
|
29
28
|
@birthdate = Time.at(params['birthdate']) if params['birthdate']
|
30
29
|
@gender = params['gender'] == 0 ? :male : params['gender'] == 1 ? :female : nil
|
31
30
|
@fat_method = params['fatmethod']
|
@@ -73,15 +72,15 @@ class Withings::User
|
|
73
72
|
end
|
74
73
|
end
|
75
74
|
|
76
|
-
|
77
|
-
|
78
|
-
@share =
|
79
|
-
connection.get_request('/user', :action => :update, :ispublic =>
|
75
|
+
def share(*devices)
|
76
|
+
devices = [Withings::SCALE, Withings::BLOOD_PRESSURE_MONITOR] if Array(devices).empty?
|
77
|
+
@share = devices.inject('|'.to_sym)
|
78
|
+
connection.get_request('/user', :action => :update, :ispublic => @share)
|
80
79
|
end
|
81
80
|
|
82
|
-
# sharing enabled?
|
83
|
-
def share?
|
84
|
-
@share
|
81
|
+
# sharing enabled for a device?
|
82
|
+
def share?(device = Withings::DEVICE_SCALE | Withings::DEVICE_BLOOD_PRESSURE_MONITOR)
|
83
|
+
@share & device
|
85
84
|
end
|
86
85
|
|
87
86
|
def to_s
|
@@ -104,9 +103,4 @@ class Withings::User
|
|
104
103
|
Withings::Connection.get_request('/once', :action => :get)['once']
|
105
104
|
end
|
106
105
|
|
107
|
-
# convert from boolean (@share) to 1/0 as required by the API
|
108
|
-
def is_public?
|
109
|
-
@share ? 1 : 0
|
110
|
-
end
|
111
|
-
|
112
106
|
end
|
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{simplificator-withings}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.3.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["pascalbetz"]
|
9
|
-
s.date = %q{
|
9
|
+
s.date = %q{2011-03-01}
|
10
10
|
s.description = %q{A withings API implementation in ruby. Created for the evita project at evita.ch}
|
11
11
|
s.email = %q{info@simplificator.com}
|
12
12
|
s.extra_rdoc_files = [
|
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:
|
5
|
-
prerelease:
|
4
|
+
hash: 19
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- pascalbetz
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-03-01 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
114
|
requirements: []
|
115
115
|
|
116
116
|
rubyforge_project:
|
117
|
-
rubygems_version: 1.
|
117
|
+
rubygems_version: 1.4.2
|
118
118
|
signing_key:
|
119
119
|
specification_version: 3
|
120
120
|
summary: API implementation for withings.com
|