Skip to content

Commit

Permalink
Unduplication
Browse files Browse the repository at this point in the history
scrutinizer was complaining about duplication, and since she was right...
  • Loading branch information
mattjmattj committed Apr 7, 2015
1 parent 84b9bd7 commit adb648a
Showing 1 changed file with 8 additions and 22 deletions.
30 changes: 8 additions & 22 deletions src/Yo/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,42 +28,28 @@ public function __construct(HTTP\Client $http, $apiToken)

public function yo($username, Payload $payload = null)
{
$request = $this->prepareYoRequest($username, $payload);
$request = $this->prepareEmptyYoRequest($payload);
$request->path = '/yo/';
$request->parameters += [
'username' => $username,
];

return $this->http->post($request);
}

public function yoAll(Link $payload = null)
{
$request = $this->prepareYoallRequest($payload);
$request = $this->prepareEmptyYoRequest($payload);
$request->path = '/yoall/';

return $this->http->post($request);
}

private function prepareYoRequest($username, Payload $payload = null)
{
$request = new HTTP\Request();
$request->https = true;
$request->host = 'api.justyo.co';
$request->path = '/yo/';
$request->parameters = [
'api_token' => $this->apiToken,
'username' => $username,
];

if (!empty($payload)) {
$request->parameters += $payload->toHTTPParameters();
}

return $request;
}

private function prepareYoallRequest(Link $payload = null)
private function prepareEmptyYoRequest(Payload $payload = null)
{
$request = new HTTP\Request();
$request->https = true;
$request->host = 'api.justyo.co';
$request->path = '/yoall/';
$request->parameters = [
'api_token' => $this->apiToken,
];
Expand Down

0 comments on commit adb648a

Please sign in to comment.