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

hathitrust / holdings-backend / 14274462258

04 Apr 2025 09:26PM UTC coverage: 74.271%. First build
14274462258

Pull #372

github

web-flow
Merge 4720881ff into cf4a99761
Pull Request #372: DEV-1590: API for ETAS access queries

31 of 34 new or added lines in 1 file covered. (91.18%)

6368 of 8574 relevant lines covered (74.27%)

40.59 hits per line

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

91.18
/lib/api/etas_api.rb
1
require "cluster"
1✔
2
require "clusterable/ht_item"
1✔
3
require "services"
1✔
4
require "sinatra"
1✔
5

6
class EtasAPI < Sinatra::Base
1✔
7
  set :show_exceptions, ENV["show_sinatra_exceptions"] || false
1✔
8
  no_matching_data_error = {"application_error" => "no matching data"}.to_json
1✔
9

10
  get "/ping" do
1✔
11
    "pong"
1✔
12
  end
13

14
  get "/etas/item_access" do
1✔
15
    # ArgumentError if missing organization / ht_id.
16
    validate_params(params, ["organization", "ht_id"])
14✔
17

18
    organization = params["organization"]
11✔
19
    ht_id = params["ht_id"]
11✔
20

21
    ht_item = Clusterable::HtItem.find(item_id: ht_id)
11✔
22
    cluster = ht_item.cluster
10✔
23

24
    return_doc = {
25
      "lock_id" => ht_item.ocns.sort.join(","),
10✔
26
      "n_enum" => ht_item.n_enum,
27
      "copy_count" => cluster.copy_counts[organization]
28
    }
29
    return_doc.to_json
10✔
30
  end
31

32
  def validate_params(params, to_validate)
1✔
33
    argument_errors = []
14✔
34
    to_validate.each do |param_name|
14✔
35
      if !params.key?(param_name) || params[param_name].empty?
28✔
36
        argument_errors << "missing param: #{param_name}"
4✔
37
      end
38
    end
39
    if argument_errors.any?
14✔
40
      raise ArgumentError, argument_errors.join("; ")
3✔
41
    end
42
  end
43

44
  error ArgumentError do
1✔
45
    status 404
3✔
46
    {"application_error" => env["sinatra.error"].message}.to_json
3✔
47
  end
48

49
  error Sequel::NoMatchingRow do
1✔
50
    status 404
1✔
51
    no_matching_data_error
1✔
52
  end
53

54
  error do
1✔
NEW
55
    Services.logger.error env["sinatra.error"].message
×
NEW
56
    status 404
×
NEW
57
    "Error"
×
58
  end
59
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

© 2026 Coveralls, Inc