flinks 0.3.0 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5bbbf0a02763ddebf7cc99bdada61f89ffd254e9edafa4d48fca314619bcb18b
4
- data.tar.gz: 72a81130480e91ce328d5e7e142d3b7b968f5fcb4ebf08c722d169b3af8e6f74
3
+ metadata.gz: 8b7a392806d3c94ce6e355367e627315f520970216796aa47b77f9a0208e55e1
4
+ data.tar.gz: f17b1804a6d60dbe6c11342b01b95a978e94cd6a15297a07b164402080c6941f
5
5
  SHA512:
6
- metadata.gz: 6e23c086214b89d665dc871ed5125dbca516019f864509ba2c61151288a0bf87c331de5e688a90321f09d422f4fb124f8548ca78fd7f374b1608438ba0ac05fd
7
- data.tar.gz: ddd6594be9862596243394081bf307f4204098629934d9ff4e01cbc6cebef81005e091609442d2e59faadb0746ab2c61facbc7d0247040b560a6001d6575c46f
6
+ metadata.gz: c19e8dc8039795b03b503ebbedf33cfb5b6012cf34d78204d32a34ecd5f2b7355b45032a93d27e43ec6f3f8ffe6a7e902a40d264fe32a91a78e50ba604adccec
7
+ data.tar.gz: 3482beb2baf3ad3d5a2fcfd40a47e40509c7dfcf4bc2c4a498ea74b75ae81195f32abb5cb13fd1a4d882da76896dd009d387ea15a74c0bc83027ce5c2067687e
@@ -5,9 +5,9 @@ env:
5
5
  language: ruby
6
6
 
7
7
  rvm:
8
- - 2.3.6
9
- - 2.4.3
10
- - 2.5.0
8
+ - 2.3
9
+ - 2.4
10
+ - 2.5
11
11
 
12
12
  before_script:
13
13
  - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
data/README.md CHANGED
@@ -21,34 +21,42 @@ gem 'flinks', require: 'flinks'
21
21
 
22
22
  ## Usage
23
23
 
24
- This library needs to be configured with your API customer ID.
24
+ This library needs to be configured with your API customer ID and API endpoint.
25
25
 
26
26
  ```ruby
27
- flinks = Flinks.new(customer_id: ENV['FLINKS_CUSTOMER_ID'])
27
+ flinks = Flinks.new(customer_id: ENV['FLINKS_CUSTOMER_ID'], api_endpoint: "https://YOURNAME-api.private.fin.ag/v3/")
28
28
  ```
29
29
 
30
- Configure `on_error` to catch API requests returning a 400..599 HTTP status.
30
+ Configure `on_error` to catch API requests returning a `400..599` HTTP status.
31
31
 
32
32
  ```ruby
33
33
  flinks = Flinks.new({
34
34
  customer_id: ENV['FLINKS_CUSTOMER_ID'],
35
+ api_endpoint: "https://YOURNAME-api.private.fin.ag/v3/",
35
36
  on_error: Proc.new do |status, message, body|
36
37
  p [status, message, body]
37
38
  end
38
39
  })
39
40
  ```
40
41
 
41
- Configure `debug` to print every API responses.
42
+ Configure `debug` to print every API requests and responses.
42
43
 
43
44
  ```ruby
44
45
  flinks = Flinks.new({
45
46
  customer_id: ENV['FLINKS_CUSTOMER_ID'],
47
+ api_endpoint: "https://YOURNAME-api.private.fin.ag/v3/",
46
48
  debug: true
47
49
  })
48
50
  ```
49
51
 
50
52
  ### Endpoints
51
53
 
54
+ #### Authorize
55
+
56
+ - `authorize(login_id:, options:)`
57
+ - `authorize_with_credentials(username:, password:, institution:, options:)`
58
+ - `authorize_multiple(login_ids:)`
59
+
52
60
  #### Account
53
61
 
54
62
  - `accounts_summary(request_id:, options:)`
