-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from ideal-postcodes/uri_fix
- Loading branch information
Showing
46 changed files
with
3,005 additions
and
2,928 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: CI | ||
on: | ||
push: | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
ruby: | ||
- '2.5' | ||
- '2.6' | ||
- '2.7' | ||
- '3.0' | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: ${{ matrix.ruby }} | ||
bundler-cache: true | ||
- name: Run tests | ||
run: bundle exec rake |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
# Allows to reference by ideal_postcodes | ||
require 'idealpostcodes' | ||
require 'idealpostcodes' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
module IdealPostcodes | ||
module Address | ||
class SearchResult | ||
attr_reader :page, :limit, :addresses | ||
def initialize response | ||
@page = response[:result][:page] | ||
@limit = response[:result][:limit] | ||
@addresses = response[:result][:hits] | ||
end | ||
end | ||
module Address | ||
class SearchResult | ||
attr_reader :page, :limit, :addresses | ||
def initialize(response) | ||
@page = response[:result][:page] | ||
@limit = response[:result][:limit] | ||
@addresses = response[:result][:hits] | ||
end | ||
end | ||
|
||
def self.lookup udprn | ||
begin | ||
response = IdealPostcodes.request :get, "addresses/#{udprn}" | ||
address = response[:result] | ||
rescue IdealPostcodes::IdealPostcodesError => error | ||
raise error unless error.response_code == 4044 | ||
address = nil | ||
end | ||
address | ||
end | ||
def self.lookup(udprn) | ||
begin | ||
response = IdealPostcodes.request :get, "addresses/#{udprn}" | ||
address = response[:result] | ||
rescue IdealPostcodes::IdealPostcodesError => error | ||
raise error unless error.response_code == 4044 | ||
address = nil | ||
end | ||
address | ||
end | ||
|
||
def self.search search_term, options = {} | ||
query = { query: search_term } | ||
query[:limit] = options[:limit] unless options[:limit].nil? | ||
query[:page] = options[:page] unless options[:page].nil? | ||
response = IdealPostcodes.request :get, "addresses", query | ||
SearchResult.new response | ||
end | ||
end | ||
end | ||
def self.search(search_term, options = {}) | ||
query = { query: search_term } | ||
query[:limit] = options[:limit] unless options[:limit].nil? | ||
query[:page] = options[:page] unless options[:page].nil? | ||
response = IdealPostcodes.request :get, 'addresses', query | ||
SearchResult.new response | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,38 @@ | ||
module IdealPostcodes | ||
class IdealPostcodesError < StandardError | ||
attr_reader :message | ||
attr_reader :http_code | ||
attr_reader :http_body | ||
attr_reader :response_code | ||
class IdealPostcodesError < StandardError | ||
attr_reader :message | ||
attr_reader :http_code | ||
attr_reader :http_body | ||
attr_reader :response_code | ||
|
||
def initialize(message = nil, http_code = nil, http_body = nil, response_code = nil) | ||
@message = message | ||
@http_code = http_code | ||
@http_body = http_body | ||
@response_code = response_code | ||
end | ||
def initialize( | ||
message = nil, | ||
http_code = nil, | ||
http_body = nil, | ||
response_code = nil | ||
) | ||
@message = message | ||
@http_code = http_code | ||
@http_body = http_body | ||
@response_code = response_code | ||
end | ||
|
||
def to_s | ||
status = @http_code.nil? ? "" : "#{@http_code} error." | ||
ideal_code = @response_code.nil? ? "" : "(#{@response_code})" | ||
"#{status} error. (#{ideal_code}) #{message}" | ||
end | ||
end | ||
def to_s | ||
status = @http_code.nil? ? '' : "#{@http_code} error." | ||
ideal_code = @response_code.nil? ? '' : "(#{@response_code})" | ||
"#{status} error. (#{ideal_code}) #{message}" | ||
end | ||
end | ||
|
||
class AuthenticationError< IdealPostcodesError | ||
end | ||
class AuthenticationError < IdealPostcodesError | ||
end | ||
|
||
class TokenExhaustedError < IdealPostcodesError | ||
end | ||
class TokenExhaustedError < IdealPostcodesError | ||
end | ||
|
||
class LimitReachedError < IdealPostcodesError | ||
end | ||
class LimitReachedError < IdealPostcodesError | ||
end | ||
|
||
class ResourceNotFoundError < IdealPostcodesError | ||
end | ||
end | ||
class ResourceNotFoundError < IdealPostcodesError | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
module IdealPostcodes | ||
module Key | ||
def self.lookup api_key | ||
response = IdealPostcodes.request :get, "keys/#{api_key}" | ||
response[:result] | ||
end | ||
module Key | ||
def self.lookup(api_key) | ||
response = IdealPostcodes.request :get, "keys/#{api_key}" | ||
response[:result] | ||
end | ||
|
||
def self.lookup_details api_key, secret | ||
response = IdealPostcodes.request :get, "keys/#{api_key}", { user_token: secret } | ||
response[:result] | ||
end | ||
end | ||
end | ||
def self.lookup_details(api_key, secret) | ||
response = | ||
IdealPostcodes.request :get, "keys/#{api_key}", { user_token: secret } | ||
response[:result] | ||
end | ||
end | ||
end |
Oops, something went wrong.