Cccode
Country and Currency Code provides quick access to country and currency data via SOAP webservice provided by http://www.webservicex.net.
The data of all countries can be accessed directly via SOAP or be persisted and used via local database access.
Installation
Add this line to your application's Gemfile:
gem 'cccode'
And then execute:
$ bundle
Or install it yourself as:
$ gem install cccode
After the gem is installed you need to create the country_codes table via the gem`s generator:
$ rails g cccode:install
$ rake db:migrate
Usage
Enable usage by adding this to your class/ ruby file:
require 'Cccode'
Soap
This section explains how to call the web service via SOAP directly. For quick access via local db see next section 'Database'.
Get all countries as an array:
Cccode.get_countries
Get country code by country:
Cccode.get_country_code(<country name>)
Get currency by country:
Cccode.get_currency(<country name>)
Get currency code by currency:
Cccode.get_currency_code(<currency name>)
Note: all these actions DO NOT persist the data. To achieve that see 'Database' section!
Database
To get all available data at once and fill the database (reset is executed upfront):
Cccode.get_all
Reset (truncate) conutry_codes table:
Cccode.reset
Check if data exists:
Cccode::CountryCode.exists?
Get all data for a country:
data = Cccode::Codes.new(<country name>)
Example: data = Cccode::Codes.new('Germany') returns:
data.country = 'Germany'
data.country_code = 'de'
data.currency = 'Mark'
data.currency_code = 'DEM'
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/cherrystoned/cccode.
License
The gem is available as open source under the terms of the MIT License.