Skip to content

Commit

Permalink
Changes for dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
turbo124 committed Apr 22, 2020
1 parent 345f37a commit 7105e44
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 57 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
}
],
"require": {
"php": "^7.1",
"illuminate/support": "^6.0"
"php": "^7.3",
"guzzlehttp/guzzle": "^6.5",
"illuminate/support": "^6.0|^7.0"
},
"require-dev": {
"orchestra/testbench": "^4.0",
Expand Down
7 changes: 0 additions & 7 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,4 @@
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
</phpunit>
2 changes: 2 additions & 0 deletions src/Collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Turbo124\Collector;

use Turbo124\Collector\Collector\Generator;

class Collector
{
private $config;
Expand Down
42 changes: 40 additions & 2 deletions src/Collector/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,59 @@ class Generator

public function increment(Collector $collector)
{
date_default_timezone_set('UTC');

$data = array_merge($this->buildRequest($collector), ['action' => 'increment', 'timestamp'=> date("Y-m-d H:i:s")]);

return $this->fire($data);
}

public function decrement(Collector $collector)
{

$data = array_merge($this->buildRequest($collector), ['action' => 'decrement', 'timestamp'=> date("Y-m-d H:i:s")]);
}

private function endPoint()
{
return config('collector.endpoint');
return config('collector.endpoint') . '/collect';
}

private function apiKey()
{
return config('collect.api_key');
}

private function httpClient()
{
return new \GuzzleHttp\Client(['headers' => ['X-API-KEY' => $this->apiKey()]]);
}

private function buildRequest(Collector $collector)
{
return [
'name' => $collector->getName(),
'type' => $collector->getType(),
];
}

private function fire(array $data)
{
$client = $this->httpClient();
$response = $client->request('POST',$this->endPoint(), ['body' => $data]);
return $this->handleResponse($response);
}

private function handleResponse($response)
{
switch ($response->getStatusCode()) {
case 200:
# code...
break;

default:
//we may need to cache the action and retry until we get a 200
break;
}
}

}
26 changes: 1 addition & 25 deletions src/CollectorServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,12 @@ class CollectorServiceProvider extends ServiceProvider
*/
public function boot()
{
/*
* Optional methods to load your package assets
*/
// $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'collector');
// $this->loadViewsFrom(__DIR__.'/../resources/views', 'collector');
// $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
// $this->loadRoutesFrom(__DIR__.'/routes.php');

if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__.'/../config/collector.php' => config_path('collector.php'),
], 'config');

// Publishing the views.
/*$this->publishes([
__DIR__.'/../resources/views' => resource_path('views/vendor/collector'),
], 'views');*/

// Publishing assets.
/*$this->publishes([
__DIR__.'/../resources/assets' => public_path('vendor/collector'),
], 'assets');*/

// Publishing the translation files.
/*$this->publishes([
__DIR__.'/../resources/lang' => resource_path('lang/vendor/collector'),
], 'lang');*/

// Registering package commands.
// $this->commands([]);
}
}

Expand All @@ -50,7 +26,7 @@ public function boot()
public function register()
{
// Automatically apply the package configuration
$this->mergeConfigFrom(__DIR__.'/../config/config.php', 'collector');
$this->mergeConfigFrom(__DIR__.'/../config/collector.php', 'collector');

// Register the main class to use with the facade
$this->app->singleton('collector', function () {
Expand Down
21 changes: 0 additions & 21 deletions tests/ExampleTest.php

This file was deleted.

0 comments on commit 7105e44

Please sign in to comment.