@@ -75,6 +83,12 @@ flinks = Flinks.new({
75
83
 
76
84
  See the [API docs](https://sandbox-api.flinks.io).
77
85
 
86
+ ## Supported Ruby versions
87
+
88
+ - MRI 2.3
89
+ - MRI 2.4
90
+ - MRI 2.5
91
+
78
92
  ## Development
79
93
 
80
94
  Run all tests:
@@ -82,3 +96,7 @@ Run all tests:
82
96
  ```bash
83
97
  bundle exec rspec
84
98
  ```
99
+
100
+ ## License
101
+
102
+ [MIT](LICENSE.txt)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: flinks 0.3.0 ruby lib
5
+ # stub: flinks 0.3.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "flinks".freeze
9
- s.version = "0.3.0"
9
+ s.version = "0.3.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Philippe Dionne".freeze]
14
- s.date = "2018-02-14"
14
+ s.date = "2018-02-16"
15
15
  s.description = "Flinks financial services API client".freeze
16
16
  s.email = "dionne.phil@gmail.com".freeze
17
17
  s.extra_rdoc_files = [
@@ -41,10 +41,10 @@ module Flinks
41
41
  # @param options [Hash]
42
42
  # @return [Hash]
43
43
  def accounts_summary(request_id:, options: {})
44
- payload = AccountSummaryRequestSchema.call(options.merge(request_id: request_id))
45
- raise ArgumentError, error_message(payload) unless payload.success?
44
+ payload = options.merge(request_id: request_id)
45
+ validate_request!(AccountSummaryRequestSchema, payload)
46
46
 
47
- post("#{customer_id}/BankingServices/GetAccountsSummary", body: payload.to_h)
47
+ post("#{customer_id}/BankingServices/GetAccountsSummary", body: payload)
48
48
  end
49
49
 
50
50
  # @see https://sandbox-api.flinks.io/Readme/#get-accounts-detail
@@ -52,10 +52,10 @@ module Flinks
52
52
  # @param options [Hash]
53
53
  # @return [Hash]
54
54
  def accounts_detail(request_id:, options: {})
55
- payload = AccountDetailRequestSchema.call(options.merge(request_id: request_id))
56
- raise ArgumentError, error_message(payload) unless payload.success?
55
+ payload = options.merge(request_id: request_id)
56
+ validate_request!(AccountDetailRequestSchema, payload)
57
57
 
58
- post("#{customer_id}/BankingServices/GetAccountsDetail", body: payload.to_h)
58
+ post("#{customer_id}/BankingServices/GetAccountsDetail", body: payload)
59
59
  end
60
60
 
61
61
  # @see https://sandbox-api.flinks.io/Readme/#get-accounts-summary
@@ -42,10 +42,10 @@ module Flinks
42
42
  # @param options [Hash]
43
43
  # @return [Hash]
44
44
  def authorize(login_id:, options: {})
45
- payload = AuthorizeRequestSchema.call(options.merge(login_id: login_id))
46
- raise ArgumentError, error_message(payload) unless payload.success?
45
+ payload = options.merge(login_id: login_id)
46
+ validate_request!(AuthorizeRequestSchema, payload)
47
47
 
48
- post("#{customer_id}/BankingServices/Authorize", body: payload.to_hash)
48
+ post("#{customer_id}/BankingServices/Authorize", body: payload)
49
49
  end
50
50
 
51
51
  # @see https://sandbox-api.flinks.io/Readme/#authorize
@@ -54,20 +54,20 @@ module Flinks
54
54
  # @param institution [String]
55
55
  # @param options [Hash]
56
56
  def authorize_with_credentials(username:, password:, institution:, options: {})
57
- payload = AuthorizeWithCredentialsRequestSchema.call(options.merge(username: username, password: password, institution: institution))
58
- raise ArgumentError, error_message(payload) unless payload.success?
57
+ payload = options.merge(username: username, password: password, institution: institution)
58
+ validate_request!(AuthorizeWithCredentialsRequestSchema, payload)
59
59
 
60
- post("#{customer_id}/BankingServices/Authorize", body: payload.to_hash)
60
+ post("#{customer_id}/BankingServices/Authorize", body: payload)
61
61
  end
62
62
 
63
63
  # @see https://sandbox-api.flinks.io/Readme/#authorize-multiple
64
64
  # @param login_ids [Array]
65
65
  # @return [Hash]
66
66
  def authorize_multiple(login_ids:)
67
- payload = AuthorizeMultipleRequestSchema.call(options.merge(login_ids: login_ids))
68
- raise ArgumentError, error_message(payload) unless payload.success?
67
+ payload = options.merge(login_ids: login_ids)
68
+ validate_request!(AuthorizeMultipleRequestSchema, payload)
69
69
 
70
- post("#{customer_id}/BankingServices/AuthorizeMultiple", body: payload.to_hash)
70
+ post("#{customer_id}/BankingServices/AuthorizeMultiple", body: payload)
71
71
  end
72
72
  end
73
73
  end
@@ -15,10 +15,8 @@ module Flinks
15
15
  # @param options [Hash]
16
16
  # @return [Hash]
17
17
  def statements(options: {})
18
- payload = StatementRequestSchema.call(options)
19
- raise ArgumentError, error_message(payload) unless payload.success?
20
-
21
- post("#{customer_id}/BankingServices/GetStatements", body: payload.to_h)
18
+ validate_request!(StatementRequestSchema, options)
19
+ post("#{customer_id}/BankingServices/GetStatements", body: options)
22
20
  end
23
21
 
24
22
  # @see https://sandbox-api.flinks.io/Readme/#get-pdf-statements
@@ -26,11 +26,25 @@ module Flinks
26
26
  option :on_error, default: proc { proc {} }
27
27
  option :debug, default: proc { false }
28
28
 
29
+
30
+ private
31
+
32
+ # Builds an error message from a validation object
29
33
  #
30
34
  # @param validation [Dry::Validation::Result]
31
35
  # @return [String]
32
36
  def error_message(validation)
33
37
  validation.messages(full: true).values.flatten.to_sentence
34
38
  end
39
+
40
+ # Validates a request payload against a schema object
41
+ #
42
+ # @param schema [Class]
43
+ # @param options [Hash]
44
+ # @raise [ArgumentError]
45
+ def validate_request!(schema, options)
46
+ payload = schema.call(options)
47
+ raise ArgumentError, error_message(payload) unless payload.success?
48
+ end
35
49
  end
36
50
  end
@@ -1,3 +1,4 @@
1
+ require 'active_support/core_ext/hash/indifferent_access'
1
2
  require 'http'
2
3
 
3
4
  require 'flinks/error'
@@ -10,7 +11,7 @@ module Flinks
10
11
  # @param path [String]
11
12
  # @param params [Hash]
12
13
  def get(path, params: {})
13
- request(:get, URI.parse(api_endpoint).merge(path), params: params)
14
+ request(:get, path, params: params)
14
15
  end
15
16
 
16
17
  # Performs a HTTP Post request
@@ -19,7 +20,7 @@ module Flinks
19
20
  # @param params [Hash]
20
21
  # @param body [Hash]
21
22
  def post(path, params: {}, body: {})
22
- request(:post, URI.parse(api_endpoint).merge(path), params: params, body: body)
23
+ request(:post, path, params: params, body: body)
23
24
  end
24
25
 
25
26
  # Performs a HTTP Patch request
@@ -28,7 +29,7 @@ module Flinks
28
29
  # @param params [Hash]
29
30
  # @param body [Hash]
30
31
  def patch(path, params: {}, body: {})
31
- request(:patch, URI.parse(api_endpoint).merge(path), params: params, body: body)
32
+ request(:patch, path, params: params, body: body)
32
33
  end
33
34
 
34
35
 
@@ -38,18 +39,26 @@ module Flinks
38
39
  # @raise [Flinks::Error]
39
40
  def request(method, path, params: {}, body: {})
40
41
  headers = {
41
- 'Accept' => "application/json",
42
- 'User-Agent' => user_agent
42
+ 'Content-Type' => "application/json",
43
+ 'Accept' => "application/json",
44
+ 'User-Agent' => user_agent
43
45
  }
44
46
 
47
+ # Build URL
48
+ url = URI.parse(api_endpoint).merge(path)
49
+
45
50
  # Build payload
46
51
  payload = body.transform_keys { |k| k.to_s.camelize }
47
52
 
48
53
  # Perform request
49
- response = Http.headers(headers).send(method, path, params: params, json: payload)
54
+ response = Http.headers(headers).send(method, url, params: params, json: payload)
50
55
 
51
56
  if debug
52
- p response
57
+ p "Method: #{method}"
58
+ p "Url: #{url}"
59
+ p "Headers: #{headers}"
60
+ p "Payload: #{payload}"
61
+ p "Response: #{response}"
53
62
  end
54
63
 
55
64
  # Pass on errors when HTTP status included in 400 to 599
@@ -59,8 +68,11 @@ module Flinks
59
68
  on_error.call(response.code, response.reason, body)
60
69
  end
61
70
 
62
- # Return parsed json body
63
- response.parse
71
+ # Parse body
72
+ data = response.parse
73
+
74
+ # Transform data
75
+ data.deep_transform_keys { |k| k.underscore }.with_indifferent_access
64
76
  end
65
77
  end
66
78
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flinks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philippe Dionne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-14 00:00:00.000000000 Z
11
+ date: 2018-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http