承接 devhelp/piwik-api 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

devhelp/piwik-api

最新稳定版本:1.0

Composer 安装命令:

composer require devhelp/piwik-api

包简介

Provides self-contained piwik methods that are able to make call to api with predefined or/and runtime arguments

README 文档

README

Build Status Scrutinizer Code Quality

Purpose

Helps creating self-contained Piwik methods that are able to make call to Piwik API with predefined or/and runtime arguments. Helps in using Piwik segmentation and in lazy-loading api parameters values on method call.

Installation

$ composer require devhelp/piwik-api

Please check composer website for more information.

Usage

Basically only thing that you need to implement in order to be able to use the Method is your PiwikClient class. There is an already implemented PiwikGuzzleClient for which you have to configure the Guzzle http client.

You can include PiwikGuzzleClient by adding devhelp/piwik-api-guzzle in composer.json

Standalone Method usage

$myPiwikClient = new MyPiwikClient();

$method = new Method($myPiwikClient, 'http://my.piwik.pro', 'MyModule.myAction')

$method->call(array('token_auth' => $myPiwikToken));

Creating multiple methods with Api

$myPiwikClient = new MyPiwikClient();

$api = new Api($myPiwikClient, 'http://my.piwik.pro');
$api->setDefaultParams(array(
    'token_auth' => $myPiwikToken,
));

$api->getMethod('MyModule.myAction')->call();
$api->getMethod('MyOtherModule.myOtherAction')->call();
$api->getMethod('MyXXXModule.myXXXAction')->call();

Passing parameters to the call

This can be done be passing an array on method call or setting it as default params for the method or the whole api. Parameters can be either a scalar, a callback or an object implementing Param interface.

When parameter value implements a Param interface or is a callback then it's final value is resolved on call() runtime (resulting in lazy-loaded param value). There is a Segment param that will be explained later. Lazy-loading can be particularly useful for returning a token_auth by user that is currently logged in

$params = array(
    'myCustomVar1' => 'someValue',
    'myCustomVar2' => function() {/*..*/},
    'token_auth' => new LazyTokenAuthValue()
);

$api->getMethod('MyModule.myAction')->call($params);

/*
 * params to which $params array will be resolved on method call are:
 * array(
 *     'myCustomVar1' => 'someValue',
 *     'myCustomVar2' => ..., //this what was resolved from anonymous function
 *     'token_auth' => ..., //this what was resolved from LazyTokenAuthValue
 * );
 */

Using segments

Segment param has its own implementation that allows to build Piwik segment query. It's value is resolved on call

use Devhelp\Piwik\Api\Param\Segment as SegmentParam;
use Devhelp\Piwik\Api\Param\Segment\Segment;

$segment = new Segment();

$segment->where(new Equals('country', 'PL'))
        ->andWhere(new NotEquals('actions', 1))
        ->andWhere(new Contains('referrerName', 'piwik'))
        ->orWhere(new DoesNotContain('referrerKeyword', 'myBrand'));

$params = array('segment' => new SegmentParam($segment));

/*
 * this will be resolved to
 * array('segment' => 'country==PL;actions!=1;referrerName=@piwik,referrerKeyword!@myBrand');
 */

Integrations

Credits

Brought to you by: devhelp.pl

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 4
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-01-31