pfs 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d53fb6ce5c9683637596438a427cccce4ce657c1832f5dfa39d746175a474344
4
+ data.tar.gz: 4afa2887ffb5663b916c9f78fb9d2b6f79336793ed8b1866f6fff98902ce8c39
5
+ SHA512:
6
+ metadata.gz: 68d23a3e05f5d0d8f921e4647765b386ac1db9114711656479e80f0d6903c4f592e77e989d0bafbc8a9a0406e6b4f1b73121a7708291f3a45158264dc1936e16
7
+ data.tar.gz: 1810aee630ba56917b9d399ba57e15558ef519d7b7c79efd868620fff6c39e3c04ffb4ab52728e1c7a248114b3ba0ea842173835db4b9cc1fea22f29d8134c2f
@@ -0,0 +1,48 @@
1
+ ---
2
+ name: ci
3
+
4
+ on:
5
+ push:
6
+ pull_request:
7
+ # Allows you to run this workflow manually from the Actions tab
8
+ workflow_dispatch:
9
+
10
+ jobs:
11
+ markdownlint-cli:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - name: Checkout Code
15
+ uses: actions/checkout@v2
16
+ - name: Run markdownlint-cli
17
+ uses: nosborn/github-action-markdown-cli@v2.0.0
18
+ with:
19
+ files: .
20
+ config_file: ".markdownlint.yaml"
21
+
22
+ yamllint:
23
+ runs-on: ubuntu-latest
24
+ steps:
25
+ - name: Checkout Code
26
+ uses: actions/checkout@v2
27
+ - name: Run YAML Lint
28
+ uses: actionshub/yamllint@main
29
+
30
+ build:
31
+ needs: [markdownlint-cli, yamllint]
32
+ runs-on: ubuntu-latest
33
+ name: Ruby ${{ matrix.ruby-version }}
34
+ strategy:
35
+ matrix:
36
+ ruby-version:
37
+ - "2.6"
38
+ - "2.7"
39
+ - "3.0"
40
+ - "3.1"
41
+ steps:
42
+ - uses: actions/checkout@v2
43
+ - name: Set up Ruby
44
+ uses: ruby/setup-ruby@v1
45
+ with:
46
+ ruby-version: ${{ matrix.ruby-version }}
47
+ bundler-cache: true
48
+ - run: bundle exec rake
@@ -0,0 +1,19 @@
1
+ ---
2
+ name: release
3
+
4
+ on:
5
+ push:
6
+ tags:
7
+ - v*.*.*
8
+ jobs:
9
+ publish:
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+
15
+ - name: Release Gem
16
+ uses: cadwallion/publish-rubygems-action@8f9e0538302643309e4e43bf48cd34173ca48cfc # yamllint disable-line
17
+ env:
18
+ RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
19
+ RELEASE_COMMAND: rake release
data/.gitignore ADDED
@@ -0,0 +1,41 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ # Ignore Byebug command history file.
17
+ .byebug_history
18
+
19
+ ## Documentation cache and generated files:
20
+ /.yardoc/
21
+ /_yardoc/
22
+ /doc/
23
+ /rdoc/
24
+
25
+ ## Environment normalization:
26
+ /.bundle/
27
+ /vendor/bundle
28
+ /lib/bundler/man/
29
+
30
+ # for a library or gem, you might want to ignore these files since the code is
31
+ # intended to run in multiple environments; otherwise, check them in:
32
+ Gemfile.lock
33
+ .ruby-version
34
+ .ruby-gemset
35
+
36
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
37
+ .rvmrc
38
+
39
+
40
+ # rspec failure tracking
41
+ .rspec_status
@@ -0,0 +1,3 @@
1
+ ---
2
+ default: true
3
+ line-length: false
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,3 @@
1
+ ---
2
+ inherit_from:
3
+ - .rubocop_devengo.yml
@@ -0,0 +1,300 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+ TargetRubyVersion: 2.7
4
+ SuggestExtensions: false
5
+ NewCops: enable
6
+ Exclude:
7
+ - db/schema.rb
8
+ - db/migrate/**/*
9
+ - vendor/bundle/**/*
10
+ - node_modules/**/*
11
+ - Procfile
12
+
13
+ require:
14
+ - "test_prof/rubocop"
15
+ - rubocop-rspec
16
+ - rubocop-performance
17
+ - rubocop-rake
18
+
19
+ Layout/CaseIndentation:
20
+ EnforcedStyle: end
21
+
22
+ Layout/SpaceAroundMethodCallOperator:
23
+ Enabled: true
24
+
25
+ Layout/FirstArrayElementIndentation:
26
+ EnforcedStyle: consistent
27
+
28
+ Layout/FirstHashElementIndentation:
29
+ EnforcedStyle: consistent
30
+
31
+ Layout/LineLength:
32
+ # Commonly used screens these days easily fit more than 80 characters.
33
+ Max: 120
34
+ Exclude:
35
+ - "spec/**/*.rb"
36
+
37
+ Layout/EmptyLinesAroundAttributeAccessor:
38
+ Enabled: true
39
+
40
+ Layout/BeginEndAlignment:
41
+ Enabled: true
42
+
43
+ Metrics/BlockLength:
44
+ Exclude:
45
+ - "lib/devengo/container/**/*.rb"
46
+ - "lib/devengo/container/container.rb"
47
+ - "**/*.rake"
48
+ - "spec/**/*.rb"
49
+
50
+ Metrics/MethodLength:
51
+ Max: 50
52
+
53
+ Metrics/ModuleLength:
54
+ Enabled: false
55
+
56
+ Naming/VariableNumber:
57
+ Enabled: false
58
+
59
+ Style/Documentation:
60
+ Enabled: false
61
+
62
+ Style/SymbolArray:
63
+ EnforcedStyle: brackets
64
+
65
+ Style/AccessModifierDeclarations:
66
+ EnforcedStyle: inline
67
+
68
+ Style/ClassEqualityComparison:
69
+ Enabled: true
70
+
71
+ Style/FrozenStringLiteralComment:
72
+ EnforcedStyle: always
73
+
74
+ Style/StringLiterals:
75
+ EnforcedStyle: double_quotes
76
+
77
+ Style/TrailingCommaInArrayLiteral:
78
+ EnforcedStyleForMultiline: consistent_comma
79
+
80
+ Style/TrailingCommaInHashLiteral:
81
+ EnforcedStyleForMultiline: consistent_comma
82
+
83
+ Style/NumericPredicate:
84
+ Enabled: false
85
+
86
+ Style/HashEachMethods:
87
+ Enabled: True
88
+
89
+ Style/HashTransformKeys:
90
+ Enabled: True
91
+
92
+ Style/HashTransformValues:
93
+ Enabled: true
94
+
95
+ Style/ExponentialNotation:
96
+ Enabled: true
97
+
98
+ Style/SlicingWithRange:
99
+ Enabled: true
100
+
101
+ Style/RedundantFetchBlock:
102
+ Enabled: true
103
+
104
+ Style/RedundantRegexpCharacterClass:
105
+ Enabled: true
106
+
107
+ Style/RedundantRegexpEscape:
108
+ Enabled: true
109
+
110
+ Style/AccessorGrouping:
111
+ Enabled: true
112
+
113
+ Style/BisectedAttrAccessor:
114
+ Enabled: true
115
+
116
+ Style/RedundantAssignment:
117
+ Enabled: true
118
+
119
+ Style/ArrayCoercion:
120
+ Enabled: true
121
+
122
+ Style/CaseLikeIf:
123
+ Enabled: true
124
+
125
+ Style/HashAsLastArrayItem:
126
+ Enabled: true
127
+
128
+ Style/HashLikeCase:
129
+ Enabled: true
130
+
131
+ Style/RedundantFileExtensionInRequire:
132
+ Enabled: true
133
+
134
+ Style/ExplicitBlockArgument:
135
+ Enabled: true
136
+
137
+ Style/GlobalStdStream:
138
+ Enabled: true
139
+
140
+ Style/OptionalBooleanParameter:
141
+ Enabled: true
142
+
143
+ Style/SingleArgumentDig:
144
+ Enabled: true
145
+
146
+ Style/StringConcatenation:
147
+ Enabled: true
148
+
149
+ Style/CombinableLoops:
150
+ Enabled: true
151
+
152
+ Style/KeywordParametersOrder:
153
+ Enabled: true
154
+
155
+ Style/RedundantSelfAssignment:
156
+ Enabled: true
157
+
158
+ Style/SoleNestedConditional:
159
+ Enabled: true
160
+
161
+ Style/ArgumentsForwarding: # (new in 1.1)
162
+ Enabled: true
163
+
164
+ Style/DocumentDynamicEvalDefinition: # (new in 1.1)
165
+ Enabled: true
166
+
167
+ Style/SwapValues: # (new in 1.1)
168
+ Enabled: true
169
+
170
+ Style/CollectionCompact: # (new in 1.2)
171
+ Enabled: true
172
+
173
+ Style/NegatedIfElseCondition: # (new in 1.2)
174
+ Enabled: true
175
+
176
+ Style/NilLambda: # (new in 1.3)
177
+ Enabled: true
178
+
179
+ Style/RedundantArgument: # (new in 1.4)
180
+ Enabled: true
181
+
182
+ Style/FetchEnvVar:
183
+ Enabled: false
184
+
185
+ Lint/RaiseException:
186
+ Enabled: true
187
+
188
+ Lint/StructNewOverride:
189
+ Enabled: true
190
+
191
+ Lint/DeprecatedOpenSSLConstant:
192
+ Enabled: true
193
+
194
+ Lint/MixedRegexpCaptureTypes:
195
+ Enabled: true
196
+
197
+ Lint/DuplicateElsifCondition:
198
+ Enabled: true
199
+
200
+ Lint/BinaryOperatorWithIdenticalOperands:
201
+ Enabled: true
202
+
203
+ Lint/DuplicateRescueException:
204
+ Enabled: true
205
+
206
+ Lint/EmptyConditionalBody:
207
+ Enabled: true
208
+
209
+ Lint/FloatComparison:
210
+ Enabled: true
211
+
212
+ Lint/HashCompareByIdentity:
213
+ Enabled: true
214
+
215
+ Lint/MissingSuper:
216
+ Enabled: true
217
+
218
+ Lint/OutOfRangeRegexpRef:
219
+ Enabled: true
220
+
221
+ Lint/RedundantSafeNavigation:
222
+ Enabled: true
223
+
224
+ Lint/SelfAssignment:
225
+ Enabled: true
226
+
227
+ Lint/TopLevelReturnWithArgument:
228
+ Enabled: true
229
+
230
+ Lint/UnreachableLoop:
231
+ Enabled: true
232
+
233
+ Lint/ConstantDefinitionInBlock:
234
+ Enabled: true
235
+
236
+ Lint/DuplicateRequire:
237
+ Enabled: true
238
+
239
+ Lint/EmptyFile:
240
+ Enabled: true
241
+
242
+ Lint/IdentityComparison:
243
+ Enabled: true
244
+
245
+ Lint/TrailingCommaInAttributeDeclaration:
246
+ Enabled: true
247
+
248
+ Lint/UselessMethodDefinition:
249
+ Enabled: true
250
+
251
+ Lint/UselessTimes:
252
+ Enabled: true
253
+
254
+ Lint/DuplicateRegexpCharacterClassElement: # (new in 1.1)
255
+ Enabled: true
256
+
257
+ Lint/EmptyBlock: # (new in 1.1)
258
+ Enabled: true
259
+
260
+ Lint/ToEnumArguments: # (new in 1.1)
261
+ Enabled: true
262
+
263
+ Lint/UnmodifiedReduceAccumulator: # (new in 1.1)
264
+ Enabled: true
265
+
266
+ Lint/NoReturnInBeginEndBlocks: # (new in 1.2)
267
+ Enabled: true
268
+
269
+ Lint/DuplicateBranch: # (new in 1.3)
270
+ Enabled: true
271
+
272
+ Lint/EmptyClass: # (new in 1.3)
273
+ Enabled: true
274
+
275
+ Lint/UnexpectedBlockArity: # (new in 1.5)
276
+ Enabled: true
277
+
278
+ RSpec/AggregateExamples:
279
+ AddAggregateFailuresMetadata: true
280
+
281
+ RSpec/MultipleExpectations:
282
+ Enabled: false
283
+
284
+ RSpec/MultipleMemoizedHelpers:
285
+ Enabled: false
286
+
287
+ RSpec/ExampleLength:
288
+ Enabled: false
289
+
290
+ RSpec/MultipleDescribes:
291
+ Enabled: false
292
+
293
+ RSpec/NestedGroups:
294
+ Max: 4
295
+
296
+ RSpec/BeNil:
297
+ Enabled: false
298
+
299
+ RSpec/BeEq:
300
+ Enabled: false
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at aitor@linkingpaths.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in pfs.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Aitor García Rey
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Aitor García Rey
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,45 @@
1
+ # Pfs
2
+
3
+ Ruby client for PFS (cf. <https://staging-api.prepaidfinancialservices.com/apidocumentation>)
4
+
5
+ Run `bin/console` for an interactive prompt to experiment with the code.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem "pfs"
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ ```sh
18
+ bundle install
19
+ ```
20
+
21
+ Or install it yourself as:
22
+
23
+ ```sh
24
+ gem install pfs
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ## Development
30
+
31
+ 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.
32
+
33
+ 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).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/aitor/pfs>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/aitor/pfs/blob/master/CODE_OF_CONDUCT.md).
38
+
39
+ ## License
40
+
41
+ The gem is available as open-source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
42
+
43
+ ## Code of Conduct
44
+
45
+ Everyone interacting in the PFS project's codebases, issue trackers, chat rooms, and mailing lists is expected to follow the [code of conduct](https://github.com/aitor/pfs/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pfs"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PFS
4
+ module API
5
+ class AccountsService < Service
6
+ def balance(account_id)
7
+ response = client.get("/Account/#{account_id}/Balance")
8
+ Resources::Accounts::Balance.new(response)
9
+ end
10
+
11
+ def credit(account_id, currency, amount, fee_code = "**API", description = "Deposit To Card API")
12
+ attributes = {
13
+ amount: amount,
14
+ currencyCode: currency,
15
+ feeCode: fee_code,
16
+ transactionDescription: description,
17
+ }
18
+ response = client.post("/Account/#{account_id}/Balance/Credit", attributes)
19
+ Resources::Accounts::BalanceCredit.new(response)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PFS
4
+ module API
5
+ class AuthenticationService < Service
6
+ def login(username, password, options = {})
7
+ attributes = {
8
+ username: username,
9
+ password: password,
10
+ }
11
+ response = client.post("/Auth/Jwt", attributes, options)
12
+ Resources::Authentication::Token.new(response)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PFS
4
+ module API
5
+ class Service
6
+ attr_reader :client
7
+
8
+ def initialize(client)
9
+ @client = client
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "service"
4
+ require_relative "accounts_service"
5
+ require_relative "authentication_service"
6
+ require_relative "transactions_service"
7
+ require_relative "transfers_service"
8
+
9
+ module PFS
10
+ module API
11
+ module Services
12
+ def authentication
13
+ @services[:authentication] ||= API::AuthenticationService.new(self)
14
+ end
15
+
16
+ def accounts
17
+ @services[:accounts] ||= API::AccountsService.new(self)
18
+ end
19
+
20
+ def transfers
21
+ @services[:transfers] ||= API::TransfersService.new(self)
22
+ end
23
+
24
+ def transactions
25
+ @services[:transactions] ||= API::TransactionsService.new(self)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PFS
4
+ module API
5
+ class TransactionsService < Service
6
+ def history(account_id:, start_date:, end_date:)
7
+ response = client.get("/Account/#{account_id}/Transactions?StartDate=#{start_date}&EndDate=#{end_date}")
8
+ transactions_raw = response.body.dig(:data, :transactions)
9
+ Resources::Transactions::Transactions.from_raw(transactions_raw)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PFS
4
+ module API
5
+ class TransfersService < Service
6
+ def create(account_id, currency, amount, destination, destination_id, country, first_name, last_name, options = {})
7
+ data = {
8
+ currency: currency,
9
+ paymentamount: amount,
10
+ accountidentifier: destination,
11
+ bankidentifier: destination_id,
12
+ countrycode: country,
13
+ firstname: first_name,
14
+ lastname: last_name,
15
+ }
16
+ data[:isinstant] = true if options[:instant]
17
+ data[:reference] = options[:reference] if options[:reference]
18
+ response = client.post("/BankPayment/#{account_id}/OneOffPayment", data, options)
19
+ Resources::Transfers::Transfer.new(response)
20
+ end
21
+ end
22
+ end
23
+ end
data/lib/pfs/client.rb ADDED
@@ -0,0 +1,128 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ # require "faraday_middleware"
5
+ require_relative "api/services"
6
+ require_relative "resources/base"
7
+ module PFS
8
+ class Client
9
+ include PFS::API::Services
10
+
11
+ BASE_URL = "https://api.prepaidfinancialservices.com/finac/api"
12
+
13
+ attr_reader :base_url, :origin, :proxy, :username, :token, :logger_enabled
14
+
15
+ def initialize(options = {})
16
+ @base_url = options[:base_url] || BASE_URL
17
+ @origin = options[:origin] || default_origin
18
+ @proxy = options[:proxy]
19
+ @username = options[:username] || ENV["PFS_USERNAME"]
20
+ @password = options[:password] || ENV["PFS_PASSWORD"]
21
+ @token = nil
22
+ @logger_enabled = options[:logger_enabled].nil? ? true : options[:logger_enabled]
23
+ @services = {}
24
+ end
25
+
26
+ def connection
27
+ @connection ||= Faraday.new do |builder|
28
+ builder.use Faraday::Response::RaiseError
29
+ builder.response :json,
30
+ content_type: /\bjson$/,
31
+ preserve_raw: true,
32
+ parser_options: { symbolize_names: true }
33
+ builder.proxy = @proxy if proxy
34
+ if @logger_enabled
35
+ builder.response :logger, nil, { headers: true, bodies: true } do |logger|
36
+ logger.filter(/("password":)"(\w+)"/, '\1[FILTERED]')
37
+ end
38
+ end
39
+ builder.adapter :net_http
40
+ end
41
+ end
42
+
43
+ def resources
44
+ @resources ||= {}
45
+ end
46
+
47
+ def default_origin
48
+ "PFS/#{PFS::VERSION} Ruby Client (Faraday/#{Faraday::VERSION})"
49
+ end
50
+
51
+ def get(path, options = {})
52
+ execute :get, path, nil, options
53
+ end
54
+
55
+ def post(path, data = nil, options = {})
56
+ execute :post, path, data, options
57
+ end
58
+
59
+ def execute(method, path, data = nil, options = {})
60
+ request(method, path, data, options)
61
+ end
62
+
63
+ def request(method, path, data = nil, options = {})
64
+ request_options = request_options(method, path, data, options)
65
+ uri = "#{base_url}#{path}"
66
+
67
+ begin
68
+ connection.run_request(method, uri, request_options[:body], request_options[:headers])
69
+ rescue StandardError => e
70
+ handle_request_error(e)
71
+ end
72
+ end
73
+
74
+ def request_options(_method, path, data, _options)
75
+ default_options.tap do |defaults|
76
+ add_auth_options!(defaults) unless login_path?(path)
77
+ defaults[:body] = JSON.dump(data) if data
78
+ end
79
+ end
80
+
81
+ def handle_request_error(error)
82
+ case error
83
+ when Faraday::ClientError
84
+ if error.response
85
+ handle_error_response(error)
86
+ else
87
+ handle_network_error(error)
88
+ end
89
+ else
90
+ raise error
91
+ end
92
+ end
93
+
94
+ def handle_error_response(error)
95
+ puts "ERROR #{error.response}"
96
+ raise error
97
+ end
98
+
99
+ def handle_network_error(error)
100
+ raise error
101
+ end
102
+
103
+ def login_path?(path)
104
+ path == "/Auth/Jwt"
105
+ end
106
+
107
+ def add_auth_options!(options)
108
+ login! unless @token&.valid?
109
+
110
+ options[:headers][:authorization] = "Bearer #{@token.access_token}"
111
+ end
112
+
113
+ def login!
114
+ @token = authentication.login(@username, @password)
115
+ end
116
+
117
+ private def default_options
118
+ {
119
+ url: base_url,
120
+ headers: {
121
+ content_type: "application/json",
122
+ "f-origin": default_origin,
123
+ "f-message-id": SecureRandom.uuid,
124
+ },
125
+ }
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PFS
4
+ module Resources
5
+ module Accounts
6
+ class Balance < Resources::Base
7
+ attr_accessor :currency,
8
+ :availableBalance,
9
+ :ledgerBalance
10
+
11
+ alias available availableBalance
12
+ alias ledger ledgerBalance
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PFS
4
+ module Resources
5
+ module Accounts
6
+ class BalanceCredit < Base
7
+ attr_accessor :amount,
8
+ :currencyCode,
9
+ :feeAmount,
10
+ :newBalance,
11
+ :oldBalance
12
+ alias current_code currencyCode
13
+ alias fee_amount feeAmount
14
+ alias new_balance newBalance
15
+ alias old_balance oldBalance
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PFS
4
+ module Resources
5
+ module Accounts
6
+ class Transaction < Base
7
+ attr_accessor :date,
8
+ :transactionType,
9
+ :authenticationNumber,
10
+ :transactionOrigin,
11
+ :transactionDescription,
12
+ :amount,
13
+ :fee,
14
+ :availableBalance,
15
+ :ledgerBalance,
16
+ :terminalID,
17
+ :terminalLocation,
18
+ :terminalOwner,
19
+ :transactionCodeDescription,
20
+ :transactionResult,
21
+ :authenticationNumber,
22
+ :authenticationNumber
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PFS
4
+ module Resources
5
+ module Authentication
6
+ class Token < Base
7
+ attr_accessor :accessToken,
8
+ :expiresIn
9
+
10
+ alias access_token accessToken
11
+ alias expires_in expiresIn
12
+
13
+ def initialize(response)
14
+ super(response)
15
+ @expires_on = Time.now + expires_in
16
+ end
17
+
18
+ def valid?
19
+ @expires_on > Time.now
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PFS
4
+ module Resources
5
+ class Base
6
+ attr_reader :response
7
+
8
+ def initialize(response, root = :data)
9
+ @response = response
10
+ attributes = response.body[root]
11
+ attributes.each do |key, value|
12
+ m = "#{key}=".to_sym
13
+ send(m, value) if respond_to?(m)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ require_relative "accounts/balance"
21
+ require_relative "accounts/balance_credit"
22
+ require_relative "accounts/transaction"
23
+ require_relative "accounts/transaction"
24
+ require_relative "authentication/token"
25
+ require_relative "transfers/transfer"
26
+ require_relative "transactions/transaction"
27
+ require_relative "transactions/transactions"
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PFS
4
+ module Resources
5
+ class Collection
6
+ include Enumerable
7
+
8
+ attr_reader :response
9
+
10
+ def initialize(response, item_klass, data)
11
+ @response = response
12
+ @items = (data || []).map { |item| item_klass.new(response, item) }
13
+ end
14
+
15
+ def each(&block)
16
+ @items.each(&block)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PFS
4
+ module Resources
5
+ module Transactions
6
+ class Transaction
7
+ attr_reader :amount,
8
+ :currency,
9
+ :transaction_description,
10
+ :transaction_origin,
11
+ :transaction_type,
12
+ :date,
13
+ :unique_reference,
14
+ :transfer_response_reference
15
+
16
+ def self.from_raw(raw_transaction)
17
+ new(
18
+ amount: raw_transaction[:amount],
19
+ currency: raw_transaction[:currency],
20
+ transaction_description: raw_transaction[:transactionDescription],
21
+ transaction_origin: raw_transaction[:transactionOrigin],
22
+ transaction_type: raw_transaction[:transactionType],
23
+ date: raw_transaction[:date],
24
+ unique_reference: raw_transaction[:uniqueReference],
25
+ transfer_response_reference: raw_transaction[:terminalID]
26
+ )
27
+ end
28
+
29
+ def initialize(
30
+ amount:,
31
+ currency:,
32
+ transaction_description:,
33
+ transaction_origin:,
34
+ transaction_type:,
35
+ date:,
36
+ unique_reference:,
37
+ transfer_response_reference:
38
+ )
39
+ @amount = amount
40
+ @currency = currency
41
+ @transaction_description = transaction_description
42
+ @transaction_origin = transaction_origin
43
+ @transaction_type = transaction_type
44
+ @date = date
45
+ @unique_reference = unique_reference
46
+ @transfer_response_reference = transfer_response_reference
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PFS
4
+ module Resources
5
+ module Transactions
6
+ class Transactions
7
+ include Enumerable
8
+
9
+ def self.from_raw(raw_transactions)
10
+ transactions = raw_transactions.map do |transaction|
11
+ Transaction.from_raw(transaction)
12
+ end
13
+ new(transactions)
14
+ end
15
+
16
+ def initialize(transactions)
17
+ @transactions = transactions
18
+ end
19
+
20
+ def each(&block)
21
+ @transactions.each(&block)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PFS
4
+ module Resources
5
+ module Transfers
6
+ class Transfer < Base
7
+ attr_accessor :bankPaymentReferenceId
8
+
9
+ alias payment_reference_id bankPaymentReferenceId
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module PFS
2
+ VERSION = "0.0.1"
3
+ end
data/lib/pfs.rb ADDED
@@ -0,0 +1,5 @@
1
+
2
+ require "pfs/version"
3
+ require "pfs/client"
4
+ module PFS
5
+ end
data/pfs.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ require_relative 'lib/pfs/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "pfs"
5
+ spec.version = PFS::VERSION
6
+ spec.authors = ["Aitor García Rey"]
7
+ spec.email = ["aitor@devengo.com"]
8
+
9
+ spec.summary = %q{PFS Finac API ruby client}
10
+ spec.description = %q{A ruby client to consume PFS Finac API}
11
+ spec.homepage = "https://github.com/devengo/pfs-ruby"
12
+ spec.license = "MIT"
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = "https://github.com/devengo/pfs-ruby"
16
+ spec.metadata["changelog_uri"] = "https://github.com/devengo/pfs-ruby/CHANGELOG.md"
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ # spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.required_ruby_version = ">= 2.5.0"
28
+ spec.add_dependency "faraday", '>= 0.15'
29
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pfs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Aitor García Rey
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-06-07 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
+ description: A ruby client to consume PFS Finac API
28
+ email:
29
+ - aitor@devengo.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".github/workflows/ci.yml"
35
+ - ".github/workflows/release.yml"
36
+ - ".gitignore"
37
+ - ".markdownlint.yaml"
38
+ - ".rspec"
39
+ - ".rubocop.yml"
40
+ - ".rubocop_devengo.yml"
41
+ - CODE_OF_CONDUCT.md
42
+ - Gemfile
43
+ - LICENSE
44
+ - LICENSE.txt
45
+ - README.md
46
+ - Rakefile
47
+ - bin/console
48
+ - bin/setup
49
+ - lib/pfs.rb
50
+ - lib/pfs/api/accounts_service.rb
51
+ - lib/pfs/api/authentication_service.rb
52
+ - lib/pfs/api/service.rb
53
+ - lib/pfs/api/services.rb
54
+ - lib/pfs/api/transactions_service.rb
55
+ - lib/pfs/api/transfers_service.rb
56
+ - lib/pfs/client.rb
57
+ - lib/pfs/resources/accounts/balance.rb
58
+ - lib/pfs/resources/accounts/balance_credit.rb
59
+ - lib/pfs/resources/accounts/transaction.rb
60
+ - lib/pfs/resources/authentication/token.rb
61
+ - lib/pfs/resources/base.rb
62
+ - lib/pfs/resources/collection.rb
63
+ - lib/pfs/resources/transactions/transaction.rb
64
+ - lib/pfs/resources/transactions/transactions.rb
65
+ - lib/pfs/resources/transfers/transfer.rb
66
+ - lib/pfs/version.rb
67
+ - pfs.gemspec
68
+ homepage: https://github.com/devengo/pfs-ruby
69
+ licenses:
70
+ - MIT
71
+ metadata:
72
+ homepage_uri: https://github.com/devengo/pfs-ruby
73
+ source_code_uri: https://github.com/devengo/pfs-ruby
74
+ changelog_uri: https://github.com/devengo/pfs-ruby/CHANGELOG.md
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 2.5.0
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubygems_version: 3.3.7
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: PFS Finac API ruby client
94
+ test_files: []