simplificator-withings 0.6.6 → 0.6.8

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 147bfa6804b84781eac7a30dfbdd240008aab378
4
+ data.tar.gz: dcc0e0dbcb32340918f6f30257c62390273f1b8f
5
+ SHA512:
6
+ metadata.gz: a3e7d6d8bf35d6bb557dafd028982664764a497e89a96930409bb1670a9108d7c613584a8fbf12686f4a164157c11a03d2011161cc457ad353afa73688c02170
7
+ data.tar.gz: 2168a3cb270e6cc1a6a52893211a53847b897695706f2f20d9427909881745ed71ee462c850c1988e874b04e7b3487904b86ee670441fb59cfa55685a1670cae
data/README.rdoc CHANGED
@@ -4,6 +4,15 @@ This is a ruby implementation for the Withings API. Description of the API can b
4
4
 
5
5
  == Versions ==
6
6
 
7
+ === 0.6.8 ===
8
+
9
+ * updated README (thanks to jmaddi)
10
+
11
+ === 0.6.7 ===
12
+
13
+ * Swap ruby-hmac for openssl
14
+ * Allow string userid in User.authenticate
15
+
7
16
  === 0.6.6 ===
8
17
 
9
18
  Added list_notifications method to user.
@@ -33,7 +42,7 @@ Note that this release breaks the API of previous releases:
33
42
  === User.authenticate ===
34
43
 
35
44
  User.authenticate() has been replaced by User.userlist
36
-
45
+
37
46
  There is no description available and no guarantee on the order that users are returned by the API (and yes, there can be many users for a single Account)
38
47
  so it seems best to leave the decision to the users of the API.
39
48
 
@@ -42,7 +51,7 @@ The old method is still there but please update your code. It will be removed in
42
51
  === MeasurementGroup ===
43
52
 
44
53
  MeasurementGroup#createt_at has been replaced by MeasurementGroup#taken_on
45
-
54
+
46
55
  Created at is usually the timestamp at which a record was created. But MeasurementGroup#created_at was the timestamp when you actually took the measurement. You can also take measurements (via the Web UI on withings.com) which are for a past date. The record is created today, but the measurement
47
56
  was taken on 2 weeks ago.
48
57
 
@@ -95,7 +104,7 @@ Require the API implementation
95
104
 
96
105
  All classes are name-spaced, if your other code allows you can include Withings
97
106
  include Withings
98
-
107
+
99
108
  Setup
100
109
  Withings.consumer_secret = '1234'
101
110
  Withings.consumer_key = 'abcd'
@@ -107,9 +116,9 @@ A user can be authenticated using user id and oauth token/secret
107
116
 
108
117
  You can handle subscriptions through the API (all devices currently known => Scale + Blood Pressure Monitor)
109
118
  user.subscribe_notification('http://foo.bar.com', 'test subscription')
110
- Specify what devices you are interested
119
+ Specify what devices you are interested
111
120
  user.subscribe_notification('http://foo.bar.com', 'test subscription', Withings::SCALE, Withings::BLOOD_PRESSURE_MONITOR)
112
-
121
+
113
122
  user.describe_notification('http://foo.bar.com')
114
123
  user.revoke_notification('http://foo.bar.com')
115
124
 
@@ -123,7 +132,7 @@ And finally you can get measurements, after all this is what it's for
123
132
  user.measurement_groups(:start_at => Time.at(12345), :end_at => Time.at(67890))
124
133
  user.measurement_groups(:measurement_type => MeasurementGroup::TYPE_FAT)
125
134
  user.measurement_groups(:device => Withings::SCALE)
126
-
135
+
127
136
 
128
137
  == Note on keys in hashes
129
138
 
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ end
10
10
 
11
11
  task :default => :test
12
12
 
13
- require 'rake/rdoctask'
13
+ require 'rdoc/task'
14
14
  Rake::RDocTask.new do |rdoc|
15
15
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
16
16
 
@@ -74,7 +74,7 @@ class Withings::Connection
74
74
 
75
75
  secret = [Withings.consumer_secret, oauth_token_secret].join('&')
76
76
 
77
- digest = HMAC::SHA1.digest(secret, base_string)
77
+ digest = OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), secret, base_string)
78
78
  Base64.encode64(digest).chomp.gsub( /\n/, '' )
79
79
  end
80
80
 
data/lib/withings/user.rb CHANGED
@@ -3,7 +3,7 @@ class Withings::User
3
3
 
4
4
  def self.authenticate(user_id, oauth_token, oauth_token_secret)
5
5
  response = Withings::Connection.get_request('/user', oauth_token, oauth_token_secret, :action => :getbyuserid, :userid => user_id)
6
- user_data = response['users'].detect { |item| item['id'] == user_id }
6
+ user_data = response['users'].detect { |item| item['id'] == user_id.to_i }
7
7
  raise Withings::ApiError.new(2555, 'No user found', '') unless user_data
8
8
  Withings::User.new(user_data.merge({:oauth_token => oauth_token, :oauth_token_secret => oauth_token_secret}))
9
9
  end
@@ -22,21 +22,21 @@ class Withings::User
22
22
  @oauth_token_secret = params['oauth_token_secret']
23
23
  end
24
24
 
25
- def subscribe_notification(callback_url, description, device = SCALE)
25
+ def subscribe_notification(callback_url, description, device = Withings::SCALE)
26
26
  connection.get_request('/notify', :action => :subscribe, :callbackurl => callback_url, :comment => description, :appli => device)
27
27
  end
28
28
 
29
- def revoke_notification(callback_url, device = SCALE)
29
+ def revoke_notification(callback_url, device = Withings::SCALE)
30
30
  connection.get_request('/notify', :action => :revoke, :callbackurl => callback_url, :appli => device)
31
31
  end
32
32
 
33
- def describe_notification(callback_url, device = SCALE)
33
+ def describe_notification(callback_url, device = Withings::SCALE)
34
34
  response = connection.get_request('/notify', :action => :get, :callbackurl => callback_url, :appli => device)
35
35
  Withings::NotificationDescription.new(response.merge(:callbackurl => callback_url))
36
36
  end
37
37
 
38
- # List the notifications for a device (defaults to SCALE), pass nil to list all devices.
39
- def list_notifications(device = SCALE)
38
+ # List the notifications for a device (defaults to Withings::SCALE), pass nil to list all devices.
39
+ def list_notifications(device = Withings::SCALE)
40
40
  options = (device.nil? ? {} : {:appli => device})
41
41
  response = connection.get_request('/notify', options.merge({:action => :list}))
42
42
  response['profiles'].map do |item|
@@ -89,4 +89,4 @@ class Withings::User
89
89
  @connection ||= Withings::Connection.new(self)
90
90
  end
91
91
 
92
- end
92
+ end
data/lib/withings.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  require 'httparty'
2
2
  require 'cgi'
3
- require 'hmac-sha1'
4
3
 
5
4
  %w(base notification_description connection measurement_group error user).each do |part|
6
5
  require File.join(File.dirname(__FILE__), 'withings', part)
7
- end
6
+ end
@@ -2,10 +2,10 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{simplificator-withings}
5
- s.version = "0.6.6"
5
+ s.version = "0.6.8"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["pascalbetz"]
8
+ s.authors = ["pascalbetz", 'invernizzi']
9
9
  s.date = %q{2011-04-18}
10
10
  s.description = %q{A withings API implementation in ruby. Created for the evita project at evita.ch}
11
11
  s.email = %q{info@simplificator.com}
