Skip to content

Conversation

@sheub
Copy link
Contributor

@sheub sheub commented Apr 15, 2018

Happy to contribute with the Here provider.

@willdurand willdurand self-requested a review April 15, 2018 13:25
Copy link
Member

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. Good job!

We just need to add some tests. It is integration tests. So you basically need to select an address and verify the result is as you expect.
When you run the tests (with your API key) some files in .cached_responses will be created. These should also be checked in to the repo.

You run the test simply by

cd src/Procider/Here
composer update
composer test


The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.

## 4.0.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets do 1.0.0 for a new provider.

private $appCode = null;

/**
* @param HttpAdapterInterface $adapter An HTTP adapter.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong. This should be HttpClient

@Mechazawa
Copy link
Contributor

Thanks for making a PR @sheub! I've been needing this provider support for a while.

@sheub
Copy link
Contributor Author

sheub commented Apr 18, 2018

So, if I skip the Ipv4 Test ($testIpv4 = false;) I get results:

OK, but incomplete, skipped, or risky tests!
Tests: 24, Assertions: 109, Skipped: 2.

* @param string $appId An App ID.
* @param string $apoCode An App code.
*/
public function __construct(HttpClient $client, $appId, $appCode)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would typehint the $appId and appCode parameters as string. Than we can remove the exception in the constructor.

@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2011 — William Durand <william.durand1@gmail.com>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you want to change it to your name?

