codat 0.1.2 → 0.1.6

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: 0a1b2456d6687df09540e3f231fb900684a379771bece070ac5ca515070fc4b0
4
+ data.tar.gz: 15b72b23934fcfbfd404affa282ee004316778b69c79f3e349719a5dcd9fbb8b
5
5
  SHA512:
6
- metadata.gz: 2bb60e32a71c375260ad46d6da81505068b9a18dbdeb256674c204d56fcacd7797779109cf7c115a3fb1ce3e46d6c671df9358cf491cb9a8c15c0aa40902b71c
7
- data.tar.gz: f8a0417775eefeefc554f593542f88d296e61f9dd614a015a45b1b72f3981218c6b461530f0960da6509c35d4558a4c9dc3b13d7be0d8d4b36d4ead46bc644f7
6
+ metadata.gz: d5e4e98c94b48af0f8dbda9af71a093f3ff93e69e1b1aeabdc2bb890c9208868b87aae423ca39079f1a990f7ecfa6222b047e54e1b9578ed404ba5e002d15fc9
7
+ data.tar.gz: 8d70d18e2bd0de1063b0b93fe82be49d0cf4f82369fb3271e37b23c0090b2713ac52016c0ef9c78bdafa2361dfc737721802ee914ce7e7e453120cc7884a49cf
data/.gitignore CHANGED
@@ -8,6 +8,7 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  Gemfile.lock
11
+ .DS_Store
11
12
 
12
13
  # rspec failure tracking
13
14
  .rspec_status
data/.gitlab-ci.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  before_script:
2
2
  - ruby -v
3
3
  - which ruby
4
- - gem install bundler --no-ri --no-rdoc
4
+ - gem install bundler
5
5
  - bundle install --jobs $(nproc) "${FLAGS[@]}"
6
6
 
7
7
  rspec:
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.6
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/bin/console CHANGED
@@ -12,8 +12,8 @@ Codat.configure do |config|
12
12
  end
13
13
 
14
14
  # To avoid having to namespace everything when inside the console.
15
- Object.send(:include, Codat)
16
- Object.send(:include, Codat::Models)
15
+ Object.include(Codat)
16
+ Object.include(Codat::Models)
17
17
 
18
18
  require 'pry'
19
19
  Pry.start
data/codat.gemspec CHANGED
@@ -25,13 +25,15 @@ Gem::Specification.new do |spec|
25
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
26
  spec.require_paths = ['lib']
27
27
 
28
+ spec.required_ruby_version = '>= 2.5'
29
+
28
30
  spec.add_dependency 'faraday', '~> 0.15'
29
31
  spec.add_dependency 'faraday_middleware', '~> 0.12'
30
32
  spec.add_dependency 'faraday_middleware-multi_json', '~> 0.0.6'
31
33
  spec.add_dependency 'multi_json', '~> 1.13'
32
34
  spec.add_dependency 'rainbow', '~> 3.0'
33
35
 
34
- spec.add_development_dependency 'bundler', '~> 1.16'
36
+ spec.add_development_dependency 'bundler'
35
37
  spec.add_development_dependency 'dotenv', '~> 2.5'
36
38
  spec.add_development_dependency 'pry-byebug', '~> 3.6'
37
39
  spec.add_development_dependency 'rake', '~> 10.0'
@@ -40,5 +42,5 @@ Gem::Specification.new do |spec|
40
42
  spec.add_development_dependency 'rubocop-rspec', '~> 1.27'
41
43
  spec.add_development_dependency 'simplecov', '~> 0.16'
42
44
  spec.add_development_dependency 'vcr', '~> 4.0.0'
43
- spec.add_development_dependency 'webmock', '~> 3.4.2'
45
+ spec.add_development_dependency 'webmock', '~> 3.7.2'
44
46
  end
data/lib/codat.rb CHANGED
@@ -7,9 +7,10 @@ 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
+ require 'codat/models/integration'
13
14
 
14
15
  module Codat
15
16
  module_function
@@ -39,6 +39,12 @@ module Codat
39
39
 
40
40
  formatted
41
41
  end
42
+
43
+ # As per Codat API doc
44
+ # https://docs.codat.io/reference/errors
45
+ def successful_response?(result)
46
+ result.status < 400
47
+ end
42
48
  end
43
49
 
44
50
  # Sets all the instance variables by reading the JSON from Codat and converting the keys from
@@ -16,7 +16,7 @@ module Codat
16
16
 
17
17
  result = get(url)
18
18
 
19
- return [] if result.status == 404
19
+ return [] unless successful_response?(result)
20
20
 
21
21
  result.body.map { |account| new(json: account) }
22
22
  end
@@ -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 unless successful_response?(result)
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
@@ -18,9 +18,7 @@ module Codat
18
18
  def self.all(params = {})
