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

pulibrary / allsearch_api / ed1cefda-f43b-4b58-95dd-12a33b7f1f7a

02 Jul 2025 06:23PM UTC coverage: 96.252% (-3.2%) from 99.494%
ed1cefda-f43b-4b58-95dd-12a33b7f1f7a

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

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

94 existing lines in 20 files now uncovered.

976 of 1014 relevant lines covered (96.25%)

63.21 hits per line

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

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

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

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

12
  def number
2✔
13
    service_response['search']['numFound']
5✔
14
  end
15

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

20
  def documents
2✔
21
    service_response['search']['results']
4✔
22
  end
23

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

35
  private
2✔
36

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

41
  def request
2✔
42
    libanswers_request = Net::HTTP::Get.new(uri)
5✔
43

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