codat 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.gitlab-ci.yml +13 -0
- data/.rspec +3 -0
- data/.rubocop.yml +39 -0
- data/.travis.yml +5 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +104 -0
- data/LICENSE.txt +21 -0
- data/README.md +99 -0
- data/Rakefile +8 -0
- data/bin/console +19 -0
- data/bin/setup +8 -0
- data/codat.gemspec +44 -0
- data/lib/codat.rb +27 -0
- data/lib/codat/base_model.rb +64 -0
- data/lib/codat/camelizer.rb +14 -0
- data/lib/codat/client.rb +41 -0
- data/lib/codat/configuration.rb +12 -0
- data/lib/codat/errors.rb +15 -0
- data/lib/codat/faraday_codat_auth.rb +27 -0
- data/lib/codat/models/bank_account.rb +25 -0
- data/lib/codat/models/bank_statement.rb +27 -0
- data/lib/codat/models/company.rb +35 -0
- data/lib/codat/models/financial.rb +58 -0
- data/lib/codat/models/report.rb +25 -0
- data/lib/codat/version.rb +5 -0
- metadata +280 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 92ae19ae782d5a282bfe31ac82a20578fe5f69c7ddf3db320580e4d23af4a511
|
4
|
+
data.tar.gz: c76eb6c58326f6bc12b8c6b2bdb622541e5dd93ac07c3e369af0d59b01004488
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c4f2c95fb7cdd9c33f059ea0892af826e3c9b24aeec3f01a300fbf3633d4f7a1a4dad3d6b73680035ab0fd6b669e2d4aede3cb3e66ee8de5fe6153ad7ba4f68c
|
7
|
+
data.tar.gz: 6548792832997f953b496bc7e108ea67f6efe334e45e06f81389ef8d6d9f29e1555bf387467b5fb72a40d0cf77c49089b920c6ca8b32c250140c213a6a0ae11d
|
data/.gitignore
ADDED
data/.gitlab-ci.yml
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require: rubocop-rspec
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
TargetRubyVersion: 2.5.1
|
5
|
+
|
6
|
+
# Don't force top level comments in every class
|
7
|
+
Style/Documentation:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
# A good line length is 100 chars
|
11
|
+
Metrics/LineLength:
|
12
|
+
Max: 100
|
13
|
+
AllowURI: true
|
14
|
+
|
15
|
+
Metrics/BlockLength:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Metrics/ClassLength:
|
19
|
+
Max: 300
|
20
|
+
|
21
|
+
Metrics/MethodLength:
|
22
|
+
Max: 20
|
23
|
+
|
24
|
+
Metrics/AbcSize:
|
25
|
+
Max: 30
|
26
|
+
|
27
|
+
RSpec/ExampleLength:
|
28
|
+
Enabled: false
|
29
|
+
|
30
|
+
RSpec/MultipleExpectations:
|
31
|
+
Max: 10
|
32
|
+
|
33
|
+
RSpec/RepeatedExample:
|
34
|
+
Exclude:
|
35
|
+
- 'spec/policies/**/*'
|
36
|
+
|
37
|
+
RSpec/RepeatedDescription:
|
38
|
+
Exclude:
|
39
|
+
- 'spec/policies/**/*'
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
codat (0.1.1)
|
5
|
+
faraday (~> 0.15)
|
6
|
+
faraday_middleware (~> 0.12)
|
7
|
+
faraday_middleware-multi_json (~> 0.0.6)
|
8
|
+
multi_json (~> 1.13)
|
9
|
+
rainbow (~> 3.0)
|
10
|
+
|
11
|
+
GEM
|
12
|
+
remote: https://rubygems.org/
|
13
|
+
specs:
|
14
|
+
addressable (2.5.2)
|
15
|
+
public_suffix (>= 2.0.2, < 4.0)
|
16
|
+
ast (2.4.0)
|
17
|
+
byebug (10.0.2)
|
18
|
+
coderay (1.1.2)
|
19
|
+
crack (0.4.3)
|
20
|
+
safe_yaml (~> 1.0.0)
|
21
|
+
diff-lcs (1.3)
|
22
|
+
docile (1.3.1)
|
23
|
+
dotenv (2.5.0)
|
24
|
+
faraday (0.15.3)
|
25
|
+
multipart-post (>= 1.2, < 3)
|
26
|
+
faraday_middleware (0.12.2)
|
27
|
+
faraday (>= 0.7.4, < 1.0)
|
28
|
+
faraday_middleware-multi_json (0.0.6)
|
29
|
+
faraday_middleware
|
30
|
+
multi_json
|
31
|
+
hashdiff (0.3.7)
|
32
|
+
jaro_winkler (1.5.1)
|
33
|
+
json (2.1.0)
|
34
|
+
method_source (0.9.0)
|
35
|
+
multi_json (1.13.1)
|
36
|
+
multipart-post (2.0.0)
|
37
|
+
parallel (1.12.1)
|
38
|
+
parser (2.5.1.2)
|
39
|
+
ast (~> 2.4.0)
|
40
|
+
powerpack (0.1.2)
|
41
|
+
pry (0.11.3)
|
42
|
+
coderay (~> 1.1.0)
|
43
|
+
method_source (~> 0.9.0)
|
44
|
+
pry-byebug (3.6.0)
|
45
|
+
byebug (~> 10.0)
|
46
|
+
pry (~> 0.10)
|
47
|
+
public_suffix (3.0.3)
|
48
|
+
rainbow (3.0.0)
|
49
|
+
rake (10.5.0)
|
50
|
+
rspec (3.8.0)
|
51
|
+
rspec-core (~> 3.8.0)
|
52
|
+
rspec-expectations (~> 3.8.0)
|
53
|
+
rspec-mocks (~> 3.8.0)
|
54
|
+
rspec-core (3.8.0)
|
55
|
+
rspec-support (~> 3.8.0)
|
56
|
+
rspec-expectations (3.8.1)
|
57
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
58
|
+
rspec-support (~> 3.8.0)
|
59
|
+
rspec-mocks (3.8.0)
|
60
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
61
|
+
rspec-support (~> 3.8.0)
|
62
|
+
rspec-support (3.8.0)
|
63
|
+
rubocop (0.59.2)
|
64
|
+
jaro_winkler (~> 1.5.1)
|
65
|
+
parallel (~> 1.10)
|
66
|
+
parser (>= 2.5, != 2.5.1.1)
|
67
|
+
powerpack (~> 0.1)
|
68
|
+
rainbow (>= 2.2.2, < 4.0)
|
69
|
+
ruby-progressbar (~> 1.7)
|
70
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
71
|
+
rubocop-rspec (1.29.1)
|
72
|
+
rubocop (>= 0.58.0)
|
73
|
+
ruby-progressbar (1.10.0)
|
74
|
+
safe_yaml (1.0.4)
|
75
|
+
simplecov (0.16.1)
|
76
|
+
docile (~> 1.1)
|
77
|
+
json (>= 1.8, < 3)
|
78
|
+
simplecov-html (~> 0.10.0)
|
79
|
+
simplecov-html (0.10.2)
|
80
|
+
unicode-display_width (1.4.0)
|
81
|
+
vcr (4.0.0)
|
82
|
+
webmock (3.4.2)
|
83
|
+
addressable (>= 2.3.6)
|
84
|
+
crack (>= 0.3.2)
|
85
|
+
hashdiff
|
86
|
+
|
87
|
+
PLATFORMS
|
88
|
+
ruby
|
89
|
+
|
90
|
+
DEPENDENCIES
|
91
|
+
bundler (~> 1.16)
|
92
|
+
codat!
|
93
|
+
dotenv (~> 2.5)
|
94
|
+
pry-byebug (~> 3.6)
|
95
|
+
rake (~> 10.0)
|
96
|
+
rspec (~> 3.0)
|
97
|
+
rubocop (~> 0.58)
|
98
|
+
rubocop-rspec (~> 1.27)
|
99
|
+
simplecov (~> 0.16)
|
100
|
+
vcr (~> 4.0.0)
|
101
|
+
webmock (~> 3.4.2)
|
102
|
+
|
103
|
+
BUNDLED WITH
|
104
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Ricardo Otero
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
# Codat
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'codat'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install codat
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Bank bankAccounts
|
22
|
+
|
23
|
+
To get a list of bank accounts:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
list = BankAccount.all(company_id: 'a49b891d-a593-43aa-bb82-0d8b108eb3ac')
|
27
|
+
# => []
|
28
|
+
```
|
29
|
+
|
30
|
+
### Financial financials
|
31
|
+
|
32
|
+
To get a financial reports - profit & loss:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
list = Financial.profit_and_loss(
|
36
|
+
company_id: 'a49b891d-a593-43aa-bb82-0d8b108eb3ac',
|
37
|
+
period_length: '2',
|
38
|
+
periods_to_compare: '2'
|
39
|
+
)
|
40
|
+
# => []
|
41
|
+
```
|
42
|
+
|
43
|
+
To get a financial reports - balance sheet:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
list = BankAccount.balance_sheet(
|
47
|
+
company_id: 'a49b891d-a593-43aa-bb82-0d8b108eb3ac',
|
48
|
+
period_length: period_length,
|
49
|
+
periods_to_compare: periods_to_compare
|
50
|
+
)
|
51
|
+
```
|
52
|
+
|
53
|
+
### Company companies
|
54
|
+
|
55
|
+
To get a list of companies (paginated):
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
list = Company.all(page: '1')
|
59
|
+
# => []
|
60
|
+
```
|
61
|
+
|
62
|
+
To create a company:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
response = Company.create(name: 'company name')
|
66
|
+
# => {}
|
67
|
+
```
|
68
|
+
|
69
|
+
### Report reports
|
70
|
+
|
71
|
+
To get a list of reports for aged debtor:
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
list = Report.all(company_id: 'a49b891d-a593-43aa-bb82-0d8b108eb3ac')
|
75
|
+
# => []
|
76
|
+
```
|
77
|
+
|
78
|
+
### BankStatement bankStatements
|
79
|
+
|
80
|
+
To get a list of bank statements:
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
list = BankStatement.all(company_id: 'a49b891d-a593-43aa-bb82-0d8b108eb3ac')
|
84
|
+
# => []
|
85
|
+
```
|
86
|
+
|
87
|
+
## Development
|
88
|
+
|
89
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
90
|
+
|
91
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
92
|
+
|
93
|
+
## Contributing
|
94
|
+
|
95
|
+
Bug reports and pull requests are welcome on GitHub at https://gitlab.com/finpoint/codat.
|
96
|
+
|
97
|
+
## License
|
98
|
+
|
99
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'codat'
|
6
|
+
|
7
|
+
require 'dotenv'
|
8
|
+
Dotenv.load
|
9
|
+
|
10
|
+
Codat.configure do |config|
|
11
|
+
config.api_key = ENV['API_KEY']
|
12
|
+
end
|
13
|
+
|
14
|
+
# To avoid having to namespace everything when inside the console.
|
15
|
+
Object.send(:include, Codat)
|
16
|
+
Object.send(:include, Codat::Models)
|
17
|
+
|
18
|
+
require 'pry'
|
19
|
+
Pry.start
|
data/bin/setup
ADDED
data/codat.gemspec
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
|
7
|
+
require 'codat/version'
|
8
|
+
|
9
|
+
Gem::Specification.new do |spec|
|
10
|
+
spec.name = 'codat'
|
11
|
+
spec.version = Codat::VERSION
|
12
|
+
spec.authors = ['Ricardo Otero']
|
13
|
+
spec.email = ['oterosantos@gmail.com']
|
14
|
+
|
15
|
+
spec.summary = 'Codat API wrapper in Ruby'
|
16
|
+
spec.description = spec.summary
|
17
|
+
spec.homepage = 'https://gitlab.com/finpoint/codat'
|
18
|
+
spec.license = 'MIT'
|
19
|
+
|
20
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
21
|
+
f.match(%r{^(test|spec|features)/})
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.bindir = 'exe'
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ['lib']
|
27
|
+
|
28
|
+
spec.add_dependency 'faraday', '~> 0.15'
|
29
|
+
spec.add_dependency 'faraday_middleware', '~> 0.12'
|
30
|
+
spec.add_dependency 'faraday_middleware-multi_json', '~> 0.0.6'
|
31
|
+
spec.add_dependency 'multi_json', '~> 1.13'
|
32
|
+
spec.add_dependency 'rainbow', '~> 3.0'
|
33
|
+
|
34
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
35
|
+
spec.add_development_dependency 'dotenv', '~> 2.5'
|
36
|
+
spec.add_development_dependency 'pry-byebug', '~> 3.6'
|
37
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
38
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
39
|
+
spec.add_development_dependency 'rubocop', '~> 0.58'
|
40
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 1.27'
|
41
|
+
spec.add_development_dependency 'simplecov', '~> 0.16'
|
42
|
+
spec.add_development_dependency 'vcr', '~> 4.0.0'
|
43
|
+
spec.add_development_dependency 'webmock', '~> 3.4.2'
|
44
|
+
end
|
data/lib/codat.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'codat/version'
|
4
|
+
require 'codat/configuration'
|
5
|
+
require 'codat/client'
|
6
|
+
|
7
|
+
require 'codat/models/bank_account'
|
8
|
+
require 'codat/models/financial'
|
9
|
+
require 'codat/models/company'
|
10
|
+
require 'codat/models/report'
|
11
|
+
require 'codat/models/bank_statement'
|
12
|
+
|
13
|
+
module Codat
|
14
|
+
module_function
|
15
|
+
|
16
|
+
def configure
|
17
|
+
yield(configuration)
|
18
|
+
end
|
19
|
+
|
20
|
+
def client
|
21
|
+
@client ||= Client.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def configuration
|
25
|
+
@configuration ||= Configuration.new
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'codat/errors'
|
4
|
+
require 'codat/camelizer'
|
5
|
+
|
6
|
+
module Codat
|
7
|
+
class BaseModel
|
8
|
+
class << self
|
9
|
+
def get(path, params = {})
|
10
|
+
result = Codat.client.get(path.strip, params)
|
11
|
+
|
12
|
+
raise APIKeyError, result.body[:error] if result.status == 401
|
13
|
+
|
14
|
+
result
|
15
|
+
end
|
16
|
+
|
17
|
+
def post(path, params = {})
|
18
|
+
result = Codat.client.post(path.strip, params)
|
19
|
+
|
20
|
+
raise APIKeyError, result.body[:error] if result.status == 401
|
21
|
+
|
22
|
+
result
|
23
|
+
end
|
24
|
+
|
25
|
+
def attributes(*attributes)
|
26
|
+
@attributes ||= []
|
27
|
+
|
28
|
+
return @attributes unless attributes
|
29
|
+
|
30
|
+
attr_accessor(*attributes)
|
31
|
+
|
32
|
+
@attributes += attributes
|
33
|
+
end
|
34
|
+
|
35
|
+
def format_url(url, params)
|
36
|
+
formatted = url.dup.strip
|
37
|
+
|
38
|
+
params.each { |key, value| formatted.sub!(":#{key}", value) }
|
39
|
+
|
40
|
+
formatted
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Sets all the instance variables by reading the JSON from Codat and converting the keys from
|
45
|
+
# camelCase to snake_case, as it's the standard in Ruby.
|
46
|
+
def initialize(json: {}, key_transformer: Camelizer)
|
47
|
+
self.class.attributes.each do |attr|
|
48
|
+
send("#{attr}=", json[key_transformer.transform(attr)])
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def get(path, params = {})
|
53
|
+
self.class.get(path, params)
|
54
|
+
end
|
55
|
+
|
56
|
+
def post(path, params = {})
|
57
|
+
self.class.post(path, params)
|
58
|
+
end
|
59
|
+
|
60
|
+
def format_url(url, params)
|
61
|
+
self.class.format_url(url, params)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Codat
|
4
|
+
class Camelizer
|
5
|
+
# Converts this_is_my_string to thisIsMyString and returns it as a symbol.
|
6
|
+
def self.transform(underscore_string)
|
7
|
+
parts = underscore_string.to_s.split('_')
|
8
|
+
|
9
|
+
rest = parts[1..-1].map(&:capitalize)
|
10
|
+
|
11
|
+
rest.unshift(parts[0]).join.to_sym
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/codat/client.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'faraday'
|
4
|
+
require 'faraday_middleware/multi_json'
|
5
|
+
require 'codat/faraday_codat_auth'
|
6
|
+
|
7
|
+
module Codat
|
8
|
+
class Client
|
9
|
+
BASE_URLS = {
|
10
|
+
production: 'https://api.codat.io/',
|
11
|
+
uat: 'https://api-uat.codat.io/'
|
12
|
+
}.freeze
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
Faraday::Request.register_middleware codat_auth: -> { Codat::FaradayCodatAuth }
|
16
|
+
end
|
17
|
+
|
18
|
+
def get(path, params = {})
|
19
|
+
connection.get(path, params)
|
20
|
+
end
|
21
|
+
|
22
|
+
def post(path, params = {})
|
23
|
+
connection.post(path, MultiJson.dump(params))
|
24
|
+
end
|
25
|
+
|
26
|
+
def connection
|
27
|
+
@connection ||= Faraday.new(url: api_url) do |conn|
|
28
|
+
conn.request :codat_auth, Codat.configuration.api_key
|
29
|
+
conn.response :multi_json, symbolize_keys: true
|
30
|
+
# conn.response :logger # if Codat.configuration.debug?
|
31
|
+
conn.adapter Faraday.default_adapter
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def api_url
|
38
|
+
BASE_URLS.dig(Codat.configuration.environment.to_sym)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/codat/errors.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Codat
|
4
|
+
class APIKeyError < StandardError
|
5
|
+
end
|
6
|
+
|
7
|
+
class GenericError < StandardError
|
8
|
+
end
|
9
|
+
|
10
|
+
class CompanyNotProvidedError < StandardError
|
11
|
+
end
|
12
|
+
|
13
|
+
class InvalidRequestError < StandardError
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'base64'
|
4
|
+
require 'codat/version'
|
5
|
+
require 'codat/errors'
|
6
|
+
|
7
|
+
module Codat
|
8
|
+
class FaradayCodatAuth < Faraday::Middleware
|
9
|
+
def initialize(app, api_key = '', options = {})
|
10
|
+
@app = app
|
11
|
+
@api_key = api_key
|
12
|
+
@options = options
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
unless @api_key&.size&.positive?
|
17
|
+
raise APIKeyError, 'Missing api_key! Use a Codat.configure block to add your key.'
|
18
|
+
end
|
19
|
+
|
20
|
+
env[:request_headers]['Authorization'] = "Basic #{Base64.encode64(@api_key)}"
|
21
|
+
env[:request_headers]['Content-Type'] = 'application/json'
|
22
|
+
env[:request_headers]['User-Agent'] = "finpoint/#{Codat::VERSION}"
|
23
|
+
|
24
|
+
@app.call(env)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'codat/base_model'
|
4
|
+
|
5
|
+
module Codat
|
6
|
+
module Models
|
7
|
+
# Bank accounts for a given company.
|
8
|
+
class BankAccount < BaseModel
|
9
|
+
ENDPOINT = '/companies/:company_id/data/bankAccounts'
|
10
|
+
|
11
|
+
attributes :id, :account_name, :from_date, :to_date, :sort_code, :account_number, :iban
|
12
|
+
attributes :currency, :balance, :available_balance, :modified_date, :source_modified_date
|
13
|
+
|
14
|
+
def self.all(company_id:)
|
15
|
+
url = format_url(ENDPOINT, company_id: company_id.to_s.strip)
|
16
|
+
|
17
|
+
result = get(url)
|
18
|
+
|
19
|
+
return [] if result.status == 404
|
20
|
+
|
21
|
+
result.body.map { |account| new(json: account) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'codat/base_model'
|
4
|
+
|
5
|
+
module Codat
|
6
|
+
module Models
|
7
|
+
# Bank statements for a given company.
|
8
|
+
class BankStatement < BaseModel
|
9
|
+
ENDPOINT = '/companies/:company_id/data/bankStatements/accounts'
|
10
|
+
|
11
|
+
attributes :id, :date, :description, :reconciled, :amount, :balance, :transaction_type
|
12
|
+
attributes :modified_date, :source_modifiedDate
|
13
|
+
|
14
|
+
def self.all(company_id:)
|
15
|
+
url = format_url(
|
16
|
+
ENDPOINT, company_id: company_id.to_s.strip
|
17
|
+
)
|
18
|
+
|
19
|
+
result = get(url)
|
20
|
+
|
21
|
+
return [] if result.status == 404
|
22
|
+
|
23
|
+
result.body.map { |bank_statement| new(json: bank_statement) }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'codat/base_model'
|
4
|
+
|
5
|
+
module Codat
|
6
|
+
module Models
|
7
|
+
# Companies for a given company.
|
8
|
+
class Company < BaseModel
|
9
|
+
ENDPOINT = '/companies'
|
10
|
+
|
11
|
+
attributes :id, :name, :platform, :redirect, :status, :last_sync, :data_connections
|
12
|
+
attributes :integration_id, :source_id, :platform_name, :link_url
|
13
|
+
|
14
|
+
def self.all(params = {})
|
15
|
+
result = get(ENDPOINT, params)
|
16
|
+
|
17
|
+
return [] if result.status == 404
|
18
|
+
|
19
|
+
return result.body if result.status == 400
|
20
|
+
|
21
|
+
result.body[:results].map { |company| new(json: company) }
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.create(params = {})
|
25
|
+
url = format_url(ENDPOINT, {})
|
26
|
+
|
27
|
+
result = post(url, params)
|
28
|
+
|
29
|
+
return { error: 'An error occured.' } if result.status == 404 || result.status == 400
|
30
|
+
|
31
|
+
new(json: result.body)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'codat/base_model'
|
4
|
+
|
5
|
+
module Codat
|
6
|
+
module Models
|
7
|
+
# Financials for a given company.
|
8
|
+
class Financial < BaseModel
|
9
|
+
ENDPOINT = {
|
10
|
+
profit_and_loss: '/companies/:company_id/data/financials/profitAndLoss',
|
11
|
+
balance_sheet: '/companies/:company_id/data/financials/balanceSheet'
|
12
|
+
}.freeze
|
13
|
+
|
14
|
+
attributes :from_date, :to_date, :income, :account_id, :name, :value, :items
|
15
|
+
attributes :cost_of_sales, :gross_profit, :expenses, :net_operating_profit, :other_expenses
|
16
|
+
attributes :other_income, :net_other_income, :net_profit
|
17
|
+
|
18
|
+
def self.profit_and_loss(params = {})
|
19
|
+
company_id = params.delete(:company_id)
|
20
|
+
|
21
|
+
raise CompanyNotProvidedError if company_id.nil? || company_id.empty?
|
22
|
+
|
23
|
+
url = format_url(
|
24
|
+
ENDPOINT[:profit_and_loss],
|
25
|
+
company_id: company_id.to_s.strip
|
26
|
+
)
|
27
|
+
|
28
|
+
params = params.map { |key, value| [Camelizer.transform(key), value] }.to_h
|
29
|
+
|
30
|
+
result = get(url, params)
|
31
|
+
|
32
|
+
return [] if result.status == 404 || result.status == 400
|
33
|
+
|
34
|
+
result.body[:reports].map { |report| new(json: report) }
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.balance_sheet(params = {})
|
38
|
+
company_id = params.delete(:company_id)
|
39
|
+
|
40
|
+
raise CompanyNotProvidedError if company_id.nil? || company_id.empty?
|
41
|
+
|
42
|
+
url = format_url(
|
43
|
+
ENDPOINT[:balance_sheet],
|
44
|
+
company_id: company_id.to_s.strip
|
45
|
+
)
|
46
|
+
|
47
|
+
params.delete(:company_id)
|
48
|
+
params = params.map { |key, value| [Camelizer.transform(key), value] }.to_h
|
49
|
+
|
50
|
+
result = get(url, params)
|
51
|
+
|
52
|
+
return [] if result.status == 404 || result.status == 400
|
53
|
+
|
54
|
+
result.body[:reports].map { |report| new(json: report) }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'codat/base_model'
|
4
|
+
|
5
|
+
module Codat
|
6
|
+
module Models
|
7
|
+
# Reports for a given company.
|
8
|
+
class Report < BaseModel
|
9
|
+
ENDPOINT = '/companies/:company_id/reports/agedDebtor'
|
10
|
+
|
11
|
+
attributes :id, :customer_id, :customer_name, :aged_currency_outstanding, :currency
|
12
|
+
attributes :aged_outstanding_amounts, :from_date, :to_date, :amount
|
13
|
+
|
14
|
+
def self.all(company_id:)
|
15
|
+
url = format_url(ENDPOINT, company_id: company_id.to_s.strip)
|
16
|
+
|
17
|
+
result = get(url)
|
18
|
+
|
19
|
+
return [] if result.status == 404
|
20
|
+
|
21
|
+
result.body[:data].map { |report| new(json: report) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,280 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: codat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ricardo Otero
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-09-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.15'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.12'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday_middleware-multi_json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.0.6
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.0.6
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: multi_json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.13'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.13'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rainbow
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.16'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.16'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: dotenv
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.5'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.5'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry-byebug
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.6'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.6'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rake
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '10.0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '10.0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rspec
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '3.0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '3.0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rubocop
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0.58'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0.58'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: rubocop-rspec
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '1.27'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '1.27'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: simplecov
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - "~>"
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0.16'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - "~>"
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0.16'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: vcr
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - "~>"
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: 4.0.0
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - "~>"
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: 4.0.0
|
209
|
+
- !ruby/object:Gem::Dependency
|
210
|
+
name: webmock
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - "~>"
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: 3.4.2
|
216
|
+
type: :development
|
217
|
+
prerelease: false
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - "~>"
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: 3.4.2
|
223
|
+
description: Codat API wrapper in Ruby
|
224
|
+
email:
|
225
|
+
- oterosantos@gmail.com
|
226
|
+
executables: []
|
227
|
+
extensions: []
|
228
|
+
extra_rdoc_files: []
|
229
|
+
files:
|
230
|
+
- ".gitignore"
|
231
|
+
- ".gitlab-ci.yml"
|
232
|
+
- ".rspec"
|
233
|
+
- ".rubocop.yml"
|
234
|
+
- ".travis.yml"
|
235
|
+
- Gemfile
|
236
|
+
- Gemfile.lock
|
237
|
+
- LICENSE.txt
|
238
|
+
- README.md
|
239
|
+
- Rakefile
|
240
|
+
- bin/console
|
241
|
+
- bin/setup
|
242
|
+
- codat.gemspec
|
243
|
+
- lib/codat.rb
|
244
|
+
- lib/codat/base_model.rb
|
245
|
+
- lib/codat/camelizer.rb
|
246
|
+
- lib/codat/client.rb
|
247
|
+
- lib/codat/configuration.rb
|
248
|
+
- lib/codat/errors.rb
|
249
|
+
- lib/codat/faraday_codat_auth.rb
|
250
|
+
- lib/codat/models/bank_account.rb
|
251
|
+
- lib/codat/models/bank_statement.rb
|
252
|
+
- lib/codat/models/company.rb
|
253
|
+
- lib/codat/models/financial.rb
|
254
|
+
- lib/codat/models/report.rb
|
255
|
+
- lib/codat/version.rb
|
256
|
+
homepage: https://gitlab.com/finpoint/codat
|
257
|
+
licenses:
|
258
|
+
- MIT
|
259
|
+
metadata: {}
|
260
|
+
post_install_message:
|
261
|
+
rdoc_options: []
|
262
|
+
require_paths:
|
263
|
+
- lib
|
264
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
265
|
+
requirements:
|
266
|
+
- - ">="
|
267
|
+
- !ruby/object:Gem::Version
|
268
|
+
version: '0'
|
269
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
270
|
+
requirements:
|
271
|
+
- - ">="
|
272
|
+
- !ruby/object:Gem::Version
|
273
|
+
version: '0'
|
274
|
+
requirements: []
|
275
|
+
rubyforge_project:
|
276
|
+
rubygems_version: 2.7.3
|
277
|
+
signing_key:
|
278
|
+
specification_version: 4
|
279
|
+
summary: Codat API wrapper in Ruby
|
280
|
+
test_files: []
|