-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.camunda.latera.bss.connectors | ||
|
||
import org.camunda.bpm.engine.delegate.DelegateExecution | ||
import org.camunda.latera.bss.http.HTTPRestProcessor | ||
import org.camunda.latera.bss.logging.SimpleLogger | ||
|
||
class GoogleMaps { | ||
String url | ||
String path | ||
private String token | ||
HTTPRestProcessor http | ||
SimpleLogger logger | ||
|
||
GoogleMaps(DelegateExecution execution) { | ||
this.logger = new SimpleLogger(execution) | ||
def ENV = System.getenv() | ||
|
||
this.url = ENV['GOOGLE_MAPS_URL'] ?: 'https://maps.googleapis.com/maps/api' | ||
this.token = ENV['GOOGLE_MAPS_TOKEN'] ?: execution.getVariable('googleMapsToken') | ||
|
||
this.http = new HTTPRestProcessor( | ||
baseUrl : url, | ||
execution : execution | ||
) | ||
} | ||
|
||
def sendRequest(Map input, CharSequence method = 'get') { | ||
if (input.query) { | ||
input.query += [key: this.token] | ||
} | ||
if (input.path) { | ||
input.path = "${input.path}/json" | ||
} | ||
return http.sendRequest(input, method) | ||
} | ||
|
||
Map geocodeAddress(CharSequence address){ | ||
try { | ||
return sendRequest( | ||
'post', | ||
path: 'geocode', | ||
body: [ | ||
address: address | ||
] | ||
).results[0] | ||
} | ||
catch (Exception e) { | ||
logger.error(e) | ||
return null | ||
} | ||
} | ||
} |