Skip to content

cwadding/sensit-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

sensit-php

Official Sensit API library client for PHP

This library is generated by alpaca

Installation

Make sure you have composer installed.

Add the following to your composer.json

{
    "require": {
        "cwadding/sensit-client": "*"
    }
}

Update your dependencies

$ php composer.phar update

This package follows the PSR-0 convention names for its classes, which means you can easily integrate these classes loading in your own autoloader.

Versions

Works with [ 5.4 / 5.5 ]

Usage

<?php

// This file is generated by Composer
require_once 'vendor/autoload.php';

// Then we instantiate a client (as shown below)

Build a client

Without any authentication
$client = new Sensit\Client();

// If you need to send options
$client = new Sensit\Client(array(), $options);
Authorization header token
$client = new Sensit\Client('1a2b3', $options);

Response information

$response = $client->klass('args')->method('args');

$response->body;
// >>> 'Hello world!'

$response->code;
// >>> 200

$response->headers;
// >>> array('content-type' => 'text/html')
HTML response
$response->body;
// >>> 'The username is pksunkara!'
JSON response
$response->body;
// >>> array('user' => 'pksunkara')

Request body information

RAW request
$body = 'username=pksunkara';
FORM request
$body = array('user' => 'pksunkara');
JSON request
$body = array('user' => 'pksunkara');

Client Options

The following options are available while instantiating a client:

  • base: Base url for the api
  • api_version: Default version of the api (to be used in url)
  • user_agent: Default user-agent for all requests
  • headers: Default headers for all requests
  • request_type: Default format of the request body

Method Options

The following options are available while calling a method of an api:

  • api_version: Version of the api (to be used in url)
  • headers: Headers for the request
  • query: Query parameters for the url
  • body: Body of the request
  • request_type: Format of the request body

Percolator api

A Percolator is a reverse query much like a match rule which is run whenever a new feed is added. These can be used to create alerts by causing the sensit to publish the feed that was just added. A percolator query is defined by a name and and valid query according to the according the the elasticsearch Query DSL. For more information about Percolator queries please refer to the elasticsearch percolator documentation.

The following arguments are required:

  • topic_id: The key for the parent topic
  • id: The name of the percolator query
$percolator = $client->percolator("my_rule", "my_topic");
List of Percolations for a Topic (GET /api/topics/:topic_id/percolators)

Returns a list or percolators for a given topic. Requires authorization of read_any_percolators, or read_application_percolators.

$response = $percolator->list($options);
Get the Percolator (GET /api/topics/:topic_id/percolators/:id)

Return a specific percolator of the associated Topic by Id. Requires authorization of read_any_percolators, or read_application_percolators.

$response = $percolator->find($options);
Create a Percolator (POST /api/topics/:topic_id/percolators)

Create a percolator on the associated Topic with the specified name and query. Requires authorization of manage_any_percolators, or manage_application_percolators.

The following arguments are required:

  • percolator: A Hash containing name: The name of the percolator(required).query: The query hash according to the according the the elasticsearch Query DSL
$response = $percolator->create("{name: 'Kimchy-User', query:{term: {user: 'kimchy'}}}", $options);
Update a Percolator (PUT /api/topics/:topic_id/percolators/:id)

Update the query for a specific percolator. Requires authorization of manage_any_percolators, or manage_application_percolators.

The following arguments are required:

$response = $percolator->update("{query:{term: {user: 'kimchy'}}}", $options);
Delete a Percolator (DELETE /api/topics/:topic_id/percolators/:id)

Delete a percolator on the associated topic. Requires authorization of manage_any_percolators, or manage_application_percolators.

$response = $percolator->delete($options);

Report api

Reports are stored filter and facet queries on the Feed data. A report is a assigned a name and the query is any elasticsearch query which filters only the desired data for the facets (See the elasticsearch Query DSL for valid queries). A report can have many facets with each facet is referred to by a user defined name. Valid type's of facet include terms, range, histogram, filter, statistical, query, terms_stats, or geo_distance. The query within a facet defines the field counts or statistics which the data is calculated over. See the elasticsearch facet dsl for information about the various facet types and valid query fields.

The following arguments are required:

  • topic_id: The key for the parent topic
  • id: The identifier of the report
$report = $client->report("my_report", "my_topic");
List of Reports for a Topic (GET /api/topics/:topic_id/reports)

Get all reports for the associated Topic. Requires authorization of read_any_reports, or read_application_reports.

$response = $report->list($options);
Get a Report (GET /api/topics/:topic_id/reports/:id)

Retrieve a specific report on the associated topic by Id. Requires authorization of read_any_reports, or read_application_reports.

$response = $report->find($options);
Create a Report (POST /api/topics/:topic_id/reports)

Create a new report on the associated Topic which can be easily retrieved later using an id. Requires authorization of manage_any_reports, or manage_application_reports.

The following arguments are required:

  • report: A Hash containing name: The name of the report (required).query:The search query acccording to the elasticsearch Query DSL to filter the data for the facets (Defaults to match all).facets:An array of facet hashes which each contain a name ad type of the facet along with its query hash (required).
