bridge_bankin 0.1.0 → 0.1.1

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.
@@ -2,7 +2,19 @@
2
2
 
3
3
  module BridgeBankin
4
4
  module API
5
+ #
6
+ # Error is the base error from which all other more specific BridgeBankin errors derive.
7
+ #
5
8
  class Error < StandardError
9
+ #
10
+ # Initializes Error
11
+ #
12
+ # @param [String] code the HTTP code returned by the API
13
+ # @param [Hash] response_body the parsed API response
14
+ # @option response_body [String] :type the machine readable error message
15
+ # @option response_body [String] :message the human readable error message
16
+ # @option response_body [String] :documentation_url the optional link to documentation
17
+ #
6
18
  def initialize(code, response_body = {})
7
19
  @payload = response_body
8
20
  @code = code
@@ -2,14 +2,17 @@
2
2
 
3
3
  module BridgeBankin
4
4
  module API
5
+ #
6
+ # Extend any resource class with API specific methods
7
+ #
5
8
  module Resource
9
+ private
10
+
6
11
  def protected_resource(access_token)
7
12
  api_client.access_token = access_token
8
13
  yield
9
14
  end
10
15
 
11
- private
12
-
13
16
  def api_client
14
17
  @api_client ||= API::Client.new
15
18
  end
@@ -3,9 +3,18 @@
3
3
  require "time"
4
4
 
5
5
  module BridgeBankin
6
+ #
7
+ # User authentication & authorization
8
+ #
6
9
  class Authorization
7
10
  attr_reader :access_token, :expires_at
8
11
 
12
+ #
13
+ # Initializes Authorization
14
+ #
15
+ # @param [String] access_token access token the access token provided by the API
16
+ # @param [Time] expires_at the expiration time for the provided access token
17
+ #
9
18
  def initialize(access_token, expires_at)
10
19
  @access_token = access_token
11
20
  @expires_at = Time.parse(expires_at)
@@ -14,6 +23,14 @@ module BridgeBankin
14
23
  class << self
15
24
  include API::Resource
16
25
 
26
+ #
27
+ # Authenticate user with the corresponding credentials
28
+ #
29
+ # @param [String] email the registered user email
30
+ # @param [String] password the registered user password
31
+ #
32
+ # @return [Authorization] the authorization informations provided by the API
33
+ #
17
34
  def generate_token(email:, password:)
18
35
  response = api_client.post("/v2/authenticate", email: email, password: password)
19
36
  new(response[:access_token], response[:expires_at])
@@ -1,17 +1,35 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BridgeBankin
4
+ #
5
+ # Bank resource
6
+ #
4
7
  class Bank < BridgeObject
5
8
  RESOURCE_TYPE = "bank"
6
9
 
7
10
  class << self
8
11
  include API::Resource
9
12
 
13
+ #
14
+ # List all banks supported by the Bridge API
15
+ #
16
+ # @param [Hash] params any params that might be required (or optional) to communicate with the API
17
+ #
18
+ # @return [Array<Bank>] the supported banks list
19
+ #
10
20
  def list(**params)
11
21
  data = api_client.get("/v2/banks", params)
12
22
  convert_to_bridge_object(data)
13
23
  end
14
24
 
25
+ #
26
+ # Retrieve a single bank
27
+ #
28
+ # @param [Integer] id the id of the requested resource
29
+ # @param [Hash] params any params that might be required (or optional) to communicate with the API
30
+ #
31
+ # @return [Bank] the requested bank
32
+ #
15
33
  def find(id:, **params)
16
34
  data = api_client.get("/v2/banks/#{id}", params)
17
35
  convert_to_bridge_object(data)
@@ -1,14 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BridgeBankin
4
+ #
5
+ # BridgeObject is the base class from which all other more specific BridgeBankin resources derive.
6
+ #
4
7
  class BridgeObject
5
8
  HIDDEN_ATTRIBUTES = %i[resource_type resource_uri].freeze
6
9
 
10
+ #
11
+ # Initializes BridgeObject
12
+ #
13
+ # @param [Hash] attrs any informations returned by the API as a valid response
14
+ #
7
15
  def initialize(**attrs)
8
16
  define_instance_variables(attrs)
9
17
  end
10
18
 
11
19
  class << self
20
+ #
21
+ # Convert any API response body with its corresponding resource object if exists
22
+ #
23
+ # @param [Hash] data parsed API response body
24
+ #
25
+ # @return [Account, Bank, Category, Item, Stock, Transaction, Transfer, User, BridgeObject] a resource object
26
+ #
12
27
  def convert_to_bridge_object(**data)
