simplificator-withings 0.2.1 → 0.2.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.
data/README.rdoc CHANGED
@@ -2,9 +2,6 @@
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.
7
-
8
5
  == Installation
9
6
 
10
7
  gem install simplificator-withings
@@ -19,8 +16,14 @@ user_id and public_key attributes populated and you can store them for further u
19
16
  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
17
  will make an API call to populate the attributes, User.new just requires user_id/public_key.
21
18
 
19
+ == TODO
20
+
21
+ * Need to test parameter generation for get measurement
22
+ * Integration Test? But i don't want to share my credentials... Perhaps with a test account on withings?
23
+
22
24
  == Remarks
23
25
 
26
+ * The gem is still under development and the API might change a bit.
24
27
  * 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
28
  * 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
29
  * 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.
data/lib/withings/user.rb CHANGED
@@ -46,25 +46,26 @@ class Withings::User
46
46
 
47
47
 
48
48
  # list measurement groups
49
- # - :per_page
50
- # - :page
51
- # - :category
52
- # - :measurement_type
53
- # - :start_at
54
- # - :end_at
55
- # - :last_udpated_at
49
+ # The limit and offset parameters are converted to will_paginate style parameters (:per_page, :page)
50
+ # - :per_page (default: 100)
51
+ # - :page (default: 1)
52
+ # - :category (default: empty)
53
+ # - :measurement_type (default: empty)
54
+ # - :start_at (default: empty)
55
+ # - :end_at (default: empty)
56
+ # - :last_udpated_at (default: empty)
56
57
  #
57
- # Parameters are described in WBS api, names are "rubyfied" (startdate -> start_at and so on)
58
+ # Parameters are described in WBS api
58
59
  def measurement_groups(params = {})
59
60
  params = params.stringify_keys
60
61
  options = {:limit => 100, :offset => 0}
61
- options[:meastype] = params[:measurement_type] if params.has_key?(:measurement_type)
62
- options[:category] = params[:category] if params.has_key?(:category)
63
- options[:limit] = params[:per_page] if params.has_key?(:per_page)
64
- options[:offset] = ((params[:page] || 1) - 1) * options[:limit]
65
- options[:startdate] = params[:start_at].to_i if params[:start_at]
66
- options[:enddate] = params[:end_at].to_i if params[:end_at]
67
- options[:lastupdate] = params[:last_update].to_i if params[:last_updated_at]
62
+ options[:limit] = params['per_page'] if params.has_key?('per_page')
63
+ options[:offset] = ((params['page'] || 1) - 1) * options[:limit]
64
+ options[:category] = params['category'] if params.has_key?('category')
65
+ options[:meastype] = params['measurement_type'] if params.has_key?('measurement_type')
66
+ options[:startdate] = params['start_at'].to_i if params['start_at']
67
+ options[:enddate] = params['end_at'].to_i if params['end_at']
68
+ options[:lastupdate] = params['last_updated_at'].to_i if params['last_updated_at']
68
69
 
69
70
  response = connection.get_request('/measure', options.merge(:action => :getmeas))
70
71
  response['measuregrps'].map do |group|
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{simplificator-withings}
5
- s.version = "0.2.1"
5
+ s.version = "0.2.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["pascalbetz"]
data/test/users_test.rb CHANGED
@@ -70,6 +70,55 @@ class UsersTest < Test::Unit::TestCase
70
70
  end
71
71
  end
72
72
 
73
+ context 'measurement_groups' do
74
+ setup do
75
+ @user = User.new(:user_id => 'lala', :public_key => 'lili')
76
+ @returns = {'measuregrps' => []}
77
+ end
78
+ should 'not require parameters' do
79
+ Connection.any_instance.expects(:get_request).with('/measure', :action => :getmeas, :limit => 100, :offset => 0).returns(@returns)
80
+ @user.measurement_groups
81
+ end
82
+ should 'set page and current_page A' do
83
+ Connection.any_instance.expects(:get_request).with('/measure', :action => :getmeas, :limit => 10, :offset => 10).returns(@returns)
84
+ @user.measurement_groups(:page => 2, :per_page => 10)
85
+ end
86
+ should 'set page and current_page B' do
87
+ Connection.any_instance.expects(:get_request).with('/measure', :action => :getmeas, :limit => 5, :offset => 15).returns(@returns)
88
+ @user.measurement_groups(:page => 4, :per_page => 5)
89
+ end
90
+ should 'set page and current_page C' do
91
+ Connection.any_instance.expects(:get_request).with('/measure', :action => :getmeas, :limit => 23, :offset => 207).returns(@returns)
92
+ @user.measurement_groups(:page => 10, :per_page => 23)
93
+ end
94
+
95
+ should 'limit the category' do
96
+ Connection.any_instance.expects(:get_request).with('/measure', :action => :getmeas, :limit => 100, :offset => 0, :category => 1).returns(@returns)
97
+ @user.measurement_groups(:page => 1, :per_page => 100, :category => 1)
98
+ end
99
+
100
+ should 'limit the measurement_type' do
101
+ Connection.any_instance.expects(:get_request).with('/measure', :action => :getmeas, :limit => 100, :offset => 0, :meastype => 1).returns(@returns)
102
+ @user.measurement_groups(:page => 1, :per_page => 100, :measurement_type => 1)
103
+ end
104
+
105
+ should 'limit start at' do
106
+ Connection.any_instance.expects(:get_request).with('/measure', :action => :getmeas, :limit => 100, :offset => 0, :startdate => 1234).returns(@returns)
107
+ @user.measurement_groups(:page => 1, :start_at => Time.at(1234))
108
+ end
109
+
110
+ should 'limit end at' do
111
+ Connection.any_instance.expects(:get_request).with('/measure', :action => :getmeas, :limit => 100, :offset => 0, :enddate => 1234).returns(@returns)
112
+ @user.measurement_groups(:page => 1, :end_at => Time.at(1234))
113
+ end
114
+
115
+ should 'limit last updated at' do
116
+ Connection.any_instance.expects(:get_request).with('/measure', :action => :getmeas, :limit => 100, :offset => 0, :lastupdate => 1234).returns(@returns)
117
+ @user.measurement_groups(:page => 1, :last_updated_at => Time.at(1234))
118
+ end
119
+
120
+ end
121
+
73
122
 
74
123
  context 'constructor' do
75
124
  should 'assign short_name' 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: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 1
10
- version: 0.2.1
9
+ - 2
10
+ version: 0.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - pascalbetz