Skip to content

Commit

Permalink
feat: allow for http adapter param
Browse files Browse the repository at this point in the history
- Base client class now accepts Http Adapter object as param.
- Add http adapter interface
  • Loading branch information
saas786 committed Mar 2, 2023
1 parent 5d43100 commit f33fe4a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/recurly/base_client.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ abstract class BaseClient
* In addition to the options managed by BaseClient, it accepts the following options:
* - "region" to define the Data Center connection - defaults to "us";
*/
public function __construct(string $api_key, LoggerInterface $logger = null, array $options = [])
public function __construct(string $api_key, LoggerInterface $logger = null, array $options = [], HttpAdapterInterface $http_adapter = null)
{
$this->_api_key = $api_key;
if (isset($options['region'])) {
Expand All @@ -41,6 +41,11 @@ public function __construct(string $api_key, LoggerInterface $logger = null, arr
$this->baseUrl = BaseClient::API_HOSTS[$options['region']];
}

if (is_null($http_adapter)) {
$http_adapter = new HttpAdapter;
}
$this->http = $http_adapter;

$this->http = new HttpAdapter;
if (is_null($logger)) {
$logger = new \Recurly\Logger('Recurly', LogLevel::WARNING);
Expand Down
11 changes: 11 additions & 0 deletions lib/recurly/http_adapter_interface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Recurly;

/**
* @codeCoverageIgnore
*/
interface HttpAdapterInterface
{
public function execute($method, $url, $body, $headers): array;
}

0 comments on commit f33fe4a

Please sign in to comment.