Skip to content

Commit d1334a4

Browse files
committed
Use Uri objects
1 parent a6759fb commit d1334a4

13 files changed

Lines changed: 148 additions & 108 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"license": "GPL-2.0-or-later",
88
"require": {
99
"php": "^5.3.10|~7.0",
10-
"joomla/http": "^1.2.2|~2.0",
10+
"joomla/http": "~1.3|~2.0",
1111
"joomla/registry": "^1.4.5|~2.0",
1212
"joomla/uri": "~1.0|~2.0"
1313
},

src/Package/Activity/Notifications.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Notifications extends AbstractPackage
3737
public function getList($all = true, $participating = true, \DateTime $since = null, \DateTime $before = null)
3838
{
3939
// Build the request path.
40-
$path = '/notifications?';
40+
$path = '/notifications';
4141

4242
$uri = new Uri($this->fetchUrl($path));
4343

@@ -61,9 +61,7 @@ public function getList($all = true, $participating = true, \DateTime $since = n
6161
$uri->setVar('before', $before->format(\DateTime::RFC3339));
6262
}
6363

64-
return $this->processResponse(
65-
$this->client->get((string) $uri)
66-
);
64+
return $this->processResponse($this->client->get($uri));
6765
}
6866

6967
/**
@@ -85,7 +83,7 @@ public function getList($all = true, $participating = true, \DateTime $since = n
8583
public function getListRepository($owner, $repo, $all = true, $participating = true, \DateTime $since = null, \DateTime $before = null)
8684
{
8785
// Build the request path.
88-
$path = '/repos/' . $owner . '/' . $repo . '/notifications?';
86+
$path = '/repos/' . $owner . '/' . $repo . '/notifications';
8987

9088
$uri = new Uri($this->fetchUrl($path));
9189

@@ -109,9 +107,7 @@ public function getListRepository($owner, $repo, $all = true, $participating = t
109107
$uri->setVar('before', $before->format(\DateTime::RFC3339));
110108
}
111109

112-
return $this->processResponse(
113-
$this->client->get((string) $uri)
114-
);
110+
return $this->processResponse($this->client->get($uri));
115111
}
116112

117113
/**

src/Package/Activity/Starring.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,12 @@ public function getRepositories($user = '', $sort = 'created', $direction = 'des
8484
? '/users' . $user . '/starred'
8585
: '/user/starred';
8686

87-
$path .= "?sort=$sort&direction=$direction";
87+
$uri = new Uri($this->fetchUrl($path));
88+
$uri->setVar('sort', $sort);
89+
$uri->setVar('direction', $direction);
8890

89-
return $this->processResponse(
90-
$this->client->get($this->fetchUrl($path))
91-
);
91+
// Send the request.
92+
return $this->processResponse($this->client->get($uri));
9293
}
9394

9495
/**

src/Package/Gists.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use Joomla\Github\AbstractPackage;
1212
use Joomla\Http\Exception\UnexpectedResponseException;
13+
use Joomla\Uri\Uri;
1314

1415
/**
1516
* GitHub API Gists class for the Joomla Framework.
@@ -236,11 +237,15 @@ public function getList($page = 0, $limit = 0)
236237
public function getListByUser($user, $page = 0, $limit = 0, \DateTime $since = null)
237238
{
238239
// Build the request path.
239-
$path = '/users/' . $user . '/gists';
240-
$path .= ($since) ? '?since=' . $since->format(\DateTime::RFC3339) : '';
240+
$uri = new Uri($this->fetchUrl('/users/' . $user . '/gists', $page, $limit));
241+
242+
if ($since)
243+
{
244+
$uri->setVar('since', $since->format(\DateTime::RFC3339));
245+
}
241246

242247
// Send the request.
243-
return $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit)));
248+
return $this->processResponse($this->client->get($uri));
244249
}
245250

246251
/**
@@ -258,11 +263,15 @@ public function getListByUser($user, $page = 0, $limit = 0, \DateTime $since = n
258263
public function getListPublic($page = 0, $limit = 0, \DateTime $since = null)
259264
{
260265
// Build the request path.
261-
$path = '/gists/public';
262-
$path .= ($since) ? '?since=' . $since->format(\DateTime::RFC3339) : '';
266+
$uri = new Uri($this->fetchUrl('/gists/public', $page, $limit));
267+
268+
if ($since)
269+
{
270+
$uri->setVar('since', $since->format(\DateTime::RFC3339));
271+
}
263272

264273
// Send the request.
265-
return $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit)));
274+
return $this->processResponse($this->client->get($uri));
266275
}
267276

268277
/**
@@ -280,11 +289,15 @@ public function getListPublic($page = 0, $limit = 0, \DateTime $since = null)
280289
public function getListStarred($page = 0, $limit = 0, \DateTime $since = null)
281290
{
282291
// Build the request path.
283-
$path = '/gists/starred';
284-
$path .= ($since) ? '?since=' . $since->format(\DateTime::RFC3339) : '';
292+
$uri = new Uri($this->fetchUrl('/gists/starred', $page, $limit));
293+
294+
if ($since)
295+
{
296+
$uri->setVar('since', $since->format(\DateTime::RFC3339));
297+
}
285298

286299
// Send the request.
287-
return $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit)));
300+
return $this->processResponse($this->client->get($uri));
288301
}
289302

290303
/**

src/Package/Issues.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,7 @@ public function getList($filter = null, $state = null, $labels = null, $sort = n
205205
)
206206
{
207207
// Build the request path.
208-
$path = '/issues';
209-
210-
$uri = new Uri($this->fetchUrl($path, $page, $limit));
208+
$uri = new Uri($this->fetchUrl('/issues', $page, $limit));
211209

212210
if ($filter)
213211
{
@@ -240,7 +238,7 @@ public function getList($filter = null, $state = null, $labels = null, $sort = n
240238
}
241239

242240
// Send the request.
243-
return $this->processResponse($this->client->get((string) $uri));
241+
return $this->processResponse($this->client->get($uri));
244242
}
245243

246244
/**
@@ -314,7 +312,7 @@ public function getListByRepository($user, $repo, $milestone = null, $state = nu
314312
}
315313

316314
// Send the request.
317-
return $this->processResponse($this->client->get((string) $uri));
315+
return $this->processResponse($this->client->get($uri));
318316
}
319317

320318
/**

src/Package/Issues/Comments.php

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

1111
use Joomla\Github\AbstractPackage;
12+
use Joomla\Uri\Uri;
1213

1314
/**
1415
* GitHub API Comments class for the Joomla Framework.
@@ -41,12 +42,16 @@ public function getList($owner, $repo, $issueId, $page = 0, $limit = 0, \DateTim
4142
{
4243
// Build the request path.
4344
$path = '/repos/' . $owner . '/' . $repo . '/issues/' . (int) $issueId . '/comments';
44-
$path .= ($since) ? '?since=' . $since->format(\DateTime::RFC3339) : '';
45+
46+
$uri = new Uri($this->fetchUrl($path, $page, $limit));
47+
48+
if ($since)
49+
{
50+
$uri->setVar('since', $since->format(\DateTime::RFC3339));
51+
}
4552

4653
// Send the request.
47-
return $this->processResponse(
48-
$this->client->get($this->fetchUrl($path, $page, $limit))
49-
);
54+
return $this->processResponse($this->client->get($uri));
5055
}
5156

5257
/**
@@ -87,16 +92,17 @@ public function getRepositoryList($owner, $repo, $sort = 'created', $direction =
8792
);
8893
}
8994

90-
$path .= '?sort=' . $sort;
91-
$path .= '&direction=' . $direction;
95+
$uri = new Uri($this->fetchUrl($path));
96+
$uri->setVar('sort', $sort);
97+
$uri->setVar('direction', $direction);
9298

9399
if ($since)
94100
{
95-
$path .= '&since=' . $since->format(\DateTime::RFC3339);
101+
$uri->setVar('since', $since->format(\DateTime::RFC3339));
96102
}
97103

98104
// Send the request.
99-
return $this->processResponse($this->client->get($this->fetchUrl($path)));
105+
return $this->processResponse($this->client->get($uri));
100106
}
101107

102108
/**

src/Package/Issues/Milestones.php

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

1111
use Joomla\Github\AbstractPackage;
12+
use Joomla\Uri\Uri;
1213

1314
/**
1415
* GitHub API Milestones class for the Joomla Framework.
@@ -38,14 +39,15 @@ class Milestones extends AbstractPackage
3839
public function getList($user, $repo, $state = 'open', $sort = 'due_date', $direction = 'desc', $page = 0, $limit = 0)
3940
{
4041
// Build the request path.
41-
$path = '/repos/' . $user . '/' . $repo . '/milestones?';
42+
$path = '/repos/' . $user . '/' . $repo . '/milestones';
4243

43-
$path .= 'state=' . $state;
44-
$path .= '&sort=' . $sort;
45-
$path .= '&direction=' . $direction;
44+
$uri = new Uri($this->fetchUrl($path, $page, $limit));
45+
$uri->setVar('state', $state);
46+
$uri->setVar('sort', $sort);
47+
$uri->setVar('direction', $direction);
4648

4749
// Send the request.
48-
return $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit)));
50+
return $this->processResponse($this->client->get($uri));
4951
}
5052

5153
/**

src/Package/Repositories.php

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

1111
use Joomla\Github\AbstractPackage;
12+
use Joomla\Uri\Uri;
1213

1314
/**
1415
* GitHub API Activity class for the Joomla Framework.
@@ -70,15 +71,13 @@ public function getListOwn($type = 'all', $sort = 'full_name', $direction = '')
7071
}
7172

7273
// Build the request path.
73-
$path = '/user/repos'
74-
. '?type=' . $type
75-
. '&sort=' . $sort
76-
. '&direction=' . $direction;
74+
$uri = new Uri($this->fetchUrl('/user/repos'));
75+
$uri->setVar('type', $type);
76+
$uri->setVar('sort', $sort);
77+
$uri->setVar('direction', $direction);
7778

7879
// Send the request.
79-
return $this->processResponse(
80-
$this->client->get($this->fetchUrl($path))
81-
);
80+
return $this->processResponse($this->client->get($uri));
8281
}
8382

8483
/**
@@ -117,15 +116,13 @@ public function getListUser($user, $type = 'all', $sort = 'full_name', $directio
117116
}
118117

119118
// Build the request path.
120-
$path = '/users/' . $user . '/repos'
121-
. '?type=' . $type
122-
. '&sort=' . $sort
123-
. '&direction=' . $direction;
119+
$uri = new Uri($this->fetchUrl('/users/' . $user . '/repos'));
120+
$uri->setVar('type', $type);
121+
$uri->setVar('sort', $sort);
122+
$uri->setVar('direction', $direction);
124123

125124
// Send the request.
126-
return $this->processResponse(
127-
$this->client->get($this->fetchUrl($path))
128-
);
125+
return $this->processResponse($this->client->get($uri));
129126
}
130127

131128
/**
@@ -149,13 +146,11 @@ public function getListOrg($org, $type = 'all')
149146
}
150147

151148
// Build the request path.
152-
$path = '/orgs/' . $org . '/repos'
153-
. '?type=' . $type;
149+
$uri = new Uri($this->fetchUrl('/orgs/' . $org . '/repos'));
150+
$uri->setVar('type', $type);
154151

155152
// Send the request.
156-
return $this->processResponse(
157-
$this->client->get($this->fetchUrl($path))
158-
);
153+
return $this->processResponse($this->client->get($uri));
159154
}
160155

161156
/**
@@ -173,13 +168,15 @@ public function getListOrg($org, $type = 'all')
173168
public function getList($id = 0)
174169
{
175170
// Build the request path.
176-
$path = '/repositories';
177-
$path .= ($id) ? '?since=' . (int) $id : '';
171+
$uri = new Uri($this->fetchUrl('/repositories'));
172+
173+
if ($id)
174+
{
175+
$uri->setVar('since', (int) $id);
176+
}
178177

179178
// Send the request.
180-
return $this->processResponse(
181-
$this->client->get($this->fetchUrl($path))
182-
);
179+
return $this->processResponse($this->client->get($uri));
183180
}
184181

185182
/**
@@ -314,14 +311,15 @@ public function edit($owner, $repo, $name, $description = '', $homepage = '', $p
314311
public function getListContributors($owner, $repo, $anon = false)
315312
{
316313
// Build the request path.
317-
$path = '/repos/' . $owner . '/' . $repo . '/contributors';
314+
$uri = new Uri($this->fetchUrl('/repos/' . $owner . '/' . $repo . '/contributors'));
318315

319-
$path .= ($anon) ? '?anon=true' : '';
316+
if ($anon)
317+
{
318+
$uri->setVar('anon', 'true');
319+
}
320320

321321
// Send the request.
322-
return $this->processResponse(
323-
$this->client->get($this->fetchUrl($path))
324-
);
322+
return $this->processResponse($this->client->get($uri));
325323
}
326324

327325
/**

src/Package/Repositories/Commits.php

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,37 @@ class Commits extends AbstractPackage
4444
public function getList($user, $repo, $sha = '', $path = '', $author = '', \DateTime $since = null, \DateTime $until = null)
4545
{
4646
// Build the request path.
47-
$rPath = '/repos/' . $user . '/' . $repo . '/commits?';
47+
$rPath = '/repos/' . $user . '/' . $repo . '/commits';
4848

49-
$rPath .= ($sha) ? '&sha=' . $sha : '';
50-
$rPath .= ($path) ? '&path=' . $path : '';
51-
$rPath .= ($author) ? '&author=' . $author : '';
52-
$rPath .= ($since) ? '&since=' . $since->format(\DateTime::RFC3339) : '';
53-
$rPath .= ($until) ? '&until=' . $until->format(\DateTime::RFC3339) : '';
49+
$uri = new Uri($this->fetchUrl($rPath));
50+
51+
if ($sha)
52+
{
53+
$uri->setVar('sha', $sha);
54+
}
55+
56+
if ($path)
57+
{
58+
$uri->setVar('path', $path);
59+
}
60+
61+
if ($author)
62+
{
63+
$uri->setVar('author', $author);
64+
}
65+
66+
if ($since)
67+
{
68+
$uri->setVar('since', $since->format(\DateTime::RFC3339));
69+
}
70+
71+
if ($until)
72+
{
73+
$uri->setVar('until', $until->format(\DateTime::RFC3339));
74+
}
5475

5576
// Send the request.
56-
return $this->processResponse($this->client->get($this->fetchUrl($rPath)));
77+
return $this->processResponse($this->client->get($uri));
5778
}
5879

5980
/**

0 commit comments

Comments
 (0)