wiscale 0.0.1 → 0.0.2

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.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/wiscale.rb +55 -0
  3. metadata +3 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -1,5 +1,60 @@
1
+ require 'rubygems'
2
+ require 'httparty'
3
+ require 'json'
4
+ require 'ostruct'
5
+
1
6
 
2
7
  class WiScale
3
8
 
9
+ def initialize(*params)
10
+ @publickey = params[0][:publickey] if params.length > 0
11
+ @userid = params[0][:userid] if params.length > 0
12
+ end
13
+
14
+ def get_status()
15
+ ret_val = JSON.parse(HTTParty.get(api_url + '/once', :query => {:action => 'probe'}))
16
+ return ret_val['status']
17
+ end
18
+
19
+ def get_once()
20
+ ret_val = JSON.parse(HTTParty.get(api_url + '/once', :query => {:action => 'get'}))
21
+ return ret_val['body']['once']
22
+ end
23
+
24
+ def get_meas(*params)
25
+ if params.length == 1
26
+ #TODO pass params to api for things like limie
27
+ ret_val = JSON.parse(HTTParty.get(api_url + '/measure', :query => {:action => 'getmeas', :userid => userid, :publickey => publickey}))
28
+ else
29
+ ret_val = JSON.parse(HTTParty.get(api_url + '/measure', :query => {:action => 'getmeas', :userid => userid, :publickey => publickey}))
30
+ end
31
+
32
+
33
+ if ret_val['status'] == 0
34
+ OpenStruct.new(ret_val['body'])
35
+ end
36
+ end
37
+
38
+ #TODO this should call get_meas(:limit=>1) once first todo is done
39
+ def get_last_meas
40
+ ret_val = JSON.parse(HTTParty.get(api_url + '/measure', :query => {:action => 'getmeas', :userid => userid, :publickey => publickey, :limit => 1}))
41
+
42
+ if ret_val['status'] == 0
43
+ return OpenStruct.new(ret_val['body'])
44
+ end
45
+ end
46
+
47
+ def api_url
48
+ @api_url || @api_url = 'http://wbsapi.withings.net'
49
+ end
50
+
51
+ def userid
52
+ @userid
53
+ end
54
+
55
+ def publickey
56
+ @publickey
57
+ end
58
+
4
59
  end
5
60
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jon
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-29 00:00:00 -04:00
17
+ date: 2010-03-30 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency