fractal_api 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d89b28a760db6011b437eaedb3e3e63a2a74fc46a409a2432b672b6aa940cf27
4
- data.tar.gz: 8c26a4ae622327159607d7c8da3ebe43f0c67f795a47e700682b5ba2291b8903
3
+ metadata.gz: 3f69db059dd2de004347bdda6abab14f73c54a42e1977d6443daca3dc39cf8ea
4
+ data.tar.gz: 7bd7622a2f7a8771de1ba1aff2fee460115b30f46375d88535e204e0a22f22e5
5
5
  SHA512:
6
- metadata.gz: 8543f1bdbad21a672d63583d1e638809a4c8411c445afdaf32aa1c077ec76470264e32576cfea5f42a0ef398bbdad0f04654ae8489d12f07270b606e89dc156f
7
- data.tar.gz: c82c9cdba46ccf45773275fc90d721a9e473e58ead8864928d84e6ba4395b260d0811cb10a0017979f2f8911ca7acdbe86c40bd98088daab98fb7616bfca2293
6
+ metadata.gz: e7ce8cd567a6268bc854f41cf163f8f98ac0919fe41e1369025dfac13a4ce3e41fd87f1d0ae71037003f9b12de1fc6fba38cf9ffa892d92b31281f1953b183dc
7
+ data.tar.gz: d6411a3228f4d22eef65e90dbbdb0fb03138ed797e565c82d3159118e09c56b6be340140393bdef76898c08f5afb52c037e33a5ed381b69c4336d0677345ebbe
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fractal_api (0.1.1)
4
+ fractal_api (0.1.2)
5
5
  faraday
6
6
  faraday_middleware
7
7
  faraday_middleware-multi_json
@@ -17,11 +17,15 @@ GEM
17
17
  rexml
18
18
  diff-lcs (1.4.4)
19
19
  dotenv (2.7.6)
20
- faraday (1.3.0)
20
+ faraday (1.4.1)
21
+ faraday-excon (~> 1.1)
21
22
  faraday-net_http (~> 1.0)
23
+ faraday-net_http_persistent (~> 1.1)
22
24
  multipart-post (>= 1.2, < 3)
23
- ruby2_keywords
25
+ ruby2_keywords (>= 0.0.4)
26
+ faraday-excon (1.1.0)
24
27
  faraday-net_http (1.0.1)
28
+ faraday-net_http_persistent (1.1.0)
25
29
  faraday_middleware (1.0.0)
26
30
  faraday (~> 1.0)
27
31
  faraday_middleware-multi_json (0.0.6)
data/lib/fractal_api.rb CHANGED
@@ -10,6 +10,9 @@ require 'fractal_api/consent'
10
10
  require 'fractal_api/bank_account'
11
11
  require 'fractal_api/balance'
12
12
  require 'fractal_api/transaction'
13
+ require 'fractal_api/forecasting/forecast'
14
+ require 'fractal_api/forecasting/balance'
15
+ require 'fractal_api/forecasting/transaction'
13
16
 
14
17
  module FractalApi
15
18
  module_function
@@ -38,6 +41,7 @@ module FractalApi
38
41
 
39
42
  yield
40
43
 
44
+ ensure
41
45
  Thread.current[:fractal_api_token] = nil
42
46
  end
43
47
 
@@ -49,13 +49,15 @@ module FractalApi
49
49
 
50
50
  case response.status
51
51
  when 400
52
- raise InvalidRequestError, response.body
52
+ raise InvalidRequestError, response.body.inspect
53
53
  when 401
54
- raise APIKeyError, response.body
54
+ raise APIKeyError, response.body.inspect
55
55
  when 403
56
- raise UnauthorizedError, response.body
56
+ raise UnauthorizedError, response.body.inspect
57
+ when 404
58
+ raise NotFoundError, response.body.inspect
57
59
  else
58
- raise GenericError, response.body
60
+ raise GenericError, "#{response.status}: #{response.body.inspect}"
59
61
  end
60
62
  end
61
63
  end
@@ -7,5 +7,7 @@ module FractalApi
7
7
 
8
8
  class GenericError < StandardError; end
9
9
 
10
+ class NotFoundError < StandardError; end
11
+
10
12
  class InvalidRequestError < StandardError; end
11
13
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'time'
4
+ require 'fractal_api/base_model'
5
+ require 'fractal_api/paginator'
6
+
7
+ module FractalApi
8
+ module Forecasting
9
+ class Balance < BaseModel
10
+ attributes :id, :bank_id, :forecast_id, :account_id,
11
+ :amount, :currency, :date, :type, :source
12
+
13
+ def self.all(company_id, filters = {})
14
+ filters = filters.transform_keys { |key| key_transformer.transform(key) }
15
+
16
+ Paginator.new('/forecasting/v2/balances', self) do |url|
17
+ get(
18
+ url,
19
+ params: filters,
20
+ headers: { 'X-Company-Id' => company_id }
21
+ )
22
+ end
23
+ end
24
+
25
+ def self.build(json:)
26
+ super.tap do |record|
27
+ record.date = Time.parse(record.date) if record.date
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'time'
4
+ require 'fractal_api/base_model'
5
+ require 'fractal_api/paginator'
6
+
7
+ module FractalApi
8
+ module Forecasting
9
+ class Forecast < BaseModel
10
+ attributes :id, :bank_id, :account_id,
11
+ :name, :date, :type, :source
12
+
13
+ def self.all(company_id, filters = {})
14
+ filters = filters.transform_keys { |key| key_transformer.transform(key) }
15
+
16
+ Paginator.new('/forecasting/v2/forecasts', self) do |url|
17
+ get(
18
+ url,
19
+ params: filters,
20
+ headers: { 'X-Company-Id' => company_id }
21
+ )
22
+ end
23
+ end
24
+
25
+ def self.build(json:)
26
+ super.tap do |record|
27
+ record.date = Time.parse(record.date) if record.date
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'time'
4
+ require 'fractal_api/base_model'
5
+ require 'fractal_api/paginator'
6
+
7
+ module FractalApi
8
+ module Forecasting
9
+ class Transaction < BaseModel
10
+ attributes :id, :bank_id, :forecast_id, :account_id,
11
+ :value_date, :amount, :currency,
12
+ :type, :merchant, :category, :reasons, :source
13
+
14
+ def self.all(company_id, filters = {})
15
+ filters = filters.transform_keys { |key| key_transformer.transform(key) }
16
+
17
+ Paginator.new('/forecasting/v2/transactions', self) do |url|
18
+ get(
19
+ url,
20
+ params: filters,
21
+ headers: { 'X-Company-Id' => company_id }
22
+ )
23
+ end
24
+ end
25
+
26
+ def self.build(json:)
27
+ super.tap do |record|
28
+ record.value_date = Time.parse(record.value_date) if record.value_date
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FractalApi
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fractal_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Finpoint
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-02 00:00:00.000000000 Z
11
+ date: 2021-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -197,6 +197,9 @@ files:
197
197
  - lib/fractal_api/consent.rb
198
198
  - lib/fractal_api/errors.rb
199
199
  - lib/fractal_api/faraday_auth.rb
200
+ - lib/fractal_api/forecasting/balance.rb
201
+ - lib/fractal_api/forecasting/forecast.rb
202
+ - lib/fractal_api/forecasting/transaction.rb
200
203
  - lib/fractal_api/merchant.rb
201
204
  - lib/fractal_api/paged_response.rb
202
205
  - lib/fractal_api/paginator.rb