wiscale 0.0.3 → 0.0.4
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/VERSION +1 -1
- data/lib/wiscale.rb +15 -1
- data/test/test_wiscale.rb +23 -0
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/lib/wiscale.rb
CHANGED
@@ -32,7 +32,8 @@ class WiScale
|
|
32
32
|
ret_val = JSON.parse(HTTParty.get(api_url + '/measure', :query => params[0]))
|
33
33
|
|
34
34
|
if ret_val['status'] == 0
|
35
|
-
|
35
|
+
measures = ret_val['body']['measuregrps'].collect { |meas| OpenStruct.new(meas) }
|
36
|
+
OpenStruct.new({:updatetime => ret_val['body']['updatetime'], :measures => measures})
|
36
37
|
else
|
37
38
|
ret_val['status']
|
38
39
|
end
|
@@ -42,6 +43,19 @@ class WiScale
|
|
42
43
|
get_meas(:limit => 1)
|
43
44
|
end
|
44
45
|
|
46
|
+
def get_by_userid
|
47
|
+
ret_val = JSON.parse(HTTParty.get(api_url + '/user', :query => {
|
48
|
+
:action => 'getbyuserid',
|
49
|
+
:userid => userid,
|
50
|
+
:publickey => publickey}))
|
51
|
+
|
52
|
+
if ret_val['status'] == 0
|
53
|
+
ret_val['body']['users'].collect { |user| OpenStruct.new(user) }
|
54
|
+
else
|
55
|
+
ret_val['status']
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
45
59
|
def api_url
|
46
60
|
@api_url || @api_url = 'http://wbsapi.withings.net'
|
47
61
|
end
|
data/test/test_wiscale.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'helper'
|
2
|
+
require 'yaml'
|
2
3
|
|
3
4
|
class TestWiscaleRuby < Test::Unit::TestCase
|
4
5
|
context "no login required" do
|
@@ -13,5 +14,27 @@ class TestWiscaleRuby < Test::Unit::TestCase
|
|
13
14
|
client = WiScale.new(:userid => '2384', :publickey => 'asdf')
|
14
15
|
assert_equal 2555, client.get_last_meas
|
15
16
|
end
|
17
|
+
|
18
|
+
should "succeed to get last measurement" do
|
19
|
+
config = YAML.load_file("credentials.yml")
|
20
|
+
client = WiScale.new(:userid => config['userid'], :publickey => config['publickey'])
|
21
|
+
|
22
|
+
assert_not_equal 2555, client.get_last_meas
|
23
|
+
end
|
16
24
|
end
|
25
|
+
|
26
|
+
context "user information" do
|
27
|
+
should "fail to get user info with invalid creds" do
|
28
|
+
client = WiScale.new(:userid => 'fake', :publickey => 'fake')
|
29
|
+
assert_equal 247, client.get_by_userid
|
30
|
+
end
|
31
|
+
|
32
|
+
should "get a single users info with valid creds" do
|
33
|
+
config = YAML.load_file("credentials.yml")
|
34
|
+
client = WiScale.new(:userid => config['userid'], :publickey => config['publickey'])
|
35
|
+
users = client.get_by_userid
|
36
|
+
assert_equal config['userid'].to_i, users[0].id.to_i
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
17
40
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 4
|
9
|
+
version: 0.0.4
|
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-
|
17
|
+
date: 2010-04-01 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|