Skip to content
This repository has been archived by the owner on Mar 20, 2022. It is now read-only.

Commit

Permalink
first commit ..
Browse files Browse the repository at this point in the history
  • Loading branch information
nickurt committed May 8, 2018
0 parents commit 5b62d3a
Show file tree
Hide file tree
Showing 17 changed files with 590 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/vendor
composer.phar
composer.lock
.DS_Store
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## Laravel HostFact
### Installation
Install this package with composer:
```
composer require nickurt/laravel-hostfact:1.*
```

Add the provider to config/app.php file

```php
'nickurt\HostFact\ServiceProvider',
```

and the facade in the file

```php
'HostFact' => 'nickurt\HostFact\Facade',
```

Copy the config files for the HostFact-plugin

```
php artisan vendor:publish --provider="nickurt\HostFact\ServiceProvider" --tag="config"
```
Add the HostFact credentials to your .env file
```
HOSTFACT_DEFAULT_URL=
HOSTFACT_DEFAULT_KEY=
```
### Tests
```sh
phpunit
```
- - -
32 changes: 32 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "nickurt/laravel-hostfact",
"description": "HostFact for Laravel 5",
"keywords": ["hostfact", "laravel"],
"license": "MIT",
"require": {
"php": "^7.0",
"laravel/framework": "~5.5.0|~5.6.0"
},
"require-dev": {
"phpunit/phpunit" : "^6.2|^7.0"
},
"autoload": {
"psr-4": {
"nickurt\\HostFact\\": "src/"
},
"files": [
"src/helpers.php"
]
},
"minimum-stability": "dev",
"extra": {
"laravel": {
"providers": [
"nickurt\\HostFact\\ServiceProvider"
],
"aliases": {
"HostFact": "nickurt\\HostFact\\Facade"
}
}
}
}
16 changes: 16 additions & 0 deletions config/hostfact.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

return [

'default' => env('HOSTFACT_CONNECTION', 'default'),

'panels' => [

'default' => [
'url' => env('HOSTFACT_DEFAULT_URL'),
'key' => env('HOSTFACT_DEFAULT_KEY'),
],

],

];
22 changes: 22 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Laravel HostFact Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
</phpunit>
34 changes: 34 additions & 0 deletions src/Api/AbstractApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace nickurt\HostFact\Api;

use nickurt\HostFact\Client;

abstract class AbstractApi implements ApiInterface
{
/**
* @var Client
*/
public $client;

/**
* AbstractApi constructor.
* @param Client $client
*/
public function __construct(Client $client)
{
$this->client = $client;
}

/**
* @param $parameters
* @return mixed
* @throws \GuzzleHttp\Exception\GuzzleException
*/
protected function post($parameters)
{
return $this->client->getHttpClient()->post(array_merge([
'api_key' => $this->client->getHttpClient()->getOptions()['key']
], $parameters));
}
}
8 changes: 8 additions & 0 deletions src/Api/ApiInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace nickurt\HostFact\Api;

interface ApiInterface
{

}
66 changes: 66 additions & 0 deletions src/Api/Debtors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace nickurt\HostFact\Api;

class Debtors extends AbstractApi
{
public function add($params)
{
//
}

public function attachmentAdd($params)
{
//
}

public function attachmentDelete($params)
{
//
}

public function attachmentDownload($params)
{
//
}

public function checkLogin($params)
{
//
}

public function edit($params)
{
//
}

public function generatePdf($params)
{
//
}

/**
* @param $params
* @return mixed
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function list($params)
{
return $this->post(array_merge(['controller' => 'debtor', 'action' => 'list'], $params));
}

public function sendEmail($params)
{
//
}

public function show($params)
{
//
}

public function updateLoginCredentials($params)
{
//
}
}
84 changes: 84 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace nickurt\HostFact;

use \nickurt\HostFact\HttpClient\HttpClient;

class Client
{
/**
* @var
*/
protected $httpClient;

/**
* @var array
*/
protected $classes = [
'debtors' => 'Debtors'
];

/**
* @var array
*/
protected $options = [];

/**
* @param $method
* @param $args
* @return mixed
*/
public function __call($method, $args)
{
try {
return $this->api($method);
} catch (InvalidArgumentException $e) {
throw new \BadMethodCallException(sprintf('Undefined method called:"%s"', $method));
}
}

/**
* @param $name
* @return mixed
*/
public function api($name)
{
if (!isset($this->classes[$name])) {
throw new \InvalidArgumentException(sprintf('Undefined method called:"%s"', $name));
}

$class = '\\nickurt\\HostFact\\Api\\' . $this->classes[$name];

return new $class($this);
}

/**
* @return HttpClient
*/
public function getHttpClient()
{
if (!isset($this->httpClient)) {
$this->httpClient = new HttpClient();
}

$this->httpClient->setOptions($this->getOptions());

return $this->httpClient;
}

/**
* @return array
*/
public function getOptions()
{
return $this->options;
}

/**
* @param $options
*/
public function setOptions($options)
{
$this->options = $options;
}
}
8 changes: 8 additions & 0 deletions src/ClientInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace nickurt\HostFact;

interface ClientInterface
{

}
14 changes: 14 additions & 0 deletions src/Facade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace nickurt\HostFact;

class Facade extends \Illuminate\Support\Facades\Facade
{
/**
* {@inheritDoc}
*/
protected static function getFacadeAccessor()
{
return 'HostFact';
}
}
Loading

0 comments on commit 5b62d3a

Please sign in to comment.