Skip to content
This repository was archived by the owner on Sep 18, 2019. It is now read-only.

Commit 370ec32

Browse files
bump version and added integration tests, also fixed error in bulkPost method
1 parent 07ab366 commit 370ec32

File tree

6 files changed

+68
-10
lines changed

6 files changed

+68
-10
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
vendor
2-
composer.lock
2+
composer.lock
3+
apiKey.php

HISTORY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
History
22
=======
33

4+
1.0.6 (2014-01-26)
5+
------------------
6+
* Added integration tests and fixed issue where post data was being encoded twice.
7+
48
1.0.5 (2014-01-23)
59
------------------
610
* Specified minimum version of Guzzle at >=3.7.0

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "stanley/geocodio-php",
33
"description": "Thin wrapper for the Geocodio API",
4-
"version": "1.0.5",
4+
"version": "1.0.6",
55
"authors": [
66
{
77
"name": "David Stanley",

phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@
1515
<testsuite name="unit">
1616
<directory>./tests/unit/</directory>
1717
</testsuite>
18+
<testsuite name="integration">
19+
<directory>./tests/integration/</directory>
20+
</testsuite>
1821
</testsuites>
1922
</phpunit>

src/Stanley/Geocodio/Client.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function get($data, $key = null, $verb = 'geocode')
7777
public function post($data, $key = null)
7878
{
7979
if ($key) $this->apiKey = $key;
80-
$request = $this->bulkPost(json_encode($data));
80+
$request = $this->bulkPost($data);
8181
return $this->newDataObject($request->getBody());
8282
}
8383

@@ -103,15 +103,14 @@ public function parse($data, $key = null)
103103
protected function getRequest($data, $verb)
104104
{
105105
$params = [
106-
'q' => $data,
106+
'q' => str_replace(' ', '+', $data),
107107
'api_key' => $this->apiKey
108108
];
109-
109+
$address = urlencode(str_replace(' ', '+', $data));
110110
$request = $this->client->get(self::BASE_URL . $verb, [], [
111111
'query' => $params
112112
]);
113-
114-
$response = $this->client->send($request);
113+
$response = $request->send();
115114
return $this->checkResponse($response);
116115
}
117116

@@ -125,12 +124,11 @@ protected function getRequest($data, $verb)
125124
protected function bulkPost($data, $verb = 'geocode')
126125
{
127126
$url = self::BASE_URL . $verb . "?api_key=" . $this->apiKey;
128-
$headers = [ 'content-type' => 'application\json' ];
127+
$headers = [ 'Content-Type' => 'application/json' ];
129128
$payload = json_encode($data);
130129

131130
$request = $this->client->post($url, $headers, $payload, []);
132-
$response = $this->client->send($request);
133-
131+
$response = $request->send();
134132
return $this->checkResponse($response);
135133
}
136134

tests/integration/ApiTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
class ApiTest extends BaseTest
4+
{
5+
protected $apiKey;
6+
7+
/**
8+
* Class constructor
9+
*/
10+
public function __construct()
11+
{
12+
// I put my real key in this file within an array. These tests won't run without it.
13+
$key = require __DIR__ .'/../../apiKey.php';
14+
$this->apiKey = $key['apiKey'];
15+
}
16+
17+
/**
18+
* @test
19+
*/
20+
public function testSingleGoodAddress()
21+
{
22+
$goodAddress = '42370 Bob Hope Drive, Rancho Mirage, CA 22334';
23+
$client = new Stanley\Geocodio\Client($this->apiKey);
24+
$result = $client->geocode($goodAddress);
25+
$this->assertInstanceOf('Stanley\Geocodio\Data', $result);
26+
}
27+
28+
/**
29+
* @test
30+
*/
31+
public function testParseAddress()
32+
{
33+
$badAddress = '123 Anywhere St Anytown, CA 12345';
34+
$client = new Stanley\Geocodio\Client($this->apiKey);
35+
$result = $client->parse($badAddress);
36+
$this->assertInstanceOf('Stanley\Geocodio\Data', $result);
37+
}
38+
39+
/**
40+
* @test
41+
*/
42+
public function testPostMultipleAddresses()
43+
{
44+
$multipleAddresses = [
45+
'42370 Bob Hope Drive, Rancho Mirage CA',
46+
'1290 Northbrook Court Mall, Northbrook IL'
47+
];
48+
$client = new Stanley\Geocodio\Client($this->apiKey);
49+
$result = $client->post($multipleAddresses);
50+
$this->assertInstanceOf('Stanley\Geocodio\Data', $result);
51+
}
52+
}

0 commit comments

Comments
 (0)