$response = $report->create("{name:'My report', query:{match_all: { }}, facets:[{name: 'facet1', type: 'terms', query: { field: 'value1'}}]}", $options);
Update a Report for a Topic (PUT /api/topics/:topic_id/reports/:id)

Update the query, facets or name of the report. Requires authorization of manage_any_reports, or manage_application_reports.

The following arguments are required:

  • report: A Hash containing name: The name of the report (required).query:The search query acccording to the elasticsearch Query DSL to filter the data for the facets (Defaults to match all).facets:An array of facet hashes which each contain a name ad type of the facet along with its query hash (required).
$response = $report->update("{name:'My report', query:{match_all: { }}, facets:[{name: 'facet1', type: 'terms', query: { field: 'value1'}}]}", $options);
Delete a Report (DELETE /api/topics/:topic_id/reports/:id)

Remove a saved report on the associated Topic by Id. Requires authorization of manage_any_reports, or manage_application_reports.

$response = $report->delete($options);

api

$user = $client->user();
(GET /api/user)
$response = $user->profile($options);

Topic api

A topic is root that data is attached to. It is the equivalent of a source in searchlight/solink and acts as a table which has columns(Fields) and rows(Feeds).

$topic = $client->topic();
List of Topics (GET /api/topics)

Requires authorization of read_any_data, or read_application_data.

$response = $topic->list($options);
Get this Topic (GET /api/topics/:id)

Requires authorization of read_any_data, or read_application_data.

$response = $topic->find($options);
Create a Topic (POST /api/topics)

Requires authorization of manage_any_data, or manage_application_data.

The following arguments are required:

  • topic: A hash containing the name/id of the topic (required) and a description of the topic.
$response = $topic->create("{name:'my_topic', description:'Event data from source A.'}", $options);
Update a Topic (PUT /api/topics/:id)

Requires authorization of manage_any_data, or manage_application_data.

The following arguments are required:

  • topic: A hash containing the name/id of the topic (required) and a description of the topic.
$response = $topic->update("{name:'my_topic', description:'Event data from source A.'}", $options);
Delete a Topic (DELETE /api/topics/:id)

Requires authorization of manage_any_data, or manage_application_data.

$response = $topic->delete($options);

Feed api

Returns api instance to get auxilary information about Buffer useful when creating your app.

The following arguments are required:

  • topic_id: The key for the parent topic
  • id: The id of the feed
$feed = $client->feed("1", "my_topic");
List of Feeds (GET /api/topics/:topic_id/feeds)

Returns a list of feeds for a given topic. Requires authorization of read_any_data, or read_application_data.

$response = $feed->list($options);
Get a Feed (GET /api/topics/:topic_id/feeds/:id)

Returns a specific feed for a topic. Requires authorization of read_any_data, or read_application_data.

$response = $feed->find($options);
Create a Feed (POST /api/topics/:topic_id/feeds)

Create a feed on a given topic. Requires authorization of read_any_data, or read_application_data.

The following arguments are required:

  • feed: A Hash containing at: a formatted time of the event. Defaults to the current time if not present.tz: The time zone of the time given in at. Defaults to UTCdata:A hash of data to be stored
$response = $feed->create("{at: '2013-02-14T16:13:33.378Z', tz: 'Eastern Time (US & Canada)', data:{key1:123, key2:456.2, city:'alabama'}}", $options);
Update a Feed (PUT /api/topics/:topic_id/feeds/:id)

Update an associated Feed to the Topic. Requires authorization of read_any_data, or read_application_data.

The following arguments are required:

  • feed: A hash containing data:A hash of data to be stored
$response = $feed->update("{data:{key1:123, key2:456.2, city:'alabama'}}", $options);
Delete a Feed (DELETE /api/topics/:topic_id/feeds/:id)

Deletes the desired feed. Requires authorization of read_any_data, or read_application_data.

$response = $feed->delete($options);

Get Feed data api

Get the value of a specific field within a feed

The following arguments are required:

  • topic_id: The key for the parent topic
  • feed_id: The id of the parent feed
  • id: The key of the specific field
$data = $client->data("my_topic", "2", "captured_at");
Get Feed data with a Topic (GET /api/topics/:topic_id/feeds/:feed_id/data/:id)

Requires authorization of read_any_data, or read_application_data.

$response = $data->find($options);
Update Feed data (PUT /api/topics/:topic_id/feeds/:feed_id/data/:id)

Update a specific value of a field within a feed with the data passed in. Requires authorization of read_any_data, or read_application_data.

$response = $data->update($options);

Subscription api

Subscriptions allows feed data to imported using a socket rather than just using the Feed REST API. By creating a subscription sensit will start to listen for feed data being imported using the specified host and while using the topic name as the channel name.

The following arguments are required:

  • id: The identifier for the subscription
$subscription = $client->subscription("subscription1");
List of Subscriptions (GET /api/subscriptions)

Get the list of all subscriptions for importing feed data to the associated topics. Requires authorization of read_any_subscriptions, or read_application_subscriptions.

$response = $subscription->list($options);
Get a Subscription (GET /api/subscriptions/:id)

Get the information of a specific subscription. Requires authorization of read_any_subscriptions, or read_application_subscriptions.

