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

pulibrary / lsp-data / dd922cfe-e03f-4f7b-a329-c6e835b06192

17 Dec 2024 02:41PM UTC coverage: 99.482% (-0.5%) from 100.0%
dd922cfe-e03f-4f7b-a329-c6e835b06192

push

circleci

mzelesky
ApiPolInvoiceList class

30 of 33 new or added lines in 2 files covered. (90.91%)

576 of 579 relevant lines covered (99.48%)

5.53 hits per line

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

90.63
/lib/lsp-data/api_pol_invoice_list.rb
1
# frozen_string_literal: true
2

3
module LspData
1✔
4
  ### Returns a hash with the response code and an array of invoices;
5
  ###   if the response code is not 200, return an empty array
6
  class ApiPolInvoiceList
1✔
7
    attr_reader :pol, :api_key, :conn
1✔
8

9
    def initialize(pol:, api_key:, conn:)
1✔
10
      @pol = pol
2✔
11
      @api_key = api_key
2✔
12
      @conn = conn
2✔
13
    end
14

15
    def invoices
1✔
16
      @invoices ||= all_invoices
3✔
17
    end
18

19
    private
1✔
20

21
    def all_invoices
1✔
22
      initial_response = api_call(offset: 0)
2✔
23
      total_invoice_count = initial_response[:body]['total_record_count']
2✔
24
      results = initial_response[:body]['invoice'].map do |invoice|
2✔
25
        ApiInvoice.new(invoice_json: invoice)
1✔
26
      end
27
      if total_invoice_count.size.positive?
2✔
28
        total_calls = (total_invoice_count / 100).floor
2✔
29
        1.upto(total_calls).each do |call|
2✔
NEW
30
          info = api_call(offset: (call * 100))
×
NEW
31
          results += info[:body]['invoice'].map do |invoice|
×
NEW
32
            ApiInvoice.new(invoice_json: invoice)
×
33
          end
34
        end
35
      end
36
      @all_invoices = results
2✔
37
    end
38

39
    def api_call(offset:)
1✔
40
      response = conn.get do |req|
2✔
41
        req.url 'almaws/v1/acq/invoices/'
2✔
42
        req.headers['Content-Type'] = 'application/json'
2✔
43
        req.headers['Accept'] = 'application/json'
2✔
44
        req.params['apikey'] = api_key
2✔
45
        req.params['limit'] = 100
2✔
46
        req.params['offset'] = offset
2✔
47
        req.params['q'] = "pol_number~#{pol}"
2✔
48
      end
49
      parse_api_response(response)
2✔
50
    end
51
  end
52
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