Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability to do a text base search #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
"homepage": "http://joshtronic.com"
}],
"require": {
"php": ">=5.3.0"
"php": ">=5.3.0",
"phpunit/phpunit": "4.0.*"
},
"require-dev": {
"satooshi/php-coveralls": "dev-master"
},
"autoload": {
"psr-4": {"joshtronic\\": "src/"}
}

}
20 changes: 20 additions & 0 deletions src/GooglePlaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace joshtronic;

use SebastianBergmann\Exporter\Exception;

class GooglePlaces
{
public $client = '';
Expand All @@ -24,6 +26,9 @@ class GooglePlaces
public $placeid = null;
public $reference = null;
public $opennow = null;
//added these for text search.
public $textsearch = null;
public $query = null;

public $subradius = null;
public $getmax = true;
Expand Down Expand Up @@ -212,6 +217,14 @@ private function methodChecker($parameters, $method)
}

break;

//added this for text search
case 'textsearch':
if(!isset($parameters['query'])){

throw new Exception('You must specify the string you want to search for');
}
break;
}
}

Expand Down Expand Up @@ -240,13 +253,20 @@ private function queryGoogle($url, $parameters)
$querystring .= '&';
}

// added this to remove spaces from text search
if(preg_match('/\s/',$value)){

$value = str_replace(' ', '+', $value);
}

$querystring .= $variable . '=' . $value;
}

$response = $this->client->get($url . '?' . $querystring);

if ($this->output == 'json')
{

$response = json_decode($response, true);

if ($response === null)
Expand Down
3 changes: 3 additions & 0 deletions tests/GooglePlacesTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php

require '../vendor/autoload.php';

require_once '../src/GooglePlaces.php';
require_once '../src/GooglePlacesClient.php';


class GooglePlacesTest extends PHPUnit_Framework_TestCase
{
private $places;
Expand Down
20 changes: 20 additions & 0 deletions tests/Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* Created by IntelliJ IDEA.
* User: dylanaird
* Date: 9/2/17
* Time: 3:13 PM
*/

require '../vendor/autoload.php';

require_once '../src/GooglePlaces.php';
require_once '../src/GooglePlacesClient.php';


$google_places = new joshtronic\GooglePlaces('AIzaSyCBadIpHu7WgpO0IXGKZw143orleCgi_A4');

$google_places->query = "Shop 111 Epping Plaza High Street";
$results = $google_places->textsearch();

highlight_string("<?php\n\$data =\n" . var_export($results, true) . ";\n?>");