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,3 @@
1
+ module FCP
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,46 @@
1
+ =begin
2
+ #First Class Postcodes
3
+
4
+ #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.
5
+
6
+ The version of the OpenAPI document: 0.0.1
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 4.0.0
10
+
11
+ =end
12
+
13
+ require 'spec_helper'
14
+ require 'json'
15
+
16
+ # Unit tests for FCP::APIApi
17
+ # Automatically generated by openapi-generator (https://openapi-generator.tech)
18
+ # Please update as you see appropriate
19
+ describe 'APIApi' do
20
+ before do
21
+ # run before each test
22
+ @api_instance = FCP::APIApi.new
23
+ end
24
+
25
+ after do
26
+ # run after each test
27
+ end
28
+
29
+ describe 'test an instance of APIApi' do
30
+ it 'should create an instance of APIApi' do
31
+ expect(@api_instance).to be_instance_of(FCP::APIApi)
32
+ end
33
+ end
34
+
35
+ # unit tests for get_specification
36
+ # OpenAPI Specification
37
+ # Retrieve the OpenAPI Specification for this base path.
38
+ # @param [Hash] opts the optional parameters
39
+ # @return [Object]
40
+ describe 'get_specification test' do
41
+ it 'should work' do
42
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+ require 'json'
3
+
4
+ describe 'DataApi' do
5
+
6
+ let(:instance) { FCP::DataApi.new }
7
+
8
+ specify { expect(instance).to be_instance_of(FCP::DataApi) }
9
+
10
+ # tests for #get_lookup
11
+ # Geo Lookup
12
+ #
13
+ # 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).
14
+ #
15
+ # Test positions are based upon data here:
16
+ #
17
+ # https://github.com/firstclasspostcodes/firstclasspostcodes-mock/blob/master/DATA.md
18
+ #
19
+ # @param latitude The latitude for the query
20
+ # @param longitude The latitude for the query
21
+ # @param [Hash] opts the optional parameters
22
+ # @option opts [Float] :radius The radius, in kilometers.
23
+ # @return [Array<Point>]
24
+ describe '#get_lookup' do
25
+ [%w(51.469275 -0.266110), %w(51.469284 -0.266096)].each do |position|
26
+ specify { expect(instance.get_lookup(*position)).to all(be_instance_of(FCP::Point)) }
27
+ end
28
+
29
+ describe 'when an unsupported position' do
30
+ specify { expect(instance.get_lookup(51.90026, 2.62673)).to be_nil }
31
+ end
32
+ end
33
+
34
+ # tests for #get_postcode
35
+ # Postcode Lookup
36
+ #
37
+ # Retrieves street numbers, address and location information for a specific postcode provided in the search query parameter.
38
+ #
39
+ # Test postcodes are based upon data here:
40
+ #
41
+ # https://github.com/firstclasspostcodes/firstclasspostcodes-mock/blob/master/DATA.md
42
+ #
43
+ # @param search The postcode to retrieve address information for.
44
+ # @param [Hash] opts the optional parameters
45
+ # @return [Address]
46
+ describe '#get_postcode' do
47
+ ['TW9 1XW', 'tw91xw', 'tw9 1xw'].each do |postcode|
48
+ describe "Response when '?search=#{postcode}'" do
49
+ specify { expect(instance.get_postcode(postcode)).to be_instance_of(FCP::Address) }
50
+ end
51
+ end
52
+
53
+ describe 'with an unsupported postcode' do
54
+ specify { expect(instance.get_postcode('XX43 FGH')).to be_nil }
55
+ end
56
+ end
57
+
58
+ # tests for #get_typeahead
59
+ # Typeahead Search
60
+ #
61
+ # Performs a typeahead search for an address, allowing the user to enter their address naturally.
62
+ #
63
+ # @param search The typeahead search query to return matching results for.
64
+ # @param [Hash] opts the optional parameters
65
+ # @return [Array<Typeahead>]
66
+ describe '#get_typeahead' do
67
+ ['fl', 'fla', 'flat', '1', '13', '25'].each do |search|
68
+ describe "Response when '?search=#{search}'" do
69
+ specify { expect(instance.get_typeahead(search)).to all(be_instance_of(FCP::Typeahead)) }
70
+ end
71
+ end
72
+ end
73
+
74
+ end
@@ -0,0 +1,214 @@
1
+ require 'spec_helper'
2
+
3
+ describe FCP::ApiClient do
4
+ context 'initialization' do
5
+ context 'URL stuff' do
6
+ context 'host' do
7
+ it 'removes http from host' do
8
+ FCP.configure { |c| c.host = 'http://example.com' }
9
+ expect(FCP::Configuration.default.host).to eq('example.com')
10
+ end
11
+
12
+ it 'removes https from host' do
13
+ FCP.configure { |c| c.host = 'https://wookiee.com' }
14
+ expect(FCP::ApiClient.default.config.host).to eq('wookiee.com')
15
+ end
16
+
17
+ it 'removes trailing path from host' do
18
+ FCP.configure { |c| c.host = 'hobo.com/v4' }
19
+ expect(FCP::Configuration.default.host).to eq('hobo.com')
20
+ end
21
+ end
22
+
23
+ context 'base_path' do
24
+ it "prepends a slash to base_path" do
25
+ FCP.configure { |c| c.base_path = 'v4/dog' }
26
+ expect(FCP::Configuration.default.base_path).to eq('/v4/dog')
27
+ end
28
+
29
+ it "doesn't prepend a slash if one is already there" do
30
+ FCP.configure { |c| c.base_path = '/v4/dog' }
31
+ expect(FCP::Configuration.default.base_path).to eq('/v4/dog')
32
+ end
33
+
34
+ it "ends up as a blank string if nil" do
35
+ FCP.configure { |c| c.base_path = nil }
36
+ expect(FCP::Configuration.default.base_path).to eq('')
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ describe 'params_encoding in #build_request' do
43
+ let(:config) { FCP::Configuration.new }
44
+ let(:api_client) { FCP::ApiClient.new(config) }
45
+
46
+ it 'defaults to nil' do
47
+ expect(FCP::Configuration.default.params_encoding).to eq(nil)
48
+ expect(config.params_encoding).to eq(nil)
49
+
50
+ request = api_client.build_request(:get, '/test')
51
+ expect(request.options[:params_encoding]).to eq(nil)
52
+ end
53
+
54
+ it 'can be customized' do
55
+ config.params_encoding = :multi
56
+ request = api_client.build_request(:get, '/test')
57
+ expect(request.options[:params_encoding]).to eq(:multi)
58
+ end
59
+ end
60
+
61
+ describe 'timeout in #build_request' do
62
+ let(:config) { FCP::Configuration.new }
63
+ let(:api_client) { FCP::ApiClient.new(config) }
64
+
65
+ it 'defaults to 0' do
66
+ expect(FCP::Configuration.default.timeout).to eq(0)
67
+ expect(config.timeout).to eq(0)
68
+
69
+ request = api_client.build_request(:get, '/test')
70
+ expect(request.options[:timeout]).to eq(0)
71
+ end
72
+
73
+ it 'can be customized' do
74
+ config.timeout = 100
75
+ request = api_client.build_request(:get, '/test')
76
+ expect(request.options[:timeout]).to eq(100)
77
+ end
78
+ end
79
+
80
+ describe '#deserialize' do
81
+ it "handles Array<Integer>" do
82
+ api_client = FCP::ApiClient.new
83
+ headers = { 'Content-Type' => 'application/json' }
84
+ response = double('response', headers: headers, body: '[12, 34]')
85
+ data = api_client.deserialize(response, 'Array<Integer>')
86
+ expect(data).to be_instance_of(Array)
87
+ expect(data).to eq([12, 34])
88
+ end
89
+
90
+ it 'handles Array<Array<Integer>>' do
91
+ api_client = FCP::ApiClient.new
92
+ headers = { 'Content-Type' => 'application/json' }
93
+ response = double('response', headers: headers, body: '[[12, 34], [56]]')
94
+ data = api_client.deserialize(response, 'Array<Array<Integer>>')
95
+ expect(data).to be_instance_of(Array)
96
+ expect(data).to eq([[12, 34], [56]])
97
+ end
98
+
99
+ it 'handles Hash<String, String>' do
100
+ api_client = FCP::ApiClient.new
101
+ headers = { 'Content-Type' => 'application/json' }
102
+ response = double('response', headers: headers, body: '{"message": "Hello"}')
103
+ data = api_client.deserialize(response, 'Hash<String, String>')
104
+ expect(data).to be_instance_of(Hash)
105
+ expect(data).to eq(:message => 'Hello')
106
+ end
107
+ end
108
+
109
+ describe "#object_to_hash" do
110
+ it 'ignores nils and includes empty arrays' do
111
+ # uncomment below to test object_to_hash for model
112
+ # api_client = FCP::ApiClient.new
113
+ # _model = FCP::ModelName.new
114
+ # update the model attribute below
115
+ # _model.id = 1
116
+ # update the expected value (hash) below
117
+ # expected = {id: 1, name: '', tags: []}
118
+ # expect(api_client.object_to_hash(_model)).to eq(expected)
119
+ end
120
+ end
121
+
122
+ describe '#build_collection_param' do
123
+ let(:param) { ['aa', 'bb', 'cc'] }
124
+ let(:api_client) { FCP::ApiClient.new }
125
+
126
+ it 'works for csv' do
127
+ expect(api_client.build_collection_param(param, :csv)).to eq('aa,bb,cc')
128
+ end
129
+
130
+ it 'works for ssv' do
131
+ expect(api_client.build_collection_param(param, :ssv)).to eq('aa bb cc')
132
+ end
133
+
134
+ it 'works for tsv' do
135
+ expect(api_client.build_collection_param(param, :tsv)).to eq("aa\tbb\tcc")
136
+ end
137
+
138
+ it 'works for pipes' do
139
+ expect(api_client.build_collection_param(param, :pipes)).to eq('aa|bb|cc')
140
+ end
141
+
142
+ it 'works for multi' do
143
+ expect(api_client.build_collection_param(param, :multi)).to eq(['aa', 'bb', 'cc'])
144
+ end
145
+
146
+ it 'fails for invalid collection format' do
147
+ expect(proc { api_client.build_collection_param(param, :INVALID) }).to raise_error(RuntimeError, 'unknown collection format: :INVALID')
148
+ end
149
+ end
150
+
151
+ describe '#json_mime?' do
152
+ let(:api_client) { FCP::ApiClient.new }
153
+
154
+ it 'works' do
155
+ expect(api_client.json_mime?(nil)).to eq false
156
+ expect(api_client.json_mime?('')).to eq false
157
+
158
+ expect(api_client.json_mime?('application/json')).to eq true
159
+ expect(api_client.json_mime?('application/json; charset=UTF8')).to eq true
160
+ expect(api_client.json_mime?('APPLICATION/JSON')).to eq true
161
+
162
+ expect(api_client.json_mime?('application/xml')).to eq false
163
+ expect(api_client.json_mime?('text/plain')).to eq false
164
+ expect(api_client.json_mime?('application/jsonp')).to eq false
165
+ end
166
+ end
167
+
168
+ describe '#select_header_accept' do
169
+ let(:api_client) { FCP::ApiClient.new }
170
+
171
+ it 'works' do
172
+ expect(api_client.select_header_accept(nil)).to be_nil
173
+ expect(api_client.select_header_accept([])).to be_nil
174
+
175
+ expect(api_client.select_header_accept(['application/json'])).to eq('application/json')
176
+ expect(api_client.select_header_accept(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8')
177
+ expect(api_client.select_header_accept(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON')
178
+
179
+ expect(api_client.select_header_accept(['application/xml'])).to eq('application/xml')
180
+ expect(api_client.select_header_accept(['text/html', 'application/xml'])).to eq('text/html,application/xml')
181
+ end
182
+ end
183
+
184
+ describe '#select_header_content_type' do
185
+ let(:api_client) { FCP::ApiClient.new }
186
+
187
+ it 'works' do
188
+ expect(api_client.select_header_content_type(nil)).to eq('application/json')
189
+ expect(api_client.select_header_content_type([])).to eq('application/json')
190
+
191
+ expect(api_client.select_header_content_type(['application/json'])).to eq('application/json')
192
+ expect(api_client.select_header_content_type(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8')
193
+ expect(api_client.select_header_content_type(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON')
194
+ expect(api_client.select_header_content_type(['application/xml'])).to eq('application/xml')
195
+ expect(api_client.select_header_content_type(['text/plain', 'application/xml'])).to eq('text/plain')
196
+ end
197
+ end
198
+
199
+ describe '#sanitize_filename' do
200
+ let(:api_client) { FCP::ApiClient.new }
201
+
202
+ it 'works' do
203
+ expect(api_client.sanitize_filename('sun')).to eq('sun')
204
+ expect(api_client.sanitize_filename('sun.gif')).to eq('sun.gif')
205
+ expect(api_client.sanitize_filename('../sun.gif')).to eq('sun.gif')
206
+ expect(api_client.sanitize_filename('/var/tmp/sun.gif')).to eq('sun.gif')
207
+ expect(api_client.sanitize_filename('./sun.gif')).to eq('sun.gif')
208
+ expect(api_client.sanitize_filename('..\sun.gif')).to eq('sun.gif')
209
+ expect(api_client.sanitize_filename('\var\tmp\sun.gif')).to eq('sun.gif')
210
+ expect(api_client.sanitize_filename('c:\var\tmp\sun.gif')).to eq('sun.gif')
211
+ expect(api_client.sanitize_filename('.\sun.gif')).to eq('sun.gif')
212
+ end
213
+ end
214
+ end
@@ -0,0 +1,28 @@
1
+ require 'uri'
2
+ require 'spec_helper'
3
+
4
+ describe FCP::Configuration do
5
+ let(:config) { FCP::Configuration.default }
6
+
7
+ before(:each) do
8
+ uri = URI.parse("https://api.firstclasspostcodes.com/data")
9
+ FCP.configure do |c|
10
+ c.scheme = 'https'
11
+ c.host = uri.host
12
+ c.base_path = uri.path
13
+ end
14
+ end
15
+
16
+ describe '#base_url' do
17
+ it 'should have the default value' do
18
+ expect(config.base_url).to eq("https://api.firstclasspostcodes.com/data")
19
+ end
20
+
21
+ it 'should remove trailing slashes' do
22
+ [nil, '', '/', '//'].each do |base_path|
23
+ config.base_path = base_path
24
+ expect(config.base_url).to eq("https://api.firstclasspostcodes.com")
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+ require 'json'
3
+ require 'date'
4
+
5
+ # Unit tests for FCP::Address
6
+ # Automatically generated by openapi-generator (https://openapi-generator.tech)
7
+ # Please update as you see appropriate
8
+ describe 'Address' do
9
+ before do
10
+ # run before each test
11
+ @instance = FCP::Address.new
12
+ end
13
+
14
+ after do
15
+ # run after each test
16
+ end
17
+
18
+ describe 'test an instance of Address' do
19
+ it 'should create an instance of Address' do
20
+ expect(@instance).to be_instance_of(FCP::Address)
21
+ end
22
+ end
23
+ describe 'test attribute "street"' do
24
+ it 'should work' do
25
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
26
+ end
27
+ end
28
+
29
+ describe 'test attribute "numbers"' do
30
+ it 'should work' do
31
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
32
+ end
33
+ end
34
+
35
+ describe 'test attribute "city"' do
36
+ it 'should work' do
37
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
38
+ end
39
+ end
40
+
41
+ describe 'test attribute "district"' do
42
+ it 'should work' do
43
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
44
+ end
45
+ end
46
+
47
+ describe 'test attribute "county"' do
48
+ it 'should work' do
49
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
50
+ end
51
+ end
52
+
53
+ describe 'test attribute "postcode"' do
54
+ it 'should work' do
55
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
56
+ end
57
+ end
58
+
59
+ describe 'test attribute "country"' do
60
+ it 'should work' do
61
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
62
+ end
63
+ end
64
+
65
+ describe 'test attribute "position"' do
66
+ it 'should work' do
67
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
68
+ end
69
+ end
70
+
71
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+ require 'json'
3
+ require 'date'
4
+
5
+ # Unit tests for FCP::ErrorRawGateway
6
+ # Automatically generated by openapi-generator (https://openapi-generator.tech)
7
+ # Please update as you see appropriate
8
+ describe 'ErrorRawGateway' do
9
+ before do
10
+ # run before each test
11
+ @instance = FCP::ErrorRawGateway.new
12
+ end
13
+
14
+ after do
15
+ # run after each test
16
+ end
17
+
18
+ describe 'test an instance of ErrorRawGateway' do
19
+ it 'should create an instance of ErrorRawGateway' do
20
+ expect(@instance).to be_instance_of(FCP::ErrorRawGateway)
21
+ end
22
+ end
23
+ describe 'test attribute "type"' do
24
+ it 'should work' do
25
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
26
+ end
27
+ end
28
+
29
+ describe 'test attribute "message"' do
30
+ it 'should work' do
31
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
32
+ end
33
+ end
34
+
35
+ end