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

pulibrary / bibdata / f04bc944-f9b4-4a42-8b26-dcacd0e3e688

11 Mar 2025 10:27PM UTC coverage: 34.017% (-58.1%) from 92.162%
f04bc944-f9b4-4a42-8b26-dcacd0e3e688

Pull #2653

circleci

christinach
Add new lc_subject_facet field.
Helps with the vocabulary work https://github.com/pulibrary/orangelight/pull/3386
In this new field we index only the lc subject heading and the subdivisions
So that when the user searches using the Details section, they can query solr for
all the subject headings and their divisions.

This is needed for the Subject browse Vocabulary work.
example: "lc_subject_facet": [
             "Booksellers and bookselling—Italy—Directories",
             "Booksellers and bookselling-Italy",
             "Booksellers and bookselling"
              ]
Pull Request #2653: Add new lc_subject_facet field.

1 of 3 new or added lines in 1 file covered. (33.33%)

2215 existing lines in 93 files now uncovered.

1294 of 3804 relevant lines covered (34.02%)

0.99 hits per line

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

26.79
/app/models/concerns/scsb.rb
1
module Scsb
1✔
2
  extend ActiveSupport::Concern
1✔
3

4
  # if id comes from 001 source is scsb
5
  # if id comes from 009 source is the owning library
6
  def items_by_id(id, source = 'scsb')
1✔
UNCOV
7
    request_body = scsb_bib_id_request(id, source)
×
UNCOV
8
    request_body_json = request_body.to_json
×
UNCOV
9
    scsb_request_response_customize(scsb_request_response: scsb_request('/sharedCollection/bibAvailabilityStatus', request_body_json))
×
10
  end
11

12
  # Retrieves items from the SCSB endpoint using a barcode
13
  def items_by_barcode(barcodes)
1✔
UNCOV
14
    request_body = scsb_barcode_request(barcodes)
×
UNCOV
15
    request_body_json = request_body.to_json
×
UNCOV
16
    scsb_request_response_customize(scsb_request_response: scsb_request('/sharedCollection/itemAvailabilityStatus', request_body_json))
×
17
  end
18

19
  def scsb_request_response_customize(scsb_request_response:)
1✔
UNCOV
20
    scsb_request_response.each do |r|
×
UNCOV
21
      r['itemAvailabilityStatus'] = 'Unavailable' if r['itemAvailabilityStatus'] == 'Not Available'
×
22
    end
23
  end
24

25
  def scsb_barcode_request(barcodes)
1✔
26
    {
UNCOV
27
      barcodes:
×
28
    }
29
  end
30

31
  def scsb_bib_id_request(id, source)
1✔
32
    {
UNCOV
33
      bibliographicId: id,
×
34
      institutionId: source
35
    }
36
  end
37

38
  def scsb_conn
1✔
UNCOV
39
    Faraday.new(url: scsb_server) do |faraday|
×
UNCOV
40
      faraday.request  :url_encoded # form-encode POST params
×
UNCOV
41
      faraday.response :logger unless Rails.env.test? # log requests to STDOUT
×
UNCOV
42
      faraday.adapter  Faraday.default_adapter # make requests with Net::HTTP
×
43
    end
44
  end
45

46
  def parse_scsb_message(message)
1✔
UNCOV
47
    parsed = JSON.parse(message)
×
48
    parsed.instance_of?(Hash) ? parsed.with_indifferent_access : parsed
×
49
  rescue JSON::ParserError
UNCOV
50
    Rails.logger.error("Failed to parse a message from the SCSB server: #{message}")
×
UNCOV
51
    {}
×
52
  end
53

54
  def scsb_response_json(response)
1✔
UNCOV
55
    if response.status != 200
×
UNCOV
56
      Rails.logger.error("The request to the SCSB server failed: #{response.body}")
×
UNCOV
57
      return {}
×
58
    end
59

UNCOV
60
    JSON.parse(response.body)
×
61
  rescue JSON::ParserError
UNCOV
62
    Rails.logger.error("Failed to parse the response from the SCSB server: #{response.body}")
×
UNCOV
63
    {}
×
64
  end
65

66
  def parse_scsb_response(response)
1✔
UNCOV
67
    parsed = scsb_response_json(response)
×
UNCOV
68
    parsed.instance_of?(Hash) ? parsed.with_indifferent_access : parsed
×
69
  end
70

71
  private
1✔
72

73
    def scsb_auth_key
1✔
UNCOV
74
      if Rails.env.test?
×
UNCOV
75
        'TESTME'
×
76
      else
77
        ENV['SCSB_AUTH_KEY']
×
78
      end
79
    end
80

81
    def scsb_server
1✔
UNCOV
82
      if Rails.env.test?
×
UNCOV
83
        'https://test.api.com/'
×
84
      else
85
        ENV['SCSB_SERVER']
×
86
      end
87
    end
88

89
    def scsb_request(request_path, request_body)
1✔
UNCOV
90
      response = self.scsb_conn.post do |req|
×
UNCOV
91
        req.url request_path
×
UNCOV
92
        req.headers['Content-Type'] = 'application/json'
×
UNCOV
93
        req.headers['Accept'] = 'application/json'
×
UNCOV
94
        req.headers['api_key'] = scsb_auth_key
×
UNCOV
95
        req.body = request_body
×
96
      end
UNCOV
97
      parse_scsb_response(response)
×
98
    rescue Faraday::ConnectionFailed, Faraday::TimeoutError => e
UNCOV
99
      Rails.logger.warn("#{self.class}: Connection error for #{scsb_server}")
×
UNCOV
100
      raise e
×
101
    end
102
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