simplificator-withings 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.rdoc +64 -6
- data/Rakefile +1 -35
- data/lib/withings/measurement_group.rb +3 -13
- data/lib/withings/user.rb +7 -15
- data/simplificator-withings.gemspec +59 -0
- data/test/users_test.rb +3 -3
- metadata +6 -10
- data/.gitignore +0 -22
- data/VERSION +0 -1
- data/sample.rb +0 -29
- data/test/test_simplificator-withings.rb +0 -7
data/README.rdoc
CHANGED
@@ -2,20 +2,74 @@
|
|
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
|
+
== Status
|
6
|
+
The gem is still under development and the API might change a bit.
|
5
7
|
|
6
|
-
== Installation
|
8
|
+
== Installation
|
7
9
|
|
8
10
|
gem install simplificator-withings
|
9
11
|
|
12
|
+
== Authentication
|
10
13
|
|
11
|
-
|
14
|
+
The WBS API provides a way to login by user_id and public_key. You can either ask your users to enter the user_id/public_key manually
|
15
|
+
(they can be found in the sharing overlay on my.withings.com) or ask them for email/password once and then use those credentials
|
16
|
+
to authenticate through the API (User.authenticate(email, password)). The User instance returned will have the
|
17
|
+
user_id and public_key attributes populated and you can store them for further use.
|
12
18
|
|
13
|
-
|
19
|
+
As soon as you have user_id/public_key available you can either use User.info or User.new to create a User instance. While User.info
|
20
|
+
will make an API call to populate the attributes, User.new just requires user_id/public_key.
|
21
|
+
|
22
|
+
== Remarks
|
23
|
+
|
24
|
+
* Authentication by user_id/public_key is only supported when the user has activated sharing. He can do this either in the sharing overlay on my.withings.com or through the api (user.share = true) after authentication by email/password
|
25
|
+
* As soon as the user sets sharing to false (user.share = false) the public_key is reset and upon next activation of sharing (user.share = true) a new public_key is assigned.
|
26
|
+
* All the methods making remote calls can throw Withing::ApiError if something goes wrong (wrong public_key, missing parameters, ...). You can find more details on the error by looking at the status code in the error.
|
27
|
+
|
28
|
+
== How To
|
29
|
+
|
30
|
+
Require the API implementation
|
31
|
+
|
32
|
+
require 'rubygems'
|
33
|
+
require 'withings'
|
34
|
+
|
35
|
+
All classes are name-spaced, if your other code allows you can include Withings
|
36
|
+
|
37
|
+
include Withings
|
38
|
+
|
39
|
+
A user can be authenticated with email address and password
|
40
|
+
|
41
|
+
user = User.authenticate('<YOUR EMAIL ADDRESS>', '<YOUR PASSWORD>')
|
42
|
+
|
43
|
+
Or you can fetch details if you have the user id and public key
|
44
|
+
|
45
|
+
user = User.info('<YOUR USER ID>', '<YOUR PUBLIC KEY>')
|
46
|
+
|
47
|
+
If you already have user id and public key and you do not need further information on the user
|
48
|
+
|
49
|
+
user = User.new(:user_id => '<YOUR USER ID>', :public_key => '<YOUR PUBLIC_KEY>')
|
50
|
+
|
51
|
+
enable/disable sharing, disabling it will reset the public key
|
52
|
+
|
53
|
+
user.share=true
|
54
|
+
|
55
|
+
You can handle subscriptions through the API
|
56
|
+
|
57
|
+
user.subscribe_notification('http://foo.bar.com', 'test subscription')
|
58
|
+
user.describe_notification('http://foo.bar.com')
|
59
|
+
user.revoke_notification('http://foo.bar.com')
|
60
|
+
|
61
|
+
And finally you can get measurements, after all it's a scale
|
62
|
+
|
63
|
+
user.measurement_groups(:per_page => 10, :page => 1, :end_at => Time.now)
|
64
|
+
user.measurement_groups(:category => MeasurementGroup::CATEGORY_TARGET)
|
65
|
+
user.measurement_groups(:last_updated_at => Time.at(12345))
|
66
|
+
user.measurement_groups(:start_at => Time.at(12345), :end_at => Time.at(67890))
|
67
|
+
user.measurement_groups(:measurement_type => MeasurementGroup::TYPE_FAT)
|
14
68
|
|
15
69
|
== Note on keys in hashes
|
16
70
|
|
17
71
|
Keys to constructors (User, MeasurementGroup and NotificationDescription) and methods (User.measurement_groups)
|
18
|
-
can be either
|
72
|
+
can be either String or Symbol
|
19
73
|
|
20
74
|
== Note on naming convention
|
21
75
|
|
@@ -25,8 +79,6 @@ The constructors for User, MeasurementGroup and NotificationDescription accept t
|
|
25
79
|
to a more "ruby" way.
|
26
80
|
An exception to this are the "id" and "publickey" parameters for User.new, they are accepted as "user_id" and "public_key" as well.
|
27
81
|
|
28
|
-
|
29
|
-
|
30
82
|
== Note on Patches/Pull Requests
|
31
83
|
|
32
84
|
* Fork the project.
|
@@ -37,6 +89,12 @@ An exception to this are the "id" and "publickey" parameters for User.new, they
|
|
37
89
|
(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)
|
38
90
|
* Send me a pull request. Bonus points for topic branches.
|
39
91
|
|
92
|
+
== Dependencies
|
93
|
+
|
94
|
+
HTTParty is used for making the HTTP requests and Shoulda and Mocha are used for testing.
|
95
|
+
Thanks for these Gems.
|
96
|
+
|
97
|
+
|
40
98
|
== Copyright
|
41
99
|
|
42
100
|
Copyright (c) 2010 simplificator. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -1,47 +1,13 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake'
|
3
3
|
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "simplificator-withings"
|
8
|
-
gem.summary = %Q{API implementation for withings.com}
|
9
|
-
gem.description = %Q{A withings API implementation in ruby. Created for the evita project}
|
10
|
-
gem.email = "info@simplificator.com"
|
11
|
-
gem.homepage = "http://github.com/simplificator/simplificator-withings"
|
12
|
-
gem.authors = ["pascalbetz"]
|
13
|
-
gem.add_development_dependency 'shoulda'
|
14
|
-
gem.add_development_dependency 'mocha'
|
15
|
-
gem.add_dependency('httparty')
|
16
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
-
end
|
18
|
-
Jeweler::GemcutterTasks.new
|
19
|
-
rescue LoadError
|
20
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
-
end
|
22
|
-
|
23
4
|
require 'rake/testtask'
|
24
5
|
Rake::TestTask.new(:test) do |test|
|
25
6
|
test.libs << 'lib' << 'test'
|
26
|
-
test.pattern = 'test
|
7
|
+
test.pattern = 'test/**/*_test.rb'
|
27
8
|
test.verbose = true
|
28
9
|
end
|
29
10
|
|
30
|
-
begin
|
31
|
-
require 'rcov/rcovtask'
|
32
|
-
Rcov::RcovTask.new do |test|
|
33
|
-
test.libs << 'test'
|
34
|
-
test.pattern = 'test/**/test_*.rb'
|
35
|
-
test.verbose = true
|
36
|
-
end
|
37
|
-
rescue LoadError
|
38
|
-
task :rcov do
|
39
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
task :test => :check_dependencies
|
44
|
-
|
45
11
|
task :default => :test
|
46
12
|
|
47
13
|
require 'rake/rdoctask'
|
@@ -14,7 +14,7 @@ class Withings::MeasurementGroup
|
|
14
14
|
TYPE_FAT_MASS_WEIGHT = 8
|
15
15
|
|
16
16
|
attr_reader :group_id, :attribution, :created_at, :category
|
17
|
-
attr_reader :weight, :height, :fat
|
17
|
+
attr_reader :weight, :height, :fat, :ratio, :fat_free
|
18
18
|
def initialize(params)
|
19
19
|
params = params.keys_as_string
|
20
20
|
@group_id = params['grpid']
|
@@ -27,7 +27,8 @@ class Withings::MeasurementGroup
|
|
27
27
|
when TYPE_WEIGHT then @weight = value
|
28
28
|
when TYPE_SIZE then @height = value
|
29
29
|
when TYPE_FAT_MASS_WEIGHT then @fat = value
|
30
|
-
when TYPE_FAT_RATIO
|
30
|
+
when TYPE_FAT_RATIO then @ratio = value
|
31
|
+
when TYPE_FAT_FREE_MASS_WEIGHT then @fat_free = value
|
31
32
|
else raise "Unknown #{measure.inspect}"
|
32
33
|
end
|
33
34
|
end
|
@@ -41,17 +42,6 @@ class Withings::MeasurementGroup
|
|
41
42
|
self.category == CATEGORY_TARGET
|
42
43
|
end
|
43
44
|
|
44
|
-
# while fat_ratio and fat_free_mass_weight is provided by the API as well i've seen responses where they were not included. Since
|
45
|
-
# they can be calculated as soon as weight and fat is provided we do it ourselves
|
46
|
-
def fat_ratio
|
47
|
-
(self.weight / self.fat) if self.weight && self.fat
|
48
|
-
end
|
49
|
-
|
50
|
-
def fat_free_weight
|
51
|
-
(self.weight - self.fat) if self.weight && self.fat
|
52
|
-
end
|
53
|
-
|
54
|
-
|
55
45
|
def bmi
|
56
46
|
if self.height && self.weight
|
57
47
|
self.weight / (self.height ** 2)
|
data/lib/withings/user.rb
CHANGED
@@ -1,31 +1,23 @@
|
|
1
1
|
class Withings::User
|
2
|
+
attr_reader :short_name, :public_key, :user_id, :birthdate, :fat_method, :first_name, :last_name, :gender
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
else
|
7
|
-
by_user_id(email_or_user_id, password_or_public_key)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
# Authenticate by email and password
|
12
|
-
def self.by_email(email, password)
|
4
|
+
# Authenticate a user by email/password
|
5
|
+
#
|
6
|
+
def self.authenticate(email, password)
|
13
7
|
response = Connection.get_request('/account', :action => :getuserslist, :email => email, :hash => auth_hash(email, password))
|
14
8
|
User.new(response['users'].first)
|
15
9
|
end
|
16
|
-
|
17
|
-
def self.
|
10
|
+
|
11
|
+
def self.info(user_id, public_key)
|
18
12
|
response = Connection.get_request('/account', :action => :getbyuserid, :userid => user_id, :publickey => public_key)
|
19
13
|
User.new(response['users'].first)
|
20
14
|
end
|
21
15
|
|
22
16
|
|
23
|
-
attr_reader :short_name, :public_key, :user_id, :birthdate, :fat_method, :first_name, :last_name, :gender
|
24
|
-
|
25
|
-
|
26
17
|
#
|
27
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'
|
28
19
|
#
|
20
|
+
|
29
21
|
def initialize(params)
|
30
22
|
params = params.stringify_keys
|
31
23
|
@short_name = params['shortname']
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{simplificator-withings}
|
5
|
+
s.version = "0.2.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["pascalbetz"]
|
9
|
+
s.date = %q{2010-08-03}
|
10
|
+
s.description = %q{A withings API implementation in ruby. Created for the evita project}
|
11
|
+
s.email = %q{info@simplificator.com}
|
12
|
+
s.extra_rdoc_files = [
|
13
|
+
"LICENSE",
|
14
|
+
"README.rdoc"
|
15
|
+
]
|
16
|
+
s.files = [
|
17
|
+
".document",
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc",
|
20
|
+
"Rakefile",
|
21
|
+
"lib/withings.rb",
|
22
|
+
"lib/withings/base.rb",
|
23
|
+
"lib/withings/connection.rb",
|
24
|
+
"lib/withings/error.rb",
|
25
|
+
"lib/withings/measurement_group.rb",
|
26
|
+
"lib/withings/notification_description.rb",
|
27
|
+
"lib/withings/user.rb",
|
28
|
+
"simplificator-withings.gemspec",
|
29
|
+
]
|
30
|
+
s.homepage = %q{http://github.com/simplificator/simplificator-withings}
|
31
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
32
|
+
s.require_paths = ["lib"]
|
33
|
+
s.rubygems_version = %q{1.3.7}
|
34
|
+
s.summary = %q{API implementation for withings.com}
|
35
|
+
s.test_files = [
|
36
|
+
"test/helper.rb",
|
37
|
+
"test/users_test.rb",
|
38
|
+
]
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
46
|
+
s.add_development_dependency(%q<mocha>, [">= 0"])
|
47
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0"])
|
48
|
+
else
|
49
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
50
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
51
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
52
|
+
end
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
55
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
56
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
data/test/users_test.rb
CHANGED
@@ -54,11 +54,11 @@ class UsersTest < Test::Unit::TestCase
|
|
54
54
|
returns({'users' => [{}]})
|
55
55
|
end
|
56
56
|
should 'authenticate with hashed password' do
|
57
|
-
User.
|
57
|
+
User.authenticate('king@kong.com', 'kongking')
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
context '
|
61
|
+
context 'info by user_id' do
|
62
62
|
setup do
|
63
63
|
user_id = 'kongking'
|
64
64
|
public_key = 'abcdef'
|
@@ -66,7 +66,7 @@ class UsersTest < Test::Unit::TestCase
|
|
66
66
|
returns({'users' => [{}]})
|
67
67
|
end
|
68
68
|
should 'authenticate with hashed password' do
|
69
|
-
User.
|
69
|
+
User.info('kongking', 'abcdef')
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
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: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.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: 2010-08-
|
18
|
+
date: 2010-08-03 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -71,11 +71,9 @@ extra_rdoc_files:
|
|
71
71
|
- README.rdoc
|
72
72
|
files:
|
73
73
|
- .document
|
74
|
-
- .gitignore
|
75
74
|
- LICENSE
|
76
75
|
- README.rdoc
|
77
76
|
- Rakefile
|
78
|
-
- VERSION
|
79
77
|
- lib/withings.rb
|
80
78
|
- lib/withings/base.rb
|
81
79
|
- lib/withings/connection.rb
|
@@ -83,9 +81,8 @@ files:
|
|
83
81
|
- lib/withings/measurement_group.rb
|
84
82
|
- lib/withings/notification_description.rb
|
85
83
|
- lib/withings/user.rb
|
86
|
-
-
|
84
|
+
- simplificator-withings.gemspec
|
87
85
|
- test/helper.rb
|
88
|
-
- test/test_simplificator-withings.rb
|
89
86
|
- test/users_test.rb
|
90
87
|
has_rdoc: true
|
91
88
|
homepage: http://github.com/simplificator/simplificator-withings
|
@@ -123,5 +120,4 @@ specification_version: 3
|
|
123
120
|
summary: API implementation for withings.com
|
124
121
|
test_files:
|
125
122
|
- test/helper.rb
|
126
|
-
- test/test_simplificator-withings.rb
|
127
123
|
- test/users_test.rb
|
data/.gitignore
DELETED
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.1.1
|
data/sample.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'withings'
|
3
|
-
|
4
|
-
# All classes are name-spaced
|
5
|
-
include Withings
|
6
|
-
|
7
|
-
# A user can be authenticated with email address and password
|
8
|
-
user = User.authenticate('<YOUR EMAIL ADDRESS>', '<YOUR PASSWORD>')
|
9
|
-
|
10
|
-
# Or you can fetch details if you have the user id and public key
|
11
|
-
user = User.authenticate('<YOUR USER ID>', '<YOUR PUBLIC KEY>')
|
12
|
-
|
13
|
-
# or if you already have user id and public key, you can create ir yourself
|
14
|
-
user = User.new(:user_id => '<YOUR USER ID>', :public_key => '<YOUR PUBLIC_KEY>')
|
15
|
-
|
16
|
-
# enable/disable sharing, disabling it will reset the public key
|
17
|
-
user.share=true
|
18
|
-
|
19
|
-
# subscribe for notification for url and pass a description
|
20
|
-
user.subscribe_notification('http://foo.bar.com', 'test')
|
21
|
-
|
22
|
-
# describe the notification for a given url, this is important for expiration dates
|
23
|
-
user.describe_notification('http://foo.bar.com')
|
24
|
-
|
25
|
-
# revoke notification for an url
|
26
|
-
user.revoke_notification('http://foo.bar.com')
|
27
|
-
|
28
|
-
# list measurement groups
|
29
|
-
user.measurement_groups(:per_page => 10, :page => 1, :end_at => Time.now).join("\n")
|