• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / allsearch_api / 7d3a0de1-6c4f-435c-a05a-b461e285fc5e

02 Jul 2025 06:25PM UTC coverage: 99.507% (+0.01%) from 99.494%
7d3a0de1-6c4f-435c-a05a-b461e285fc5e

Pull #381

circleci

sandbergja
Refactor RackResponseController so that subclasses don't need to implement #json

Co-authored-by: Christina Chortaria <christinach@users.noreply.github.com>
Pull Request #381: Rewrite DPUL and FindingAids controllers as rack applications

30 of 30 new or added lines in 3 files covered. (100.0%)

36 existing lines in 8 files now uncovered.

1009 of 1014 relevant lines covered (99.51%)

96.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/app/models/art_museum.rb
1
# frozen_string_literal: true
2

3
# This class is responsible for querying the Art Museum API
4
class ArtMuseum
3✔
5
  include ActiveModel::API
3✔
6
  include Parsed
3✔
7
  attr_reader :service, :service_response
3✔
8

9
  def initialize(query_terms:)
3✔
UNCOV
10
    @query_terms = query_terms
16✔
UNCOV
11
    @service = 'artmuseum'
16✔
UNCOV
12
    @service_response = art_museum_service_response
16✔
13
  end
14

15
  def query_terms
3✔
UNCOV
16
    @query_terms.truncate(220, omission: '', separator: /\s/)
47✔
17
  end
18

19
  private
3✔
20

21
  def art_museum_service_response
3✔
UNCOV
22
    uri = URI::HTTPS.build(host: 'data.artmuseum.princeton.edu', path: '/search',
16✔
23
                           query: "q=#{query_terms}&type=all&size=3")
UNCOV
24
    response = Net::HTTP.get(uri)
16✔
25
    begin
UNCOV
26
      JSON.parse(response, symbolize_names: true)
16✔
27
    rescue JSON::ParserError
UNCOV
28
      handle_parser_error response
1✔
29
    end
30
  end
31

32
  def number
3✔
UNCOV
33
    service_response.dig(:hits, :total)
14✔
34
  end
35

36
  def more_link
3✔
UNCOV
37
    URI::HTTPS.build(host: 'artmuseum.princeton.edu', path: '/search/collections',
28✔
38
                     query: "mainSearch=\"#{query_terms}\"")
39
  end
40

41
  def documents
3✔
UNCOV
42
    @documents ||= service_response.dig(:hits, :hits)
14✔
43
  end
44

45
  def handle_parser_error(response)
3✔
UNCOV
46
    raise AllsearchError.new(
1✔
47
      problem: 'UPSTREAM_ERROR',
48
      msg: "Query to upstream failed with #{ActionController::Base.helpers.strip_tags(response)}"
49
    )
50
  end
51
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc