The gem wraps the MapMyFitness v7 API. It needs an OAuth2 authorization token, which can be retrieved via the MapMyFitness OAuth2 OmniAuth Strategy.
Add this line to your application's Gemfile:
gem 'mapmyfitness'
And then execute:
$ bundle
Or install it yourself as:
$ gem install mapmyfitness
So far, you can use the library to...
When you use the OmniAuth strategy to login with MapMyFitness v7 OAuth2 API, your callback URL will receive a large hash of data. The User
class will parse it into an easy-to-use Ruby object instance. Starting in a sessions_controller#create
which handles the callback:
user_data = MapMyFitness::User.new(request.env["omniauth.auth"])
Then, if you'd like to save the data to your database, you could do something like this:
user_data = MapMyFitness::User.new(request.env["omniauth.auth"])
@user = User.find_or_create_by_auth(user_data)
And down in the User
model:
def self.find_or_create_by_auth(user_data)
find_or_create_by_provider_and_uid(user_data.provider,
user_data.uid,
username: user_data.username,
email: user_data.email,
token: user_data.token)
end
Once you have a user OAuth2 token, then you can request the workouts for that user. For example:
store = MapMyFitness::WorkoutStore.new(current_user.token)
store.workouts_by(current_user.uid)
The token
is used to sign the request, while the uid
identifies the user who owns the workout data.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request