Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
[api] changed Requestable->send() signature
Browse files Browse the repository at this point in the history
  • Loading branch information
hans-lizihan committed Aug 30, 2017
1 parent c931c67 commit 0cb0688
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 69 deletions.
6 changes: 3 additions & 3 deletions src/Couriers.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct($apiKey = '', Requestable $request = null)
*/
public function get()
{
return $this->request->send('couriers', 'GET');
return $this->request->send('GET', 'couriers');
}

/**
Expand All @@ -45,7 +45,7 @@ public function get()
*/
public function all()
{
return $this->request->send('couriers/all', 'GET');
return $this->request->send('GET', 'couriers/all');
}

/**
Expand All @@ -66,6 +66,6 @@ public function detect($trackingNumber, array $params = array())

// Fill the tracking number into the params array
$params['tracking_number'] = $trackingNumber;
return $this->request->send('couriers/detect/', 'POST', ['tracking' => $params]);
return $this->request->send('POST', 'couriers/detect/', ['tracking' => $params]);
}
}
4 changes: 2 additions & 2 deletions src/LastCheckPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function get($slug, $trackingNumber, array $params = array())
throw new AfterShipException('Tracking number cannot be empty');
}

return $this->request->send('last_checkpoint/' . $slug . '/' . $trackingNumber, 'GET', $params);
return $this->request->send('GET', 'last_checkpoint/' . $slug . '/' . $trackingNumber, $params);
}

/**
Expand All @@ -65,6 +65,6 @@ public function getById($trackingId, array $params = [])
throw new AfterShipException('Tracking ID cannot be empty');
}

return $this->request->send('last_checkpoint/' . $trackingId, 'GET', $params);
return $this->request->send('GET', 'last_checkpoint/' . $trackingId, $params);
}
}
18 changes: 9 additions & 9 deletions src/Notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function create($slug, $trackingNumber, array $params = array())
throw new AfterShipException('Tracking number cannot be empty');
}

return $this->request->send('notifications/' . $slug . '/' . $trackingNumber . '/add', 'POST',
return $this->request->send('POST', 'notifications/' . $slug . '/' . $trackingNumber . '/add',
['notification' => $params]);
}

Expand All @@ -62,7 +62,7 @@ public function createById($trackingId, array $params = [])
throw new AfterShipException('Tracking ID cannot be empty');
}

return $this->request->send('notifications/' . $trackingId . '/add', 'POST', array('notification' => $params));
return $this->request->send('POST', 'notifications/' . $trackingId . '/add', ['notification' => $params]);
}

/**
Expand All @@ -74,7 +74,7 @@ public function createById($trackingId, array $params = [])
* @return array Response body
* @throws AfterShipException
*/
public function delete($slug, $trackingNumber, array $params = array())
public function delete($slug, $trackingNumber, array $params = [])
{
if (empty($slug)) {
throw new AfterShipException('Slug cannot be empty');
Expand All @@ -84,8 +84,8 @@ public function delete($slug, $trackingNumber, array $params = array())
throw new AfterShipException('Tracking number cannot be empty');
}

return $this->request->send('notifications/' . $slug . '/' . $trackingNumber . '/remove', 'POST',
array('notification' => $params));
return $this->request->send('POST', 'notifications/' . $slug . '/' . $trackingNumber . '/remove',
['notification' => $params]);
}

/**
Expand All @@ -102,7 +102,7 @@ public function deleteById($trackingId, array $params = [])
throw new AfterShipException('Tracking ID cannot be empty');
}

return $this->request->send('notifications/' . $trackingId . '/remove', 'POST', array('notification' => $params));
return $this->request->send('POST', 'notifications/' . $trackingId . '/remove', ['notification' => $params]);
}

/**
Expand All @@ -114,7 +114,7 @@ public function deleteById($trackingId, array $params = [])
* @return array Response body
* @throws \Exception
*/
public function get($slug, $trackingNumber, array $params = array())
public function get($slug, $trackingNumber, array $params = [])
{
if (empty($slug)) {
throw new AfterShipException('Slug cannot be empty');
Expand All @@ -124,7 +124,7 @@ public function get($slug, $trackingNumber, array $params = array())
throw new AfterShipException('Tracking number cannot be empty');
}

return $this->request->send('notifications/' . $slug . '/' . $trackingNumber, 'GET', $params);
return $this->request->send('GET', 'notifications/' . $slug . '/' . $trackingNumber, $params);
}

