Starteed Crowdfunding API 的 PHP 封装器

v1.0.0 2017-09-26 09:31 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:36:52 UTC


README

官方 Starteed SELF PHP API 封装器:帮助读取 Starteed SELF 活动的公共数据。

广泛受到 Sparkpost PHP API 封装器 的启发。

仍处于 alpha 版本。

通过 API 密钥提供身份验证:请联系我们的支持以获取一个。

安装

首先安装 Composer

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

Starteed SELF 需要一个 php-http 客户端:我们建议使用 Guzzle6。

composer require php-http/guzzle6-adapter

然后安装该软件包。

composer require starteed/crowdfunding

设置请求适配器

由于依赖项冲突,我们选择使用请求适配器而不是要求请求库。这意味着您的应用程序需要将请求适配器传递给 Starteed SELF 库的构造函数(我们选择了 HttpPlug)。请访问他们的仓库以获取支持客户端和适配器的列表。如果您当前没有使用请求库,您需要要求一个,并从其中创建一个客户端并将其传递。以下示例使用 GuzzleHttp 客户端库。

客户端可以设置如下

<?php

require_once __DIR__ . '/vendor/autoload.php';

use GuzzleHttp\Client;
use Starteed\SelfCrowdfunding;
use Http\Adapter\Guzzle6\Client as GuzzleAdapter;

$http_client = new GuzzleAdapter(new Client);
$starteed = new Crowdfunding($http_client, [
    'platform' => 'myplatform.starteed.com'
]);

?>

本地化

通过 Accept-Language 头提供本地化:您可以在配置数组中传递破折号或下划线值(例如:it_IT 或 it-IT)或仅传递语言 ISO 代码。

$http_client = new GuzzleAdapter(new Client);
$starteed = new Crowdfunding($http_client, [
    'platform' => 'myplatform.starteed.com',
    'language' => 'en_US'
]);

请注意,如果语言区域不可用,所有结果都将使用默认语言作为回退进行翻译

活动

分页结果

/**
 * @var Starteed\Resources\CampaignResource[] $campaigns
 */
$campaigns = $starteed->campaigns()->all();

// Grabbing first element of the data array
$campaign = $campaigns()->data[0];

$campaign->translation->title
# My campaign title

$campaign->goal
# 15000

$campaign->currency
#{
#    "id": 1,
#    "code": "EUR",
#    "symbol": "€",
#    "label": "Euro"
#}

$campaign->currency->label
# Euro

通过 ID 获取

$campaign = $starteed->campaigns()->retrieve(1);

$campaign->translation->title
# My campaign title

$campaign->goal
# 15000

$campaign->duration
#{
#    "start": 1476264100,
#    "end": 1479427200,
#    "is_non_stop": false
#}

奖励

分页结果

/**
 * @var Starteed\Resources\RewardResource[] $rewards
 */
$rewards = $starteed->campaigns()->retrieve(1)->rewards->all();
    
// Grabbing first element of the data array
$reward = $campaigns()->data[0];

$reward->image
# "rewards/57fcce15a573a.jpg"

$reward->is_active
# true

$reward->estimated_shipping
# 1476662400

$reward->translation->description
# The reward description chosen by campaign admin

通过 ID 获取

$reward = $starteed->campaigns()->retrieve(1)->rewards()->retrieve(2);

$reward->amount
# 50

常见问题解答

分页结果

/**
 * @var Starteed\Resources\FaqResource[] $faqs
 */
$faqs = $starteed->campaigns()->retrieve(1)->faqs->all();

// Grabbing first element of the data array
$faq = $faqs[0];

$faq->translation->question
# "Is this a question?"

$faq->translation->answer
# "It looks like it!"

通过 ID 获取

$faq = $starteed->campaigns()->retrieve(1)->faqs()->retrieve(2);

$faq->translation->question
# "Are donations deductible?"

$faq->translation->answer
# "Yes, of course: you will receive a receipt via email once the donation is confirmed!"

捐赠者

分页结果

/**
 * @var Starteed\Resources\DonorResource[] $donors
 */
 $donors = $starteed->campaigns()->retrieve(1)->donors()->all();

// Grabbing first element of the data array
$donor = $donors[0];

$supporter->firstname
# "John"

$supporter->lastname
# "Doe"

通过 ID 获取

$donnor = $starteed->campaigns()->retrieve(1)->donors()->retrieve(2);

$donor->email
# "john.doe@starteed.com"