diff --git a/readme.md b/readme.md index 27bc29b..70286ee 100644 --- a/readme.md +++ b/readme.md @@ -20,12 +20,12 @@ Just import, instantiate and call: use IpApi\IpApi; $api = new IpApi(); -$response = $api->locate('ip or address'); +$location = $api->locate('ip or address'); ``` -### The \IpApi\Response object +### The \IpApi\Location object -The response object has an schema returned composed by the following fields by default: +The location object has an schema returned composed by the following fields by default: - status: Status of operation; - country: Country of address; @@ -42,18 +42,12 @@ The response object has an schema returned composed by the following fields by d - as: The AS number and name; - query: The address or IP used on query. -The response object has some others methods and features: +The location object has some others methods and features: ```php // Convert the object to an array -$data = $response->toArray(); - -// Fill the object with received array data -$response->fill([ - 'propertyOne' => 'Value one', - 'propertyTwo' => 'Value two', -]); +$data = $location->toArray(); // JSON encode -$json = json_encode($response); +$json = json_encode($location); ``` diff --git a/src/IpApi.php b/src/IpApi.php index e5b8e9f..0530973 100644 --- a/src/IpApi.php +++ b/src/IpApi.php @@ -19,14 +19,14 @@ class IpApi protected $endpoint = 'http://ip-api.com/json/'; /** - * Builds a response object from received parsed data. + * Builds a location object from received parsed data. * * @param mixed[] $data - * @return \IpApi\Response + * @return \IpApi\Location */ - protected function buildResponse(array $data) + protected function buildLocation(array $data) { - return new Response($data); + return new Location($data); } /** @@ -55,16 +55,16 @@ protected function fetch($url) * Locates the received address over api. * * @param string $address - * @return \IpApi\Response + * @return \IpApi\Location */ public function locate($address) { $url = $this->buildUrl($address); $data = $this->fetch($url); $parsed = $this->parse($data); - $response = $this->buildResponse($parsed); + $location = $this->buildLocation($parsed); - return $response; + return $location; } /** diff --git a/src/Response.php b/src/Location.php similarity index 93% rename from src/Response.php rename to src/Location.php index 007834c..d6d2c3d 100644 --- a/src/Response.php +++ b/src/Location.php @@ -3,16 +3,16 @@ namespace IpApi; /** - * Class Response. + * Class Location. * * The abstraction of a response fetched from IpApi api. * * @package IpApi */ -class Response implements \JsonSerializable +class Location implements \JsonSerializable { /** - * Response attributes collection. + * Location attributes collection. * * @var mixed[] */ diff --git a/tests/IpApiTest.php b/tests/IpApiTest.php index c7e344c..d4980d5 100644 --- a/tests/IpApiTest.php +++ b/tests/IpApiTest.php @@ -7,18 +7,18 @@ class IpApiTest extends TestCase public function testLocateReturnType() { $api = new \IpApi\IpApi(); - $result = $api->locate('8.8.8.8'); + $location = $api->locate('8.8.8.8'); - $this->assertInstanceOf(\IpApi\Response::class, $result); + $this->assertInstanceOf(\IpApi\Location::class, $location); } public function testResponseOnSuccess() { $api = new \IpApi\IpApi(); - $result = $api->locate('8.8.8.8'); + $location = $api->locate('8.8.8.8'); - $this->assertEquals('United States', $result->country); - $this->assertEquals('California', $result->regionName); - $this->assertEquals('Mountain View', $result->city); + $this->assertEquals('United States', $location->country); + $this->assertEquals('California', $location->regionName); + $this->assertEquals('Mountain View', $location->city); } } diff --git a/tests/ResponseTest.php b/tests/LocationTest.php similarity index 60% rename from tests/ResponseTest.php rename to tests/LocationTest.php index 7595e3a..cd11139 100644 --- a/tests/ResponseTest.php +++ b/tests/LocationTest.php @@ -2,27 +2,27 @@ use PHPUnit\Framework\TestCase; -class ResponseTest extends TestCase +class LocationTest extends TestCase { public function testSetting() { - $response = new \IpApi\Response(); - $response->someProp = 'some value'; + $location = new \IpApi\Location(); + $location->someProp = 'some value'; - $this->assertAttributeEquals(['someProp' => 'some value'], 'attributes', $response); + $this->assertAttributeEquals(['someProp' => 'some value'], 'attributes', $location); } public function testGetting() { - $response = new \IpApi\Response(); - $response->someProp = 'some value'; + $location = new \IpApi\Location(); + $location->someProp = 'some value'; - $this->assertEquals('some value', $response->someProp); + $this->assertEquals('some value', $location->someProp); } public function testFilling() { - $response = new \IpApi\Response([ + $location = new \IpApi\Location([ 'propOne' => 'value one', 'propTwo' => 'value two', ]); @@ -30,12 +30,12 @@ public function testFilling() $this->assertAttributeEquals([ 'propOne' => 'value one', 'propTwo' => 'value two', - ], 'attributes', $response); + ], 'attributes', $location); } public function testToArray() { - $response = new \IpApi\Response([ + $location = new \IpApi\Location([ 'propOne' => 'value one', 'propTwo' => 'value two', ]); @@ -43,14 +43,14 @@ public function testToArray() $this->assertEquals([ 'propOne' => 'value one', 'propTwo' => 'value two', - ], $response->toArray()); + ], $location->toArray()); } public function testToJson() { - $response = new \IpApi\Response(['propOne' => 'value one']); + $location = new \IpApi\Location(['propOne' => 'value one']); - $json = json_encode($response); + $json = json_encode($location); $parsed = json_decode($json, true); $this->assertEquals(['propOne' => 'value one'], $parsed);