codat 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c200bf7bf3b3702f186640149441c8cdb016b2078e374f8386da4f36d6d14a5a
4
- data.tar.gz: 0b2409f51c5a5d6c49b3f477d8d9613a759071f207fcc0359f10b75a976b62af
3
+ metadata.gz: 815e3180acc27e45f704e7cd9ba4893d55774b47d6b0417020568538ba780490
4
+ data.tar.gz: fcb66e4ccb57663cb4a1581d53271d2faecbba03602101e1758c981327101f63
5
5
  SHA512:
6
- metadata.gz: 2bb60e32a71c375260ad46d6da81505068b9a18dbdeb256674c204d56fcacd7797779109cf7c115a3fb1ce3e46d6c671df9358cf491cb9a8c15c0aa40902b71c
7
- data.tar.gz: f8a0417775eefeefc554f593542f88d296e61f9dd614a015a45b1b72f3981218c6b461530f0960da6509c35d4558a4c9dc3b13d7be0d8d4b36d4ead46bc644f7
6
+ metadata.gz: 84e5b6c95805735f2f9429dd28f7edb3b74037796528a481ac991fadbf62148544007624b39228ada5c1747ed3adf7d933042baa76690898e8bb40134f67be91
7
+ data.tar.gz: be197f35c8353eeb0136159c25517ff9af4609ca9f8b055dee54d08ad96251d7b952956edfec29452f4d0fa6abc798a2cd906d5ce75d7daf9c0bff09bde6ca80
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Codat
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/codat.svg)](https://badge.fury.io/rb/codat)
4
+
3
5
  A simple wrapper for the [Codat](https://www.codat.io/) API. Please refer to Codat's documentation
4
6
  to complement any information you need:
5
7
 
data/lib/codat.rb CHANGED
@@ -7,7 +7,7 @@ require 'codat/client'
7
7
  require 'codat/models/bank_account'
8
8
  require 'codat/models/company'
9
9
  require 'codat/models/report'
10
- require 'codat/models/bank_statement'
10
+ require 'codat/models/bank_statement_list'
11
11
  require 'codat/models/balance_sheet'
12
12
  require 'codat/models/profit_and_loss'
13
13
 
@@ -6,24 +6,8 @@ module Codat
6
6
  module Models
7
7
  # Bank statements for a given company.
8
8
  class BankStatement < BaseModel
9
- ENDPOINT = '/companies/:company_id/data/bankStatements'
10
-
11
9
  attributes :id, :date, :description, :reconciled, :amount, :balance, :transaction_type
12
10
  attributes :modified_date, :source_modifiedDate
13
-
14
- def self.all(company_id:, account_id:, page: 1)
15
- url = format_url(ENDPOINT, company_id: company_id.to_s.strip)
16
-
17
- result = get(url, accountId: account_id.to_s.strip, page: page.to_s.strip)
18
-
19
- return [] if result.status == 404
20
-
21
- records = result.body.dig(:results)
22
-
23
- return [] unless records
24
-
25
- records.map { |bank_statement| new(json: bank_statement) }
26
- end
27
11
  end
28
12
  end
29
13
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'codat/base_model'
4
+ require 'codat/models/bank_statement'
5
+ require 'codat/models/metadata'
6
+
7
+ module Codat
8
+ module Models
9
+ # Bank statements for a given company. This endpoint will return an array of records and also
10
+ # metadata (page size, page number and total results).
11
+ class BankStatementList < BaseModel
12
+ ENDPOINT = '/companies/:company_id/data/bankStatements'
13
+
14
+ attr_reader :records, :metadata
15
+
16
+ def self.for(company_id:, account_id:, page: 1)
17
+ url = format_url(ENDPOINT, company_id: company_id.to_s.strip)
18
+
19
+ result = get(url, accountId: account_id.to_s.strip, page: page.to_s.strip)
20
+
21
+ return nil if result.status == 404
22
+
23
+ new(json: result.body)
24
+ end
25
+
26
+ def initialize(json:)
27
+ super
28
+
29
+ records = json.delete(:results) || []
30
+
31
+ @records = records.map { |bank_statement| BankStatement.new(json: bank_statement) }
32
+
33
+ @metadata = Metadata.new(json: json)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'codat/base_model'
4
+
5
+ module Codat
6
+ module Models
7
+ class Metadata < BaseModel
8
+ attributes :page_number, :page_size, :total_results
9
+ end
10
+ end
11
+ end
data/lib/codat/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Codat
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricardo Otero
@@ -250,8 +250,10 @@ files:
250
250
  - lib/codat/models/balance_sheet_report.rb
251
251
  - lib/codat/models/bank_account.rb
252
252
  - lib/codat/models/bank_statement.rb
253
+ - lib/codat/models/bank_statement_list.rb
253
254
  - lib/codat/models/company.rb
254
255
  - lib/codat/models/financial_sheet.rb
256
+ - lib/codat/models/metadata.rb
255
257
  - lib/codat/models/profit_and_loss.rb
256
258
  - lib/codat/models/profit_and_loss_report.rb
257
259
  - lib/codat/models/report.rb