Skip to content

Commit

Permalink
Merge pull request #222 from EasyPost/simpler_address_verify
Browse files Browse the repository at this point in the history
refactor: removes unreachable address verification code
  • Loading branch information
Justintime50 authored Sep 21, 2022
2 parents 66e764c + 3696acc commit 6ab30f2
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 14 deletions.
16 changes: 2 additions & 14 deletions lib/EasyPost/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,7 @@ public static function create_and_verify($params = null, $apiKey = null)
$url = self::classUrl($class);
list($response, $apiKey) = $requestor->request('post', $url . '/create_and_verify', $params);

if (isset($response['address'])) {
$verifiedAddress = Util::convertToEasyPostObject($response['address'], $apiKey);

return $verifiedAddress;
} else {
return Util::convertToEasyPostObject($response, $apiKey);
}
return Util::convertToEasyPostObject($response['address'], $apiKey);
}

/**
Expand All @@ -118,12 +112,6 @@ public function verify()
$url = $this->instanceUrl() . '/verify';
list($response, $apiKey) = $requestor->request('get', $url, null);

if (isset($response['address'])) {
$verifiedAddress = Util::convertToEasyPostObject($response['address'], $apiKey);

return $verifiedAddress;
} else {
return Util::convertToEasyPostObject($response, $apiKey);
}
return Util::convertToEasyPostObject($response['address'], $apiKey);
}
}
15 changes: 15 additions & 0 deletions test/EasyPost/AddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,19 @@ public function testVerify()
$this->assertStringMatchesFormat('adr_%s', $address->id);
$this->assertEquals('388 Townsend St', $address->street1);
}

/**
* Test we throw an error for an invalid address verification.
*/
public function testVerifyInvalid()
{
VCR::insertCassette('addresses/verifyInvalid.yml');

try {
$address = Address::create(['street1' => 'invalid']);
$address->verify();
} catch (\EasyPost\Error $error) {
$this->assertEquals('Unable to verify address.', $error->getMessage());
}
}
}
151 changes: 151 additions & 0 deletions test/cassettes/addresses/verifyInvalid.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6ab30f2

Please sign in to comment.