first-class-postcodes 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a257d70ae0068268d9d809c0d7f5b081f87e53b146fd88cb2d50fd4692900a17
4
+ data.tar.gz: 25ca587f6d434487f153dfb227b0257c467f3822b4c0fbeba44555e584abd9b7
5
+ SHA512:
6
+ metadata.gz: 61029c51b6fa02d41cbbeea9737676f9a7c55e31cbbc3316d794a914c8af547c26e134012b0896cc5e1ddf163c643158831fa44011d42a26a0656d75db6f5f02
7
+ data.tar.gz: 5f419ae72b6ac43f29b0546a8ac59a6c807d964769276428c8774479f89e5aa5d9682152255785117cd39e9f39ce92afdf10024f2337ddb760ca3aa3b1b06915
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development, :test do
6
+ gem "coveralls", require: false
7
+ gem "rake", "~> 12.3.2"
8
+ gem "pry-byebug"
9
+ gem "rubocop", "~> 0.68.1"
10
+ gem "codecov", :require => false
11
+ end
@@ -0,0 +1,74 @@
1
+ # Ruby Library
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/first-class-postcodes.svg)](https://badge.fury.io/rb/first-class-postcodes) [![Build Status](https://travis-ci.org/firstclasspostcodes/firstclasspostcodes-ruby.svg?branch=master)](https://travis-ci.org/firstclasspostcodes/firstclasspostcodes-ruby) [![codecov](https://codecov.io/gh/firstclasspostcodes/firstclasspostcodes-ruby/branch/master/graph/badge.svg)](https://codecov.io/gh/firstclasspostcodes/firstclasspostcodes-ruby)
4
+
5
+ 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.
6
+
7
+ The library also provides other features. For example:
8
+
9
+ * Easy configuration path for fast setup and use.
10
+ * Built-in mechanisms for the serialization of parameters according to the expectations of our API.
11
+
12
+
13
+ ## Installation
14
+
15
+ You don't need this source code unless you want to modify the gem. If you just
16
+ want to use the package, just run:
17
+
18
+ gem install first-class-postcodes
19
+
20
+ If you want to build the gem from source:
21
+
22
+ gem build first-class-postcodes.gemspec
23
+
24
+ ### Requirements
25
+
26
+ * Ruby >= 2.2.0.
27
+
28
+ ### Bundler
29
+
30
+ 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:
31
+
32
+ ``` ruby
33
+ source 'https://rubygems.org'
34
+
35
+ gem 'rails'
36
+ gem 'first-class-postcodes'
37
+ ```
38
+
39
+ ### Install from Git
40
+
41
+ You can install directly from git, add the following into your Gemfile:
42
+
43
+ ```ruby
44
+ gem 'first-class-postcodes', :git => 'https://github.com/firstclasspostcodes/firstclasspostcodes-ruby.git'
45
+ ```
46
+
47
+ ## Usage
48
+
49
+ The library needs to be configured with your API Key, which is available on the [dashboard](https://dashboard.firstclasspostcodes.com).
50
+
51
+ ```ruby
52
+ # Load the gem
53
+ require 'first-class-postcodes'
54
+
55
+ # Setup authorization
56
+ FCP.configure do |config|
57
+ # Configure API key authorization: Authorizer
58
+ config.api_key['X-Api-Key'] = 'YOUR API KEY'
59
+ # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
60
+ #config.api_key_prefix['X-Api-Key'] = 'Bearer'
61
+ end
62
+
63
+ api_instance = FCP::DataApi.new
64
+ search = 'search_example' # String | The typeahead search query to return matching results for.
65
+
66
+ begin
67
+ #Typeahead Search
68
+ result = api_instance.get_typeahead(search)
69
+ p result
70
+ rescue FCP::ApiError => e
71
+ puts "Exception when calling DataApi->get_typeahead: #{e}"
72
+ end
73
+
74
+ ```
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rubocop/rake_task"
3
+ require "rspec/core/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ RuboCop::RakeTask.new
8
+
9
+ task default: %i[spec rubocop]
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ $:.push File.expand_path("../lib", __FILE__)
4
+ require "first-class-postcodes/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "first-class-postcodes"
8
+ s.version = FCP::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ["First Class Postcodes"]
11
+ s.email = ["support+api+ruby@firstclasspostcodes.com"]
12
+ s.homepage = "https://docs.firstclasspostcodes.com/clients/ruby"
13
+ s.summary = "First Class Postcodes Ruby API Client"
14
+ s.description = "Use this API to retrieve address information for UK postcodes. You can request by postcode, filter by geolocation and provide autocomplete suggestions using natural address entry. "
15
+ s.license = "MIT"
16
+ s.required_ruby_version = ">= 2.2.0"
17
+
18
+ s.add_runtime_dependency 'typhoeus', '~> 1.3', '>= 1.3.1'
19
+ s.add_runtime_dependency 'json', '~> 2.2', '>= 2.2.0'
20
+
21
+ s.add_development_dependency 'rspec', '~> 3.6', '>= 3.6.0'
22
+ s.add_development_dependency 'vcr', '~> 3.0', '>= 3.0.1'
23
+ s.add_development_dependency 'webmock', '~> 1.24', '>= 1.24.3'
24
+ s.add_development_dependency 'autotest', '~> 4.4', '>= 4.4.6'
25
+ s.add_development_dependency 'autotest-rails-pure', '~> 4.1', '>= 4.1.2'
26
+ s.add_development_dependency 'autotest-growl', '~> 0.2', '>= 0.2.16'
27
+ s.add_development_dependency 'autotest-fsevent', '~> 0.2', '>= 0.2.12'
28
+
29
+ s.files = `find *`.split("\n").uniq.sort.select { |f| !f.empty? }
30
+ s.test_files = `find spec/*`.split("\n")
31
+ s.executables = []
32
+ s.require_paths = ["lib"]
33
+ end
@@ -0,0 +1,36 @@
1
+ # Common files
2
+ require 'first-class-postcodes/api_client'
3
+ require 'first-class-postcodes/api_error'
4
+ require 'first-class-postcodes/version'
5
+ require 'first-class-postcodes/configuration'
6
+
7
+ # Models
8
+ require 'first-class-postcodes/models/address'
9
+ require 'first-class-postcodes/models/error'
10
+ require 'first-class-postcodes/models/error_raw'
11
+ require 'first-class-postcodes/models/error_raw_gateway'
12
+ require 'first-class-postcodes/models/point'
13
+ require 'first-class-postcodes/models/position'
14
+ require 'first-class-postcodes/models/typeahead'
15
+
16
+ # APIs
17
+ require 'first-class-postcodes/api/api_api'
18
+ require 'first-class-postcodes/api/data_api'
19
+
20
+ module FCP
21
+ class << self
22
+ # Customize default settings for the SDK using block.
23
+ # FCP.configure do |config|
24
+ # config.username = "xxx"
25
+ # config.password = "xxx"
26
+ # end
27
+ # If no block given, return the default Configuration object.
28
+ def configure
29
+ if block_given?
30
+ yield(Configuration.default)
31
+ else
32
+ Configuration.default
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,66 @@
1
+ require 'cgi'
2
+
3
+ module FCP
4
+ class APIApi
5
+ attr_accessor :api_client
6
+
7
+ def initialize(api_client = ApiClient.default)
8
+ @api_client = api_client
9
+ end
10
+ # OpenAPI Specification
11
+ # Retrieve the OpenAPI Specification for this base path.
12
+ # @param [Hash] opts the optional parameters
13
+ # @return [Object]
14
+ def get_specification(opts = {})
15
+ data, _status_code, _headers = get_specification_with_http_info(opts)
16
+ data
17
+ end
18
+
19
+ # OpenAPI Specification
20
+ # Retrieve the OpenAPI Specification for this base path.
21
+ # @param [Hash] opts the optional parameters
22
+ # @return [Array<(Object, Integer, Hash)>] Object data, response status code and response headers
23
+ def get_specification_with_http_info(opts = {})
24
+ if @api_client.config.debugging
25
+ @api_client.config.logger.debug 'Calling API: APIApi.get_specification ...'
26
+ end
27
+ # resource path
28
+ local_var_path = '/.spec'
29
+
30
+ # query parameters
31
+ query_params = opts[:query_params] || {}
32
+
33
+ # header parameters
34
+ header_params = opts[:header_params] || {}
35
+ # HTTP header 'Accept' (if needed)
36
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
37
+
38
+ # form parameters
39
+ form_params = opts[:form_params] || {}
40
+
41
+ # http body (model)
42
+ post_body = opts[:body]
43
+
44
+ # return_type
45
+ return_type = opts[:return_type] || 'Object'
46
+
47
+ # auth_names
48
+ auth_names = opts[:auth_names] || []
49
+
50
+ new_options = opts.merge(
51
+ :header_params => header_params,
52
+ :query_params => query_params,
53
+ :form_params => form_params,
54
+ :body => post_body,
55
+ :auth_names => auth_names,
56
+ :return_type => return_type
57
+ )
58
+
59
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
60
+ if @api_client.config.debugging
61
+ @api_client.config.logger.debug "API called: APIApi#get_specification\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
62
+ end
63
+ return data, status_code, headers
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,217 @@
1
+ require 'cgi'
2
+
3
+ module FCP
4
+ class DataApi
5
+ attr_accessor :api_client
6
+
7
+ def initialize(api_client = ApiClient.default)
8
+ @api_client = api_client
9
+ end
10
+ # Geo Lookup
11
+ # Takes a valid latitude, longitude and radius (in km) and returns all matching postcodes within that area. This operation does not return full addresses (which must be queried for separately).
12
+ # @param latitude [Float] The latitude for the query
13
+ # @param longitude [Float] The latitude for the query
14
+ # @param [Hash] opts the optional parameters
15
+ # @option opts [Float] :radius The radius, in kilometers. (default to 1.0)
16
+ # @return [Array<Point>]
17
+ def get_lookup(latitude, longitude, opts = {})
18
+ data, _status_code, _headers = get_lookup_with_http_info(latitude, longitude, opts)
19
+ data
20
+ end
21
+
22
+ # Geo Lookup
23
+ # Takes a valid latitude, longitude and radius (in km) and returns all matching postcodes within that area. This operation does not return full addresses (which must be queried for separately).
24
+ # @param latitude [Float] The latitude for the query
25
+ # @param longitude [Float] The latitude for the query
26
+ # @param [Hash] opts the optional parameters
27
+ # @option opts [Float] :radius The radius, in kilometers.
28
+ # @return [Array<(Array<Point>, Integer, Hash)>] Array<Point> data, response status code and response headers
29
+ def get_lookup_with_http_info(latitude, longitude, opts = {})
30
+ if @api_client.config.debugging
31
+ @api_client.config.logger.debug 'Calling API: DataApi.get_lookup ...'
32
+ end
33
+ # verify the required parameter 'latitude' is set
34
+ if @api_client.config.client_side_validation && latitude.nil?
35
+ fail ArgumentError, "Missing the required parameter 'latitude' when calling DataApi.get_lookup"
36
+ end
37
+ # verify the required parameter 'longitude' is set
38
+ if @api_client.config.client_side_validation && longitude.nil?
39
+ fail ArgumentError, "Missing the required parameter 'longitude' when calling DataApi.get_lookup"
40
+ end
41
+ if @api_client.config.client_side_validation && !opts[:'radius'].nil? && opts[:'radius'] > 5
42
+ fail ArgumentError, 'invalid value for "opts[:"radius"]" when calling DataApi.get_lookup, must be smaller than or equal to 5.'
43
+ end
44
+
45
+ if @api_client.config.client_side_validation && !opts[:'radius'].nil? && opts[:'radius'] < 0
46
+ fail ArgumentError, 'invalid value for "opts[:"radius"]" when calling DataApi.get_lookup, must be greater than or equal to 0.'
47
+ end
48
+
49
+ # resource path
50
+ local_var_path = '/lookup'
51
+
52
+ # query parameters
53
+ query_params = opts[:query_params] || {}
54
+ query_params[:'latitude'] = latitude
55
+ query_params[:'longitude'] = longitude
56
+ query_params[:'radius'] = opts[:'radius'] if !opts[:'radius'].nil?
57
+
58
+ # header parameters
59
+ header_params = opts[:header_params] || {}
60
+ # HTTP header 'Accept' (if needed)
61
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
62
+
63
+ # form parameters
64
+ form_params = opts[:form_params] || {}
65
+
66
+ # http body (model)
67
+ post_body = opts[:body]
68
+
69
+ # return_type
70
+ return_type = opts[:return_type] || 'Array<Point>'
71
+
72
+ # auth_names
73
+ auth_names = opts[:auth_names] || ['Authorizer']
74
+
75
+ new_options = opts.merge(
76
+ :header_params => header_params,
77
+ :query_params => query_params,
78
+ :form_params => form_params,
79
+ :body => post_body,
80
+ :auth_names => auth_names,
81
+ :return_type => return_type
82
+ )
83
+
84
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
85
+ if @api_client.config.debugging
86
+ @api_client.config.logger.debug "API called: DataApi#get_lookup\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
87
+ end
88
+ return data, status_code, headers
89
+ end
90
+
91
+ # Postcode Lookup
92
+ # Retrieves street numbers, address and location information for a specific postcode provided in the search query parameter.
93
+ # @param search [String] The postcode to retrieve address information for.
94
+ # @param [Hash] opts the optional parameters
95
+ # @return [Address]
96
+ def get_postcode(search, opts = {})
97
+ data, _status_code, _headers = get_postcode_with_http_info(search, opts)
98
+ data
99
+ end
100
+
101
+ # Postcode Lookup
102
+ # Retrieves street numbers, address and location information for a specific postcode provided in the search query parameter.
103
+ # @param search [String] The postcode to retrieve address information for.
104
+ # @param [Hash] opts the optional parameters
105
+ # @return [Array<(Address, Integer, Hash)>] Address data, response status code and response headers
106
+ def get_postcode_with_http_info(search, opts = {})
107
+ if @api_client.config.debugging
108
+ @api_client.config.logger.debug 'Calling API: DataApi.get_postcode ...'
109
+ end
110
+ # verify the required parameter 'search' is set
111
+ if @api_client.config.client_side_validation && search.nil?
112
+ fail ArgumentError, "Missing the required parameter 'search' when calling DataApi.get_postcode"
113
+ end
114
+ # resource path
115
+ local_var_path = '/postcode'
116
+
117
+ # query parameters
118
+ query_params = opts[:query_params] || {}
119
+ query_params[:'search'] = search
120
+
121
+ # header parameters
122
+ header_params = opts[:header_params] || {}
123
+ # HTTP header 'Accept' (if needed)
124
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
125
+
126
+ # form parameters
127
+ form_params = opts[:form_params] || {}
128
+
129
+ # http body (model)
130
+ post_body = opts[:body]
131
+
132
+ # return_type
133
+ return_type = opts[:return_type] || 'Address'
134
+
135
+ # auth_names
136
+ auth_names = opts[:auth_names] || ['Authorizer']
137
+
138
+ new_options = opts.merge(
139
+ :header_params => header_params,
140
+ :query_params => query_params,
141
+ :form_params => form_params,
142
+ :body => post_body,
143
+ :auth_names => auth_names,
144
+ :return_type => return_type
145
+ )
146
+
147
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
148
+ if @api_client.config.debugging
149
+ @api_client.config.logger.debug "API called: DataApi#get_postcode\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
150
+ end
151
+ return data, status_code, headers
152
+ end
153
+
154
+ # Typeahead Search
155
+ # Performs a typeahead search for an address, allowing the user to enter their address naturally.
156
+ # @param search [String] The typeahead search query to return matching results for.
157
+ # @param [Hash] opts the optional parameters
158
+ # @return [Array<Typeahead>]
159
+ def get_typeahead(search, opts = {})
160
+ data, _status_code, _headers = get_typeahead_with_http_info(search, opts)
161
+ data
162
+ end
163
+
164
+ # Typeahead Search
165
+ # Performs a typeahead search for an address, allowing the user to enter their address naturally.
166
+ # @param search [String] The typeahead search query to return matching results for.
167
+ # @param [Hash] opts the optional parameters
168
+ # @return [Array<(Array<Typeahead>, Integer, Hash)>] Array<Typeahead> data, response status code and response headers
169
+ def get_typeahead_with_http_info(search, opts = {})
170
+ if @api_client.config.debugging
171
+ @api_client.config.logger.debug 'Calling API: DataApi.get_typeahead ...'
172
+ end
173
+ # verify the required parameter 'search' is set
174
+ if @api_client.config.client_side_validation && search.nil?
175
+ fail ArgumentError, "Missing the required parameter 'search' when calling DataApi.get_typeahead"
176
+ end
177
+ # resource path
178
+ local_var_path = '/typeahead'
179
+
180
+ # query parameters
181
+ query_params = opts[:query_params] || {}
182
+ query_params[:'search'] = search
183
+
184
+ # header parameters
185
+ header_params = opts[:header_params] || {}
186
+ # HTTP header 'Accept' (if needed)
187
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
188
+
189
+ # form parameters
190
+ form_params = opts[:form_params] || {}
191
+
192
+ # http body (model)
193
+ post_body = opts[:body]
194
+
195
+ # return_type
196
+ return_type = opts[:return_type] || 'Array<Typeahead>'
197
+
198
+ # auth_names
199
+ auth_names = opts[:auth_names] || ['Authorizer']
200
+
201
+ new_options = opts.merge(
202
+ :header_params => header_params,
203
+ :query_params => query_params,
204
+ :form_params => form_params,
205
+ :body => post_body,
206
+ :auth_names => auth_names,
207
+ :return_type => return_type
208
+ )
209
+
210
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
211
+ if @api_client.config.debugging
212
+ @api_client.config.logger.debug "API called: DataApi#get_typeahead\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
213
+ end
214
+ return data, status_code, headers
215
+ end
216
+ end
217
+ end