Skip to content

Commit

Permalink
Add Planit API key
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolai-b committed Apr 14, 2020
1 parent 2f634af commit f00506e
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/site_configs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions app/models/site_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/views/admin/site_configs/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@
= f.input :geocoder_url
= f.input :geocoder_key, hint: "your <a href='https://www.cyclestreets.net/api/'>Cyclestreets API key</a>".html_safe
= f.input :google_street_view_api_key, hint: "see <a href='https://developers.google.com/maps/documentation/streetview/get-api-key'>Google page</a>"
= f.input :planit_api_key
= f.actions
4 changes: 4 additions & 0 deletions app/views/admin/site_configs/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddPlanitApiKeyToSiteConfigs < ActiveRecord::Migration[5.2]
def change
add_column :site_configs, :planit_api_key, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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|
Expand Down
13 changes: 10 additions & 3 deletions lib/planning_application_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions spec/factories/site_configs_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
blog_url { "http://blog.cyclescape.org/" }
blog_user_guide_url { "http://blog.cyclescape.org/guide/" }
admin_email { "[email protected]" }
planit_api_key { "planit_api_key" }
end
end
12 changes: 6 additions & 6 deletions spec/lib/planning_application_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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]
Expand Down Expand Up @@ -69,31 +69,31 @@

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)
end

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)
end

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)
end

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)
Expand Down

0 comments on commit f00506e

Please sign in to comment.