13
28
  if data[:resources]
14
29
  data[:resources].map { |resource| convert_to_bridge_object(resource) }
@@ -1,17 +1,35 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BridgeBankin
4
+ #
5
+ # Category resource
6
+ #
4
7
  class Category < BridgeObject
5
8
  RESOURCE_TYPE = "category"
6
9
 
7
10
  class << self
8
11
  include API::Resource
9
12
 
13
+ #
14
+ # List all categories supported by the Bridge API
15
+ #
16
+ # @param [Hash] params any params that might be required (or optional) to communicate with the API
17
+ #
18
+ # @return [Array<Category>] the supported categories list
19
+ #
10
20
  def list(**params)
11
21
  data = api_client.get("/v2/categories", params)
12
22
  convert_to_bridge_object(data)
13
23
  end
14
24
 
25
+ #
26
+ # Retrieve a single category
27
+ #
28
+ # @param [Integer] id the id of the requested resource
29
+ # @param [Hash] params any params that might be required (or optional) to communicate with the API
30
+ #
31
+ # @return [Category] the requested category
32
+ #
15
33
  def find(id:, **params)
16
34
  data = api_client.get("/v2/categories/#{id}", params)
17
35
  convert_to_bridge_object(data)
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ #
4
+ # BridgeBankin module
5
+ #
3
6
  module BridgeBankin
4
7
  def self.configuration
5
8
  @configuration ||= Configuration.new
@@ -13,10 +16,16 @@ module BridgeBankin
13
16
  yield configuration
14
17
  end
15
18
 
19
+ #
20
+ # Configurations setup
21
+ #
16
22
  class Configuration
17
23
  attr_reader :api_base_url, :api_version
18
24
  attr_accessor :api_client_id, :api_client_secret
19
25
 
26
+ #
27
+ # Initializes Configuration
28
+ #
20
29
  def initialize
21
30
  @api_base_url = "https://sync.bankin.com"
22
31
  @api_version = "2019-02-18"
@@ -1,10 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BridgeBankin
4
+ #
5
+ # Connect resource
6
+ #
4
7
  class Connect < BridgeObject
5
8
  class << self
6
9
  include API::Resource
7
10
 
11
+ #
12
+ # Request URL to Bridge's Connect funnel for adding an item
13
+ #
14
+ # @param [String] access_token the access token provided during the user authentication
15
+ # @param [Hash] params any params that might be required (or optional) to communicate with the API
16
+ #
17
+ # @return [BridgeObject] URL to Bridge's Connect funnel for adding an item
18
+ #
8
19
  def connect_item(access_token:, **params)
9
20
  protected_resource(access_token) do
10
21
  data = api_client.get("/v2/connect/items/add/url", params)
@@ -12,6 +23,14 @@ module BridgeBankin
12
23
  end
13
24
  end
14
25
 
26
+ #
27
+ # Returns the URL to Bridge's Connect funnel for adding an item using IBAN
28
+ #
29
+ # @param [String] access_token the access token provided during the user authentication
30
+ # @param [Hash] params any params that might be required (or optional) to communicate with the API
31
+ #
32
+ # @return [BridgeObject] the URL to Bridge's Connect funnel for adding an item using IBAN
33
+ #
15
34
  def connect_item_with_iban(access_token:, **params)
16
35
  protected_resource(access_token) do
17
36
  data = api_client.post("/v2/connect/items/add/url", params)
@@ -19,6 +38,14 @@ module BridgeBankin
19
38
  end
20
39
  end
21
40
 
41
+ #
42
+ # Request the URL to Bridge's Connect funnel for editing an item
43
+ #
44
+ # @param [String] access_token the access token provided during the user authentication
45
+ # @param [Hash] params any params that might be required (or optional) to communicate with the API
46
+ #
47
+ # @return [BridgeObject] the URL to Bridge's Connect funnel for editing an item
48
+ #
22
49
  def edit_item(access_token:, **params)
23
50
  protected_resource(access_token) do
24
51
  data = api_client.get("/v2/connect/items/edit/url", params)
@@ -26,6 +53,15 @@ module BridgeBankin
26
53
  end
27
54
  end
28
55
 
