Skip to content

Commit

Permalink
Merge branch 'develop' into release/v0
Browse files Browse the repository at this point in the history
  • Loading branch information
biscolab committed Mar 29, 2020
2 parents 0a0cf88 + c76473d commit 66fb057
Show file tree
Hide file tree
Showing 15 changed files with 427 additions and 31 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ php:
- 7.1
- 7.2
- 7.3
- 7.4

before_script:
- travis_retry composer self-update
Expand All @@ -12,4 +13,4 @@ before_script:
script:
- vendor/bin/phpunit --exclude-group http

fast_finish: true
fast_finish: true
30 changes: 19 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,47 @@ This provide simple functions to work with Google Maps APIs. You can find furthe
Google Maps provide many services, actually at this moment this package implements only **Geocoding** service but others will be available soon.

## Reference & Documentation

Go to [complete reference](https://biscolab.com/google-maps-php-reference/) or read [documentation](https://gmaps-php-docs.biscolab.com/)

## Google Maps Services

### Ready
* Geocoding :ballot_box_with_check:
* Elevation :ballot_box_with_check:
* Places :ballot_box_with_check:

- Geocoding :ballot_box_with_check:
- Elevation :ballot_box_with_check:
- Places :ballot_box_with_check:
- Time Zone :ballot_box_with_check:

### ASAP
* Directions (soon)
* Distance Matrix (soon)
* Road (soon)
* Time Zone (soon)

- Directions (soon)
- Distance Matrix (soon)
- Road (soon)

### Not scheduled
* Geolocation (not scheduled)

- Geolocation (not scheduled)

## Installation

You can install the package via composer:

```sh
composer require biscolab/google-maps-php-sdk
```

## Documentation
Notice! The package is not yet stable, you may find trouble with your minimum stability settings.
* [Complete documentation](https://gmaps-php-docs.biscolab.com/docs/getting-started)
* [API reference](https://biscolab.com/google-maps-php-reference)

Notice! The package is not yet stable, you may find trouble with your minimum stability settings.

- [Complete documentation](https://gmaps-php-docs.biscolab.com/docs/getting-started)
- [API reference](https://biscolab.com/google-maps-php-reference)

## Examples

Watch the [examples](https://github.com/biscolab/google-maps-php-sdk/tree/master/examples)

## License

[![MIT License](https://img.shields.io/github/license/biscolab/google-maps-php-sdk.svg)](https://github.com/biscolab/google-maps-php-sdk/blob/master/LICENSE)
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "biscolab/google-maps-php-sdk",
"description": "Google Maps PHP SDK.",
"license": "MIT",
"version": "0.6.0",
"version": "0.7.0",
"keywords": [
"google",
"maps",
Expand Down Expand Up @@ -46,4 +46,3 @@
"test-no-http": "phpunit --exclude-group http"
}
}

1 change: 0 additions & 1 deletion examples/Places/placesFindPlaceByPhoneNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* MIT license: https://github.com/biscolab/google-maps-php/blob/master/LICENSE
*/

use Biscolab\GoogleMaps\Api\P;
use Biscolab\GoogleMaps\Enum\GoogleMapsApiConfigFields;

// Run "composer install" command or change with your actual autoload.php file
Expand Down
1 change: 0 additions & 1 deletion examples/Places/placesFindPlaceByText.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* MIT license: https://github.com/biscolab/google-maps-php/blob/master/LICENSE
*/

use Biscolab\GoogleMaps\Api\P;
use Biscolab\GoogleMaps\Enum\GoogleMapsApiConfigFields;

// Run "composer install" command or change with your actual autoload.php file
Expand Down
1 change: 0 additions & 1 deletion examples/Places/placesTextSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* MIT license: https://github.com/biscolab/google-maps-php/blob/master/LICENSE
*/

use Biscolab\GoogleMaps\Api\P;
use Biscolab\GoogleMaps\Enum\GoogleMapsApiConfigFields;

// Run "composer install" command or change with your actual autoload.php file
Expand Down
40 changes: 40 additions & 0 deletions examples/TimeZone/timeZone.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/**
* Copyright (c) 2019 - present
* Google Maps PHP - timeZone.php
* author: Roberto Belotti - roby.belotti@gmail.com
* web : robertobelotti.com, github.com/biscolab
* Initial version created on: 9/10/2019
* MIT license: https://github.com/biscolab/google-maps-php/blob/master/LICENSE
*/

use Biscolab\GoogleMaps\Api\TimeZone;
use Biscolab\GoogleMaps\Enum\GoogleMapsApiConfigFields;
use Biscolab\GoogleMaps\Fields\LatLngFields;
use Biscolab\GoogleMaps\Object\Location;

// Run "composer install" command or change with your actual autoload.php file
require '../../vendor/autoload.php';

// Further info about API key: https://developers.google.com/maps/documentation/timezone/get-api-key
$timezone = new TimeZone([
GoogleMapsApiConfigFields::KEY => 'YOUR_API_KEY'
]);

// https://developers.google.com/maps/documentation/timezone/start#sample-request
$location = new Location([LatLngFields::LAT => 38.908133, LatLngFields::LNG => -77.047119]);
$timestamp = 1458000000;
$results = $timezone->get($location, $timestamp);

// get dstOffset: should be 3600
$results->getDdstOffset();

// get rawOffset: should be -18000
$results->getRawOffset();

// get timeZoneId: should be "America/New_York"
$results->getTimeZoneId();

// get timeZoneName: should be "Eastern Daylight Time"
$results->getTimeZoneName();
13 changes: 12 additions & 1 deletion src/Abstracts/AbstractObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function __call($name, $arguments)

$camel_field = (empty($match[0])) ? '' : $match[0];

$snake_field = camel2Snake($camel_field);
$snake_field = $this->getFieldName($camel_field);

$field_type = (empty($this->typeCheck[$snake_field])) ? null : $this->typeCheck[$snake_field];

Expand All @@ -189,4 +189,15 @@ public function __call($name, $arguments)
}
}

/**
* @param string $initial_field_name
*
* @return string
*/
protected function getFieldName(string $initial_field_name): string
{

return camel2Snake($initial_field_name);
}

}
61 changes: 61 additions & 0 deletions src/Api/TimeZone.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* Copyright (c) 2019 - present
* Google Maps PHP - TimeZone.php
* author: Roberto Belotti - roby.belotti@gmail.com
* web : robertobelotti.com, github.com/biscolab
* Initial version created on: 8/10/2019
* MIT license: https://github.com/biscolab/google-maps-php/blob/master/LICENSE
*/

namespace Biscolab\GoogleMaps\Api;

use Biscolab\GoogleMaps\Abstracts\Api;
use Biscolab\GoogleMaps\Fields\GoogleMapsRequestFields;
use Biscolab\GoogleMaps\Http\GoogleMapsResult;
use Biscolab\GoogleMaps\Http\Result\ElevationResultsCollection;
use Biscolab\GoogleMaps\Http\Result\TimeZoneResult;
use Biscolab\GoogleMaps\Object\Location;

/**
* Class TimeZone
* @package Biscolab\GoogleMaps\Api
*
* @since 0.7.0
* @see https://developers.google.com/maps/documentation/timezone/intro
*/
class TimeZone extends Api
{

/**
* @var string
*/
const SERVICE_ENDPOINT = 'timezone';

/**
* @var string
*/
protected $result_type = TimeZoneResult::class;

/**
* @param Location $location
* @param int $timestamp
* @param string|null $language
*
* @return GoogleMapsResult
*/
public function get(Location $location, int $timestamp, string $language = null): GoogleMapsResult
{

$params = [
GoogleMapsRequestFields::LOCATION => $location,
GoogleMapsRequestFields::TIMESTAMP => $timestamp,
];

if ($language) {
$params[GoogleMapsRequestFields::LANGUAGE] = $language;
}

return $this->callApi($params);
}
}
6 changes: 6 additions & 0 deletions src/Fields/GoogleMapsRequestFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,10 @@ class GoogleMapsRequestFields
* @since 0.6.0
*/
const MAXHEIGHT = 'maxheight';

/**
* @var string timestamp
* @since 0.7.0
*/
const TIMESTAMP = 'timestamp';
}
24 changes: 24 additions & 0 deletions src/Fields/GoogleMapsResultFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,28 @@ class GoogleMapsResultFields
*/
const ADR_ADDRESS = 'adr_address';

/**
* @var string dstOffset
* @since 0.7.0
*/
const DST_OFFSET = 'dstOffset';

/**
* @var string rawOffset
* @since 0.7.0
*/
const RAW_OFFSET = 'rawOffset';

/**
* @var string timeZoneId
* @since 0.7.0
*/
const TIMEZONE_ID = 'timeZoneId';

/**
* @var string timeZoneName
* @since 0.7.0
*/
const TIMEZONE_NAME = 'timeZoneName';

}
4 changes: 3 additions & 1 deletion src/Http/GoogleMapsResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ protected function parseResponse(): GoogleMapsResponse

if ($this->getStatus() != GoogleMapsResponseStatusValues::OK) {
$error_message = 'Something went wrong';
if($this->getStatus() === 'INVALID_REQUEST'){
print_r($array_response);die();}
if (!empty($array_response[GoogleMapsResponseFields::ERROR_MESSAGE])) {
$error_message = $array_response[GoogleMapsResponseFields::ERROR_MESSAGE];
$this->setErrorMessage($error_message);
Expand All @@ -154,7 +156,7 @@ protected function parseResponse(): GoogleMapsResponse
$result = $array_response[GoogleMapsResponseFields::RESULT];

} else {
throw new ResponseException('Missing "results" in GoogleMapsApi Response');
$result = $array_response;
}
$this->setResult($result);
$this->setResults($results);
Expand Down
74 changes: 74 additions & 0 deletions src/Http/Result/TimeZoneResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* Copyright (c) 2019 - present
* Google Maps PHP - TimeZoneResult.php
* author: Roberto Belotti - roby.belotti@gmail.com
* web : robertobelotti.com, github.com/biscolab
* Initial version created on: 8/10/2019
* MIT license: https://github.com/biscolab/google-maps-php/blob/master/LICENSE
*/

namespace Biscolab\GoogleMaps\Http\Result;

use Biscolab\GoogleMaps\Fields\GoogleMapsResultFields;
use Biscolab\GoogleMaps\Http\GoogleMapsResult;

/**
* Class TimeZoneResult
*
* @method setDstOffset(int $dstOffset)
* @method setRawOffset(int $rawOffset)
* @method setTimeZoneId(string $timeZoneId)
* @method setTimeZoneName(string $timeZoneName)
*
* @method int getDstOffset()
* @method int getRawOffset()
* @method string getTimeZoneId()
* @method string getTimeZoneName()
* @since 0.7.0
*/
class TimeZoneResult extends GoogleMapsResult
{

/**
* @var int
*/
protected $dstOffset = 0;

/**
* @var int
*/
protected $rawOffset = 0;

/**
* @var string
*/
protected $timeZoneId = '';

/**
* @var string
*/
protected $timeZoneName = '';

/**
* @var array
*/
protected $typeCheck = [
GoogleMapsResultFields::DST_OFFSET => 'int',
GoogleMapsResultFields::RAW_OFFSET => 'int',
GoogleMapsResultFields::TIMEZONE_ID => 'string',
GoogleMapsResultFields::TIMEZONE_NAME => 'string',
];

/**
* @param string $initial_field_name
*
* @return string
*/
protected function getFieldName(string $initial_field_name): string
{

return lcfirst($initial_field_name);
}

}
Loading

0 comments on commit 66fb057

Please sign in to comment.