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

Geolocation #94

Open
wants to merge 2 commits 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ Some important environment variables are:
- `USHAHIDI_PLATFORM_API_TIMEOUT`: Depending on your setup, you may want to set a custom timeout for requests to the Ushahidi Platform. It defaults to 2 seconds.
- `USSD_MAX_CHARACTERS_PER_PAGE`: USSD messages are limited to a fixed amount of characters depending on the telecommunications service provider. This allows to paginate the content delivered to your users. It defaults to 160 characters.

- `USHAHIDI_PLATFORM_GEO_API_TIMEOUT`, `USHAHIDI_PLATFORM_GEO_API_URL`, `USHAHIDI_PLATFORM_GEO_API_VERSION` : settings used specifically when using Ushahidi Platform for geocoding resolution. If not specified, the geocoder uses the general settings mentioned above.

## TODO
- API Specification
- Testing
Expand Down
4 changes: 2 additions & 2 deletions app/Messages/Outgoing/GeoLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Log;
use Illuminate\Validation\ValidationException;
use Ushahidi\Platform\Client;
use App\Services\PlatformGeocodingClient;

class GeoLocation extends TextQuestion
{
Expand Down Expand Up @@ -70,7 +70,7 @@ public function createsNewQuestion(): bool
public function queryLocation(string $query): array
{
try {
$sdk = resolve(Client::class);
$sdk = resolve(PlatformGeocodingClient::class);
$response = $sdk->queryLocation($query, App::getLocale());

if (isset($response['body'])) {
Expand Down
39 changes: 39 additions & 0 deletions app/Providers/PlatformGeocodingProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use App\Services\PlatformGeocodingClient;

class PlatformGeocodingProvider extends ServiceProvider
{
/**
* Register services.
*
* @return void
*/
public function register()
{
$this->app->bind(PlatformGeocodingClient::class, function () {
$timeout = env('USHAHIDI_PLATFORM_GEO_API_TIMEOUT') ?: env('USHAHIDI_PLATFORM_API_TIMEOUT') ?: 2.0;
$url = env('USHAHIDI_PLATFORM_GEO_API_URL') ?: env('USHAHIDI_PLATFORM_API_URL');
$api_version = env('USHAHIDI_PLATFORM_GEO_API_VERSION') ?: env('USHAHIDI_PLATFORM_API_VERSION') ?: 5;

$options = [
'timeout' => $timeout,
];

return new PlatformGeocodingClient($url, $options, $api_version);
});
}

/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
//
}
}
19 changes: 19 additions & 0 deletions app/Services/PlatformGeocodingClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Services;

use Ushahidi\Platform\Client;

/*
* This class just extends the SDK client, to differentiate its use
* for geocoding purposes.
*/
class PlatformGeocodingClient extends Client {

// Replicate constructor for Laravel's IoC
public function __construct(string $apiUrl, array $options = [], string $version = '5')
{
parent::__construct($apiUrl, $options, $version);
}

}
Loading