Skip to content

Commit

Permalink
Merge pull request traderinteractive#11 from krishnaramya/master
Browse files Browse the repository at this point in the history
To get zip code back by modifying database id value in netacuity
  • Loading branch information
chadicus committed Nov 11, 2015
2 parents 6f8f5a7 + 7395144 commit 3af62af
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
26 changes: 19 additions & 7 deletions src/NetAcuity.php
Expand Up @@ -41,42 +41,54 @@ public function __construct(Socket $socket, $apiId)
* @type string $region
* @type string $city
* @type string $conn-speed
* @type string $country-conf
* @type string $region-conf
* @type string $city-conf
* @type string $metro-code
* @type string $latitude
* @type string $longitude
* @type string $postal-code
* @type string $country-code
* @type string $region-code
* @type string $city-code
* @type string $continent-code
* @type string $two-letter-country
* @type string $internal-code
* @type string $area-code
* @type string $country-conf
* @type string $region-conf
* @type string $city-conf
* @type string $postal-conf
* @type string $gmt-offset
* @type string $in-dist
* }
*/
public function getGeo($ip)
{
Util::throwIfNotType(['string' => $ip], true);

$response = $this->_query($this->_buildQuery(3, $ip));
$response = $this->_query($this->_buildQuery(4, $ip));
return $this->_parseResponse(
$response,
[
'country',
'region',
'city',
'conn-speed',
'country-conf',
'region-conf',
'city-conf',
'metro-code',
'latitude',
'longitude',
'zip-code',
'country-code',
'region-code',
'city-code',
'continent-code',
'two-letter-country',
'internal-code',
'area-code',
'country-conf',
'region-conf',
'city-conf',
'postal-conf',
'gmt-offset',
'in-dist',
]
);
}
Expand Down
16 changes: 11 additions & 5 deletions tests/NetAcuityTest.php
Expand Up @@ -34,9 +34,9 @@ public function createNonIntApiId()
public function getGeo()
{
$socket = $this->getMockBuilder('\Socket\Raw\Socket')->disableOriginalConstructor()->setMethods(['write', 'read'])->getMock();
$socket->expects($this->once())->method('write')->with("3;1;1.2.3.4\r\n")->will($this->returnValue(13));
$socket->expects($this->once())->method('write')->with("4;1;1.2.3.4\r\n")->will($this->returnValue(13));
$socket->expects($this->once())->method('read')->with(1024)->will(
$this->returnValue('xxxxUSA;something;reserved;broadband;5;4;3;2;123.456;789.101;112;1314;1516;1;USxxx')
$this->returnValue('xxxxUSA;something;reserved;broadband;2;123.456;789.101;12345;112;1314;1516;1;US;1;123;2;3;4;5;6;7xxx')
);

$client = new NetAcuity($socket, 1);
Expand All @@ -47,17 +47,23 @@ public function getGeo()
'region' => 'something',
'city' => 'reserved',
'conn-speed' => 'broadband',
'country-conf' => '5',
'region-conf' => '4',
'city-conf' => '3',
'metro-code' => '2',
'latitude' => '123.456',
'longitude' => '789.101',
'zip-code' => '12345',
'country-code' => '112',
'region-code' => '1314',
'city-code' => '1516',
'continent-code' => '1',
'two-letter-country' => 'US',
'internal-code' => '1',
'area-code' => '123',
'country-conf' => '2',
'region-conf' => '3',
'city-conf' => '4',
'postal-conf' => '5',
'gmt-offset' => '6',
'in-dist' => '7',
],
$client->getGeo('1.2.3.4')
);
Expand Down

0 comments on commit 3af62af

Please sign in to comment.