Skip to content

Commit

Permalink
Add GoogleMaps connector
Browse files Browse the repository at this point in the history
  • Loading branch information
dolfinus committed Jul 14, 2019
1 parent 6d6d1b8 commit 6df2424
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/org/camunda/latera/bss/connectors/GoogleMaps.groovy
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
}
}
}

0 comments on commit 6df2424

Please sign in to comment.