定制 stevenmaguire/yelp-php 二次开发

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

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

stevenmaguire/yelp-php

Composer 安装命令:

composer require stevenmaguire/yelp-php

包简介

A php client for consuming Yelp API

README 文档

README

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads

A PHP client for authenticating with Yelp using OAuth and consuming the API.

Install

Via Composer

$ composer require stevenmaguire/yelp-php

Usage

This package currently supports v2 and v3 (Fusion) of the Yelp API. Each version of the Yelp API maps to a different client, as the APIs are very different. Each client has separate documentation; links provided below.

Create client

Each version of the Yelp API maps to a different client, as the APIs are very different. A client factory is available to create appropriate clients.

v2 Client Example

$options = array(
    'consumerKey' => 'YOUR COSUMER KEY',
    'consumerSecret' => 'YOUR CONSUMER SECRET',
    'token' => 'YOUR TOKEN',
    'tokenSecret' => 'YOUR TOKEN SECRET',
    'apiHost' => 'api.yelp.com' // Optional, default 'api.yelp.com'
);

$client = \Stevenmaguire\Yelp\ClientFactory::makeWith(
    $options,
    \Stevenmaguire\Yelp\Version::TWO
);

v3 Client Example

$options = array(
    'accessToken' => 'YOUR ACCESS TOKEN', // Required, unless apiKey is provided
    'apiHost' => 'api.yelp.com', // Optional, default 'api.yelp.com',
    'apiKey' => 'YOUR ACCESS TOKEN', // Required, unless accessToken is provided
);

$client = \Stevenmaguire\Yelp\ClientFactory::makeWith(
    $options,
    \Stevenmaguire\Yelp\Version::THREE
);

Prior to December 7, 2017 accessToken was required to authenticate requests. Since then, apiKey is the preferred authentication method. This library supports both accessToken and apiKey, prioritizing apiKey over accessToken if both are provided.

https://www.yelp.com/developers/documentation/v3/authentication#where-is-my-client-secret-going

Version Constant Documentation
v2 Stevenmaguire\Yelp\Version::TWO API-GUIDE-v2.md
v3 Stevenmaguire\Yelp\Version::THREE API-GUIDE-v3.md
Get Rate Limit data from most recent request

For the v3 client, rate limiting data is avaiable after a recent request.

// $latestRateLimit will be null if an http request hasn't been successfully completed.
$latestRateLimit = $client->getRateLimit();

// The maximum number of calls you can make per day
$latestDailyLimit = $latestRateLimit->dailyLimit;

// The number of calls remaining within the current day
$latestRemaining = $latestRateLimit->remaining;

// The time at which the current rate limiting window will expire as an ISO 8601 timestamp
$latestResetTime = $latestRateLimit->resetTime;

// The time at which the current rate limiting data was observed as an ISO 8601 timestamp
$latestCreatedAt = $latestRateLimit->createdAt;

Exceptions

If the API request results in an Http error, the client will throw a Stevenmaguire\Yelp\Exception\HttpException that includes the response body, as a string, from the Yelp API.

$responseBody = $e->getResponseBody(); // string from Http request
$responseBodyObject = json_decode($responseBody);

Advanced usage

Both the v3 client and the v2 client expose some public methods that allow overiding default behavior by providing alternative HTTP clients and requests.

$client = new \Stevenmaguire\Yelp\v3\Client(array(
    'accessToken' => $accessToken,
));

// Create a new guzzle http client
$specialHttpClient = new \GuzzleHttp\Client([
    // ... some special configuration
]);

// Update the yelp client with the new guzzle http client
// then get business data
$business = $client->setHttpClient($specialHttpClient)
    ->getBusiness('the-motel-bar-chicago');

// Create request for other yelp API resource not supported by yelp-php
$request = $client->getRequest('GET', '/v3/some-future-endpoint');

// Send that request
$response = $client->getResponse($request);

// See the contents
echo $response->getBody();

Upgrading with Yelp API v2 support from yelp-php 1.x to yelp-php 2.x

// same options for all
$options = array(
    'consumerKey' => 'YOUR COSUMER KEY',
    'consumerSecret' => 'YOUR CONSUMER SECRET',
    'token' => 'YOUR TOKEN',
    'tokenSecret' => 'YOUR TOKEN SECRET',
    'apiHost' => 'api.yelp.com' // Optional, default 'api.yelp.com'
);


// yelp-php 1.x
$client = new Stevenmaguire\Yelp\Client($options);

// yelp-php 2.x - option 1
$client = \Stevenmaguire\Yelp\ClientFactory::makeWith(
    $options,
    \Stevenmaguire\Yelp\Version::TWO
);

// yelp-php 2.x - option 2
$client = new \Stevenmaguire\Yelp\v2\Client($options);

Testing

$ ./vendor/bin/phpunit

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

stevenmaguire/yelp-php 适用场景与选型建议

stevenmaguire/yelp-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 415.87k 次下载、GitHub Stars 达 56, 最近一次更新时间为 2014 年 10 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 stevenmaguire/yelp-php 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 415.87k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 57
  • 点击次数: 17
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 56
  • Watchers: 6
  • Forks: 20
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-10-21