/**
Expand All @@ -141,6 +141,6 @@ public function getById($trackingId, array $params = array())
throw new AfterShipException('Tracking ID cannot be empty');
}

return $this->request->send('notifications/' . $trackingId, 'GET', $params);
return $this->request->send('GET', 'notifications/' . $trackingId, $params);
}
}
8 changes: 2 additions & 6 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

namespace AfterShip;

/**
* Class Request
* @package AfterShip
*/
/**
* Class Request
* @package AfterShip
Expand Down Expand Up @@ -37,13 +33,13 @@ function __construct($apiKey)
}

/**
* @param $url
* @param $method
* @param $url
* @param array $data
*
* @return mixed
*/
public function send($url, $method, array $data = [])
public function send($method, $url, array $data = [])
{
$methodUpper = strtoupper($method);
$parameters = [
Expand Down
4 changes: 2 additions & 2 deletions src/Requestable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

interface Requestable
{
public function send($url, $method, array $data = []);
}
public function send($method, $url, array $data = []);
}
20 changes: 10 additions & 10 deletions src/Trackings.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function create($trackingNumber, array $params = [])
}

$params['tracking_number'] = $trackingNumber;
return $this->request->send('trackings', 'POST', ['tracking' => $params]);
return $this->request->send('POST', 'trackings', ['tracking' => $params]);
}

/**
Expand Down Expand Up @@ -71,7 +71,7 @@ public function delete($slug, $trackingNumber)
throw new AfterShipException('Tracking number cannot be empty');
}

return $this->request->send('trackings/' . $slug . '/' . $trackingNumber, 'DELETE');
return $this->request->send('DELETE', 'trackings/' . $slug . '/' . $trackingNumber);
}

/**
Expand All @@ -87,7 +87,7 @@ public function deleteById($trackingId)
throw new AfterShipException('Tracking ID cannot be empty');
}

return $this->request->send('trackings/' . $trackingId, 'DELETE');
return $this->request->send('DELETE', 'trackings/' . $trackingId);
}

/**
Expand All @@ -98,7 +98,7 @@ public function deleteById($trackingId)
*/
public function all(array $params = [])
{
return $this->request->send('trackings', 'GET', $params);
return $this->request->send('GET', 'trackings', $params);
}

