wiscale 0.0.4 → 0.1.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/.gitignore +1 -0
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/credentials.yml.example +4 -0
- data/lib/wiscale.rb +68 -5
- data/test/test_wiscale.rb +29 -2
- metadata +16 -3
data/.gitignore
CHANGED
data/Rakefile
CHANGED
@@ -11,6 +11,7 @@ begin
|
|
11
11
|
gem.homepage = "http://github.com/jgaudette/wiscale"
|
12
12
|
gem.authors = ["Jon Gaudette"]
|
13
13
|
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
+
gem.add_development_dependency "httparty"
|
14
15
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
16
|
end
|
16
17
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/lib/wiscale.rb
CHANGED
@@ -2,8 +2,13 @@ require 'rubygems'
|
|
2
2
|
require 'httparty'
|
3
3
|
require 'json'
|
4
4
|
require 'ostruct'
|
5
|
+
require 'digest/md5'
|
5
6
|
|
6
|
-
|
7
|
+
# See API documentation for more information on return values
|
8
|
+
# http://www.withings.com/en/api/bodyscale
|
9
|
+
#
|
10
|
+
# OpenStruct used when returning the 'body' information from api
|
11
|
+
# Individual sub-measurements are returned as array of hashes
|
7
12
|
class WiScale
|
8
13
|
|
9
14
|
def initialize(*params)
|
@@ -39,10 +44,6 @@ class WiScale
|
|
39
44
|
end
|
40
45
|
end
|
41
46
|
|
42
|
-
def get_last_meas
|
43
|
-
get_meas(:limit => 1)
|
44
|
-
end
|
45
|
-
|
46
47
|
def get_by_userid
|
47
48
|
ret_val = JSON.parse(HTTParty.get(api_url + '/user', :query => {
|
48
49
|
:action => 'getbyuserid',
|
@@ -56,6 +57,68 @@ class WiScale
|
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
60
|
+
def get_users_list(email, passwd)
|
61
|
+
hash = compute_hash(email, passwd)
|
62
|
+
ret_val = JSON.parse(HTTParty.get(api_url + '/account', :query => {:action => 'getuserslist', :email => email, :hash => hash}))
|
63
|
+
|
64
|
+
if ret_val['status'] == 0
|
65
|
+
ret_val['body']['users'].collect { |user| OpenStruct.new(user) }
|
66
|
+
else
|
67
|
+
ret_val['status']
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def user_update(ispublic)
|
72
|
+
ret_val = JSON.parse(HTTParty.get(api_url + '/user', :query => {:action => 'update', :userid => userid, :publickey => publickey, :ispublic => ispublic}))
|
73
|
+
|
74
|
+
ret_val['status']
|
75
|
+
end
|
76
|
+
|
77
|
+
def notify_subscribe(callbackurl, comment)
|
78
|
+
ret_val = JSON.parse(HTTParty.get(api_url + '/notify', :query => {
|
79
|
+
:action => 'subscribe',
|
80
|
+
:userid => userid,
|
81
|
+
:publickey => publickey,
|
82
|
+
:callbackurl => URI.encode(callbackurl),
|
83
|
+
:comment => comment
|
84
|
+
}))
|
85
|
+
|
86
|
+
ret_val['status']
|
87
|
+
end
|
88
|
+
|
89
|
+
def notify_revoke(callbackurl)
|
90
|
+
ret_val = JSON.parse(HTTParty.get(api_url + '/notify', :query => {
|
91
|
+
:action => 'revoke',
|
92
|
+
:userid => userid,
|
93
|
+
:publickey => publickey,
|
94
|
+
:callbackurl => URI.encode(callbackurl)
|
95
|
+
}))
|
96
|
+
|
97
|
+
ret_val['status']
|
98
|
+
end
|
99
|
+
|
100
|
+
def notify_get(callbackurl)
|
101
|
+
ret_val = JSON.parse(HTTParty.get(api_url + '/notify', :query => {
|
102
|
+
:action => 'get',
|
103
|
+
:userid => userid,
|
104
|
+
:publickey => publickey,
|
105
|
+
:callbackurl => URI.encode(callbackurl)
|
106
|
+
}))
|
107
|
+
|
108
|
+
if ret_val['status'] == 0
|
109
|
+
OpenStruct.new(ret_val['body'])
|
110
|
+
else
|
111
|
+
ret_val['status']
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def compute_hash(email, passwd)
|
116
|
+
once = get_once
|
117
|
+
hash = email + ':' + Digest::MD5::hexdigest(passwd) + ':' + once
|
118
|
+
|
119
|
+
Digest::MD5::hexdigest(hash)
|
120
|
+
end
|
121
|
+
|
59
122
|
def api_url
|
60
123
|
@api_url || @api_url = 'http://wbsapi.withings.net'
|
61
124
|
end
|
data/test/test_wiscale.rb
CHANGED
@@ -12,14 +12,14 @@ class TestWiscaleRuby < Test::Unit::TestCase
|
|
12
12
|
context "invalid login" do
|
13
13
|
should "fail to get last measurement" do
|
14
14
|
client = WiScale.new(:userid => '2384', :publickey => 'asdf')
|
15
|
-
assert_equal 2555, client.
|
15
|
+
assert_equal 2555, client.get_meas()
|
16
16
|
end
|
17
17
|
|
18
18
|
should "succeed to get last measurement" do
|
19
19
|
config = YAML.load_file("credentials.yml")
|
20
20
|
client = WiScale.new(:userid => config['userid'], :publickey => config['publickey'])
|
21
21
|
|
22
|
-
assert_not_equal 2555, client.
|
22
|
+
assert_not_equal 2555, client.get_meas(:limit => 1)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -37,4 +37,31 @@ class TestWiscaleRuby < Test::Unit::TestCase
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
context "callback subscriptions" do
|
41
|
+
should "subscribe and revoke callback information" do
|
42
|
+
comment_str = 'testing'
|
43
|
+
config = YAML.load_file("credentials.yml")
|
44
|
+
client = WiScale.new(:userid => config['userid'], :publickey => config['publickey'])
|
45
|
+
|
46
|
+
assert_equal 0, client.notify_subscribe('http://www.myhackerdiet.com', comment_str)
|
47
|
+
assert_equal 0, client.notify_revoke('http://www.myhackerdiet.com')
|
48
|
+
|
49
|
+
# Revoking again should yield return code 294 -- 'No such subscription could be deleted'
|
50
|
+
assert_equal 294, client.notify_revoke('http://www.myhackerdiet.com')
|
51
|
+
end
|
52
|
+
|
53
|
+
should "subscribe and get callback information, then revoke" do
|
54
|
+
comment_str = 'testing'
|
55
|
+
config = YAML.load_file("credentials.yml")
|
56
|
+
client = WiScale.new(:userid => config['userid'], :publickey => config['publickey'])
|
57
|
+
|
58
|
+
assert_equal 0, client.notify_subscribe('http://www.myhackerdiet.com', comment_str)
|
59
|
+
|
60
|
+
subscription = client.notify_get('http://www.myhackerdiet.com')
|
61
|
+
assert_equal comment_str, subscription.comment
|
62
|
+
|
63
|
+
assert_equal 0, client.notify_revoke('http://www.myhackerdiet.com')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
40
67
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
|
9
|
-
version: 0.0.4
|
9
|
+
version: 0.1.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jon Gaudette
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-05 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -29,6 +29,18 @@ dependencies:
|
|
29
29
|
version: "0"
|
30
30
|
type: :development
|
31
31
|
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: httparty
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
41
|
+
version: "0"
|
42
|
+
type: :development
|
43
|
+
version_requirements: *id002
|
32
44
|
description: Ruby Wrapper for Withings Wifi Scale API
|
33
45
|
email: jon@digital-drip.com
|
34
46
|
executables: []
|
@@ -45,6 +57,7 @@ files:
|
|
45
57
|
- README.rdoc
|
46
58
|
- Rakefile
|
47
59
|
- VERSION
|
60
|
+
- credentials.yml.example
|
48
61
|
- lib/wiscale.rb
|
49
62
|
- test/helper.rb
|
50
63
|
- test/test_wiscale.rb
|