Jack S
2 years ago
15 changed files with 184 additions and 1 deletions
@ -0,0 +1,34 @@
|
||||
# Question: Which OS product can we use to do our address to UPRN lookup? |
||||
|
||||
- #UPRN: to check if provided UPRN exists |
||||
|
||||
API DOCS: https://osdatahub.os.uk/docs/places/technicalSpecification |
||||
|
||||
- #Find: freetext to search results containing UPRNs |
||||
https://api.os.uk/search/places/v1/find?query=Ordnance%20Survey%2C%20Adanac%20Drive%2C%20SO16&key= |
||||
|
||||
|
||||
# Question: Can we do API lookups? Are there any limitations on the product (API requests etc.) |
||||
|
||||
- Can't see any sort of limitation for our account: "As a member of the PSGA you are entitled to free Public Sector data transactions" |
||||
https://osdatahub.os.uk/dashboard |
||||
|
||||
|
||||
|
||||
# Additional QQ and notes: |
||||
- when searching UPRN from address there are usually multiple results and match accuracy isn't provided. Do we want users to pick the matching address or should we just pick the first match? |
||||
- could not find a free OS ruby client for the API that I would recommend using. Best option is this but seems to be relying on a private repository https://github.com/DEFRA/defra-ruby-address/ |
||||
- Auth strategy, there's 3 of them HTTP Header / Query String / OAuth2. |
||||
|
||||
|
||||
Flows that need to be handled: |
||||
- UPRN check: |
||||
- API is down / not responding |
||||
- UPRN is invalid |
||||
- UPRN is valid |
||||
- UPRN retrieval via address: |
||||
- API is down / not responding |
||||
- Address is valid but no UPRN found |
||||
- Address is valid and UPRN found |
||||
- Address is valid but multiple UPRNs found |
||||
- Address is not found and multiple UPRNs found |
@ -0,0 +1,16 @@
|
||||
class Form::Lettings::Pages::Uprn < ::Form::Page |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@id = "uprn" |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Lettings::Questions::Uprn.new(nil, nil, self), |
||||
] |
||||
end |
||||
|
||||
def routed_to?(_log, _current_user) |
||||
true |
||||
end |
||||
end |
@ -0,0 +1,16 @@
|
||||
class Form::Lettings::Pages::UprnQuery < ::Form::Page |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@id = "uprn_query" |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Lettings::Questions::UprnQuery.new(nil, nil, self), |
||||
] |
||||
end |
||||
|
||||
def routed_to?(_log, _current_user) |
||||
true |
||||
end |
||||
end |
@ -0,0 +1,16 @@
|
||||
class Form::Lettings::Pages::UprnValidation < ::Form::Page |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@id = "uprn_validation" |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Lettings::Questions::UprnValidation.new(nil, nil, self), |
||||
] |
||||
end |
||||
|
||||
def routed_to?(_log, _current_user) |
||||
true |
||||
end |
||||
end |
@ -0,0 +1,40 @@
|
||||
class Form::Lettings::Questions::Uprn < ::Form::Question |
||||
def initialize(id, hsh, page) |
||||
super |
||||
@id = "uprn" |
||||
@check_answer_label = "UPRN" |
||||
@header = "Select your address from the list so that we can retrieve its UPRN" |
||||
@type = "radio" |
||||
@answer_options = answer_options |
||||
end |
||||
|
||||
def answer_options(log = nil, user = nil) |
||||
opts = { "" => "Select an option" } |
||||
|
||||
return opts unless ActiveRecord::Base.connected? |
||||
return opts unless user |
||||
return opts unless log |
||||
|
||||
q = log.uprn_query |
||||
|
||||
return [] unless q |
||||
|
||||
# TODO: handle non-200 responses |
||||
resp = HTTParty.get("https://api.os.uk/search/places/v1/find?query=#{q}&key=#{ENV['OS_DATA_KEY']}&minmatch=0.8&maxresults=50") |
||||
opts = {} |
||||
|
||||
resp["results"]&.each do |result| |
||||
uprn = result.dig("DPA", "UPRN") |
||||
address = result.dig("DPA", "ADDRESS") |
||||
opts[uprn] = { "value" => "#{uprn}: #{address}" } |
||||
end |
||||
|
||||
opts[""] = { "value" => "I can't find my address" } |
||||
|
||||
opts |
||||
end |
||||
|
||||
def displayed_answer_options(log, user) |
||||
answer_options(log, user) |
||||
end |
||||
end |
@ -0,0 +1,9 @@
|
||||
class Form::Lettings::Questions::UprnQuery < ::Form::Question |
||||
def initialize(id, hsh, page) |
||||
super |
||||
@id = "uprn_query" |
||||
@check_answer_label = "Uprn Query" |
||||
@header = "UPRN query" |
||||
@type = "text" |
||||
end |
||||
end |
@ -0,0 +1,9 @@
|
||||
class Form::Lettings::Questions::UprnValidation < ::Form::Question |
||||
def initialize(id, hsh, page) |
||||
super |
||||
@id = "uprn" |
||||
@check_answer_label = "Uprn validation" |
||||
@header = "UPRN validation" |
||||
@type = "text" |
||||
end |
||||
end |
@ -0,0 +1,13 @@
|
||||
class AddUprnToLogs < ActiveRecord::Migration[7.0] |
||||
def change |
||||
change_table :sales_logs, bulk: true do |t| |
||||
t.column :uprn, :integer |
||||
t.column :uprn_query, :integer |
||||
end |
||||
|
||||
change_table :lettings_logs, bulk: true do |t| |
||||
t.column :uprn, :integer |
||||
t.column :uprn_query, :integer |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue