foxycart/foxyclient 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

foxycart/foxyclient

Composer 安装命令:

composer require foxycart/foxyclient

包简介

FoxyClient - a PHP Guzzle based API Client for working with the Foxy Hypermedia API

README 文档

README

FoxyClient - a PHP Guzzle based API Client for working with the Foxy Hypermedia API

Please see the Foxy Hypermedia API documentation for more information.

Installation

The best way to get started with FoxyClient is to run the foxyclient-php-example code.

Once you're familiar with how it works, you can add it as a composer package to your application as the example code does or via Packagist:

  • Install Composer

curl -sS https://getcomposer.org/installer | php

  • Add to your project

php composer.phar require foxycart/foxyclient:~1.0

If you need Guzzle 6 instead of Guzzle 5, use:

php composer.phar require foxycart/foxyclient:~2.0

Usage

As mentioned above, begin by getting familiar with the example code. The bootstrap.php file in particular is useful for configuring FoxyClient within your application. Please note how it takes advantage of HTTP caching and CSRF protection which are important for the performance and security of your application.

FoxyClient supports all HTTP methods for our Hypermedia API. It also automatically handles OAuth token refreshes and handles authorization code grants. It does not specify a persistance layer for storing OAuth tokens so you can implement that however you want. You can also support a static service with no database which would only use the client_id, client_secret, and refresh_token to obtain a new access_token as needed.

Tests

For Behat tests, please see the the example code.

Config Options

  • use_sandbox: Set to true to work with https://api-sandbox.foxycart.com. This is highly recomended when first getting familiar with the system (defaults to false).
  • client_id: Your OAuth Client id.
  • client_secret: Your OAuth Client Secret.
  • access_token: Your OAuth Acccess Token.
  • access_token_expires: A timestamp for when the access_token needs to be refreshed. If you happen to already have a stored token, you can set this here. It will be maintained via time() + expires_in.
  • refresh_token: OAuth Refresh Token.
  • handle_exceptions: Defaults to true. Set to false to let Guzzle exceptions bubble up to your application so you can handle them directly.
  • api_home: Used internally for Foxy testing.
  • authorization_endpoint: Used internally for Foxy testing.

HTTP methods

  • get($uri, $post = null)
  • post($uri, $post = null)
  • patch($uri, $post = null)
  • put($uri, $post = null)
  • delete($uri, $post = null)
  • options($uri, $post = null)
  • head($uri, $post = null)

API Methods

  • updateFromConfig($config): Update configuration options via an array
  • clearCredentials(): Clear all credentials so you can connect to the API with no OAuth
  • getLink($link_rel_string): Used to get the href of a given link relationship such as "self" or "fx:store". It also supports the short version of just "store".
  • getLinks(): Returns an array of link relationships the client has seen so far in the rel => href format. Each request stores the links in the links array.
  • clearLinks(): Clear saved links from previous API calls. Helpful for link relationships like "checkout_types" which can be returned from both a store resource and as a property helper.
  • setAccessToken($access_token) / getAccessToken(): OAuth access token
  • setAccessTokenExpires($access_token_expires) / getAccessTokenExpires(): OAuth expiration times
  • setRefreshToken($refresh_token) / getRefreshToken(): OAuth refresh token
  • setClientId($client_id) / getClientId(): OAuth client id
  • setClientSecret($client_secret) / getClientSecret(): OAuth client secret
  • setUseSandbox($use_sandbox) / getUseSandbox(): boolean for connecting to the API sandbox
  • getApiHome(): the API starting homepage
  • getErrors($data): Given a response payload, it will normalize errors and return an array of them (or any empty array).
  • getLastStatusCode(): Returns the last HTTP status code.
  • getLastResponseHeader($header): Get a header (such as "Location") from the previous response.
  • setAcceptContentType($accept_content_type): Set the Accept header content type used for the all future requests. All supported json content types on the FoxyCart API are supported such as application/hal+json and application/vnd.siren+json.
  • getAcceptContentType(): get the Accept header content type
  • getAuthorizationEndpoint(): The Authorization Code Grant server endpoint url. You'll need to forward users to this to let them grant your application access to their store or user.
  • getOAuthTokenEndpoint(): The OAuth token endpoint. Note: you shouldn't have to use this as the library takes care of all OAuth functionality for you.
  • getAccessTokenFromAuthorizationCode($code): Used when returning from our Authorization server in order to obtain an access_token and refresh_token.
  • getAccessTokenFromClientCredentials(): If we don't have a refresh token, we can use this method to obtain an access_token using just the client credentials.

foxycart/foxyclient 适用场景与选型建议

foxycart/foxyclient 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 43.52k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2016 年 05 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 foxycart/foxyclient 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 8
  • Watchers: 7
  • Forks: 11
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-05-24