19
19
  result = get(ENDPOINTS[:collection], params)
20
20
 
21
- return [] if result.status == 404
22
-
23
- return result.body if result.status == 400
21
+ return [] unless successful_response?(result)
24
22
 
25
23
  result.body[:results].map { |company| new(json: company) }
26
24
  end
@@ -30,7 +28,7 @@ module Codat
30
28
 
31
29
  result = get(url)
32
30
 
33
- return nil if result.status == 404
31
+ return nil unless successful_response?(result)
34
32
 
35
33
  new(json: result.body)
36
34
  end
@@ -38,7 +36,7 @@ module Codat
38
36
  def self.create(params = {})
39
37
  result = post(ENDPOINTS[:collection], params)
40
38
 
41
- return { error: 'An error occured.' } if result.status == 404 || result.status == 400
39
+ return { error: 'An error occured.' } unless successful_response?(result)
42
40
 
43
41
  new(json: result.body)
44
42
  end
@@ -36,7 +36,7 @@ module Codat
36
36
 
37
37
  result = get(url, build_query(params))
38
38
 
39
- return nil if result.status == 404 || result.status == 400
39
+ return nil unless successful_response?(result)
40
40
 
41
41
  new(json: result.body)
42
42
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'codat/base_model'
4
+
5
+ module Codat
6
+ module Models
7
+ class Integration < BaseModel
8
+ ENDPOINT = '/integrations'
9
+
10
+ attributes :key, :logo_url, :name, :enabled, :source_id, :integration_id, :source_type
11
+
12
+ def self.all(params = {})
13
+ result = get(ENDPOINT, params)
14
+
15
+ return [] unless successful_response?(result)
16
+
17
+ result.body.fetch(:results, []).map { |integration| new(json: integration) }
18
+ end
19
+ end
20
+ end
21
+ 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
@@ -16,7 +16,7 @@ module Codat
16
16
 
17
17
  result = get(url)
18
18
 
19
- return [] if result.status == 404
19
+ return [] unless successful_response?(result)
20
20
 
21
21
  result.body[:data].map { |report| new(json: report) }
22
22
  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.6'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
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.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricardo Otero
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-08 00:00:00.000000000 Z
11
+ date: 2021-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -84,16 +84,16 @@ dependencies:
84
84
  name: bundler
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '1.16'
89
+ version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: '1.16'
96
+ version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: dotenv
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -212,14 +212,14 @@ dependencies:
212
212
  requirements:
213
213
  - - "~>"
214
214
  - !ruby/object:Gem::Version
215
- version: 3.4.2
215
+ version: 3.7.2
216
216
  type: :development
217
217
  prerelease: false
218
218
  version_requirements: !ruby/object:Gem::Requirement
219
219
  requirements:
220
220
  - - "~>"
221
221
  - !ruby/object:Gem::Version
222
- version: 3.4.2
222
+ version: 3.7.2
223
223
  description: Codat API wrapper in Ruby
224
224
  email:
225
225
  - oterosantos@gmail.com
@@ -231,7 +231,7 @@ files:
231
231
  - ".gitlab-ci.yml"
232
232
  - ".rspec"
233
233
  - ".rubocop.yml"
234
- - ".travis.yml"
234
+ - ".ruby-version"
235
235
  - Gemfile
236
236
  - LICENSE.txt
237
237
  - README.md
@@ -250,8 +250,11 @@ 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/integration.rb
257
+ - lib/codat/models/metadata.rb
255
258
  - lib/codat/models/profit_and_loss.rb
256
259
  - lib/codat/models/profit_and_loss_report.rb
257
260
  - lib/codat/models/report.rb
@@ -261,7 +264,7 @@ homepage: https://gitlab.com/finpoint/codat
261
264
  licenses:
262
265
  - MIT
263
266
  metadata: {}
264
- post_install_message:
267
+ post_install_message:
265
268
  rdoc_options: []
266
269
  require_paths:
267
270
  - lib
@@ -269,16 +272,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
269
272
  requirements:
270
273
  - - ">="
271
274
  - !ruby/object:Gem::Version
272
- version: '0'
275
+ version: '2.5'
273
276
  required_rubygems_version: !ruby/object:Gem::Requirement
274
277
  requirements:
275
278
  - - ">="
276
279
  - !ruby/object:Gem::Version
277
280
  version: '0'
278
281
  requirements: []
279
- rubyforge_project:
280
- rubygems_version: 2.7.3
281
- signing_key:
282
+ rubygems_version: 3.2.11
283
+ signing_key:
282
284
  specification_version: 4
283
285
  summary: Codat API wrapper in Ruby
284
286
  test_files: []
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.5.0
5
- before_install: gem install bundler -v 1.16.1