2017 © Pedro Peláez
 

library piwik-api

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

image

devhelp/piwik-api

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

  • Sunday, April 2, 2017
  • by devhelp
  • Repository
  • 4 Watchers
  • 0 Stars
  • 18,098 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 6 Versions
  • 8 % Grown

The README.md

Build Status Scrutinizer Code Quality, (*1)

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., (*2)

Installation

$ composer require devhelp/piwik-api

Please check composer website for more information., (*3)

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., (*4)

You can include PiwikGuzzleClient by adding devhelp/piwik-api-guzzle in composer.json, (*5)

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., (*6)

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, (*7)

$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, (*8)

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, (*9)

The Versions

02/04 2017

dev-master

9999999-dev http://devhelp.pl

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Paweł Barański
by devhelp.pl

05/12 2015

1.0

1.0.0.0 http://devhelp.pl

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Paweł Barański
by devhelp.pl

25/11 2015

0.4

0.4.0.0 http://devhelp.pl

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Paweł Barański
by devhelp.pl

19/11 2015

0.3

0.3.0.0 http://devhelp.pl

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Paweł Barański
by devhelp.pl

18/09 2015

0.2

0.2.0.0 http://devhelp.pl

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

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Paweł Barański
by devhelp.pl

17/04 2015

0.1

0.1.0.0 http://devhelp.pl

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

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Paweł Barański
by devhelp.pl