dev-master
9999999-dev https://github.com/beebotte/bbt_phpPhP library for interfacing with Beebotte
MIT
The Requires
- php >=5.2
- ext-curl *
api rest restful realtime iot device internet of things websockets pubsub beebotte connected
PhP library for interfacing with Beebotte
what | where |
---|---|
overview | http://beebotte.com/overview |
tutorials | http://beebotte.com/tutorials |
apidoc | http://beebotte.com/api |
source | https://github.com/beebotte/bbt_php |
Think you have found a bug? Want to see a new feature in Beebotte? Please open an issue in github. Please provide as much information as possible about the issue type and how to reproduce it., (*1)
https://github.com/beebotte/bbt_php/issues, (*2)
The Beebotte PHP library is available as a composer
package
called bbt_php
(See https://packagist.org/packages/beebotte/bbt_php)., (*3)
composer require beebotte/bbt_php
Or add the following to composer.json
in your project:, (*4)
"require": { "beebotte/bbt_php": "*" }
and then run composer update
., (*5)
If you don't have composer, you can still get Beebotte PHP library by cloning the project from github:, (*6)
git clone https://github.com/beebotte/bbt_php.git
or by downloading the library source files., (*7)
To use the library, you need to be a registered user. If this is not the case, create your account at http://beebotte.com and note your access credentials., (*8)
As a reminder, Beebotte resource description uses a two levels hierarchy:, (*9)
Use your account api and secret keys to initialize Beebotte connector:, (*10)
$api_key = 'YOUR_API_KEY'; $secret_key = 'YOUR_SECRET_KEY'; $bbt = new Beebotte($api_key, $secret_key);
You can read data from one of your channel resources using:, (*11)
$records = $bbt->read("channel1", "resource1", 5 /* read last 5 records */);
You can read data from a public channel by specifying the channel owner:, (*12)
$records = $bbt->publicRead("owner", "channel1", "resource1", 5 /* read last 5 records */);
You can write data to a resource of one of your channels using:, (*13)
$bbt->write("channel1", "resource1", "Hello Horld");
If you have multiple records to write (to one or multiple resources of the same
channel), you can use the bulk write
method:, (*14)
$bbt->writeBulk("channel1", array(array("resource" => "resource1", "data" => "Hello"), array("resource" => "resource2", "data" => "World")));
You can publish data to a channel resource using:, (*15)
$bbt->publish("any_channel", "any_resource", "Hello World");
Published data is transient. It will not saved to any database; rather, it will
be delivered to active subscribers in real time. The Publish operations do not
require that the channel and resource be actually created.
They will be considered as virtual: the channel and resource exist as long as
you are publishing data to them.
By default, published data is public, publish a private message, you need to
add private-
prefix to the channel name like this:, (*16)
$bbt->publish("private-any_channel", "any_resource", "Hello World");
If you have multiple records to publish (to one or multiple resources of the
same channel), you can use the bulk publish
method:, (*17)
$bbt->publishBulk("channel1", array(array("resource" => "resource1", "data" => "Hello"), array("resource" => "resource2", "data" => "World")));
The library provides a Resource Class that can be used as follows, (*18)
//Create the resource object $resource = new Resource($bbt, "channel1", "resource1"); //Read data from public resource $records = $resource->read("owner", 2 /* last 2 records */); //Read data $records = $resource->read(null, 2 /* last 2 records */); //Read the last written record $record = $resource->recentValue(); //Write data $resource->write("Hello World"); //Publish data $resource->publish("Hola amigo");
subscribe
RequestsAs described in https://beebotte.com/docs/clientauth, you need to implement
an authentication endpoint
to grant users of your Web application access to
privileged channel resources on your Beebotte account., (*19)
The library provides utility functions to simplify the implementation of such endpoints:, (*20)
// authenticate client subscribe request given all parameters $sig = $bbt->auth_client($sid, $channel, $resource, $ttl, $read, $write);
you can also build the string to sign yourself and feed it to the library to get it signed:, (*21)
$r = $read ? "true" : "false"; $w = $write? "true" : "false"; $stringToSign = $sid . ":" . $channel . "." . $resource . ":ttl=" . $ttl . ":read=" . $r . ":write=" . $w; $sig = $bbt->sign($stringToSign);
Copyright 2013 - 2019 Beebotte., (*22)
The MIT License, (*23)
PhP library for interfacing with Beebotte
MIT
api rest restful realtime iot device internet of things websockets pubsub beebotte connected