diff --git a/app/controllers/admin/site_configs_controller.rb b/app/controllers/admin/site_configs_controller.rb
index 6b77bf51f..82ab696c3 100644
--- a/app/controllers/admin/site_configs_controller.rb
+++ b/app/controllers/admin/site_configs_controller.rb
@@ -41,7 +41,7 @@ def site_config_params
:ga_account_id, :ga_base_domain,
:default_email, :geocoder_url,
:geocoder_key, :blog_url, :blog_user_guide_url, :admin_email,
- :blog_about_url, :google_street_view_api_key
+ :blog_about_url, :google_street_view_api_key, :planit_api_key
)
end
end
diff --git a/app/models/site_config.rb b/app/models/site_config.rb
index 6b4fe5716..feccae35a 100644
--- a/app/models/site_config.rb
+++ b/app/models/site_config.rb
@@ -78,6 +78,7 @@ def wipe_cache
# google_street_view_api_key :string
# logo_uid :string
# nowhere_location :geometry({:srid= not null, geometry, 4326
+# planit_api_key :string
# small_logo_uid :string
# tile_server1_name :string default("OpenCycleMap"), not null
# tile_server1_options :string default("{}"), not null
diff --git a/app/views/admin/site_configs/_form.html.haml b/app/views/admin/site_configs/_form.html.haml
index 97cec6695..786abe04e 100644
--- a/app/views/admin/site_configs/_form.html.haml
+++ b/app/views/admin/site_configs/_form.html.haml
@@ -59,4 +59,5 @@
= f.input :geocoder_url
= f.input :geocoder_key, hint: "your Cyclestreets API key".html_safe
= f.input :google_street_view_api_key, hint: "see Google page"
+ = f.input :planit_api_key
= f.actions
diff --git a/app/views/admin/site_configs/show.html.haml b/app/views/admin/site_configs/show.html.haml
index a7bd79ac1..3c167d98e 100644
--- a/app/views/admin/site_configs/show.html.haml
+++ b/app/views/admin/site_configs/show.html.haml
@@ -67,4 +67,8 @@
%b Google Street View API key:
= @live_site_config.google_street_view_api_key
+%p
+ %b Planit API key
+ = @live_site_config.planit_api_key
+
= link_to 'Edit', edit_admin_site_config_path
diff --git a/db/migrate/20200412221843_add_planit_api_key_to_site_configs.rb b/db/migrate/20200412221843_add_planit_api_key_to_site_configs.rb
new file mode 100644
index 000000000..5bfb32037
--- /dev/null
+++ b/db/migrate/20200412221843_add_planit_api_key_to_site_configs.rb
@@ -0,0 +1,5 @@
+class AddPlanitApiKeyToSiteConfigs < ActiveRecord::Migration[5.2]
+ def change
+ add_column :site_configs, :planit_api_key, :string
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 98e3130cd..edede5357 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 2020_03_08_215608) do
+ActiveRecord::Schema.define(version: 2020_04_12_221843) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements"
@@ -542,6 +542,7 @@
t.string "tile_server2_options", default: "{}", null: false
t.string "tile_server3_options", default: "{}", null: false
t.string "google_street_view_api_key"
+ t.string "planit_api_key"
end
create_table "street_view_messages", id: :serial, force: :cascade do |t|
diff --git a/lib/planning_application_worker.rb b/lib/planning_application_worker.rb
index 9c833c33a..24164f319 100644
--- a/lib/planning_application_worker.rb
+++ b/lib/planning_application_worker.rb
@@ -77,13 +77,20 @@ def generate_authority_requests(authority, days_offset = nil)
dates = { start_date: (@end_date - 14.days + (5 * days_offset).days),
end_date: (@end_date - 10.days + (5 * days_offset).days) }
end
-
+ api_query =
+ if SiteConfig.first.planit_api_key
+ { apikey: SiteConfig.first.planit_api_key }
+ else
+ {}
+ end
{
method: :get, query:
- { auth: authority,
+ api_query.merge(
+ auth: authority,
start_date: dates[:start_date].to_date.to_s,
end_date: dates[:end_date].to_date.to_s,
- pg_sz: 500, sort: "-start_date" }
+ pg_sz: 500, sort: "-start_date"
+ )
}
end
end
diff --git a/spec/factories/site_configs_factory.rb b/spec/factories/site_configs_factory.rb
index e86747813..ef0127159 100644
--- a/spec/factories/site_configs_factory.rb
+++ b/spec/factories/site_configs_factory.rb
@@ -19,5 +19,6 @@
blog_url { "http://blog.cyclescape.org/" }
blog_user_guide_url { "http://blog.cyclescape.org/guide/" }
admin_email { "cyclescape-comment@cy.net" }
+ planit_api_key { "planit_api_key" }
end
end
diff --git a/spec/lib/planning_application_worker_spec.rb b/spec/lib/planning_application_worker_spec.rb
index 0a11f20ea..9cec39934 100644
--- a/spec/lib/planning_application_worker_spec.rb
+++ b/spec/lib/planning_application_worker_spec.rb
@@ -13,7 +13,7 @@
let!(:london_req) do
no_url = planning_record.dup.tap { |pr| pr.delete "url" }
stub_request(:get, Rails.application.config.planning_applications_url)
- .with(query: { auth: "London", start_date: (Date.today - 14.days).to_s, end_date: Date.today, sort: "-start_date", pg_sz: 500 },
+ .with(query: { apikey: "planit_api_key", auth: "London", start_date: (Date.today - 14.days).to_s, end_date: Date.today, sort: "-start_date", pg_sz: 500 },
headers: { "Accept" => "application/json", "Content-Type" => "application/json", "Host" => "www.planit.org.uk:443" })
.to_return(status: 200, body: {
"count" => 1,
@@ -26,7 +26,7 @@
no_lat = planning_record.dup.merge("uid" => "123").tap { |pr| pr.delete "lng" }
no_uid = planning_record.dup.tap { |pr| pr.delete "uid" }
stub_request(:get, Rails.application.config.planning_applications_url)
- .with(query: { auth: "Cambridge", start_date: (Date.today - 14.days).to_s, end_date: Date.today, sort: "-start_date", pg_sz: 500 },
+ .with(query: { apikey: "planit_api_key", auth: "Cambridge", start_date: (Date.today - 14.days).to_s, end_date: Date.today, sort: "-start_date", pg_sz: 500 },
headers: { "Accept" => "application/json", "Content-Type" => "application/json", "Host" => "www.planit.org.uk:443" })
.to_return(status: 200, body: {
"count" => 1, "page_size" => 500, "records" => [no_uid, planning_record, no_lat]
@@ -69,7 +69,7 @@
let!(:multi_page_tot_req) do
stub_request(:get, Rails.application.config.planning_applications_url)
- .with(query: { auth: "Multi Page LA", start_date: (Date.today - 14.days).to_s, end_date: Date.today, sort: "-start_date", pg_sz: 500 })
+ .with(query: { apikey: "planit_api_key", auth: "Multi Page LA", start_date: (Date.today - 14.days).to_s, end_date: Date.today, sort: "-start_date", pg_sz: 500 })
.to_return(status: 200, body: {
"count" => 500, "page_size" => 500, "records" => [planning_record]
}.to_json)
@@ -77,7 +77,7 @@
let!(:multi_page_0_req) do
stub_request(:get, Rails.application.config.planning_applications_url)
- .with(query: { auth: "Multi Page LA", start_date: (Date.today - 14.days).to_s, end_date: (Date.today - 10.days), sort: "-start_date", pg_sz: 500 })
+ .with(query: { apikey: "planit_api_key", auth: "Multi Page LA", start_date: (Date.today - 14.days).to_s, end_date: (Date.today - 10.days), sort: "-start_date", pg_sz: 500 })
.to_return(status: 200, body: {
"count" => 500, "page_size" => 500, "records" => [planning_record]
}.to_json)
@@ -85,7 +85,7 @@
let!(:multi_page_1_req) do
stub_request(:get, Rails.application.config.planning_applications_url)
- .with(query: { auth: "Multi Page LA", start_date: (Date.today - 9.days).to_s, end_date: (Date.today - 5.days), sort: "-start_date", pg_sz: 500 })
+ .with(query: { apikey: "planit_api_key", auth: "Multi Page LA", start_date: (Date.today - 9.days).to_s, end_date: (Date.today - 5.days), sort: "-start_date", pg_sz: 500 })
.to_return(status: 200, body: {
"count" => 500, "page_size" => 500, "records" => [planning_record]
}.to_json)
@@ -93,7 +93,7 @@
let!(:multi_page_2_req) do
stub_request(:get, Rails.application.config.planning_applications_url)
- .with(query: { auth: "Multi Page LA", start_date: (Date.today - 4.days).to_s, end_date: (Date.today - 0.days), sort: "-start_date", pg_sz: 500 })
+ .with(query: { apikey: "planit_api_key", auth: "Multi Page LA", start_date: (Date.today - 4.days).to_s, end_date: (Date.today - 0.days), sort: "-start_date", pg_sz: 500 })
.to_return(status: 200, body: {
"count" => 500, "page_size" => 500, "records" => [planning_record_alt]
}.to_json)