Add basic invoices setup

This commit is contained in:
bterkuile committed 2025-10-18 12:37:08 -05:00
1 parent 4a7b752ace
commit 9b0351576a
7 files changed
+131 -2

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
# frozen_string_literal: true
module StrikeMe
module API
# Factory helper object connecting the client to the models
class Invoices
include BaseClient
include Enumerable
autoload_default :Invoice
delegate :first, :last, :size, :any?, to: :list
def each(&block)
list.each(&block)
end
def list
return @list if @list.present?
url = 'invoices'
response = client.get url
raise ResponseError.new(url, response.body) unless response.success?
@list = response.body['items'].map { |item| Invoice.new item }
end
end
end
end
+26
View File
@@ -0,0 +1,26 @@
# frozen_string_literal: true
module StrikeMe
module API
class Invoices
class Invoice < BaseModel
attribute :invoiceId
attribute :amount
attribute :state
attribute :created, :datetime
attribute :description
attribute :issuerId
attribute :receiverId
attribute :payerId
attribute_names.select { _1.end_with? 'Id' }.each do |snake_name|
alias_attribute snake_name.underscore, snake_name
end
def paid?
state == 'PAID'
end
end
end
end
end