From ec77b50be6f846e2c2e5396a6e943e923ea02a06 Mon Sep 17 00:00:00 2001 From: Hector Correa Date: Mon, 12 Feb 2024 16:59:11 -0500 Subject: [PATCH] Fixes URL to get Plausible downloads (#567) * Fixes URL to get downloads * Adjust the test to match the updated code --- app/models/plausible.rb | 4 +++- spec/models/plausible_spec.rb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/plausible.rb b/app/models/plausible.rb index 5bd3caa5..91c9b4a7 100644 --- a/app/models/plausible.rb +++ b/app/models/plausible.rb @@ -33,7 +33,9 @@ def self.downloads(document_id) site_id = Rails.configuration.pdc_discovery.plausible_site_id page = "/discovery/catalog/#{document_id}" - url = "#{PLAUSIBLE_API_URL}/stats/breakdown?site_id=#{site_id}&property=event:props:filename&filters=event:page==#{page}&metrics=visitors,pageviews" + # Notice that the Plausible gem use above in pageviews uses "event:page==..." but when we use the raw API + # we cannot pass "==" + url = "#{PLAUSIBLE_API_URL}/stats/breakdown?site_id=#{site_id}&property=event:props:filename&filters=event:page=#{page}&metrics=visitors,pageviews" authorization = "Bearer #{ENV['PLAUSIBLE_KEY']}" response = HTTParty.get(url, headers: { 'Authorization' => authorization }) total_downloads = 0 diff --git a/spec/models/plausible_spec.rb b/spec/models/plausible_spec.rb index e25a64fc..e6ee776c 100644 --- a/spec/models/plausible_spec.rb +++ b/spec/models/plausible_spec.rb @@ -5,7 +5,7 @@ # rubocop:disable Layout/LineLength RSpec.describe Plausible do before do - stub_request(:get, "https://plausible.io/api/v1/stats/breakdown?filters=event:page==/discovery/catalog/88163&metrics=visitors,pageviews&property=event:props:filename&site_id=pdc-discovery-staging.princeton.edu") + stub_request(:get, "https://plausible.io/api/v1/stats/breakdown?filters=event:page=/discovery/catalog/88163&metrics=visitors,pageviews&property=event:props:filename&site_id=pdc-discovery-staging.princeton.edu") .with( headers: { 'Accept' => '*/*',