diff --git a/models/items/alma/loans.rb b/models/items/alma/loans.rb index 8a0adb6d..5534640a 100644 --- a/models/items/alma/loans.rb +++ b/models/items/alma/loans.rb @@ -8,38 +8,6 @@ def initialize(parsed_response:, pagination:) @pagination = pagination end - def self.renew_all(uniqname:, client: AlmaRestClient.client, connections: [], - publisher: Publisher.new) - url = "/users/#{uniqname}/loans" - publisher.publish({step: 1, count: 0, renewed: 0, uniqname: uniqname}) - response = client.get_all(url: url, record_key: "item_loan", query: {"expand" => "renewable"}) - - return response if response.code != 200 - loans = response.parsed_response["item_loan"]&.map do |loan| - Loan.new(loan) - end - renew(uniqname: uniqname, loans: loans, publisher: publisher) - end - - def self.renew(uniqname:, loans:, publisher: Publisher.new) - count = 0 - renewed = 0 - renew_statuses = [] - loans.filter { |x| x.renewable? }.each do |loan| - response = Loan.renew(uniqname: uniqname, loan_id: loan.loan_id) - if response.code != 200 - renew_statuses.push(:fail) - else - renewed += 1 - renew_statuses.push(:success) - end - count += 1 - publisher.publish({step: 2, count: count, renewed: renewed, uniqname: uniqname}) - end - publisher.publish({step: 3, count: count, renewed: renewed, uniqname: uniqname}) - RenewResponse.new(renew_statuses: renew_statuses) - end - def count @parsed_response["total_record_count"] end @@ -55,8 +23,8 @@ def self.for(uniqname:, offset: nil, limit: 15, query["limit"] = limit.nil? ? 15 : limit response = client.get(url, query: query) - raise StandardError unless response.code == 200 - pr = response.parsed_response + raise StandardError unless response.status == 200 + pr = response.body pagination_params = {url: "/current-checkouts/u-m-library", total: pr["total_record_count"]} pagination_params[:limit] = limit unless limit.nil? pagination_params[:current_offset] = offset unless offset.nil? @@ -67,10 +35,6 @@ def self.for(uniqname:, offset: nil, limit: 15, end class Loan < AlmaItem - def self.renew(uniqname:, loan_id:, client: AlmaRestClient.client) - client.post("/users/#{uniqname}/loans/#{loan_id}", query: {op: "renew"}) - end - def due_date DateTime.patron_format(@parsed_response["due_date"]) unless claims_returned? end diff --git a/spec/models/items/alma/loans_spec.rb b/spec/models/items/alma/loans_spec.rb index bd529594..a2bfc9a5 100644 --- a/spec/models/items/alma/loans_spec.rb +++ b/spec/models/items/alma/loans_spec.rb @@ -4,7 +4,7 @@ describe Loans do context "two loans" do before(:each) do - stub_alma_get_request(url: "users/jbister/loans", body: File.read("./spec/fixtures/loans.json"), query: {expand: "renewable", limit: 15, order_by: "due_date"}) + stub_alma_get_request(url: "users/jbister/loans", output: File.read("./spec/fixtures/loans.json"), query: {expand: "renewable", limit: 15, order_by: "due_date"}) end subject do Loans.for(uniqname: "jbister") @@ -31,7 +31,7 @@ end context "no loans" do before(:each) do - stub_alma_get_request(url: "users/jbister/loans", body: File.read("./spec/fixtures/no_loans.json"), query: {expand: "renewable", limit: 15, order_by: "due_date"}) + stub_alma_get_request(url: "users/jbister/loans", output: File.read("./spec/fixtures/no_loans.json"), query: {expand: "renewable", limit: 15, order_by: "due_date"}) end subject do Loans.for(uniqname: "jbister") @@ -53,7 +53,7 @@ @loan = one_loan["item_loan"].delete_at(0).to_json end it "requests loans sorted by title" do - stub_alma_get_request(url: "users/jbister/loans", body: @loan, query: {"expand" => "renewable", "offset" => 1, "limit" => 1, "direction" => "DESC", "order_by" => "title"}) + stub_alma_get_request(url: "users/jbister/loans", output: @loan, query: {"expand" => "renewable", "offset" => 1, "limit" => 1, "direction" => "DESC", "order_by" => "title"}) loans = Loans.for(uniqname: "jbister", offset: 1, limit: 1, direction: "DESC", order_by: "title") expect(loans.pagination.next.url).to include("direction=DESC") expect(loans.pagination.next.url).to include("order_by=title") @@ -64,7 +64,7 @@ before(:each) do one_loan = JSON.parse(File.read("./spec/fixtures/loans.json")) one_loan["item_loan"].delete_at(0) - stub_alma_get_request(url: "users/jbister/loans", body: one_loan.to_json, query: {"expand" => "renewable", "offset" => 1, "limit" => 1, "order_by" => "due_date"}) + stub_alma_get_request(url: "users/jbister/loans", output: one_loan.to_json, query: {"expand" => "renewable", "offset" => 1, "limit" => 1, "order_by" => "due_date"}) end subject do Loans.for(uniqname: "jbister", offset: 1, limit: 1)