$response = $subscription->find($options);
Create a Subscription (POST /api/subscriptions)

Create a subscription which will connect to the server and listen for feed data for any of the associated topics. Requires authorization of manage_any_subscriptions, or manage_application_subscriptions.

The following arguments are required:

  • subscription: A Hash containingname:The channel or name to identify the subscription(required).host:The ip address or host of the connection(required).protocol:the protocol to communicate over (http, tcp, udp, mqtt) (required)port:The port of the connection.
$response = $subscription->create("{name:'alpha', host:'10.234.12.11', protocol:'tcp', port:8800}", $options);
Update a Subscription (PUT /api/subscriptions/:id)

Returns an object with the current configuration that Buffer is using, including supported services, their icons and the varying limits of character and schedules. Requires authorization of manage_any_subscriptions, or manage_application_subscriptions.

The following arguments are required:

  • subscription: A Hash containingname:The channel or name to identify the subscription(required).host:The ip address or host of the connection(required).protocol:the protocol to communicate over (http, tcp, udp, mqtt) (required)port:The port of the connection.
$response = $subscription->update("{name:'alpha', host:'10.234.12.11', protocol:'udp', port:8800}", $options);
Delete a Subscription (DELETE /api/subscriptions/:id)

Delete the subscription and stop listening for feed data for the associated topics. Requires authorization of manage_any_subscriptions, or manage_application_subscriptions.

$response = $subscription->delete($options);

Field api

.

The following arguments are required:

  • topic_id: The key for the parent topic
  • id: Username of the user
$field = $client->field("pksunkara", "my_topic");
List all Fields for a Topic (GET /api/topics/:topic_id/fields)

Get all the fields associated with a topic. Requires authorization of read_any_data, or read_application_data

$response = $field->list($options);
Get a Field (GET /api/topics/:topic_id/fields/:id)

Get a Field of the associated a topic and Id. Requires authorization of read_any_data, or read_application_data

$response = $field->find($options);
Create a Field on a Topic (POST /api/topics/:topic_id/fields)

Adds a new field that feed data can be added too. Requires authorization of manage_any_data, or manage_application_data

The following arguments are required:

  • field: A Hash containingname: A descriptive name of the field.key:The name that is used to identify the field in a feed (required).datatype:The type of data that is stored in the field. ie. integer, float, string, bool, datetime
$response = $field->create("{name:'Transaction ID', key:'tran_id', datatype:'integer'}", $options);
Update a Field on a Topic (PUT /api/topics/:topic_id/fields/:id)

Updates the Field data and makes the corresponding changes in the index. Requires authorization of manage_any_data, or manage_application_data

The following arguments are required:

  • field: A Hash containingname: A descriptive name of the field.key:The name that is used to identify the field in a feed (required).datatype:The type of data that is stored in the field. ie. integer, float, string, bool, datetime
$response = $field->update("{name:'Transaction ID', key:'tran_id', datatype:'integer'}", $options);
Delete a Field of the associated Topic. (DELETE /api/topics/:topic_id/fields/:id)

Deletes a field and the feed data in that field. Requires authorization of manage_any_data, or manage_application_data

$response = $field->delete($options);

Publication api

Publications are stored actions which are taken when a feed is created, updated, deleted, or there is a matching percolator query.

The following arguments are required:

  • topic_id: The key for the parent topic
  • id: The identifier of the publication
$publication = $client->publication("my_publication", "my_topic");
List of Publications for a Topic (GET /api/topics/:topic_id/publications)

Get all publications for the associated Topic. Requires authorization of read_any_publications, or read_application_publications.

$response = $publication->list($options);
Get a Publication (GET /api/topics/:topic_id/publications/:id)

Retrieve a specific publication on the associated topic by Id. Requires authorization of read_any_publications, or read_application_publications.

$response = $publication->find($options);
Create a Publication (POST /api/topics/:topic_id/publications)

Create a new publication on the associated Topic which can be easily retrieved later using an id. Requires authorization of manage_any_publications, or manage_application_publications.

The following arguments are required:

  • publication: A Hash containing host:The ip address or host of the connection(required).protocol:the protocol to communicate over (http, tcp, udp, mqtt) (required)port:The port of the connection.
$response = $publication->create("{host:'10.234.12.11', protocol:'http', port:80}", $options);
Update a Publication for a Topic (PUT /api/topics/:topic_id/publications/:id)

Update a publication. Requires authorization of manage_any_publications, or manage_application_publications.

The following arguments are required:

  • publication: A Hash containing host:The ip address or host of the connection(required).protocol:the protocol to communicate over (http, tcp, udp, mqtt) (required)port:The port of the connection.
$response = $publication->update("{host:'10.234.12.11', protocol:'http', port:80}", $options);
Delete a Publication (DELETE /api/topics/:topic_id/publications/:id)

Remove a saved publication on the associated Topic by Id. Requires authorization of manage_any_publications, or manage_application_publications.

$response = $publication->delete($options);

Contributors

Here is a list of Contributors

TODO

License

MIT

Bug Reports

Report here.

Contact

Christopher Waddington (cwadding@gmail.com)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages