waynestate/parse-promos

解析Wayne State University API中的促销数组

2.0.0 2018-03-14 14:26 UTC

This package is auto-updated.

Last update: 2024-09-08 06:47:27 UTC


README

解析Wayne State University API中的促销数组

Latest Stable Version Build Status Total Downloads License

安装

要安装此库,请运行以下命令并获取最新版本

composer require waynestate/parse-promos

用法

创建对象

use Waynestate\Promotions\ParsePromos;

...

$parsePromos = new Waynestate\Promotions\ParsePromos();

进行促销的API调用

// Promotion groups to pull ( id => short_name )
$group_reference = [
    123 => 'circle',
    124 => 'alumni-links',
    125 => 'contact',
    126 => 'progress-amount',
    127 => 'progress-text',
];

// How to parse each group after the return ( short_name => config_option )
$group_config = [
    'contact' => 'first',
    'progress-amount' => 'limit:1',
    'progress-text' => 'randomize|first',
];

// Pull all the active items from the API
$params = [
    'promo_group_id' => array_keys($group_reference),
    'is_active' => '1',
    'ttl' => TTL,
];

// Get the raw promotions from the API
$raw_promos = $api->sendRequest('cms.promotions.listing', $params);

// Parse the promotions based on the config set
$parsed_promos = $parsePromos->parse($raw_promos, $group_reference, $group_config);

配置选项

'first' = Return only the first item in the list (not part of an array)
'randomize' = Take the returned list and mix it up
'limit:#' = Return just # number of results from the list
'order:start_date_desc' = Return an ordered list by 'start_date' DESC
'order:start_date_asc' = Return an ordered list by 'start_date' ASC
'order:display_date_desc' = Return an ordered list by 'display_date' DESC
'order:display_date_asc' = Return an ordered list by 'display_date' ASC
'order:title_desc' = Return an ordered list by 'title' DESC
'order:title_asc' = Return an ordered list by 'title' ASC
'page_id:#' = Return only promotions in the list marked for this page
'youtube' = Parse the 'link' field for YouTube video ID, place in a new 'video_id' field

'order:start_date_desc|first' = Options can be run in combination by piping to another config

测试

phpunit

代码覆盖率

phpunit --coverage-html ./coverage