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

pulibrary / allsearch_api / d3ae8219-3fc5-4fb5-af6a-b3e7e5a5a69f

02 Jul 2025 05:37PM UTC coverage: 99.507% (+0.01%) from 99.494%
d3ae8219-3fc5-4fb5-af6a-b3e7e5a5a69f

Pull #381

circleci

sandbergja
Convert Findingaids controller into a rack app

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

32 of 34 new or added lines in 3 files covered. (94.12%)

115 existing lines in 19 files now uncovered.

1009 of 1014 relevant lines covered (99.51%)

96.7 hits per line

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

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

3
# This class is responsible for querying Libanswers for FAQs
4
class Libanswers
3✔
5
  attr_reader :query_terms
3✔
6

7
  include Parsed
3✔
8
  def initialize(query_terms:)
3✔
UNCOV
9
    @query_terms = CGI.escape(query_terms)
12✔
10
  end
11

12
  def number
3✔
UNCOV
13
    service_response['search']['numFound']
8✔
14
  end
15

16
  def more_link
3✔
UNCOV
17
    "https://faq.library.princeton.edu/search/?t=0&q=#{query_terms.gsub(/\s+/, '+')}"
14✔
18
  end
19

20
  def documents
3✔
UNCOV
21
    service_response['search']['results']
7✔
22
  end
23

24
  def service_response
3✔
UNCOV
25
    @service_response ||= Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
16✔
UNCOV
26
      response = http.request(request)
10✔
UNCOV
27
      if response.code == '200'
9✔
UNCOV
28
        JSON.parse(response.body)
7✔
29
      else
UNCOV
30
        { 'search' => { 'results' => [], 'numFound' => 0 } }
2✔
31
      end
32
    end
33
  end
34

35
  private
3✔
36

37
  def uri
3✔
UNCOV
38
    URI.parse "https://faq.library.princeton.edu/api/1.1/search/#{query_terms}?iid=344&limit=3"
30✔
39
  end
40

41
  def request
3✔
UNCOV
42
    libanswers_request = Net::HTTP::Get.new(uri)
10✔
43

UNCOV
44
    token = OAuthToken.find_or_create_by({ service: 'libanswers',
10✔
45
                                           endpoint: 'https://faq.library.princeton.edu/api/1.1/oauth/token' }).token
UNCOV
46
    libanswers_request['Authorization'] = "Bearer #{token}"
9✔
UNCOV
47
    libanswers_request
9✔
48
  end
49
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