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

pulibrary / orangelight / 62bad3f1-d46d-40af-822c-403d653da2a8

17 Jun 2025 05:30PM UTC coverage: 0.447% (-94.9%) from 95.337%
62bad3f1-d46d-40af-822c-403d653da2a8

push

circleci

maxkadel
Install chrome & chromedriver for smoke specs

43 of 9610 relevant lines covered (0.45%)

0.01 hits per line

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

0.0
/app/models/requests/clancy_item.rb
1
# frozen_string_literal: true
2
require 'faraday'
×
3

4
module Requests
×
5
  class ClancyItem
×
6
    attr_reader :clancy_conn, :api_key, :barcode, :errors
×
7

8
    def initialize(barcode: nil, connection: Faraday.new(url: Requests.config[:clancy_base]))
×
9
      @clancy_conn = connection
×
10
      @api_key = Requests.config[:clancy_api_key]
×
11
      @barcode = barcode
×
12
      @errors = []
×
13
    end
×
14

15
    def status
×
16
      @status ||= load_clancy_status
×
17
    end
×
18

19
    def not_at_clancy?
×
20
      return true unless status["success"]
×
21
      "Item not Found" == status["status"] || status["status"].include?("Deaccessioned")
×
22
    end
×
23

24
    def at_clancy?
×
25
      !not_at_clancy?
×
26
    end
×
27

28
    def available?
×
29
      return false unless status["success"]
×
30
      ["Item In at Rest"].include?(status["status"]) # assuming there may be more than one available statuses
×
31
    end
×
32

33
    def request(hold_id:, patron:, location: 'MQ')
×
34
      response = request_item(hold_id:, patron:, location:)
×
35
      return false unless response["success"]
×
36

37
      request_response = response["results"].first
×
38
      if request_response["deny"] == "N"
×
39
        true
×
40
      else
×
41
        errors << request_response["istatus"]
×
42
        false
×
43
      end
×
44
    end
×
45

46
    private
×
47

48
      def load_clancy_status
×
49
        return empty_status if barcode.blank?
×
50

51
        response = get_clancy(url: "itemstatus/v1/#{barcode}")
×
52
        if response.success?
×
53
          JSON.parse(response.body)
×
54
        else
×
55
          errors << "Error connecting with Clancy: #{response.status}"
×
56
          empty_status
×
57
        end
×
58
      end
×
59

60
      def get_clancy(url:)
×
61
        clancy_conn.get do |req|
×
62
          req.url url
×
63
          req.headers['Content-Type'] = 'application/json'
×
64
          req.headers['Accept'] = 'application/json'
×
65
          req.headers['X-API-Key'] = api_key
×
66
        end
×
67
      end
×
68

69
      def post_clancy(url:, body:)
×
70
        clancy_conn.post do |req|
×
71
          req.url url
×
72
          req.headers['Content-Type'] = 'application/json'
×
73
          req.headers['Accept'] = 'application/json'
×
74
          req.headers['X-API-Key'] = api_key
×
75
          req.body = body
×
76
        end
×
77
      end
×
78

79
      def empty_status
×
80
        { "success" => false }
×
81
      end
×
82

83
      def request_item(location:, hold_id:, patron:, request_type: "PYR")
×
84
        body = { "requests": [{ "request_id": hold_id, "request_type": request_type, "barcode": barcode, "stop": location, "requestor": "#{patron.first_name} #{patron.last_name}", "patron_id": patron.university_id }] }
×
85
        response = post_clancy(url: "circrequests/v1", body: body.to_json)
×
86
        if response.success?
×
87
          JSON.parse(response.body)
×
88
        else
×
89
          errors << "Error connecting with Clancy: #{response.status}"
×
90
          empty_status
×
91
        end
×
92
      end
×
93
  end
×
94
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