Skip to content
Snippets Groups Projects
Commit a7e9f18d authored by Tamas Erdos's avatar Tamas Erdos
Browse files

Enabling ESRI for storing results

- `api_key` param
- `forStorage` param
- token generation
- updating README.md
parent 4d61da2f
No related branches found
No related tags found
No related merge requests found
......@@ -568,15 +568,15 @@ The [Google Places Details API](https://developers.google.com/places/documentati
#### ESRI (`:esri`)
* **API key**: none
* **API key**: optional (set `Geocoder.configure(:esri => {:api_key => ["client_id", "client_secret"]})`)
* **Quota**: Required for some scenarios (see Terms of Service)
* **Region**: world
* **SSL support**: yes
* **Languages**: English
* **Documentation**: http://resources.arcgis.com/en/help/arcgis-online-geocoding-rest-api/
* **Documentation**: https://developers.arcgis.com/rest/geocode/api-reference/overview-world-geocoding-service.htm
* **Terms of Service**: http://www.esri.com/legal/software-license
* **Limitations**: ?
* **Notes**: You can specify which projection you want to use by setting, for example: `Geocoder.configure(:esri => {:outSR => 102100})`.
* **Limitations**: Requires API key if results will be stored. Using API key will also remove rate limit.
* **Notes**: You can specify which projection you want to use by setting, for example: `Geocoder.configure(:esri => {:outSR => 102100})`. If you will store results, set the flag and provide API key: `Geocoder.configure(:esri => {:api_key => ["client_id", "client_secret"], :for_storage => true})`
#### Mapzen (`:mapzen`)
......
......@@ -41,8 +41,29 @@ module Geocoder::Lookup
else
params[:text] = query.sanitized_text
end
params[:token] = token if configuration.api_key
params[:forStorage] = configuration.for_storage if configuration.for_storage
params.merge(super)
end
def token
unless token_is_valid
getToken = Net::HTTP.post_form URI('https://www.arcgis.com/sharing/rest/oauth2/token'),
f: 'json',
client_id: configuration.api_key[0],
client_secret: configuration.api_key[1],
grant_type: 'client_credentials',
expiration: 1440 # valid for one day,
@token = JSON.parse(getToken.body)['access_token']
@token_expires = Time.now + 1.day
end
return @token
end
def token_is_valid
@token && @token_expires > Time.now
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment