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

pulibrary / allsearch_api / abab0c3b-3420-4969-a09f-56494d1bd4a7

05 May 2025 05:52PM UTC coverage: 99.49%. Remained the same
abab0c3b-3420-4969-a09f-56494d1bd4a7

push

circleci

maxkadel
Do not include apostrophes in staff links

Closes #360

0 of 1 new or added line in 1 file covered. (0.0%)

111 existing lines in 21 files now uncovered.

976 of 981 relevant lines covered (99.49%)

101.15 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✔
10
    @query_terms = query_terms
16✔
11
    @service = 'artmuseum'
16✔
12
    @service_response = art_museum_service_response
16✔
13
  end
14

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

19
  private
3✔
20

21
  def art_museum_service_response
3✔
22
    uri = URI::HTTPS.build(host: 'data.artmuseum.princeton.edu', path: '/search',
16✔
23
                           query: "q=#{query_terms}&type=all&size=3")
24
    response = Net::HTTP.get(uri)
16✔
25
    begin
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