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

pulibrary / orangelight / 106928f9-219e-42b2-9ac9-655a7c88f106

16 Sep 2024 08:34PM UTC coverage: 96.495% (-0.003%) from 96.498%
106928f9-219e-42b2-9ac9-655a7c88f106

Pull #4349

circleci

web-flow
Merge branch 'main' into refactor_illiad_patron
Pull Request #4349: Dry up Illiad patron code some

35 of 36 new or added lines in 5 files covered. (97.22%)

5975 of 6192 relevant lines covered (96.5%)

1502.8 hits per line

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

93.02
/app/models/requests/illiad_client.rb
1
# frozen_string_literal: true
2
require './lib/orangelight/illiad_patron_client'
3✔
3
require './lib/orangelight/illiad_account'
3✔
4

5
module Requests
3✔
6
  class IlliadClient
3✔
7
    attr_reader :illiad_api_base, :illiad_api_key, :error
3✔
8

9
    def initialize
3✔
10
      @illiad_api_key = Requests.config[:illiad_api_key].to_s
43✔
11
      @illiad_api_base = Requests.config[:illiad_api_base]
43✔
12
      @error = nil
43✔
13
    end
14

15
    private
3✔
16

17
      def get_json_response # rubocop:disable Naming/AccessorMethodName
3✔
18
        response = ::Orangelight::IlliadAccount.new(patron.patron_hash).illiad_patron_response
21✔
19
        return {} unless response
21✔
20
        data = JSON.parse(response.body)
20✔
21
        if response.status != 200
20✔
22
          if data
2✔
23
            Rails.logger.warn("Illiad Error Message: #{data[:message]}")
2✔
24
          else
NEW
25
            Rails.logger.warn("Illiad Error Message: #{response.reason_phrase}")
×
26
          end
27
          {}
2✔
28
        else
29
          data.with_indifferent_access
18✔
30
        end
31
      end
32

33
      def post_json_response(url:, body:)
3✔
34
        response = post_response(url:, body:)
33✔
35
        if response.blank? || response.status != 200
33✔
36
          if response.present? && response.body.present?
5✔
37
            Rails.logger.warn "Illiad Error Message: #{response.body}"
4✔
38
            @error = JSON.parse(response.body)
4✔
39
          else
40
            Rails.logger.warn "An unspecified error occurred with Illiad #{url} #{body}"
1✔
41
          end
42
          nil
43
        elsif response.present?
28✔
44
          JSON.parse(response.body)
28✔
45
        end
46
      end
47

48
      def post_response(url:, body:)
3✔
49
        Rails.logger.debug { "Illiad Posting #{illiad_api_base}/#{url} #{body}" }
66✔
50
        resp = conn.post do |req|
33✔
51
          req.url url
33✔
52
          req.headers['Content-Type'] = 'application/json'
33✔
53
          req.headers['Accept'] = 'application/json'
33✔
54
          req.headers['ApiKey'] = illiad_api_key
33✔
55
          req.body = body
33✔
56
        end
57
        Rails.logger.debug { "Illiad Post Response #{illiad_api_base}/#{url} #{resp.status} #{resp.body}" }
66✔
58
        resp
33✔
59
      rescue Faraday::ConnectionFailed
60
        Rails.logger.warn("Unable to Connect to #{@illiad_api_base}")
×
61
        nil
×
62
      end
63

64
      def conn
3✔
65
        @conn ||= ::Orangelight::IlliadPatronClient.new(patron:).conn
33✔
66
      end
67
  end
68
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