Ruby Library
The First Class Postcodes Ruby library provides convenient access to our API for applications written in the Ruby language. It includes a pre-defined set of classes for API operations and models that initialize themselves dynamically from API responses.
The library also provides other features. For example:
- Easy configuration path for fast setup and use.
- Built-in mechanisms for the serialization of parameters according to the expectations of our API.
Installation
You don't need this source code unless you want to modify the gem. If you just want to use the package, just run:
gem install first-class-postcodes
If you want to build the gem from source:
gem build first-class-postcodes.gemspec
Requirements
- Ruby >= 2.2.0.
Bundler
If you are installing via bundler, you should be sure to use the https rubygems source in your Gemfile, as any gems fetched over http could potentially be compromised in transit and alter the code of gems fetched securely over https:
source 'https://rubygems.org'
gem 'rails'
gem 'first-class-postcodes'
Install from Git
You can install directly from git, add the following into your Gemfile:
gem 'first-class-postcodes', :git => 'https://github.com/firstclasspostcodes/firstclasspostcodes-ruby.git'
Usage
The library needs to be configured with your API Key, which is available on the dashboard.
# Load the gem
require 'first-class-postcodes'
# Setup authorization
FCP.configure do |config|
# Configure API key authorization: Authorizer
config.api_key['X-Api-Key'] = 'YOUR API KEY'
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
#config.api_key_prefix['X-Api-Key'] = 'Bearer'
end
api_instance = FCP::DataApi.new
search = 'search_example' # String | The typeahead search query to return matching results for.
begin
#Typeahead Search
result = api_instance.get_typeahead(search)
p result
rescue FCP::ApiError => e
puts "Exception when calling DataApi->get_typeahead: #{e}"
end