Added HTTP client

This commit is contained in:
Walter Dal Mut
2014-09-11 15:04:12 +02:00
parent 6aa668308e
commit 8bd15a302a
16 changed files with 1325 additions and 39 deletions
+1
View File
@@ -1 +1,2 @@
vendor
tags
+10
View File
@@ -4,9 +4,19 @@ php:
- 5.5
- 5.6
before_install:
- sudo apt-get update
- sudo apt-get install libcurl4-openssl-dev libjson0-dev
- wget http://s3.amazonaws.com/influxdb/influxdb_latest_amd64.deb
- sudo useradd influxdb
- sudo dpkg -i influxdb_latest_amd64.deb
- travis_retry sudo service influxdb restart
- sudo service influxdb status
before_script:
- composer selfupdate
- composer install --prefer-source
script:
- vendor/bin/phpspec run
- vendor/bin/phpunit
+36
View File
@@ -33,3 +33,39 @@ Or place it in your require section
}
```
## Send data using HTTP json API
Actually we using Guzzle as HTTP client
```php
$influx->mark("tcp.test", ["mark" => "element"]);
```
## Prepare lib dependencies
Use your DiC or Service Locator in order to provide a configured client
```php
<?php
use InfluxDB\Client;
use InfluxDB\Options;
use InfluxDB\Adapter\GuzzleAdapter;
use GuzzleHttp\Client as GuzzleHttpClient;
$options = new Options();
$options->setHost("analytics.mine.domain.tld");
$options->setPort(8086);
$options->setUsername("root");
$options->setPassword("root");
$guzzleHttp = new GuzzleHttpClient();
$adapter = new GuzzleAdapter($guzzleHttp, $options);
$adapter->setDatabase("mine");
$influx = new Client();
$influx->setAdapter($adapter);
$influx->mark("tcp.test", ["mark" => "element"]);
```
+8 -2
View File
@@ -2,8 +2,14 @@
"name": "corley/influxdb-sdk",
"license": "MIT",
"description": "Send your app metrics to InfluxDB",
"require": {
"guzzlehttp/guzzle": "~4"
},
"require-dev": {
"phpspec/phpspec": "2.*"
"phpspec/phpspec": "2.*",
"phpunit/phpunit": "4.*",
"zendframework/zend-stdlib": "~2",
"crodas/influx-php": "dev-master"
},
"homepage": "http://www.corley.it/",
"keywords": ["influxdb", "udp", "sdk"],
@@ -23,7 +29,7 @@
],
"autoload": {
"psr-0": {
"InfluxDB": "./src/"
"InfluxDB": ["./src/", "./tests"]
}
}
}
Generated
+962 -5
View File
@@ -4,11 +4,274 @@
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "ebef29b39aea3cab015d3bf51e00121e",
"hash": "6ba22c8acf314366cc2d58a2cfaccbd3",
"packages": [
{
"name": "guzzlehttp/guzzle",
"version": "4.2.2",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
"reference": "9c4fbbf6457768f5036fbd88f1229f3fca812a5d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/9c4fbbf6457768f5036fbd88f1229f3fca812a5d",
"reference": "9c4fbbf6457768f5036fbd88f1229f3fca812a5d",
"shasum": ""
},
"require": {
"ext-json": "*",
"guzzlehttp/streams": "~2.1",
"php": ">=5.4.0"
},
"require-dev": {
"ext-curl": "*",
"phpunit/phpunit": "~4.0",
"psr/log": "~1.0"
},
"suggest": {
"ext-curl": "Guzzle will use specific adapters if cURL is present"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.2-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\": "src/"
},
"files": [
"src/functions.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients",
"homepage": "http://guzzlephp.org/",
"keywords": [
"client",
"curl",
"framework",
"http",
"http client",
"rest",
"web service"
],
"time": "2014-09-08 22:11:58"
},
{
"name": "guzzlehttp/streams",
"version": "2.1.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/streams.git",
"reference": "f91b721d73f0e561410903b3b3c90a5d0e40b534"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/streams/zipball/f91b721d73f0e561410903b3b3c90a5d0e40b534",
"reference": "f91b721d73f0e561410903b3b3c90a5d0e40b534",
"shasum": ""
},
"require": {
"php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Stream\\": "src/"
},
"files": [
"src/functions.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Provides a simple abstraction over streams of data (Guzzle 4+)",
"homepage": "http://guzzlephp.org/",
"keywords": [
"Guzzle",
"stream"
],
"time": "2014-08-17 21:15:53"
}
],
"packages-dev": [
{
"name": "crodas/influx-php",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/crodas/InfluxPHP.git",
"reference": "205bd51cb44dec70d0da06ba87e47f5c0986bdb4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/crodas/InfluxPHP/zipball/205bd51cb44dec70d0da06ba87e47f5c0986bdb4",
"reference": "205bd51cb44dec70d0da06ba87e47f5c0986bdb4",
"shasum": ""
},
"type": "library",
"autoload": {
"classmap": [
"lib/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD"
],
"authors": [
{
"name": "César D. Rodas",
"email": "crodas@php.net"
}
],
"description": "Simple client for InfluxDB",
"time": "2014-09-04 17:26:53"
},
{
"name": "ocramius/instantiator",
"version": "1.1.3",
"source": {
"type": "git",
"url": "https://github.com/Ocramius/Instantiator.git",
"reference": "e24a12178906ff2e7471b8aaf3a0eb789b59f881"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Ocramius/Instantiator/zipball/e24a12178906ff2e7471b8aaf3a0eb789b59f881",
"reference": "e24a12178906ff2e7471b8aaf3a0eb789b59f881",
"shasum": ""
},
"require": {
"ocramius/lazy-map": "1.0.*",
"php": "~5.3"
},
"require-dev": {
"athletic/athletic": "~0.1.8",
"ext-pdo": "*",
"ext-phar": "*",
"phpunit/phpunit": "~4.0",
"squizlabs/php_codesniffer": "2.0.*@ALPHA"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
},
"autoload": {
"psr-0": {
"Instantiator\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Marco Pivetta",
"email": "ocramius@gmail.com",
"homepage": "http://ocramius.github.com/"
}
],
"description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors",
"homepage": "https://github.com/Ocramius/Instantiator",
"keywords": [
"constructor",
"instantiate"
],
"time": "2014-08-25 14:48:16"
},
{
"name": "ocramius/lazy-map",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/Ocramius/LazyMap.git",
"reference": "7fe3d347f5e618bcea7d39345ff83f3651d8b752"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Ocramius/LazyMap/zipball/7fe3d347f5e618bcea7d39345ff83f3651d8b752",
"reference": "7fe3d347f5e618bcea7d39345ff83f3651d8b752",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"athletic/athletic": "~0.1.6",
"phpmd/phpmd": "1.5.*",
"phpunit/phpunit": ">=3.7",
"satooshi/php-coveralls": "~0.6",
"squizlabs/php_codesniffer": "1.4.*"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-0": {
"LazyMap\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Marco Pivetta",
"email": "ocramius@gmail.com",
"homepage": "http://ocramius.github.com/",
"role": "Developer"
}
],
"description": "A library that provides lazy instantiation logic for a map of objects",
"homepage": "https://github.com/Ocramius/LazyMap",
"keywords": [
"lazy",
"lazy instantiation",
"lazy loading",
"map",
"service location"
],
"time": "2013-11-09 22:30:54"
},
{
"name": "phpdocumentor/reflection-docblock",
"version": "2.0.3",
@@ -223,6 +486,650 @@
],
"time": "2014-07-18 21:26:55"
},
{
"name": "phpunit/php-code-coverage",
"version": "2.0.11",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
"reference": "53603b3c995f5aab6b59c8e08c3a663d2cc810b7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/53603b3c995f5aab6b59c8e08c3a663d2cc810b7",
"reference": "53603b3c995f5aab6b59c8e08c3a663d2cc810b7",
"shasum": ""
},
"require": {
"php": ">=5.3.3",
"phpunit/php-file-iterator": "~1.3",
"phpunit/php-text-template": "~1.2",
"phpunit/php-token-stream": "~1.3",
"sebastian/environment": "~1.0",
"sebastian/version": "~1.0"
},
"require-dev": {
"ext-xdebug": ">=2.1.4",
"phpunit/phpunit": "~4.1"
},
"suggest": {
"ext-dom": "*",
"ext-xdebug": ">=2.2.1",
"ext-xmlwriter": "*"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
""
],
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sb@sebastian-bergmann.de",
"role": "lead"
}
],
"description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.",
"homepage": "https://github.com/sebastianbergmann/php-code-coverage",
"keywords": [
"coverage",
"testing",
"xunit"
],
"time": "2014-08-31 06:33:04"
},
{
"name": "phpunit/php-file-iterator",
"version": "1.3.4",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-file-iterator.git",
"reference": "acd690379117b042d1c8af1fafd61bde001bf6bb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/acd690379117b042d1c8af1fafd61bde001bf6bb",
"reference": "acd690379117b042d1c8af1fafd61bde001bf6bb",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"type": "library",
"autoload": {
"classmap": [
"File/"
]
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
""
],
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sb@sebastian-bergmann.de",
"role": "lead"
}
],
"description": "FilterIterator implementation that filters files based on a list of suffixes.",
"homepage": "https://github.com/sebastianbergmann/php-file-iterator/",
"keywords": [
"filesystem",
"iterator"
],
"time": "2013-10-10 15:34:57"
},
{
"name": "phpunit/php-text-template",
"version": "1.2.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-text-template.git",
"reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/206dfefc0ffe9cebf65c413e3d0e809c82fbf00a",
"reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"type": "library",
"autoload": {
"classmap": [
"Text/"
]
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
""
],
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sb@sebastian-bergmann.de",
"role": "lead"
}
],
"description": "Simple template engine.",
"homepage": "https://github.com/sebastianbergmann/php-text-template/",
"keywords": [
"template"
],
"time": "2014-01-30 17:20:04"
},
{
"name": "phpunit/php-timer",
"version": "1.0.5",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-timer.git",
"reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/19689d4354b295ee3d8c54b4f42c3efb69cbc17c",
"reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"type": "library",
"autoload": {
"classmap": [
"PHP/"
]
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
""
],
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sb@sebastian-bergmann.de",
"role": "lead"
}
],
"description": "Utility class for timing",
"homepage": "https://github.com/sebastianbergmann/php-timer/",
"keywords": [
"timer"
],
"time": "2013-08-02 07:42:54"
},
{
"name": "phpunit/php-token-stream",
"version": "1.3.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-token-stream.git",
"reference": "f8d5d08c56de5cfd592b3340424a81733259a876"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/f8d5d08c56de5cfd592b3340424a81733259a876",
"reference": "f8d5d08c56de5cfd592b3340424a81733259a876",
"shasum": ""
},
"require": {
"ext-tokenizer": "*",
"php": ">=5.3.3"
},
"require-dev": {
"phpunit/phpunit": "~4.2"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.3-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de"
}
],
"description": "Wrapper around PHP's tokenizer extension.",
"homepage": "https://github.com/sebastianbergmann/php-token-stream/",
"keywords": [
"tokenizer"
],
"time": "2014-08-31 06:12:13"
},
{
"name": "phpunit/phpunit",
"version": "4.2.5",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "c3abe5953d1e60a0bf23012b1bc8c4d07f4832d7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c3abe5953d1e60a0bf23012b1bc8c4d07f4832d7",
"reference": "c3abe5953d1e60a0bf23012b1bc8c4d07f4832d7",
"shasum": ""
},
"require": {
"ext-dom": "*",
"ext-json": "*",
"ext-pcre": "*",
"ext-reflection": "*",
"ext-spl": "*",
"php": ">=5.3.3",
"phpunit/php-code-coverage": "~2.0",
"phpunit/php-file-iterator": "~1.3.1",
"phpunit/php-text-template": "~1.2",
"phpunit/php-timer": "~1.0.2",
"phpunit/phpunit-mock-objects": "~2.2",
"sebastian/comparator": "~1.0",
"sebastian/diff": "~1.1",
"sebastian/environment": "~1.0",
"sebastian/exporter": "~1.0",
"sebastian/version": "~1.0",
"symfony/yaml": "~2.0"
},
"suggest": {
"phpunit/php-invoker": "~1.1"
},
"bin": [
"phpunit"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.2.x-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
"",
"../../symfony/yaml/"
],
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de",
"role": "lead"
}
],
"description": "The PHP Unit Testing framework.",
"homepage": "http://www.phpunit.de/",
"keywords": [
"phpunit",
"testing",
"xunit"
],
"time": "2014-09-06 18:38:27"
},
{
"name": "phpunit/phpunit-mock-objects",
"version": "2.2.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git",
"reference": "b241b18d87a47093f20fae8b0ba40379b00bd53a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/b241b18d87a47093f20fae8b0ba40379b00bd53a",
"reference": "b241b18d87a47093f20fae8b0ba40379b00bd53a",
"shasum": ""
},
"require": {
"ocramius/instantiator": "~1.0",
"php": ">=5.3.3",
"phpunit/php-text-template": "~1.2"
},
"require-dev": {
"phpunit/phpunit": "~4.2"
},
"suggest": {
"ext-soap": "*"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.2.x-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sb@sebastian-bergmann.de",
"role": "lead"
}
],
"description": "Mock Object library for PHPUnit",
"homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/",
"keywords": [
"mock",
"xunit"
],
"time": "2014-09-06 17:32:37"
},
{
"name": "sebastian/comparator",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/comparator.git",
"reference": "f7069ee51fa9fb6c038e16a9d0e3439f5449dcf2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/f7069ee51fa9fb6c038e16a9d0e3439f5449dcf2",
"reference": "f7069ee51fa9fb6c038e16a9d0e3439f5449dcf2",
"shasum": ""
},
"require": {
"php": ">=5.3.3",
"sebastian/diff": "~1.1",
"sebastian/exporter": "~1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.1"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de",
"role": "lead"
},
{
"name": "Jeff Welch",
"email": "whatthejeff@gmail.com"
},
{
"name": "Volker Dusch",
"email": "github@wallbash.com"
},
{
"name": "Bernhard Schussek",
"email": "bschussek@2bepublished.at"
}
],
"description": "Provides the functionality to compare PHP values for equality",
"homepage": "http://www.github.com/sebastianbergmann/comparator",
"keywords": [
"comparator",
"compare",
"equality"
],
"time": "2014-05-02 07:05:58"
},
{
"name": "sebastian/diff",
"version": "1.1.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/diff.git",
"reference": "1e091702a5a38e6b4c1ba9ca816e3dd343df2e2d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/1e091702a5a38e6b4c1ba9ca816e3dd343df2e2d",
"reference": "1e091702a5a38e6b4c1ba9ca816e3dd343df2e2d",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.1-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de",
"role": "lead"
},
{
"name": "Kore Nordmann",
"email": "mail@kore-nordmann.de"
}
],
"description": "Diff implementation",
"homepage": "http://www.github.com/sebastianbergmann/diff",
"keywords": [
"diff"
],
"time": "2013-08-03 16:46:33"
},
{
"name": "sebastian/environment",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/environment.git",
"reference": "79517609ec01139cd7e9fded0dd7ce08c952ef6a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/79517609ec01139cd7e9fded0dd7ce08c952ef6a",
"reference": "79517609ec01139cd7e9fded0dd7ce08c952ef6a",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"phpunit/phpunit": "4.0.*@dev"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de",
"role": "lead"
}
],
"description": "Provides functionality to handle HHVM/PHP environments",
"homepage": "http://www.github.com/sebastianbergmann/environment",
"keywords": [
"Xdebug",
"environment",
"hhvm"
],
"time": "2014-02-18 16:17:19"
},
{
"name": "sebastian/exporter",
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/exporter.git",
"reference": "1f9a98e6f5dfe0524cb8c6166f7c82f3e9ae1529"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/1f9a98e6f5dfe0524cb8c6166f7c82f3e9ae1529",
"reference": "1f9a98e6f5dfe0524cb8c6166f7c82f3e9ae1529",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"phpunit/phpunit": "4.0.*@dev"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de",
"role": "lead"
},
{
"name": "Jeff Welch",
"email": "whatthejeff@gmail.com"
},
{
"name": "Volker Dusch",
"email": "github@wallbash.com"
},
{
"name": "Adam Harvey",
"email": "aharvey@php.net",
"role": "Lead"
},
{
"name": "Bernhard Schussek",
"email": "bschussek@2bepublished.at"
}
],
"description": "Provides the functionality to export PHP variables for visualization",
"homepage": "http://www.github.com/sebastianbergmann/exporter",
"keywords": [
"export",
"exporter"
],
"time": "2014-02-16 08:26:31"
},
{
"name": "sebastian/version",
"version": "1.0.3",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/version.git",
"reference": "b6e1f0cf6b9e1ec409a0d3e2f2a5fb0998e36b43"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/version/zipball/b6e1f0cf6b9e1ec409a0d3e2f2a5fb0998e36b43",
"reference": "b6e1f0cf6b9e1ec409a0d3e2f2a5fb0998e36b43",
"shasum": ""
},
"type": "library",
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de",
"role": "lead"
}
],
"description": "Library that helps with managing the version number of Git-hosted PHP projects",
"homepage": "https://github.com/sebastianbergmann/version",
"time": "2014-03-07 15:35:33"
},
{
"name": "symfony/console",
"version": "v2.5.4",
@@ -428,15 +1335,65 @@
"description": "Symfony Yaml Component",
"homepage": "http://symfony.com",
"time": "2014-08-31 03:22:04"
},
{
"name": "zendframework/zend-stdlib",
"version": "2.3.1",
"target-dir": "Zend/Stdlib",
"source": {
"type": "git",
"url": "https://github.com/zendframework/Component_ZendStdlib.git",
"reference": "c1f4830018b5d4f034d32fa01a9e17ea176f56f6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zendframework/Component_ZendStdlib/zipball/c1f4830018b5d4f034d32fa01a9e17ea176f56f6",
"reference": "c1f4830018b5d4f034d32fa01a9e17ea176f56f6",
"shasum": ""
},
"require": {
"php": ">=5.3.23"
},
"require-dev": {
"zendframework/zend-eventmanager": "self.version",
"zendframework/zend-serializer": "self.version",
"zendframework/zend-servicemanager": "self.version"
},
"suggest": {
"zendframework/zend-eventmanager": "To support aggregate hydrator usage",
"zendframework/zend-serializer": "Zend\\Serializer component",
"zendframework/zend-servicemanager": "To support hydrator plugin manager usage"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.3-dev",
"dev-develop": "2.4-dev"
}
},
"autoload": {
"psr-0": {
"Zend\\Stdlib\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"keywords": [
"stdlib",
"zf2"
],
"time": "2014-04-15 15:28:48"
}
],
"aliases": [
],
"minimum-stability": "stable",
"stability-flags": [
],
"stability-flags": {
"crodas/influx-php": 20
},
"prefer-stable": false,
"platform": [
+20
View File
@@ -0,0 +1,20 @@
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/3.7/phpunit.xsd"
bootstrap="tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
verbose="false">
<testsuites>
<testsuite name="InfluxDB SDK Integration Tests">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
@@ -0,0 +1,29 @@
<?php
namespace spec\InfluxDB\Adapter;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use GuzzleHttp\Client;
use InfluxDB\Options;
class GuzzleAdapterSpec extends ObjectBehavior
{
function let(Client $client, Options $options)
{
$options->getTcpEndpointFor(Argument::Any())->willReturn("localhost");
$this->beConstructedWith($client, $options);
}
function it_is_initializable()
{
$this->shouldHaveType('InfluxDB\Adapter\GuzzleAdapter');
}
function it_should_send_data_via_post(Client $client, Options $options)
{
$client->post("localhost", ['body' => json_encode(['pippo'])])->shouldBeCalledTimes(1);
$this->send(["pippo"]);
}
}
+4 -2
View File
@@ -4,12 +4,13 @@ namespace spec\InfluxDB\Adapter;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use InfluxDB\Options;
class UdpAdapterSpec extends ObjectBehavior
{
function let()
function let(Options $options)
{
$this->beConstructedWith();
$this->beConstructedWith($options);
}
function it_is_initializable()
@@ -20,5 +21,6 @@ class UdpAdapterSpec extends ObjectBehavior
function it_should_implement_adapter_interface()
{
$this->shouldImplement("InfluxDB\Adapter\AdapterInterface");
$this->shouldImplement("InfluxDB\Adapter\ConnectableInterface");
}
}
+37
View File
@@ -0,0 +1,37 @@
<?php
namespace spec\InfluxDB;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class OptionsSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('InfluxDB\Options');
}
function it_should_create_a_valid_tcp_endpoint()
{
$this->getTcpEndpointFor("mine")
->shouldReturn("http://localhost:1806/db/mine/series?u=root&p=root");
}
function it_should_allows_option_override_for_tcp_endpoint()
{
$this->setHost("influx.1.prod.tld");
$this->setPort(19385);
$this->setUsername("walter");
$this->setPassword("walter");
$this->getTcpEndpointFor("me")
->shouldReturn("http://influx.1.prod.tld:19385/db/me/series?u=walter&p=walter");
}
function it_should_allows_https_for_tcp_endpoint()
{
$this->setProtocol("https");
$this->getTcpEndpointFor("me")
->shouldReturn("https://localhost:1806/db/me/series?u=root&p=root");
}
}
+1 -7
View File
@@ -1,13 +1,7 @@
<?php
namespace InfluxDb\Adapter;
interface AdapterInterface
interface AdapterInterface
{
public function getName();
public function connect();
public function disconnect();
public function send($message);
}
@@ -0,0 +1,8 @@
<?php
namespace InfluxDb\Adapter;
interface ConnectableInterface
{
public function connect();
public function disconnect();
}
+40
View File
@@ -0,0 +1,40 @@
<?php
namespace InfluxDB\Adapter;
use GuzzleHttp\Client;
use InfluxDB\Options;
class GuzzleAdapter implements AdapterInterface
{
private $httpClient;
private $options;
private $database;
public function __construct(Client $httpClient, Options $options)
{
$this->httpClient = $httpClient;
$this->options = $options;
}
public function getDatabase()
{
return $this->database;
}
public function setDatabase($database)
{
$this->database = $database;
return $this;
}
public function send($message)
{
$httpMessage = [
"body" => json_encode($message)
];
$endpoint = $this->options->getTcpEndpointFor($this->getDatabase());
$this->httpClient->post($endpoint, $httpMessage);
}
}
+8 -23
View File
@@ -2,26 +2,16 @@
namespace InfluxDB\Adapter;
class UdpAdapter implements AdapterInterface
use InfluxDB\Options;
class UdpAdapter implements AdapterInterface, ConnectableInterface
{
private $host;
private $port;
private $username;
private $password;
private $name = __NAMESPACE__;
private $options;
private $socket;
public function __construct(
$host = "127.0.0.1",
$port = 5551,
$user = "root",
$password = "root"
)
public function __construct(Options $options)
{
$this->host = $host;
$this->port = $port;
$this->username = $user;
$this->password = $password;
$this->options = $options;
}
public function getSocket()
@@ -29,11 +19,6 @@ class UdpAdapter implements AdapterInterface
return $this->socket;
}
public function getName()
{
return $this->name;
}
public function connect()
{
$this->socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
@@ -42,12 +27,12 @@ class UdpAdapter implements AdapterInterface
public function disconnect()
{
socket_close($this->getSocket());
socket_close($this->getSocket());
}
public function send($message)
{
$message = json_encode($message);
socket_sendto($this->getSocket(), $message, strlen($message), 0, $this->host, $this->port);
}
}
}
+89
View File
@@ -0,0 +1,89 @@
<?php
namespace InfluxDB;
class Options
{
private $host;
private $port;
private $username;
private $password;
private $protocol;
public function __construct()
{
$this->host = "localhost";
$this->port = 8086;
$this->username = "root";
$this->password = "root";
$this->setProtocol("http");
}
public function getProtocol()
{
return $this->protocol;
}
public function setProtocol($protocol)
{
$this->protocol = $protocol;
return $this;
}
public function getHost()
{
return $this->host;
}
public function setHost($host)
{
$this->host = $host;
return $this;
}
public function getPort()
{
return $this->port;
}
public function setPort($port)
{
$this->port = $port;
return $this;
}
public function getUsername()
{
return $this->username;
}
public function setUsername($username)
{
$this->username = $username;
return $this;
}
public function getPassword()
{
return $this->password;
}
public function setPassword($password)
{
$this->password = $password;
return $this;
}
public function getTcpEndpointFor($database)
{
return sprintf(
"%s://%s:%d/db/%s/series?u=%s&p=%s",
$this->getProtocol(),
$this->getHost(),
$this->getPort(),
$database,
$this->getUsername(),
$this->getPassword()
);
}
}
+61
View File
@@ -0,0 +1,61 @@
<?php
namespace InfluxDB;
use InfluxDB\Adapter\GuzzleAdapter;
use InfluxDB\Options;
use GuzzleHttp\Client as GuzzleHttpClient;
use Zend\Stdlib\Hydrator\ArraySerializable;
use crodas\InfluxPHP\Client as Crodas;
class ClientTest extends \PHPUnit_Framework_TestCase
{
private $object;
private $options;
private $hydrator;
private $anotherClient;
public function setUp()
{
$options = include __DIR__ . '/../bootstrap.php';
$this->options = $options;
$this->object = new Client();
$this->hydrator = new ArraySerializable();
$client = new Crodas(
$options["tcp"]["host"],
$options["tcp"]["port"],
$options["tcp"]["username"],
$options["tcp"]["password"]
);
$client->deleteDatabase($options["tcp"]["database"]);
$client->createDatabase($options["tcp"]["database"]);
$this->anotherClient = $client;
}
public function testHttpApiWorksCorrectly()
{
$tcpOptions = $this->options["tcp"];
$options = new Options();
$options->setHost($tcpOptions["host"]);
$options->setPort($tcpOptions["port"]);
$options->setUsername($tcpOptions["username"]);
$options->setPassword($tcpOptions["password"]);
$guzzleHttp = new GuzzleHttpClient();
$adapter = new GuzzleAdapter($guzzleHttp, $options);
$adapter->setDatabase($tcpOptions["database"]);
$influx = new Client();
$influx->setAdapter($adapter);
$influx->mark("tcp.test", ["mark" => "element"]);
$cursor = $this->anotherClient->getDatabase("mine")->query("select * from tcp.test");
$this->assertCount(1, $cursor);
$this->assertEquals("element", $cursor[0]->mark);
}
}
+11
View File
@@ -0,0 +1,11 @@
<?php
return [
"tcp" => [
"host" => "localhost",
"port" => 8086,
"protocol" => "http",
"database" => "mine",
"username" => "root",
"password" => "root",
]
];