jordanpartridge / strava-client
This is my package strava-client
Fund package maintenance!
JordanPartridge
Requires
- php: ^8.2
- illuminate/contracts: ^10.0||^11.0
- saloonphp/saloon: ^3.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
README
A thoughtfully crafted Strava API integration for Laravel developers who value clean, maintainable code. Stop wrestling with OAuth and start building features that matter.
This package reflects my belief that developer tools should be both powerful and pleasant to use. Built with Laravel best practices and a focus on developer experience.
โจ Why Choose This Package?
- ๐ True Plug & Play: OAuth flow that just works, because you shouldn't need a degree in authentication
- ๐ Intelligent Token Handling: Automatic refresh handling - set it and forget it
- ๐โโ๏ธ Activity Ready: Fetch athlete activities with eloquent simplicity
- ๐ Security First: Encrypted token storage and robust error handling out of the box
- ๐ฏ Laravel Native: Built the way Laravel packages should be
- ๐ฆ Production Ready: Scales from personal projects to multi-user applications
๐ Quick Start
1. Install the package
composer require jordanpartridge/strava-client
2. Run the installer
php artisan strava-client:install
3. Set up your User model
Add the HasStravaTokens
trait and HasStravaToken
interface to your User model:
use JordanPartridge\StravaClient\Contracts\HasStravaToken; use JordanPartridge\StravaClient\Concerns\HasStravaTokens; class User extends Authenticatable implements HasStravaToken { use HasStravaTokens; }
4. Add your Strava credentials to .env
STRAVA_CLIENT_ID=your-client-id STRAVA_CLIENT_SECRET=your-client-secret
5. Connect to Strava
Visit /strava/authorize
as an authenticated user to start the OAuth flow.
6. Start building!
use JordanPartridge\StravaClient\Facades\StravaClient; // Clean, intuitive API for fetching activities $activities = StravaClient::activityForAthlete(page: 1, per_page: 10); // Direct access to specific activities $activity = StravaClient::getActivity($activityId);
๐ Behind the Scenes
The package handles all the complex OAuth interactions so you don't have to:
- Secure authorization initiation via
/strava/authorize
- Automated OAuth callback processing
- Encrypted token storage
- Automatic token refresh handling
- Clean user token associations
๐ง Configuration
Fine-tune the package behavior through config/strava-client.php
:
return [ // Customize the Strava access scope 'scope' => env('STRAVA_CLIENT_SCOPE', 'read,activity:read_all'), // Adjust token refresh behavior 'max_refresh_attempts' => env('STRAVA_CLIENT_MAX_REFRESH_ATTEMPTS', 3), // Set your post-connection redirect 'redirect_after_connect' => env('STRAVA_CLIENT_REDIRECT_AFTER_CONNECT', '/admin'), ];
โก๏ธ Professional Error Handling
Handle API interactions with confidence using custom exception types:
use JordanPartridge\StravaClient\Exceptions\Request\BadRequestException; use JordanPartridge\StravaClient\Exceptions\Request\RateLimitExceededException; use JordanPartridge\StravaClient\Exceptions\Request\ResourceNotFoundException; try { $activity = StravaClient::getActivity($id); } catch (BadRequestException $e) { // Handle malformed requests } catch (RateLimitExceededException $e) { // Handle API rate limits } catch (ResourceNotFoundException $e) { // Handle missing activities }
๐งช Quality Assurance
Run the test suite:
composer test
๐ License
The MIT License (MIT). Please see License File for more information.
๐ค About the Author
Hi! I'm Jordan Partridge, and I build packages like this with a focus on developer experience and clean, maintainable code. If you appreciate the attention to detail in this package and my approach to solving problems, I'm available for hire on Laravel and PHP projects.
Visit my website to learn more about my work and how we might collaborate on your next project.
Need help with this package or want to discuss a project? Reach me at jordan@partridge.rocks.
โค๏ธ Support
If you find this package helpful, please consider:
- Starring the repo on GitHub
- Sharing it with other developers
- Checking out my other packages
Made with โฅ๏ธ in Laravel by a developer who cares about your experience