@@ -30,7 +30,7 @@ Gem::Specification.new do |s|
30
30
  s.homepage = %q{http://github.com/simplificator/simplificator-withings}
31
31
  s.rdoc_options = ["--charset=UTF-8"]
32
32
  s.require_paths = ["lib"]
33
- s.rubygems_version = %q{1.3.7}
33
+ s.rubygems_version = %q{1.3.8}
34
34
  s.summary = %q{API implementation for withings.com}
35
35
  s.test_files = [
36
36
  "test/helper.rb",
@@ -45,19 +45,15 @@ Gem::Specification.new do |s|
45
45
  s.add_development_dependency(%q<shoulda>, [">= 0"])
46
46
  s.add_development_dependency(%q<mocha>, [">= 0"])
47
47
  s.add_runtime_dependency(%q<httparty>, [">= 0"])
48
- s.add_runtime_dependency(%q<ruby-hmac>, [">= 0"])
49
-
50
48
  else
51
49
  s.add_dependency(%q<shoulda>, [">= 0"])
52
50
  s.add_dependency(%q<mocha>, [">= 0"])
53
51
  s.add_dependency(%q<httparty>, [">= 0"])
54
- s.add_dependency(%q<ruby-hmac>, [">= 0"])
55
52
  end
56
53
  else
57
54
  s.add_dependency(%q<shoulda>, [">= 0"])
58
55
  s.add_dependency(%q<mocha>, [">= 0"])
59
56
  s.add_dependency(%q<httparty>, [">= 0"])
60
- s.add_dependency(%q<ruby-hmac>, [">= 0"])
61
57
  end
62
58
  end
63
59
 
data/test/users_test.rb CHANGED
@@ -83,4 +83,42 @@ class UsersTest < Test::Unit::TestCase
83
83
  end
84
84
 
85
85
  end
86
+
87
+ context 'authenticate' do
88
+ context 'integer userid' do
89
+ should 'return user' do
90
+ Withings::Connection.stubs(:get_request).with('/user', anything(), anything(), anything()).returns({
91
+ 'users' => [
92
+ {
93
+ 'id' => 29,
94
+ 'firstname' => 'John',
95
+ 'lastname' => 'Doe'
96
+ }
97
+ ]
98
+ })
99
+ user = User.authenticate(29, 'deadbeef', 'cafebabe')
100
+ assert_equal 29, user.user_id
101
+ end
102
+ end
103
+
104
+
105
+ context 'string userid' do
106
+ should 'return user' do
107
+ Withings::Connection.stubs(:get_request).with('/user', anything(), anything(), anything()).returns({
108
+ 'users' => [
109
+ {
110
+ 'id' => 29,
111
+ 'firstname' => 'John',
112
+ 'lastname' => 'Doe'
113
+ }
114
+ ]
115
+ })
116
+ assert_nothing_raised do
117
+ user = User.authenticate('29', 'deadbeef', 'cafebabe')
118
+ assert_equal 29, user.user_id
119
+ end
120
+ end
121
+ end
122
+
123
+ end
86
124
  end
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplificator-withings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.6
5
- prerelease:
4
+ version: 0.6.8
6
5
  platform: ruby
7
6
  authors:
8
7
  - pascalbetz
8
+ - invernizzi
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
@@ -14,65 +14,43 @@ dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: shoulda
16
16
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
17
  requirements:
19
- - - ! '>='
18
+ - - '>='
20
19
  - !ruby/object:Gem::Version
21
20
  version: '0'
22
21
  type: :development
23
22
  prerelease: false
24
23
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
24
  requirements:
27
- - - ! '>='
25
+ - - '>='
28
26
  - !ruby/object:Gem::Version
29
27
  version: '0'
30
28
  - !ruby/object:Gem::Dependency
31
29
  name: mocha
32
30
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
31
  requirements:
35
- - - ! '>='
32
+ - - '>='
36
33
  - !ruby/object:Gem::Version
37
34
  version: '0'
38
35
  type: :development
39
36
  prerelease: false
40
37
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
38
  requirements:
43
- - - ! '>='
39
+ - - '>='
44
40
  - !ruby/object:Gem::Version
45
41
  version: '0'
46
42
  - !ruby/object:Gem::Dependency
47
43
  name: httparty
48
44
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
45
  requirements:
51
- - - ! '>='
46
+ - - '>='
52
47
  - !ruby/object:Gem::Version
53
48
  version: '0'
54
49
  type: :runtime
55
50
  prerelease: false
56
51
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
52
  requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- - !ruby/object:Gem::Dependency
63
- name: ruby-hmac
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
- type: :runtime
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
53
+ - - '>='
76
54
  - !ruby/object:Gem::Version
77
55
  version: '0'
78
56
  description: A withings API implementation in ruby. Created for the evita project
@@ -100,30 +78,28 @@ files:
100
78
  - test/users_test.rb
101
79
  homepage: http://github.com/simplificator/simplificator-withings
102
80
  licenses: []
81
+ metadata: {}
103
82
  post_install_message:
104
83
  rdoc_options:
105
84
  - --charset=UTF-8
106
85
  require_paths:
107
86
  - lib
108
87
  required_ruby_version: !ruby/object:Gem::Requirement
109
- none: false
110
88
  requirements:
111
- - - ! '>='
89
+ - - '>='
112
90
  - !ruby/object:Gem::Version
113
91
  version: '0'
114
92
  required_rubygems_version: !ruby/object:Gem::Requirement
115
- none: false
116
93
  requirements:
117
- - - ! '>='
94
+ - - '>='
118
95
  - !ruby/object:Gem::Version
119
96
  version: '0'
120
97
  requirements: []
121
98
  rubyforge_project:
122
- rubygems_version: 1.8.21
99
+ rubygems_version: 2.0.6
123
100
  signing_key:
124
101
  specification_version: 3
125
102
  summary: API implementation for withings.com
126
103
  test_files:
127
104
  - test/helper.rb
128
105
  - test/users_test.rb
129
- has_rdoc: