定制 jordanpartridge/strava-client 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jordanpartridge/strava-client

Composer 安装命令:

composer require jordanpartridge/strava-client

包简介

This is my package strava-client

README 文档

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.

Latest Version on Packagist GitHub Tests Action Status Code Coverage Total Downloads

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:

  1. Secure authorization initiation via /strava/authorize
  2. Automated OAuth callback processing
  3. Encrypted token storage
  4. Automatic token refresh handling
  5. 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;
use JordanPartridge\StravaClient\Exceptions\Request\StravaServiceException;

try {
    $activity = StravaClient::getActivity($id);
} catch (BadRequestException $e) {
    // Handle malformed requests
} catch (RateLimitExceededException $e) {
    // Handle API rate limits
} catch (ResourceNotFoundException $e) {
    // Handle missing activities
} catch (StravaServiceException $e) {
    // Handle server errors (500, 502, 504)
}

🔄 Automatic Retry Logic

The package intelligently handles temporary service outages:

  • 503 Service Unavailable: Automatically retries up to 3 times with exponential backoff (1s, 2s, 4s delays)
  • Token Expiration: Automatically refreshes expired tokens and retries the original request
  • Other Server Errors: Throws StravaServiceException immediately for proper error handling

This means your application stays resilient even when Strava experiences temporary issues.

Production Considerations

When handling 503 errors in production, consider:

  1. Queue Jobs: For non-critical operations, queue jobs with delay:

    use App\Jobs\SyncStravaActivities;
    
    try {
        $activities = StravaClient::activityForAthlete(1, 50);
    } catch (\RuntimeException $e) {
        if (str_contains($e->getMessage(), 'service unavailable')) {
            // Retry in 15 minutes
            SyncStravaActivities::dispatch($user)->delay(now()->addMinutes(15));
        }
    }
  2. User Feedback: Inform users about temporary issues:

    try {
        $activity = StravaClient::getActivity($id);
    } catch (\RuntimeException $e) {
        if ($e->getCode() === 503) {
            return back()->with('error', 'Strava is temporarily unavailable. Please try again in a few minutes.');
        }
    }
  3. Monitoring: Log retry attempts for visibility into API health

🧪 Quality Assurance

Run the test suite:

composer test

🔄 Compatibility

This package supports:

  • PHP 8.2 or higher
  • Laravel 10.x and 11.x
  • Laravel 12.x (in development)

📝 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

jordanpartridge/strava-client 适用场景与选型建议

jordanpartridge/strava-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 434 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 10 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「JordanPartridge」 「strava-client」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 jordanpartridge/strava-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jordanpartridge/strava-client 我们能提供哪些服务?
定制开发 / 二次开发

基于 jordanpartridge/strava-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 434
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-10-28