simplificator-withings 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -9
- data/lib/withings/error.rb +1 -2
- data/lib/withings/measurement_group.rb +2 -2
- data/lib/withings/user.rb +2 -2
- data/simplificator-withings.gemspec +1 -1
- data/test/helper.rb +1 -1
- data/test/users_test.rb +2 -2
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= simplificator-withings
|
2
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
|
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
5
|
== Status
|
6
6
|
The gem is still under development and the API might change a bit.
|
@@ -28,38 +28,30 @@ will make an API call to populate the attributes, User.new just requires user_id
|
|
28
28
|
== How To
|
29
29
|
|
30
30
|
Require the API implementation
|
31
|
-
|
32
31
|
require 'rubygems'
|
33
32
|
require 'withings'
|
34
33
|
|
35
34
|
All classes are name-spaced, if your other code allows you can include Withings
|
36
|
-
|
37
35
|
include Withings
|
38
36
|
|
39
37
|
A user can be authenticated with email address and password
|
40
|
-
|
41
38
|
user = User.authenticate('<YOUR EMAIL ADDRESS>', '<YOUR PASSWORD>')
|
42
39
|
|
43
40
|
Or you can fetch details if you have the user id and public key
|
44
|
-
|
45
41
|
user = User.info('<YOUR USER ID>', '<YOUR PUBLIC KEY>')
|
46
42
|
|
47
43
|
If you already have user id and public key and you do not need further information on the user
|
48
|
-
|
49
44
|
user = User.new(:user_id => '<YOUR USER ID>', :public_key => '<YOUR PUBLIC_KEY>')
|
50
45
|
|
51
46
|
enable/disable sharing, disabling it will reset the public key
|
52
|
-
|
53
47
|
user.share=true
|
54
48
|
|
55
49
|
You can handle subscriptions through the API
|
56
|
-
|
57
50
|
user.subscribe_notification('http://foo.bar.com', 'test subscription')
|
58
51
|
user.describe_notification('http://foo.bar.com')
|
59
52
|
user.revoke_notification('http://foo.bar.com')
|
60
53
|
|
61
54
|
And finally you can get measurements, after all it's a scale
|
62
|
-
|
63
55
|
user.measurement_groups(:per_page => 10, :page => 1, :end_at => Time.now)
|
64
56
|
user.measurement_groups(:category => MeasurementGroup::CATEGORY_TARGET)
|
65
57
|
user.measurement_groups(:last_updated_at => Time.at(12345))
|
data/lib/withings/error.rb
CHANGED
@@ -7,13 +7,12 @@ class Withings::ApiError < StandardError
|
|
7
7
|
293 => "The callback URL is either absent or incorrect",
|
8
8
|
294 => "No such subscription could be deleted",
|
9
9
|
304 => "The comment is either absent or incorrect",
|
10
|
-
2554 => "Invalid Parameters . Not sure about this error message, it's not documented",
|
11
10
|
2555 => "An unknown error occurred",
|
12
11
|
}
|
13
12
|
|
14
13
|
attr_reader :status
|
15
14
|
def initialize(status)
|
16
|
-
super(STATUS_CODES[status] ||
|
15
|
+
super(STATUS_CODES[status] || "Undefined status code. We do not have any description about the code #{status}. If you know more, then please let me know.")
|
17
16
|
@status = status
|
18
17
|
end
|
19
18
|
|
@@ -16,7 +16,7 @@ class Withings::MeasurementGroup
|
|
16
16
|
attr_reader :group_id, :attribution, :created_at, :category
|
17
17
|
attr_reader :weight, :height, :fat, :ratio, :fat_free
|
18
18
|
def initialize(params)
|
19
|
-
params = params.
|
19
|
+
params = params.stringify_keys
|
20
20
|
@group_id = params['grpid']
|
21
21
|
@attribution = params['attrib']
|
22
22
|
@created_at = Time.at(params['date'])
|
@@ -49,7 +49,7 @@ class Withings::MeasurementGroup
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def to_s
|
52
|
-
"[ Weight: #{self.weight}, Fat: #{self.fat}, Height: #{self.height}, BMI: #{self.bmi}, Ratio: #{self.
|
52
|
+
"[ Weight: #{self.weight}, Fat: #{self.fat}, Height: #{self.height}, BMI: #{self.bmi}, Ratio: #{self.ratio}, Free: #{self.fat_free}, ID: #{self.group_id}]"
|
53
53
|
end
|
54
54
|
|
55
55
|
def inspect
|
data/lib/withings/user.rb
CHANGED
@@ -9,7 +9,7 @@ class Withings::User
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.info(user_id, public_key)
|
12
|
-
response = Connection.get_request('/
|
12
|
+
response = Connection.get_request('/user', :action => :getbyuserid, :userid => user_id, :publickey => public_key)
|
13
13
|
User.new(response['users'].first)
|
14
14
|
end
|
15
15
|
|
@@ -31,7 +31,7 @@ class Withings::User
|
|
31
31
|
@fat_method = params['fatmethod']
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
34
|
+
def subscribe_notification(callback_url, description)
|
35
35
|
connection.get_request('/notify', :action => :subscribe, :callbackurl => callback_url, :comment => description)
|
36
36
|
end
|
37
37
|
|
data/test/helper.rb
CHANGED
data/test/users_test.rb
CHANGED
@@ -14,7 +14,7 @@ class UsersTest < Test::Unit::TestCase
|
|
14
14
|
|
15
15
|
should 'subscribe to notification' do
|
16
16
|
Withings::Connection.any_instance.expects(:get_request).with('/notify', :action => :subscribe, :callbackurl => 'http://schni.com', :comment => 'descri')
|
17
|
-
@user.
|
17
|
+
@user.subscribe_notification('http://schni.com', 'descri')
|
18
18
|
end
|
19
19
|
|
20
20
|
should 'revoke notification' do
|
@@ -62,7 +62,7 @@ class UsersTest < Test::Unit::TestCase
|
|
62
62
|
setup do
|
63
63
|
user_id = 'kongking'
|
64
64
|
public_key = 'abcdef'
|
65
|
-
Connection.expects(:get_request).with('/
|
65
|
+
Connection.expects(:get_request).with('/user', :action => :getbyuserid, :userid => user_id, :publickey => public_key).
|
66
66
|
returns({'users' => [{}]})
|
67
67
|
end
|
68
68
|
should 'authenticate with hashed password' do
|
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: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- pascalbetz
|