Skip to content

Commit f331095

Browse files
mbabkerwilsonge
authored andcommitted
Deprecate Http subclass (#43)
* Deprecate Http subclass * GitHub requires User Agent
1 parent 6828be1 commit f331095

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

src/AbstractGithubObject.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace Joomla\Github;
1010

1111
use Joomla\Http\Exception\UnexpectedResponseException;
12+
use Joomla\Http\Http as BaseHttp;
1213
use Joomla\Http\Response;
1314
use Joomla\Uri\Uri;
1415
use Joomla\Registry\Registry;
@@ -75,14 +76,14 @@ abstract class AbstractGithubObject
7576
* Constructor.
7677
*
7778
* @param Registry $options GitHub options object.
78-
* @param Http $client The HTTP client object.
79+
* @param BaseHttp $client The HTTP client object.
7980
*
8081
* @since 1.0
8182
*/
82-
public function __construct(Registry $options = null, Http $client = null)
83+
public function __construct(Registry $options = null, BaseHttp $client = null)
8384
{
84-
$this->options = isset($options) ? $options : new Registry;
85-
$this->client = isset($client) ? $client : new Http($this->options);
85+
$this->options = $options ?: new Registry;
86+
$this->client = $client ?: new Http($this->options);
8687

8788
$this->package = get_class($this);
8889
$this->package = substr($this->package, strrpos($this->package, '\\') + 1);

src/AbstractPackage.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace Joomla\Github;
1010

11+
use Joomla\Http\Http as BaseHttp;
1112
use Joomla\Registry\Registry;
1213

1314
/**
@@ -21,11 +22,11 @@ abstract class AbstractPackage extends AbstractGithubObject
2122
* Constructor.
2223
*
2324
* @param Registry $options GitHub options object.
24-
* @param Http $client The HTTP client object.
25+
* @param BaseHttp $client The HTTP client object.
2526
*
2627
* @since 1.0
2728
*/
28-
public function __construct(Registry $options = null, Http $client = null)
29+
public function __construct(Registry $options = null, BaseHttp $client = null)
2930
{
3031
parent::__construct($options, $client);
3132

src/Github.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace Joomla\Github;
1010

11+
use Joomla\Http\Http as BaseHttp;
1112
use Joomla\Registry\Registry;
1213

1314
/**
@@ -50,20 +51,27 @@ class Github
5051
* Constructor.
5152
*
5253
* @param Registry $options GitHub options object.
53-
* @param Http $client The HTTP client object.
54+
* @param BaseHttp $client The HTTP client object.
5455
*
5556
* @since 1.0
5657
*/
57-
public function __construct(Registry $options = null, Http $client = null)
58+
public function __construct(Registry $options = null, BaseHttp $client = null)
5859
{
59-
$this->options = isset($options) ? $options : new Registry;
60-
$this->client = isset($client) ? $client : new Http($this->options);
60+
$this->options = $options ?: new Registry;
61+
62+
// Setup the default user agent if not already set.
63+
if (!$this->getOption('userAgent'))
64+
{
65+
$this->setOption('userAgent', 'JGitHub/2.0');
66+
}
6167

6268
// Setup the default API url if not already set.
6369
if (!$this->getOption('api.url'))
6470
{
6571
$this->setOption('api.url', 'https://api.github.com');
6672
}
73+
74+
$this->client = $client ?: new Http($this->options);
6775
}
6876

6977
/**

src/Http.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,29 @@
1414
/**
1515
* HTTP client class for connecting to a GitHub instance.
1616
*
17-
* @since 1.0
17+
* @since 1.0
18+
* @deprecated 2.0 Use Joomla\Http\Http instead
1819
*/
1920
class Http extends BaseHttp
2021
{
2122
/**
2223
* @const integer Use no authentication for HTTP connections.
2324
* @since 1.0
25+
* @deprecated 2.0
2426
*/
2527
const AUTHENTICATION_NONE = 0;
2628

2729
/**
2830
* @const integer Use basic authentication for HTTP connections.
2931
* @since 1.0
32+
* @deprecated 2.0
3033
*/
3134
const AUTHENTICATION_BASIC = 1;
3235

3336
/**
3437
* @const integer Use OAuth authentication for HTTP connections.
3538
* @since 1.0
39+
* @deprecated 2.0
3640
*/
3741
const AUTHENTICATION_OAUTH = 2;
3842

@@ -43,6 +47,7 @@ class Http extends BaseHttp
4347
* @param TransportInterface $transport The HTTP transport object.
4448
*
4549
* @since 1.0
50+
* @deprecated 2.0
4651
*/
4752
public function __construct($options = array(), TransportInterface $transport = null)
4853
{

0 commit comments

Comments
 (0)