Convert an array of Postcode to an array of place info, include long, lat, and format address.
##Requirement
- ruby > 1.9, recommend > 2.0.0
- redis
##DEMO
- Demo page sgpostcode.herokuapp.com.
- Source code at https://github.com/duykhoa/sg_postcode_demo. Sample data is under the card ๐
I also create a docker version for the demo, it use Passenger Docker Image. Thanks you for saving my life ๐
##Install ๐
To install this gem, simply use gem install sg_postcode
or add this line
gem 'sg_postcode', '~> 1.2.6'
to the Gemfile, and run bundle install
. ๐
##Usage ๐
Follow this snippet
require 'sg_postcode'
postcode = ['238432', '234444']
SgPostcode::Array.new(postcodes).convert
There are some options:
response_type
: default is:json
host
: default:Google
cache
:true
orfalse
Actually right now, this gem only accept these default value ๐
####ADVANCE USAGES: ๐ก
- Key Path
To edit the response data's fields, you can take a look at lib/sg_postcode/response/config.rb
We use #dig
method, that is implement in this tutorial to get the value in the hash. So we call key_path
for the path of a key sequence.
Checkout this snippet for more information.
- Redis config
In default, Redis will use localhost
and port 6379
, if you want to customize, you can set the value for the environment variable REDIS_URL
.
For example:
ENV['REDIS_URL'] = 'redis://:[email protected]:6380/15'
Check out the redis
gem for more information.
The gem use Hash type to store the postcode request. The Hash key is defined in lib/sg_postcode/services/cache_adapter.rb
You can change it, just call SgPostcode::CacheAdapter.hashname = 'IamAwesomeStore'
##Contribute ๐
Feel free to fork it and send me PRs and Issues, comments to help it better. ๐
This project use Zenhub as a PM tool.
##Copyright ๐ฏ
This project rocks and uses MIT-LICENSE.