/**
Expand All @@ -120,7 +120,7 @@ public function get($slug, $trackingNumber, array $params = [])
throw new AfterShipException('Tracking number cannot be empty');
}

return $this->request->send('trackings/' . $slug . '/' . $trackingNumber, 'GET', $params);
return $this->request->send('GET', 'trackings/' . $slug . '/' . $trackingNumber, $params);
}

/**
Expand All @@ -137,7 +137,7 @@ public function getById($trackingId, array $params = [])
throw new AfterShipException('Tracking ID cannot be empty');
}

return $this->request->send('trackings/' . $trackingId, 'GET', $params);
return $this->request->send('GET', 'trackings/' . $trackingId, $params);
}

/**
Expand All @@ -159,7 +159,7 @@ public function update($slug, $trackingNumber, array $params = [])
throw new AfterShipException('Tracking number cannot be empty');
}

return $this->request->send('trackings/' . $slug . '/' . $trackingNumber, 'PUT', ['tracking' => $params]);
return $this->request->send('PUT', 'trackings/' . $slug . '/' . $trackingNumber, ['tracking' => $params]);
}

/**
Expand All @@ -176,7 +176,7 @@ public function updateById($trackingId, array $params = [])
throw new AfterShipException('Tracking ID cannot be empty');
}

return $this->request->send('trackings/' . $trackingId, 'PUT', ['tracking' => $params]);
return $this->request->send('PUT', 'trackings/' . $trackingId, ['tracking' => $params]);
}

/**
Expand All @@ -197,7 +197,7 @@ public function retrack($slug, $trackingNumber)
throw new AfterShipException('Tracking number cannot be empty');
}

return $this->request->send('trackings/' . $slug . '/' . $trackingNumber . '/retrack', 'POST');
return $this->request->send('POST', 'trackings/' . $slug . '/' . $trackingNumber . '/retrack');
}

/**
Expand All @@ -213,7 +213,7 @@ public function retrackById($trackingId)
throw new AfterShipException('Tracking ID cannot be empty');
}

return $this->request->send('trackings/' . $trackingId . '/retrack', 'POST');
return $this->request->send('POST', 'trackings/' . $trackingId . '/retrack');
}

}
10 changes: 5 additions & 5 deletions tests/AfterShip/CouriersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public function it_gets_all_couriers_when_calling_get()

$request
->with(
$this->equalTo('couriers'),
$this->equalTo('GET')
$this->equalTo('GET'),
$this->equalTo('couriers')
);

$couriers->get();
Expand All @@ -39,8 +39,8 @@ public function it_will_get_all_couriers_available()

$request
->with(
$this->equalTo('couriers/all'),
$this->equalTo('GET')
$this->equalTo('GET'),
$this->equalTo('couriers/all')
);

$couriers->all();
Expand All @@ -60,8 +60,8 @@ public function it_will_call_detect_endpoint()

$request
->with(
$this->equalTo('couriers/detect/'),
$this->equalTo('POST'),
$this->equalTo('couriers/detect/'),
$this->equalTo([
'tracking' => [
'tracking_number' => 'tracking_number',
Expand Down
8 changes: 4 additions & 4 deletions tests/AfterShip/LastCheckPointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public function it_should_get_last_checkpoint_by_slug_and_tracking_number()
list($request, $lastTrackingNumber) = $this->buildLastCheckPoint();
$request
->with(
$this->equalTo('last_checkpoint/ups/tracking_number'),
$this->equalTo('GET')
$this->equalTo('GET'),
$this->equalTo('last_checkpoint/ups/tracking_number')
);
$lastTrackingNumber->get('ups', 'tracking_number');
}
Expand All @@ -54,8 +54,8 @@ public function it_should_get_last_checkpoint_by_id()
list($request, $lastTrackingNumber) = $this->buildLastCheckPoint();
$request
->with(
$this->equalTo('last_checkpoint/last_checkpoint_id'),
$this->equalTo('GET')
$this->equalTo('GET'),
$this->equalTo('last_checkpoint/last_checkpoint_id')
);
$lastTrackingNumber->getById('last_checkpoint_id');
}
Expand Down
18 changes: 9 additions & 9 deletions tests/AfterShip/NotificationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ public function it_should_create_a_notfication()

$request
->with(
$this->equalTo('notifications/dhl/tracking_number/add'),
$this->equalTo('POST'),
$this->equalTo('notifications/dhl/tracking_number/add'),
$this->equalTo([
'notification' => []
])
);

$notification->create('dhl', 'tracking_number');
}

/** @test */
public function create_throws_an_error_when_empty_slug()
{
Expand All @@ -53,8 +53,8 @@ public function could_create_notification_by_id()

$request
->with(
$this->equalTo('notifications/tracking_id/add'),
$this->equalTo('POST'),
$this->equalTo('notifications/tracking_id/add'),
$this->equalTo([
'notification' => []
])
Expand All @@ -76,8 +76,8 @@ public function it_should_delete_a_notfication()

$request
->with(
$this->equalTo('notifications/dhl/tracking_number/remove'),
$this->equalTo('POST'),
$this->equalTo('notifications/dhl/tracking_number/remove'),
$this->equalTo([
'notification' => []
])
Expand Down Expand Up @@ -105,8 +105,8 @@ public function could_delete_notification_by_id()

$request
->with(
$this->equalTo('notifications/tracking_id/remove'),
$this->equalTo('POST'),
$this->equalTo('notifications/tracking_id/remove'),
$this->equalTo([
'notification' => []
])
Expand All @@ -128,8 +128,8 @@ public function it_should_get_a_notfication()

$request
->with(
$this->equalTo('notifications/dhl/tracking_number'),
$this->equalTo('GET')
$this->equalTo('GET'),
$this->equalTo('notifications/dhl/tracking_number')
);

$notification->get('dhl', 'tracking_number');
Expand All @@ -154,8 +154,8 @@ public function could_get_notification_by_id()

$request
->with(
$this->equalTo('notifications/tracking_id'),
$this->equalTo('GET')
$this->equalTo('GET'),
$this->equalTo('notifications/tracking_id')
);

$notification->getById('tracking_id');
Expand Down
14 changes: 14 additions & 0 deletions tests/AfterShip/RequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

use AfterShip\Request;
use PHPUnit\Framework\TestCase;

class RequestTest extends TestCase
{
/* @test */
function it_should_have_correct_url_and_api_version_constants()
{
$this->equalTo(Request::API_URL, 'https://api.aftership.com');
$this->equalTo(Request::API_VERSION, 'v4');
}
}
Loading

0 comments on commit 0cb0688

Please sign in to comment.