56
+ #
57
+ # Request the URL to Bridge's Connect funnel for managing
58
+ # a Strong Customer Authentication and synchronizing an item
59
+ #
60
+ # @param [String] access_token the access token provided during the user authentication
61
+ # @param [Hash] params any params that might be required (or optional) to communicate with the API
62
+ #
63
+ # @return [BridgeObject] the URL to Bridge's Connect funnel for managing
64
+ #
29
65
  def item_sync(access_token:, **params)
30
66
  protected_resource(access_token) do
31
67
  data = api_client.get("/v2/connect/items/sync", params)
@@ -33,6 +69,14 @@ module BridgeBankin
33
69
  end
34
70
  end
35
71
 
72
+ #
73
+ # Request the URL to Bridge's Connect funnel for validating a user's email
74
+ #
75
+ # @param [String] access_token the access token provided during the user authentication
76
+ # @param [Hash] params any params that might be required (or optional) to communicate with the API
77
+ #
78
+ # @return [BridgeObject] the URL to Bridge's Connect funnel for validating a user's email
79
+ #
36
80
  def validate_email(access_token:, **params)
37
81
  protected_resource(access_token) do
38
82
  data = api_client.get("/v2/connect/users/email/confirmation/url", params)
@@ -40,6 +84,14 @@ module BridgeBankin
40
84
  end
41
85
  end
42
86
 
87
+ #
88
+ # Request the URL to Bridge's Connect funnel for validating pro items
89
+ #
90
+ # @param [String] access_token the access token provided during the user authentication
91
+ # @param [Hash] params any params that might be required (or optional) to communicate with the API
92
+ #
93
+ # @return [BridgeObject] the URL to Bridge's Connect funnel for validating pro items
94
+ #
43
95
  def validate_pro_items(access_token:, **params)
44
96
  protected_resource(access_token) do
45
97
  data = api_client.get("/v2/connect/items/pro/confirmation/url", params)
@@ -1,10 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BridgeBankin
4
+ #
5
+ # Insight resource
6
+ #
4
7
  class Insight < BridgeObject
5
8
  class << self
6
9
  include API::Resource
7
10
 
11
+ #
12
+ # Categories statistics provided by Bridge
13
+ #
14
+ # @param [String] access_token the access token provided during the user authentication
15
+ # @param [Hash] params any params that might be required (or optional) to communicate with the API
16
+ #
17
+ # @return [Insight] the statistics generated by Bridge API
18
+ #
8
19
  def categories_insights(access_token:, **params)
9
20
  protected_resource(access_token) do
10
21
  data = api_client.get("/v2/insights/category", params)
@@ -1,6 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BridgeBankin
4
+ #
5
+ # Item resource (bank connector)
6
+ #
4
7
  class Item < BridgeObject
5
8
  RESOURCE_TYPE = "item"
6
9
 
@@ -9,6 +12,14 @@ module BridgeBankin
9
12
  class << self
10
13
  include API::Resource
11
14
 
15
+ #
16
+ # List all logged in user items
17
+ #
18
+ # @param [String] access_token the access token provided during the user authentication
19
+ # @param [Hash] params any params that might be required (or optional) to communicate with the API
20
+ #
21
+ # @return [Array<Item>] the user items
22
+ #
12
23
  def list(access_token:, **params)
13
24
  protected_resource(access_token) do
14
25
  data = api_client.get("/v2/items", params)
@@ -16,6 +27,15 @@ module BridgeBankin
16
27
  end
17
28
  end
18
29
 
30
+ #
31
+ # Retrieve a single item for logged in user
32
+ #
33
+ # @param [Integer] id the id of the requested resource
34
+ # @param [String] access_token the access token provided during the user authentication
35
+ # @param [Hash] params any params that might be required (or optional) to communicate with the API
36
+ #
37
+ # @return [Account] the requested user item
38
+ #
19
39
  def find(id:, access_token:, **params)
20
40
  protected_resource(access_token) do
21
41
  data = api_client.get("/v2/items/#{id}", params)
@@ -23,6 +43,15 @@ module BridgeBankin
23
43
  end
24
44
  end
25
45
 
46
+ #
47
+ # Trigger a refresh for a specific item
48
+ #
49
+ # @param [Integer] id the id of the requested resource
50
+ # @param [String] access_token the access token provided during the user authentication
51
+ # @param [Hash] params any params that might be required (or optional) to communicate with the API
52
+ #
53
+ # @return [BridgeObject] the item refresh status path
54
+ #
26
55
  def refresh(id:, access_token:, **params)
