Skip to content
swswissPublic

About

Wahoo SDK Ruby

Resources

Code of conduct

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

wahoo

Tests Gem Version

A Ruby client for the Wahoo Cloud API. OAuth 2.0 (standard + PKCE), workouts, routes, plans, power zones, the user, file uploads and webhooks — with first-class models, automatic pagination, unit conversions, and automatic retries.

Installation

gem "wahoo"

Then bundle install, or gem install wahoo.

Configuration

Wahoo.configure do |c|
  c.client_id     = ENV["WAHOO_CLIENT_ID"]
  c.client_secret = ENV["WAHOO_CLIENT_SECRET"]
  c.redirect_uri  = "https://yourapp.com/wahoo/callback"
end

Register your redirect URI in the Wahoo developer portal — it must match redirect_uri exactly.

Authentication

Standard OAuth 2.0

url    = Wahoo::OAuth.authorize_url(scope: "user_read workouts_read")
tokens = Wahoo::OAuth.exchange_code(params[:code])   # in your callback
tokens = Wahoo::OAuth.refresh(tokens.refresh_token) if tokens.expired?

PKCE (public apps — set "Confidential? = No" in the portal)

verifier  = Wahoo::OAuth.generate_code_verifier
challenge = Wahoo::OAuth.code_challenge_for(verifier)

url = Wahoo::OAuth.authorize_url(scope: "user_read workouts_read",
                                 code_challenge: challenge)
# store `verifier`, then in your callback:
tokens = Wahoo::OAuth.exchange_code(params[:code], code_verifier: verifier)

Usage

client = Wahoo::Client.new(access_token: tokens.access_token)

# User
client.user.get                       # => Wahoo::Models::User
client.user.update(weight: 72)

# Workouts
client.workouts.list                  # all pages, as models
client.workouts.list(limit: 50)
client.workouts.get(id)
client.workouts.create(name: "Ride", workout_token: "abc",
                       workout_type_id: 0, starts: Time.now.iso8601, minutes: 60)
client.workouts.update(id, name: "New name")
client.workouts.delete(id)
client.workouts.summary(id)           # the workout summary

# Routes, plans, power zones (full CRUD)
client.routes.list
client.plans.list
client.power_zones.list

# Upload a FIT file (async — Wahoo generates the workout + summary)
upload = client.uploads.create(file: "ride.fit")
upload = client.uploads.get(upload.token)   # poll until upload.complete?

# Revoke access
client.deauthorize

Models & conversions

Responses are objects. Wahoo returns decimals as strings; the helpers handle that:

w = client.workouts.get(id)
w.name
w.workout_type        # "BIKING" (from workout_type_id)
w.distance_km         # 45.23  (from the string "45230.50")
w.duration_human      # "1h 40m 12s"
w.avg_speed_kmh
w.raw                 # the original hash

Webhooks

Set your webhook URL and token in the developer portal (requires offline_data).

Wahoo.configure { |c| c.webhook_secret = "your_token" }

event = Wahoo::Webhooks::Handler.verify_token!(request.raw_post)
if event.workout_summary?
  event.user_id
  event.workout_summary.distance_km
  event.workout
end

Automatic retries

Retries on 429 and 5xx with backoff:

Wahoo.configure do |c|
  c.max_retries   = 3
  c.retry_backoff = 2
end

Notes on Wahoo's behavior

  • Wahoo returns decimal values as strings (e.g. "450.00"); the model helpers convert them.
  • Workouts you create via the API are owned by your app (fitness_app_id > 1000) and won't appear in the Wahoo mobile app the same way device-recorded workouts do — this is Wahoo's policy, not a bug.
  • routes, plans and power_zones list only the records your app created, not ones created in the Wahoo app.
  • Sandbox apps have low rate limits; production apps require Wahoo review.

Error handling

rescue Wahoo::Unauthorized         # 401 — refresh the token
rescue Wahoo::Forbidden            # 403 — missing scope
rescue Wahoo::UnprocessableEntity  # 422 — bad params / app not approved
rescue Wahoo::RateLimited => e     # 429 — e.retry_after
rescue Wahoo::Error => e           # e.status, e.body

CLI

Get a token from the terminal (uses HTTPS on localhost):

WAHOO_CLIENT_ID=... WAHOO_CLIENT_SECRET=... bundle exec wahoo-oauth-token

Development

bin/setup
bundle exec rspec

Contributing

Bug reports and pull requests are welcome on GitHub.

License

MIT

About

Wahoo SDK Ruby

Resources

Code of conduct

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages