onesky/api-library-php5

OneSky 平台 API 的 PHP 接口

v1.0.5 2015-06-09 02:00 UTC

This package is not auto-updated.

Last update: 2024-09-23 05:52:18 UTC


README

Build Status Code Coverage

OneSky PHP5 API 库

OneSky API 的 PHP5 库

要求

  • PHP 5.1 或更高版本
  • CURL 扩展

安装

使用 composer require onesky/api-library-php5 安装最新版本

如何使用

创建实例

use Onesky\Api\Client;

$client = new Client();

设置 API 密钥和密钥

$client->setApiKey('<api-key>')->setSecret('<api-secret>');

请求方式

// resource   => name of resource in camelcase with 's' tailing such as 'projectTypes', 'quotations', 'importTasks'
// action     => action to take such as 'list', 'show', 'upload', 'export'
// parameters => parameters passed in the request including URL param such as 'project_id', 'files', 'locale'
$client->{resource}('{action}', array({parameters}));

示例请求和以数组形式获取响应

// list project groups
$response = $client->projectTypes('list');
$response = json_decode($response, true);

// show a project
$response = $client->projects('show', array('project_id' => 999));
$response = json_decode($response, true);

// upload file
$response = $client->files('upload', array(
    'project_id'  => 999,
    'file'        => 'path/to/string.yml',
    'file_format' => 'YAML',
    'locale'      => 'fr'
));
$response = json_decode($response, true);

// export translation
$response = $client->translations('export', array(
    'project_id' => 999,
    'locale'     => 'ja',
    'source_file_name' => 'string.yml'
));
file_put_contents('path/to/file', $response);

// create order
$response = $client->orders('create', array(
    'project_id' => 999,
    'files'      => 'string.yml',
    'to_locale'  => 'de'
));
$response = json_decode($response, true);

如何贡献

或者选择 以下问题 并创建 PR 来解决。

如何运行测试

注意:需要使用 composer 安装依赖以使用 phpunit。

vendor/bin/phpunit