= simplificator-withings This is a ruby implementation for the Withings API. Description of the API can be found here: http://www.withings.com/en/api == Installation gem install simplificator-withings == Authentication The WBS API provides a way to login by user_id and public_key. You can either ask your users to enter the user_id/public_key manually (they can be found in the sharing overlay on my.withings.com) or ask them for email/password once and then use those credentials to authenticate through the API (User.authenticate(email, password)). The User instance returned will have the user_id and public_key attributes populated and you can store them for further use. 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 will make an API call to populate the attributes, User.new just requires user_id/public_key. == TODO * Integration Test? But i don't want to share my credentials... Perhaps with a test account on withings? Solution from Withings support: Hi, The easiest is that you just create a regular account (http://start.withings.com), associate it with one scale, then create a user (like any regular customer). Once this is done, the account is activated. You may then go to My account/My scale and dissociate the scale, the account will stay opened. That account may be used by who ever you think it should for test purposes and will not be associated to a specific scale. Thanks for your enquiry ! fred == Remarks * The gem is still under development and the API might change a bit. * 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 ) after authentication by email/password * As soon as the user sets sharing to false (user.share = false) the public_key is reset and upon next activation of sharing a new public_key is assigned. * 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. == How To Require the API implementation require 'rubygems' require 'withings' All classes are name-spaced, if your other code allows you can include Withings include Withings A user can be authenticated with email address and password user = User.authenticate('', '') Or you can fetch details if you have the user id and public key user = User.info('', '') If you already have user id and public key and you do not need further information on the user user = User.new(:user_id => '', :public_key => '') enable/disable sharing, disabling it will reset the public key user.share(Withings::SCALE, Withings::BLOOD_PRESSURE_MONITOR) user.share(0) You can handle subscriptions through the API user.subscribe_notification('http://foo.bar.com', 'test subscription') user.describe_notification('http://foo.bar.com') user.revoke_notification('http://foo.bar.com') And finally you can get measurements, after all this is what it's for user.measurement_groups(:per_page => 10, :page => 1, :end_at => Time.now) user.measurement_groups(:category => MeasurementGroup::CATEGORY_TARGET) user.measurement_groups(:last_updated_at => Time.at(12345)) user.measurement_groups(:start_at => Time.at(12345), :end_at => Time.at(67890)) user.measurement_groups(:measurement_type => MeasurementGroup::TYPE_FAT) == Note on keys in hashes Keys to constructors (User, MeasurementGroup and NotificationDescription) and methods (User.measurement_groups) can be either String or Symbol == Note on naming convention The WBS API has parameter with shortened names (e.g. 'grpid') or names not following a consistent naming pattern. While this API implementation tries to stick as close to the API as possible it also tries to unify and simplify the parameter names. The constructors for User, MeasurementGroup and NotificationDescription accept the names provided by the API but convert the names then to a more "ruby" way. An exception to this are the "id" and "publickey" parameters for User.new, they are accepted as "user_id" and "public_key" as well. == Note on Patches/Pull Requests * Fork the project. * Make your feature addition or bug fix. * Add tests for it. This is important so I don't break it in a future version unintentionally. * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull) * Send me a pull request. Bonus points for topic branches. == Dependencies HTTParty is used for making the HTTP requests and Shoulda and Mocha are used for testing. Thanks for these Gems. == Copyright Copyright (c) 2010 simplificator. See LICENSE for details.