Skip to content

Commit

Permalink
Merge pull request #72 from MinterTeam/dev
Browse files Browse the repository at this point in the history
set http client #70
  • Loading branch information
grkamil authored Nov 14, 2019
2 parents cd722d3 + e839c96 commit 728669f
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 64 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"minter/minter-php-bip-44": "1.0.0",
"bitwasp/bitcoin-lib": "1.0.4",
"simplito/elliptic-php": "1.0.3",
"minter/php-rlp": "^0.2.4"
"minter/php-rlp": "^0.2.4",
"ext-json": "*"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
42 changes: 12 additions & 30 deletions src/Minter/Library/Http.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

namespace Minter\Library;

use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\RequestException;

/**
Expand All @@ -11,51 +13,30 @@
Trait Http
{
/**
* guzzle client
* HTTP API client
*
* @Client
* @var Client
*/
protected $client;

/**
* Set base API url.
* Set API http client
*
* @param string $url
* @param Client $client
*/
public function setApiUrl(string $url): void
protected function setClient(Client $client): void
{
$config = [
'base_uri' => $url,
'connect_timeout' => 15.0,
'timeout' => 30.0,
];

if ($this->client instanceof \GuzzleHttp\Client)
{
$config = $this->client->getConfig();
$config['base_uri'] = $url;
}

$this->setClient(new \GuzzleHttp\Client($config));
$this->client = $client;
}

/**
* Set client
*
* @param Client $client
*/
protected function setClient(\GuzzleHttp\Client $client): void
{
$this->client = $client;
}

/**
* http get request
*
* @param string $url
* @param string $url
* @param array|null $parameters
* @return mixed
* @throws \Exception
* @throws GuzzleException
*/
protected function get(string $url, array $parameters = null)
{
Expand All @@ -74,9 +55,10 @@ protected function get(string $url, array $parameters = null)
* http post request
*
* @param string $url
* @param array $parameters
* @param array $parameters
* @return mixed
* @throws \Exception
* @throws GuzzleException
*/
protected function post(string $url, array $parameters = [])
{
Expand Down
Loading

0 comments on commit 728669f

Please sign in to comment.