$provider = new Here(
$this->getMockedHttpClient(
'{
"type": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use spaces instead of tabs.

use Http\Client\HttpClient;

/**
* @author Sébastien Barré <sebastien@sheub.eu>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the Here class you annotate the class with info@zoestha.de and here with sebastien@sheub.eu. Is this intended or do you want to fix this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the Review. I have corrected the Here Class.

@Nyholm
Copy link
Member

Nyholm commented Apr 23, 2018

Thank you.
You should add an entry for HERE_APP_ID in phpunit.xml.dist. See https://github.com/geocoder-php/Geocoder/blob/master/phpunit.xml.dist#L27

<server name="HERE_APP_ID" value="YOUR_APP_ID" />
<server name="HERE_APP_CODE" value="YOUR_APP_CODE" />
@sheub
Copy link
Contributor Author

sheub commented May 7, 2018

Hey there,
still get InvalidCredentials.
please let me know what should be done before the merge.

@sheub
Copy link
Contributor Author

sheub commented May 27, 2018

Can anyone give me instructions on how to finalize this PR? In advance Thank you.

@sheub sheub closed this May 27, 2018
@sheub sheub reopened this May 27, 2018
@Baachi
Copy link
Member

Baachi commented May 28, 2018

Hey @sheub,

the TravisCI checks must be passed. A failing PR can't get merged.

@sheub
Copy link
Contributor Author

sheub commented May 28, 2018

Hey @Baachi,
Thanks for your reaction.

The errors from Travis are :
Geocoder\Exception\InvalidCredentials.

But he integration tests passed when I run them at home with my credentials.

I have commit all the files created in Tests/.cached_responses and I have added

<server name="HERE_APP_ID" value="YOUR_APP_ID" />
<server name="HERE_APP_CODE" value="YOUR_APP_CODE" />

in phpunit.xml.dist

I see also (at home) that when I rerun the composer test, the execution is much faster, so I suppose that the tests is running on the ./cached_responses.

I don't understand why Travis is not executing the tests on the ./cached_responses
I am missing something? Thanks for your support.

@sheub
Copy link
Contributor Author

sheub commented May 29, 2018

Hi, it seems that the files created in the ./cached_responses will get a different Hash code for each HERE_APP_ID/HERE_APP_CODE pair.

see:
geocoder.api.here.com_62eb9554b9240ece07c143250a367bf2a534ac37
and
geocoder.api.here.com_194f5df1c578dfb8b688908c8e87c11d2afdcf9d
if I run with a real credentials or with YOUR_APP_ID YOUR_APP_CODE

For that reason the tests is not run on the ./cached_responses.

Any Idea? Thanks for your support.

@sheub
Copy link
Contributor Author

sheub commented May 31, 2018

Hi @Nyholm ,
May I kindly ask you to point me out in the right direction so I can resolve this issue.
I can't see why the tests won't run on the ./cached_responses
Many thanks for your time.

@sheub
Copy link
Contributor Author

sheub commented Jun 4, 2018

Hi @Nyholm ,

I could find out why the tests wouldn't run on the cached files.
The problem is that the HERE provider requires 2 Credential keys in the url: the app_id & the app_code.

and only one apiKey is searched for and replaced in the body part of the cacheKey:
Geocoder\IntegrationTest\CachedResponseClient

     public function sendRequest(RequestInterface $request)
    {
        $url = (string) $request->getUri();
        $host = (string) $request->getUri()->getHost();
        if (!empty($this->apiKey)) {
            $url = str_replace($this->apiKey, '[apikey]', $url);
        }

        $file = sprintf('%s/%s_%s', $this->cacheDir, $host, sha1($url));
        if (is_file($file) && is_readable($file)) {
            return new Response(200, [], (new StreamFactory())->createStream(unserialize(file_get_contents($file))));
        }

        $response = $this->delegate->sendRequest($request);
        file_put_contents($file, serialize($response->getBody()->getContents()));

        return $response;
    }

I could get it work properly at home, but I had to (slightly) modify three files from geocoder-php/provider-integration-tests:

  • Geocoder\IntegrationTest\ProviderIntegrationTest,
  • Geocoder\IntegrationTest\CachedResponseClient
  • Geocoder\IntegrationTest\BaseTestCase

In a way that both the app_id & the app_code are replaced in the url.

This solution is working, but it requires that the geocoder-php/provider-integration-tests will be modified...

@jbelien
Copy link
Member

jbelien commented Jun 4, 2018

Hello @sheub ,

I didn't check in details but Google Maps provider also requires 2 parameters (ClientId and APIKey) ; so I guess it should also work with HERE without having to modify the Geocoder\IntegrationTest.

Have a look at https://github.com/geocoder-php/Geocoder/blob/master/src/Provider/GoogleMaps/

@sheub
Copy link
Contributor Author

sheub commented Jun 4, 2018

I'll have a look, but I am using the Google Maps provider with only one key (GOOGLEMAP_API_KEY)

@sheub
Copy link
Contributor Author

sheub commented Jun 12, 2018

Maybe someone could tell me if it is for sure possible to get the caching to work with the 2 Credential keys, before I spend some more hours on it. Thank you.

@sheub
Copy link
Contributor Author

sheub commented Jun 22, 2018

So, The TravisCI build have passed :).

I still had to do an override of the class CachedResponseClient to add the appCode variable which is needed for the Here provider. The override HereCachedResponseClient.php file is loaded in Here\Tests\IntegrationTest with require_once.

This override could be omitted simply by adding the variable to Geocoder\IntegrationTest\CachedResponseClient directly. This is a slight modification which would not change anything for the other providers.
This would be my prefered solution as it would work also for all other providers which need 2 keys (e.g. Algolia places).

Copy link
Member

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

Thanks for all the reviews and your work

/**
* @var string
*/
private $appCode = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not need the = null

```bash
composer require geocoder-php/here-provider
```
### Note
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should be removed.

composer require geocoder-php/here-provider
```
### Note
## App Id and App Code
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ### instead of ##

## App Id and App Code
Get your Here credentials at https://developer.here.com/

## Language parameter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ### instead of ##

*
* @author Sébastien Barré <sebastien@sheub.eu> override the provider-integration-tests: CachedResponseClient class
*/
class HereCachedResponseClient extends CachedResponseClient
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the best solution I could think of. I suggest to modify the CachedResponseClient only if other providers also need this functionality.

@Nyholm
Copy link
Member

Nyholm commented Jun 26, 2018

I added some notes. These are just minors. I will merge this PR now and prepare the package.

@Nyholm Nyholm merged commit a76ed30 into geocoder-php:master Jun 26, 2018
@Nyholm
Copy link
Member

Nyholm commented Jun 26, 2018

The package is added: https://packagist.org/packages/geocoder-php/here-provider

You could improve your tests now when 1.1.0 is released of the integration tests. That version includes your PR.

Let me know when I should tag version 1.0.0 of this new package. (Ie after you test it a little bit)

jbelien pushed a commit that referenced this pull request Sep 14, 2018
* Add Here Provider

* Rename here.php to Here.php

* Update Here.php

* Update HereAddress.php

* Update Here.php

* Update HereAddress.php

* Update Here.php

* Update Here.php

* Review Corrections

* +     * @param string     $appId   An App ID.
+     * @param string     $apoCode An App code.

* Add Tests files

* Add phpunit.xml.dist

* Corrections after running tests

* use{}

* FIX IT!

* Few Styles #844

* HereMaps->Here

* .Some more tests

* style

* Build Test OK if $testIpv4 = false;

* Update HereTest.php

* Code review from Baachi

* Update Here.php

* Update Readme.md

* updated Here_Test and cached_responses

* Add
<server name="HERE_APP_ID" value="YOUR_APP_ID" />
<server name="HERE_APP_CODE" value="YOUR_APP_CODE" />

* Update Readme.md

* Reworking of the Tests with adjustments to fit the two Credentials keys (appID and AppCode) of the Here Provider

* style-ci correction + override testGeocodeQueryWithNoResults, testReverseQuery and testReverseQueryWithNoResults

* Styles

* Update IntegrationTest.php

* Correct the extends and the naming (to HereCachedResponseClient)

* Remove Overriding file HereCachedResponseClient.php

* update cached_responses

* set provider-integration-tests requirement 1.1.0

* Update Readme.md

* Update Readme.md

* Update composer.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants