Skip to content

Commit

Permalink
use url as usage report id. #260
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed May 17, 2019
1 parent 5bec197 commit 0bf039e
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 116 deletions.
10 changes: 7 additions & 3 deletions app/models/usage_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ class UsageReport
include Modelable

def self.find_by_id(id)
url = Rails.env.production? ? "https://api.datacite.org/reports/#{id}" : "https://api.test.datacite.org/reports/#{id}"
base_url = Rails.env.production? ? "https://api.datacite.org/reports" : "https://api.test.datacite.org/reports"
return {} unless id.starts_with?(base_url)

url = id

response = Maremma.get(url)

Expand All @@ -23,14 +26,15 @@ def self.query(query, options={})
number = (options.dig(:page, :number) || 1).to_i
size = (options.dig(:page, :size) || 25).to_i

url = Rails.env.production? ? "https://api.datacite.org/reports?page[size]=#{size}&page[number]=#{number}" : "https://api.test.datacite.org/reports?page[size]=#{size}&page[number]=#{number}"
base_url = Rails.env.production? ? "https://api.datacite.org/reports" : "https://api.test.datacite.org/reports"
url = base_url + "?page[size]=#{size}&page[number]=#{number}"

response = Maremma.get(url)

return {} if response.status != 200

data = response.body.dig("data", "reports").map do |message|
parse_message(id: message['id'], message: message)
parse_message(id: base_url + "/#{message["id"]}", message: message)
end
meta = { "total" => response.body.dig("data", "meta", "total") }
errors = response.body.fetch("errors", nil)
Expand Down
17 changes: 9 additions & 8 deletions spec/fixtures/vcr_cassettes/UsageReport/find_by_id/found.yml

Large diffs are not rendered by default.

45 changes: 0 additions & 45 deletions spec/fixtures/vcr_cassettes/UsageReport/find_by_id/not_found.yml

This file was deleted.

Loading

0 comments on commit 0bf039e

Please sign in to comment.