Skip to content

Commit

Permalink
Conventions in doc too
Browse files Browse the repository at this point in the history
  • Loading branch information
bakura10 committed Dec 9, 2013
1 parent 5a30ccc commit 870835a
Showing 1 changed file with 37 additions and 37 deletions.
74 changes: 37 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ The Keen IO API lets developers build analytics features directly into their app
[![Build Status](https://travis-ci.org/keenlabs/KeenClient-PHP.png?branch=master)](https://travis-ci.org/keenlabs/KeenClient-PHP)

Installation with Composer
------------
--------------------------
1. Install composer via via `curl -s http://getcomposer.org/installer | php` (on windows, download
http://getcomposer.org/installer and execute it with PHP)
1. Edit your `composer.json` file with following contents:
2. Edit your `composer.json` file with following contents:

```json
"require": {
"keen-io/keen-io": "dev-master"
"keen-io/keen-io": "~1.1"
}
```
3. Run `php composer.phar install`

Usage
---
-----

This client was built using [Guzzle](http://guzzlephp.org/), a PHP HTTP client & framework for building RESTful web service clients.

Expand All @@ -35,7 +35,7 @@ For a list of required and available parameters for the different API Endpoints,
[API Reference Docs](https://keen.io/docs/api/reference/).


####Configuring the Client
#### Configuring the Client

The factory method accepts an array of configuration settings for the Keen IO Webservice Client.

Expand All @@ -52,36 +52,36 @@ that matches that version. That Service Description defines the operations avail

Currently the Keen IO Webservice Client only supports - and automatically defaults - to the current version (`3.0`) of the API.

######Example
###### Example
```php
use KeenIO\Client\KeenIOClient;

$client = KeenIOClient::factory([
'projectId' => $projectId,
'writeKey' => $writeKey,
'readKey' => $readKey
'writeKey' => $writeKey,
'readKey' => $readKey
]);
```

####Configuration can be updated to reuse the same Client:
#### Configuration can be updated to reuse the same Client:
You can reconfigure the Keen IO Client configuration options through available getters and setters. You can get and set the following options:
`projectId`, `readKey`, `writeKey`, `masterKey`, & `version`.

######Example
###### Example
```php

//Get the current Project Id
$client->getProjectId();

//Set a new Project Id
$client->setProjectId( $someNewProjectId );
$client->setProjectId($someNewProjectId);

//Get the current Read Key
$client->getReadKey();

//Set a new Read Key
$newReadKey = $client->getScopedKey( $masterKey, $filters, $allowed_operations );
$client->setReadKey( $newReadKey );
$newReadKey = $client->getScopedKey($masterKey, $filters, $allowedOperations);
$client->setReadKey($newReadKey);

```

Expand All @@ -90,58 +90,58 @@ Once you've created a `KeenIOClient`, sending events is simple:

######Example
```php
$event = [ 'purchase' => [ 'item' => 'Golden Elephant' ] ];
$event = ['purchase' => ['item' => 'Golden Elephant']];

$client->addEvent( 'purchases', [ 'data' => $event ] );
$client->addEvent('purchases', ['data' => $event]);
```

####Send batched events to Keen
#### Send batched events to Keen
You can upload multiple Events to multiple Event Collections at once!

In the example below, we will create two new purchase events in the `purchases` event collection and a single
new event in the `sign_ups` event collection. Note that the keys of the `data` array specify the `event_collection`
where those events should be stored.

######Example
###### Example
```php
$purchases = [
[ 'purchase' => [ 'item' => 'Golden Elephant' ] ],
[ 'purchase' => [ 'item' => 'Magenta Elephant' ] ]
['purchase' => ['item' => 'Golden Elephant']],
['purchase' => ['item' => 'Magenta Elephant']]
];
$signUps = [
[ 'name' => 'foo', 'email' => '[email protected]' ]
['name' => 'foo', 'email' => '[email protected]']
];

$client->addEvents([ 'data' => [ 'purchases' => $purchases, 'sign_ups' => $signUps ] ]);
$client->addEvents(['data' => ['purchases' => $purchases, 'sign_ups' => $signUps]]);
```

####Get Analysis on Events
#### Get Analysis on Events
All Analysis Endpoints should be supported. See the [API Reference Docs](https://keen.io/docs/api/reference/) for required parameters.
You can also check the [Service Description](/src/KeenIO/Resources/config/keen-io-3_0.json) for configured API Endpoints.

Below are a few example calls to some of the Analysis methods available.

######Example
```php
###### Example

```php
//Count
$totalPurchases = $client->count( 'purchases' );
$totalPurchases = $client->count('purchases');

//Count Unqiue
$totalItems = $client->countUnique( 'purchases', [ 'target_property' => 'purchase.item' ]);
$totalItems = $client->countUnique('purchases', ['target_property' => 'purchase.item']);

//Select Unique
$items = $client->selectUnique( 'purchases', [ 'target_property' => 'purchase.item' ]);
$items = $client->selectUnique('purchases', ['target_property' => 'purchase.item']);

//Multi Analysis
$analyses = [
'clicks' => [ "analysis_type" => "count" ],
'average price' => [ "analysis_type" => "average", "target_property" => "purchase.price" ]
'clicks' => ['analysis_type' => 'count'],
'average price' => ['analysis_type' => 'average', 'target_property' => 'purchase.price']
];
$stats = $client->multiAnalysis( 'purchases', [ 'analyses' => $analyses ]);
$stats = $client->multiAnalysis('purchases', ['analyses' => $analyses]);
```

###Create a Scoped Key
### Create a Scoped Key

Scoped keys allow you to secure the requests to the API Endpoints and are especially useful when you are providing
access to multiple clients or applications. You should read the Keen IO docs concerning [Scoped Keys](https://keen.io/docs/security/#scoped-key)
Expand All @@ -150,14 +150,14 @@ for more details.
######Example
```php
$filter = [
'property_name' => 'user_id',
'operator' => 'eq',
'property_value' => '123'
'property_name' => 'user_id',
'operator' => 'eq',
'property_value' => '123'
];

$filters = [ $filter ];
$allowed_operations = [ 'read' ];
$filters = [$filter];
$allowed_operations = ['read'];

$scopedKey = $client->getScopedKey( $masterKey, $filters, $allowed_operations );
$scopedKey = $client->getScopedKey($masterKey, $filters, $allowedOperations);
```

0 comments on commit 870835a

Please sign in to comment.