27
56
  protected_resource(access_token) do
28
57
  data = api_client.post("/v2/items/#{id}/refresh", params)
@@ -30,6 +59,15 @@ module BridgeBankin
30
59
  end
31
60
  end
32
61
 
62
+ #
63
+ # Request the refresh status of a specific item
64
+ #
65
+ # @param [Integer] id the id of the requested resource
66
+ # @param [String] access_token the access token provided during the user authentication
67
+ # @param [Hash] params any params that might be required (or optional) to communicate with the API
68
+ #
69
+ # @return [BridgeObject] the user item refresh status
70
+ #
33
71
  def refresh_status(id:, access_token:, **params)
34
72
  protected_resource(access_token) do
35
73
  data = api_client.get("/v2/items/#{id}/refresh/status", params)
@@ -37,10 +75,19 @@ module BridgeBankin
37
75
  end
38
76
  end
39
77
 
78
+ #
79
+ # Delete a specific item
80
+ #
81
+ # @param [Integer] id the id of the requested resource
82
+ # @param [String] access_token the access token provided during the user authentication
83
+ # @param [Hash] params any params that might be required (or optional) to communicate with the API
84
+ #
85
+ # @return [Boolean] the request success status
86
+ #
40
87
  def delete(id:, access_token:, **params)
41
88
  protected_resource(access_token) do
42
- data = api_client.delete("/v2/items/#{id}", params)
43
- convert_to_bridge_object(data)
89
+ api_client.delete("/v2/items/#{id}", params)
90
+ true
44
91
  end
45
92
  end
46
93
  end
@@ -1,7 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BridgeBankin
4
+ #
5
+ # Supported resources types
6
+ #
4
7
  module ObjectTypes
8
+ #
9
+ # Matches API resources with corresponding gem classes
10
+ #
11
+ # @return [Account, Bank, Category, Item, Stock, Transaction, Transfer, User, nil] the matched resource or nil
12
+ #
5
13
  def self.resource_types_to_classes
6
14
  {
7
15
  Account::RESOURCE_TYPE => Account,
@@ -1,25 +1,59 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BridgeBankin
4
+ #
5
+ # Stock resource
6
+ #
4
7
  class Stock < BridgeObject
5
8
  RESOURCE_TYPE = "stock"
6
9
 
7
10
  class << self
8
11
  include API::Resource
9
12
 
10
- def list(**params)
11
- data = api_client.get("/v2/stocks", params)
12
- convert_to_bridge_object(data)
13
+ #
14
+ # List all logged in user stocks
15
+ #
16
+ # @param [String] access_token the access token provided during the user authentication
17
+ # @param [Hash] params any params that might be required (or optional) to communicate with the API
18
+ #
19
+ # @return [Array<Stock>] the user accounts
20
+ #
21
+ def list(access_token:, **params)
22
+ protected_resource(access_token) do
23
+ data = api_client.get("/v2/stocks", params)
24
+ convert_to_bridge_object(data)
25
+ end
13
26
  end
14
27
 
15
- def list_updated(**params)
16
- data = api_client.get("/v2/stocks/updated", params)
17
- convert_to_bridge_object(data)
28
+ #
29
+ # List all logged in user updated stocks
30
+ #
31
+ # @param [String] access_token the access token provided during the user authentication
32
+ # @param [Hash] params any params that might be required (or optional) to communicate with the API
33
+ #
34
+ # @return [Array<Stock>] the user accounts
35
+ #
36
+ def list_updated(access_token:, **params)
37
+ protected_resource(access_token) do
38
+ data = api_client.get("/v2/stocks/updated", params)
39
+ convert_to_bridge_object(data)
40
+ end
18
41
  end
19
42
 
20
- def find(id:, **params)
21
- data = api_client.get("/v2/stocks/#{id}", params)
22
- convert_to_bridge_object(data)
43
+ #
44
+ # Retrieve a single stock for logged in user
45
+ #
46
+ # @param [Integer] id the id of the requested resource
47
+ # @param [String] access_token the access token provided during the user authentication
48
+ # @param [Hash] params any params that might be required (or optional) to communicate with the API
49
+ #
50
+ # @return [Account] the user accounts
51
+ #
52
+ def find(id:, access_token:, **params)
53
+ protected_resource(access_token) do
54
+ data = api_client.get("/v2/stocks/#{id}", params)
55
+ convert_to_bridge_object(data)
56
+ end
23
57
  end
24
58
  end
25
59
  end