Skip to content

Commit 5f2c71a

Browse files
authored
Move EndShipper to general availability (#210)
- Copy EndShipper to main namespace - Mark beta EndShipper as deprecated - Update unit tests
1 parent 1113831 commit 5f2c71a

File tree

9 files changed

+241
-164
lines changed

9 files changed

+241
-164
lines changed

lib/EasyPost/Beta/EndShipper.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
* @property string $name
1717
* @property string $company
1818
* @property string $phone
19+
*
20+
* @deprecated Use EasyPost\EndShipper instead.
1921
*/
2022

2123
class EndShipper extends EasypostResource

lib/EasyPost/EndShipper.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
namespace EasyPost;
4+
5+
/**
6+
* @package EasyPost
7+
* @property string $name
8+
* @property string $company
9+
* @property string $id
10+
* @property string $street1
11+
* @property string $street2
12+
* @property string $city
13+
* @property string $state
14+
* @property string $zip
15+
* @property string $country
16+
* @property string $phone
17+
* @property string $email
18+
*/
19+
20+
class EndShipper extends EasypostResource
21+
{
22+
/**
23+
* Create an EndShipper object.
24+
*
25+
* @param mixed $params
26+
* @param string $apiKey
27+
* @return mixed
28+
*/
29+
public static function create($params = null, $apiKey = null)
30+
{
31+
$wrappedParams = [];
32+
$wrappedParams['address'] = $params;
33+
34+
return self::createResource(get_class(), $wrappedParams, $apiKey);
35+
}
36+
37+
/**
38+
* Retrieve an EndShipper object.
39+
*
40+
* @param string $id
41+
* @param string $apiKey
42+
* @return mixed
43+
*/
44+
public static function retrieve($id, $apiKey = null)
45+
{
46+
return self::retrieveResource(get_class(), $id, $apiKey);
47+
}
48+
49+
/**
50+
* Retrieve all EndShipper objects.
51+
*
52+
* @param mixed $params
53+
* @param string $apiKey
54+
* @return mixed
55+
*/
56+
public static function all($params = null, $apiKey = null)
57+
{
58+
return self::allResources(get_class(), $params, $apiKey);
59+
}
60+
61+
/**
62+
* Update (save) an EndShipper object.
63+
*
64+
* @return $this
65+
*/
66+
public function save()
67+
{
68+
// We are passing the `Address` class here so that the request gets properly wrapped in the required object.
69+
return $this->saveResource('EasyPost\Address', false, 'put');
70+
}
71+
}

lib/EasyPost/Util.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static function convertToEasyPostObject($response, $apiKey, $parent = nul
6464
'CarrierDetail' => '\EasyPost\CarrierDetail',
6565
'CustomsInfo' => '\EasyPost\CustomsInfo',
6666
'CustomsItem' => '\EasyPost\CustomsItem',
67-
'EndShipper' => '\EasyPost\Beta\EndShipper',
67+
'EndShipper' => '\EasyPost\EndShipper',
6868
'Event' => '\EasyPost\Event',
6969
'Fee' => '\EasyPost\Fee',
7070
'Insurance' => '\EasyPost\Insurance',
@@ -103,7 +103,7 @@ public static function convertToEasyPostObject($response, $apiKey, $parent = nul
103103
'ca' => '\EasyPost\CarrierAccount',
104104
'cstinfo' => '\EasyPost\CustomsInfo',
105105
'cstitem' => '\EasyPost\CustomsItem',
106-
'es' => '\EasyPost\Beta\EndShipper',
106+
'es' => '\EasyPost\EndShipper',
107107
'evt' => '\EasyPost\Event',
108108
'fee' => '\EasyPost\Fee',
109109
'hook' => '\EasyPost\Webhook',

lib/easypost.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
require_once(dirname(__FILE__) . '/EasyPost/CustomsInfo.php');
3131
require_once(dirname(__FILE__) . '/EasyPost/CustomsItem.php');
3232
require_once(dirname(__FILE__) . '/EasyPost/Beta/EndShipper.php');
33+
require_once(dirname(__FILE__) . '/EasyPost/EndShipper.php');
3334
require_once(dirname(__FILE__) . '/EasyPost/Event.php');
3435
require_once(dirname(__FILE__) . '/EasyPost/Fee.php');
3536
require_once(dirname(__FILE__) . '/EasyPost/FieldError.php');

test/EasyPost/Beta/EndShipperTest.php renamed to test/EasyPost/EndShipperTest.php

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

33
namespace EasyPost\Test;
44

5-
use EasyPost\Beta\EndShipper;
5+
use EasyPost\EndShipper;
66
use EasyPost\EasyPost;
77
use VCR\VCR;
88

@@ -36,7 +36,7 @@ public function testCreate()
3636

3737
$endShipper = EndShipper::create(Fixture::caAddress1());
3838

39-
$this->assertInstanceOf('\EasyPost\Beta\EndShipper', $endShipper);
39+
$this->assertInstanceOf('\EasyPost\EndShipper', $endShipper);
4040
$this->assertStringMatchesFormat('es_%s', $endShipper->id);
4141
$this->assertEquals('388 TOWNSEND ST APT 20', $endShipper->street1);
4242
}
@@ -52,7 +52,7 @@ public function testRetrieve()
5252

5353
$retrievedEndShipper = EndShipper::retrieve($endShipper->id);
5454

55-
$this->assertInstanceOf('\EasyPost\Beta\EndShipper', $retrievedEndShipper);
55+
$this->assertInstanceOf('\EasyPost\EndShipper', $retrievedEndShipper);
5656
$this->assertEquals($endShipper->street1, $retrievedEndShipper->street1);
5757
}
5858

@@ -63,12 +63,15 @@ public function testAll()
6363
{
6464
VCR::insertCassette('end_shipper/all.yml');
6565

66-
$endShipper = EndShipper::all([
66+
$endShippers = EndShipper::all([
6767
'page_size' => Fixture::pageSize(),
6868
]);
6969

70-
$this->assertLessThanOrEqual($endShipper, Fixture::pageSize());
71-
$this->assertContainsOnlyInstancesOf('\EasyPost\Beta\EndShipper', $endShipper);
70+
$endShipperArray = $endShippers['end_shippers'];
71+
72+
$this->assertLessThanOrEqual($endShipperArray, Fixture::pageSize());
73+
$this->assertNotNull($endShippers['has_more']);
74+
$this->assertContainsOnlyInstancesOf('\EasyPost\EndShipper', $endShipperArray);
7275
}
7376

7477
/**
@@ -95,7 +98,7 @@ public function testUpdate()
9598
$endShipper->email = 'test@example.com';
9699
$endShipper->save();
97100

98-
$this->assertInstanceOf('\EasyPost\Beta\EndShipper', $endShipper);
101+
$this->assertInstanceOf('\EasyPost\EndShipper', $endShipper);
99102
$this->assertStringMatchesFormat('es_%s', $endShipper->id);
100103
$this->assertEquals($newName, $endShipper->name);
101104
}

test/cassettes/end_shipper/all.yml

Lines changed: 29 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/cassettes/end_shipper/create.yml

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)