modulr-api 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: 3be26f94ee469da0f933065d0840bc32db148bac2956b482ea99f1c8a09adfab
4
+ data.tar.gz: fc2825106eee34ff90f82a176a2ce82617601ee4622ebf4fd6a0b3071295aa8c
5
+ SHA512:
6
+ metadata.gz: cedec2c32074b66b9ebe2141340dce522ec8eea28fbc75595a43262cc44376da3ebbd4cc904ad35ca45d46f3a8b66af97666f6e280ce4eade667f332a90d3111
7
+ data.tar.gz: 1ff92c2a5adb6d75d6ec4288cba1dd75483ec19d776cb31503cdf659d6e87699567e714f8b2821f62b898262f3ae3512e30f333aac407ec0bc5da8bddba3ac49
@@ -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,301 @@
1
+ ---
2
+ AllCops:
3
+ DisplayCopNames: true
4
+ TargetRubyVersion: 2.7
5
+ SuggestExtensions: false
6
+ NewCops: enable
7
+ Exclude:
8
+ - db/schema.rb
9
+ - db/migrate/**/*
10
+ - vendor/bundle/**/*
11
+ - node_modules/**/*
12
+ - Procfile
13
+
14
+ require:
15
+ - "test_prof/rubocop"
16
+ - rubocop-rspec
17
+ - rubocop-performance
18
+ - rubocop-rake
19
+
20
+ Layout/CaseIndentation:
21
+ EnforcedStyle: end
22
+
23
+ Layout/SpaceAroundMethodCallOperator:
24
+ Enabled: true
25
+
26
+ Layout/FirstArrayElementIndentation:
27
+ EnforcedStyle: consistent
28
+
29
+ Layout/FirstHashElementIndentation:
30
+ EnforcedStyle: consistent
31
+
32
+ Layout/LineLength:
33
+ # Commonly used screens these days easily fit more than 80 characters.
34
+ Max: 120
35
+ Exclude:
36
+ - "spec/**/*.rb"
37
+
38
+ Layout/EmptyLinesAroundAttributeAccessor:
39
+ Enabled: true
40
+
41
+ Layout/BeginEndAlignment:
42
+ Enabled: true
43
+
44
+ Metrics/BlockLength:
45
+ Exclude:
46
+ - "lib/devengo/container/**/*.rb"
47
+ - "lib/devengo/container/container.rb"
48
+ - "**/*.rake"
49
+ - "spec/**/*.rb"
50
+
51
+ Metrics/MethodLength:
52
+ Max: 50
53
+
54
+ Metrics/ModuleLength:
55
+ Enabled: false
56
+
57
+ Naming/VariableNumber:
58
+ Enabled: false
59
+
60
+ Style/Documentation:
61
+ Enabled: false
62
+
63
+ Style/SymbolArray:
64
+ EnforcedStyle: brackets
65
+
66
+ Style/AccessModifierDeclarations:
67
+ EnforcedStyle: inline
68
+
69
+ Style/ClassEqualityComparison:
70
+ Enabled: true
71
+
72
+ Style/FrozenStringLiteralComment:
73
+ EnforcedStyle: always
74
+
75
+ Style/StringLiterals:
76
+ EnforcedStyle: double_quotes
77
+
78
+ Style/TrailingCommaInArrayLiteral:
79
+ EnforcedStyleForMultiline: consistent_comma
80
+
81
+ Style/TrailingCommaInHashLiteral:
82
+ EnforcedStyleForMultiline: consistent_comma
83
+
84
+ Style/NumericPredicate:
85
+ Enabled: false
86
+
87
+ Style/HashEachMethods:
88
+ Enabled: true
89
+
90
+ Style/HashTransformKeys:
91
+ Enabled: true
92
+
93
+ Style/HashTransformValues:
94
+ Enabled: true
95
+
96
+ Style/ExponentialNotation:
97
+ Enabled: true
98
+
99
+ Style/SlicingWithRange:
100
+ Enabled: true
101
+
102
+ Style/RedundantFetchBlock:
103
+ Enabled: true
104
+
105
+ Style/RedundantRegexpCharacterClass:
106
+ Enabled: true
107
+
108
+ Style/RedundantRegexpEscape:
109
+ Enabled: true
110
+
111
+ Style/AccessorGrouping:
112
+ Enabled: true
113
+
114
+ Style/BisectedAttrAccessor:
115
+ Enabled: true
116
+
117
+ Style/RedundantAssignment:
118
+ Enabled: true
119
+
120
+ Style/ArrayCoercion:
121
+ Enabled: true
122
+
123
+ Style/CaseLikeIf:
124
+ Enabled: true
125
+
126
+ Style/HashAsLastArrayItem:
127
+ Enabled: true
128
+
129
+ Style/HashLikeCase:
130
+ Enabled: true
131
+
132
+ Style/RedundantFileExtensionInRequire:
133
+ Enabled: true
134
+
135
+ Style/ExplicitBlockArgument:
136
+ Enabled: true
137
+
138
+ Style/GlobalStdStream:
139
+ Enabled: true
140
+
141
+ Style/OptionalBooleanParameter:
142
+ Enabled: true
143
+
144
+ Style/SingleArgumentDig:
145
+ Enabled: true
146
+
147
+ Style/StringConcatenation:
148
+ Enabled: true
149
+
150
+ Style/CombinableLoops:
151
+ Enabled: true
152
+
153
+ Style/KeywordParametersOrder:
154
+ Enabled: true
155
+
156
+ Style/RedundantSelfAssignment:
157
+ Enabled: true
158
+
159
+ Style/SoleNestedConditional:
160
+ Enabled: true
161
+
162
+ Style/ArgumentsForwarding: # (new in 1.1)
163
+ Enabled: true
164
+
165
+ Style/DocumentDynamicEvalDefinition: # (new in 1.1)
166
+ Enabled: true
167
+
168
+ Style/SwapValues: # (new in 1.1)
169
+ Enabled: true
170
+
171
+ Style/CollectionCompact: # (new in 1.2)
172
+ Enabled: true
173
+
174
+ Style/NegatedIfElseCondition: # (new in 1.2)
175
+ Enabled: true
176
+
177
+ Style/NilLambda: # (new in 1.3)
178
+ Enabled: true
179
+
180
+ Style/RedundantArgument: # (new in 1.4)
181
+ Enabled: true
182
+
183
+ Style/FetchEnvVar:
184
+ Enabled: false
185
+
186
+ Lint/RaiseException:
187
+ Enabled: true
188
+
189
+ Lint/StructNewOverride:
190
+ Enabled: true
191
+
192
+ Lint/DeprecatedOpenSSLConstant:
193
+ Enabled: true
194
+
195
+ Lint/MixedRegexpCaptureTypes:
196
+ Enabled: true
197
+
198
+ Lint/DuplicateElsifCondition:
199
+ Enabled: true
200
+
201
+ Lint/BinaryOperatorWithIdenticalOperands:
202
+ Enabled: true
203
+
204
+ Lint/DuplicateRescueException:
205
+ Enabled: true
206
+
207
+ Lint/EmptyConditionalBody:
208
+ Enabled: true
209
+
210
+ Lint/FloatComparison:
211
+ Enabled: true
212
+
213
+ Lint/HashCompareByIdentity:
214
+ Enabled: true
215
+
216
+ Lint/MissingSuper:
217
+ Enabled: true
218
+
219
+ Lint/OutOfRangeRegexpRef:
220
+ Enabled: true
221
+
222
+ Lint/RedundantSafeNavigation:
223
+ Enabled: true
224
+
225
+ Lint/SelfAssignment:
226
+ Enabled: true
227
+
228
+ Lint/TopLevelReturnWithArgument:
229
+ Enabled: true
230
+
231
+ Lint/UnreachableLoop:
232
+ Enabled: true
233
+
234
+ Lint/ConstantDefinitionInBlock:
235
+ Enabled: true
236
+
237
+ Lint/DuplicateRequire:
238
+ Enabled: true
239
+
240
+ Lint/EmptyFile:
241
+ Enabled: true
242
+
243
+ Lint/IdentityComparison:
244
+ Enabled: true
245
+
246
+ Lint/TrailingCommaInAttributeDeclaration:
247
+ Enabled: true
248
+
249
+ Lint/UselessMethodDefinition:
250
+ Enabled: true
251
+
252
+ Lint/UselessTimes:
253
+ Enabled: true
254
+
255
+ Lint/DuplicateRegexpCharacterClassElement: # (new in 1.1)
256
+ Enabled: true
257
+
258
+ Lint/EmptyBlock: # (new in 1.1)
259
+ Enabled: true
260
+
261
+ Lint/ToEnumArguments: # (new in 1.1)
262
+ Enabled: true
263
+
264
+ Lint/UnmodifiedReduceAccumulator: # (new in 1.1)
265
+ Enabled: true
266
+
267
+ Lint/NoReturnInBeginEndBlocks: # (new in 1.2)
268
+ Enabled: true
269
+
270
+ Lint/DuplicateBranch: # (new in 1.3)
271
+ Enabled: true
272
+
273
+ Lint/EmptyClass: # (new in 1.3)
274
+ Enabled: true
275
+
276
+ Lint/UnexpectedBlockArity: # (new in 1.5)
277
+ Enabled: true
278
+
279
+ RSpec/AggregateExamples:
280
+ AddAggregateFailuresMetadata: true
281
+
282
+ RSpec/MultipleExpectations:
283
+ Enabled: false
284
+
285
+ RSpec/MultipleMemoizedHelpers:
286
+ Enabled: false
287
+
288
+ RSpec/ExampleLength:
289
+ Enabled: false
290
+
291
+ RSpec/MultipleDescribes:
292
+ Enabled: false
293
+
294
+ RSpec/NestedGroups:
295
+ Max: 4
296
+
297
+ RSpec/BeNil:
298
+ Enabled: false
299
+
300
+ RSpec/BeEq:
301
+ Enabled: false
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ - Demonstrating empathy and kindness toward other people
14
+ - Being respectful of differing opinions, viewpoints, and experiences
15
+ - Giving and gracefully accepting constructive feedback
16
+ - Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ - Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ - The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ - Trolling, insulting or derogatory comments, and personal or political attacks
24
+ - Public or private harassment
25
+ - Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ - Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at aitor@devengo.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at <https://www.contributor-covenant.org/version/2/0/code_of_conduct.html>.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ <https://www.contributor-covenant.org/faq>. Translations are available at <https://www.contributor-covenant.org/translations>.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in modulr.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,94 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ modulr-api (0.0.1)
5
+ faraday (~> 1.0)
6
+ faraday_middleware (~> 1.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.4.2)
12
+ diff-lcs (1.5.0)
13
+ faraday (1.8.0)
14
+ faraday-em_http (~> 1.0)
15
+ faraday-em_synchrony (~> 1.0)
16
+ faraday-excon (~> 1.1)
17
+ faraday-httpclient (~> 1.0.1)
18
+ faraday-net_http (~> 1.0)
19
+ faraday-net_http_persistent (~> 1.1)
20
+ faraday-patron (~> 1.0)
21
+ faraday-rack (~> 1.0)
22
+ multipart-post (>= 1.2, < 3)
23
+ ruby2_keywords (>= 0.0.4)
24
+ faraday-em_http (1.0.0)
25
+ faraday-em_synchrony (1.0.0)
26
+ faraday-excon (1.1.0)
27
+ faraday-httpclient (1.0.1)
28
+ faraday-net_http (1.0.1)
29
+ faraday-net_http_persistent (1.2.0)
30
+ faraday-patron (1.0.0)
31
+ faraday-rack (1.0.0)
32
+ faraday_middleware (1.2.0)
33
+ faraday (~> 1.0)
34
+ json (2.6.2)
35
+ multipart-post (2.1.1)
36
+ parallel (1.22.1)
37
+ parser (3.1.2.0)
38
+ ast (~> 2.4.1)
39
+ rainbow (3.1.1)
40
+ rake (12.3.3)
41
+ regexp_parser (2.5.0)
42
+ rexml (3.2.5)
43
+ rspec (3.10.0)
44
+ rspec-core (~> 3.10.0)
45
+ rspec-expectations (~> 3.10.0)
46
+ rspec-mocks (~> 3.10.0)
47
+ rspec-core (3.10.1)
48
+ rspec-support (~> 3.10.0)
49
+ rspec-expectations (3.10.1)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.10.0)
52
+ rspec-mocks (3.10.2)
53
+ diff-lcs (>= 1.2.0, < 2.0)
54
+ rspec-support (~> 3.10.0)
55
+ rspec-support (3.10.3)
56
+ rubocop (1.31.2)
57
+ json (~> 2.3)
58
+ parallel (~> 1.10)
59
+ parser (>= 3.1.0.0)
60
+ rainbow (>= 2.2.2, < 4.0)
61
+ regexp_parser (>= 1.8, < 3.0)
62
+ rexml (>= 3.2.5, < 4.0)
63
+ rubocop-ast (>= 1.18.0, < 2.0)
64
+ ruby-progressbar (~> 1.7)
65
+ unicode-display_width (>= 1.4.0, < 3.0)
66
+ rubocop-ast (1.19.1)
67
+ parser (>= 3.1.1.0)
68
+ rubocop-performance (1.14.2)
69
+ rubocop (>= 1.7.0, < 2.0)
70
+ rubocop-ast (>= 0.4.0)
71
+ rubocop-rake (0.6.0)
72
+ rubocop (~> 1.0)
73
+ rubocop-rspec (2.11.1)
74
+ rubocop (~> 1.19)
75
+ ruby-progressbar (1.11.0)
76
+ ruby2_keywords (0.0.5)
77
+ test-prof (1.0.9)
78
+ unicode-display_width (2.2.0)
79
+
80
+ PLATFORMS
81
+ x86_64-linux
82
+
83
+ DEPENDENCIES
84
+ modulr-api!
85
+ rake (~> 12.0)
86
+ rspec (~> 3.0)
87
+ rubocop (~> 1.0)
88
+ rubocop-performance (~> 1.0)
89
+ rubocop-rake (~> 0.1)
90
+ rubocop-rspec (~> 2.0)
91
+ test-prof (~> 1.0)
92
+
93
+ BUNDLED WITH
94
+ 2.3.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 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,47 @@
1
+ # Modulr
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/modulr`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'modulr-api'
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 modulr-api
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ TODO: Write usage instructions here
30
+
31
+ ## Development
32
+
33
+ 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.
34
+
35
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/devengo/modulr-ruby>. 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/devengo/modulr-ruby/blob/master/CODE_OF_CONDUCT.md).
40
+
41
+ ## License
42
+
43
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
44
+
45
+ ## Code of Conduct
46
+
47
+ Everyone interacting in the Modulr project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/devengo/modulr-ruby/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: [:spec, :rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "modulr"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ 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,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Modulr
4
+ module API
5
+ class AccountsService < Service
6
+ def info(account_id:)
7
+ response = client.get("/accounts/#{account_id}")
8
+ puts response.body
9
+ Resources::Accounts::Account.new(response, response.body)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Modulr
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,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Modulr
4
+ module API
5
+ module Services
6
+ def accounts
7
+ @services[:accounts] ||= API::AccountsService.new(self)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "base64"
4
+ require "date"
5
+ require "openssl"
6
+ require "securerandom"
7
+ require "erb"
8
+
9
+ module Modulr
10
+ module Auth
11
+ class Signature
12
+ attr_reader :nonce, :signature, :timestamp, :authorization
13
+
14
+ def initialize(apikey:, nonce:, signature:, timestamp:)
15
+ @nonce = nonce
16
+ @signature = signature
17
+ @timestamp = timestamp
18
+ @authorization = [
19
+ "Signature keyId=\"#{apikey}\"",
20
+ 'algorithm="hmac-sha1"',
21
+ 'headers="date x-mod-nonce"',
22
+ "signature=\"#{signature}\"",
23
+ ].join(",")
24
+ end
25
+
26
+ def self.calculate(apikey:, apisecret:, nonce: SecureRandom.base64(30), timestamp: DateTime.now.httpdate)
27
+ signature_string = "date: #{timestamp}\nx-mod-nonce: #{nonce}"
28
+ digest = OpenSSL::HMAC.digest(
29
+ "SHA1",
30
+ apisecret.force_encoding("UTF-8"),
31
+ signature_string.force_encoding("UTF-8")
32
+ )
33
+ b64 = Base64.encode64(digest)
34
+ url_safe_code = ERB::Util.url_encode(b64.strip)
35
+
36
+ new(apikey: apikey, nonce: nonce, signature: url_safe_code, timestamp: timestamp)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,115 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "faraday_middleware"
5
+ require "json"
6
+
7
+ module Modulr
8
+ class Client
9
+ include Modulr::API::Services
10
+
11
+ BASE_URL = "https://api-sandbox.modulrfinance.com/api-sandbox"
12
+
13
+ attr_reader :base_url, :origin, :proxy, :username, :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
+ @apikey = options[:apikey] || ENV["MODULR_APIKEY"]
20
+ @apisecret = options[:apisecret] || ENV["MODULR_APISECRET"]
21
+ @logger_enabled = options[:logger_enabled].nil? ? true : options[:logger_enabled]
22
+ @services = {}
23
+ end
24
+
25
+ def connection
26
+ @connection ||= Faraday.new do |builder|
27
+ builder.use Faraday::Response::RaiseError
28
+ builder.response :json,
29
+ content_type: /\bjson$/,
30
+ preserve_raw: true,
31
+ parser_options: { symbolize_names: true }
32
+ builder.proxy = @proxy if proxy
33
+ if @logger_enabled
34
+ builder.response :logger, nil, { headers: true, bodies: true } do |logger|
35
+ logger.filter(/("password":)"(\w+)"/, '\1[FILTERED]')
36
+ end
37
+ end
38
+ builder.adapter :net_http
39
+ end
40
+ end
41
+
42
+ def get(path, options = {})
43
+ execute :get, path, nil, options
44
+ end
45
+
46
+ def post(path, data = nil, options = {})
47
+ execute :post, path, data, options
48
+ end
49
+
50
+ def execute(method, path, data = nil, options = {})
51
+ request(method, path, data, options)
52
+ end
53
+
54
+ def request(method, path, data = nil, options = {})
55
+ request_options = request_options(method, path, data, options)
56
+ uri = "#{base_url}#{path}"
57
+
58
+ begin
59
+ connection.run_request(method, uri, request_options[:body], request_options[:headers])
60
+ rescue StandardError => e
61
+ handle_request_error(e)
62
+ end
63
+ end
64
+
65
+ def request_options(_method, _path, data, _options)
66
+ default_options.tap do |defaults|
67
+ add_auth_options!(defaults)
68
+ defaults[:body] = JSON.dump(data) if data
69
+ end
70
+ end
71
+
72
+ def add_auth_options!(options)
73
+ signature = Auth::Signature.calculate(apikey: @apikey, apisecret: @apisecret)
74
+ options[:headers][:authorization] = signature.authorization
75
+ options[:headers][:date] = signature.timestamp
76
+ options[:headers][:"x-mod-nonce"] = signature.nonce
77
+ end
78
+
79
+ def handle_request_error(error)
80
+ case error
81
+ when Faraday::ClientError
82
+ if error.response
83
+ handle_error_response(error)
84
+ else
85
+ handle_network_error(error)
86
+ end
87
+ else
88
+ raise error
89
+ end
90
+ end
91
+
92
+ def handle_error_response(error)
93
+ puts "Client Error: #{error.response}"
94
+ raise error
95
+ end
96
+
97
+ def handle_network_error(error)
98
+ puts "Network error: #{error.response}"
99
+ raise error
100
+ end
101
+
102
+ def default_origin
103
+ "Modulr/#{Modulr::VERSION} Ruby Client (Faraday/#{Faraday::VERSION})"
104
+ end
105
+
106
+ private def default_options
107
+ {
108
+ url: base_url,
109
+ headers: {
110
+ content_type: "application/json",
111
+ },
112
+ }
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Modulr
4
+ module Resources
5
+ module Accounts
6
+ class Account < Base
7
+ attr_reader :identifiers
8
+
9
+ STATUS = {
10
+ active: "ACTIVE",
11
+ blocked: "BLOCKED",
12
+ closed: "CLOSED",
13
+ client_blocked: "CLIENT_BLOCKED",
14
+ }.freeze
15
+ map :id, :id
16
+ map :balance, :balance
17
+ map :availableBalance, :available_balance
18
+ map :currency, :currency
19
+ map :status, :status
20
+ map :customerId, :customer_id
21
+ map :customerName, :customer_name
22
+ map :externalReference, :external_reference
23
+ map :createdDate, :created_at
24
+ map :directDebit, :direct_debit
25
+
26
+ def initialize(response, attributes = {})
27
+ super(response, attributes)
28
+ @identifiers = Accounts::Identifiers.new(response, attributes[:identifiers])
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Modulr
4
+ module Resources
5
+ module Accounts
6
+ class Identifier < Base
7
+ map :type, :type
8
+ map :accountNumber, :account_number
9
+ map :sortCode, :sort_code
10
+ map :iban, :sort_code
11
+ map :bic, :sort_code
12
+ map :currency, :sort_code
13
+ map :countrySpecificDetails, :country_details
14
+ map :providerExtraInfo, :provider_extra_info
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Modulr
4
+ module Resources
5
+ module Accounts
6
+ class Identifiers < Collection
7
+ def initialize(response, attributes_collection)
8
+ super(response, Identifier, attributes_collection)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Modulr
4
+ module Resources
5
+ class Base
6
+ attr_reader :response
7
+
8
+ def initialize(response, attributes = {})
9
+ @response = response
10
+ attributes.each do |key, value|
11
+ m = "#{key}=".to_sym
12
+ send(m, value) if respond_to?(m)
13
+ end
14
+ end
15
+
16
+ def self.map(original_attribute, mapped_attributes)
17
+ class_eval { attr_writer original_attribute.to_sym }
18
+ mapped_attributes = [mapped_attributes].flatten
19
+ mapped_attributes.each do |mapped_attribute|
20
+ define_method(mapped_attribute) { instance_variable_get("@#{original_attribute}") }
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Modulr
4
+ module Resources
5
+ class Collection
6
+ include Enumerable
7
+ attr_reader :response
8
+
9
+ def initialize(response, item_klass, attributes_collection = [])
10
+ @response = response
11
+ @attributes_collection = attributes_collection
12
+ @items = attributes_collection.map { |attributes_item| item_klass.new(nil, attributes_item) }
13
+ end
14
+
15
+ def each(&block)
16
+ @items.each(&block)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Modulr
4
+ VERSION = "0.0.1"
5
+ end
data/lib/modulr.rb ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "modulr/version"
4
+
5
+ require_relative "modulr/auth/signature"
6
+
7
+ require_relative "modulr/api/service"
8
+ require_relative "modulr/api/services"
9
+ require_relative "modulr/api/accounts_service"
10
+
11
+ require_relative "modulr/resources/base"
12
+ require_relative "modulr/resources/collection"
13
+ require_relative "modulr/resources/accounts/account"
14
+ require_relative "modulr/resources/accounts/identifier"
15
+ require_relative "modulr/resources/accounts/identifiers"
16
+
17
+ require_relative "modulr/client"
18
+
19
+ module Modulr
20
+ class Error < StandardError; end
21
+ end
data/modulr.gemspec ADDED
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/modulr/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "modulr-api"
7
+ spec.version = Modulr::VERSION
8
+ spec.authors = ["Aitor García Rey"]
9
+ spec.email = ["aitor@devengo.com"]
10
+
11
+ spec.summary = "Ruby client for Modulr Finance API."
12
+ spec.description = "Ruby client for Modulr Finance API."
13
+ spec.homepage = "https://github.com/devengoapp/modulr-ruby"
14
+
15
+ spec.license = "MIT"
16
+ spec.required_ruby_version = ">= 2.7.0"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://github.com/devengoapp/modulr-ruby"
20
+ spec.metadata["changelog_uri"] = "https://github.com/devengoapp/modulr-ruby/blob/master/CHANGELOG.md"
21
+ spec.metadata["rubygems_mfa_required"] = "true"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
28
+ end
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ spec.add_dependency "faraday", "~> 1.0"
35
+ spec.add_dependency "faraday_middleware", "~> 1.0"
36
+ spec.add_development_dependency "rake", "~> 12.0"
37
+ spec.add_development_dependency "rspec", "~> 3.0"
38
+ spec.add_development_dependency "rubocop", "~> 1.0"
39
+ spec.add_development_dependency "rubocop-performance", "~> 1.0"
40
+ spec.add_development_dependency "rubocop-rake", "~> 0.1"
41
+ spec.add_development_dependency "rubocop-rspec", "~> 2.0"
42
+ spec.add_development_dependency "test-prof", "~> 1.0"
43
+ end
data/sig/modulr.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Modulr
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,199 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: modulr-api
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: exe
10
+ cert_chain: []
11
+ date: 2022-07-16 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: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
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: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-performance
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.1'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.1'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: test-prof
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.0'
139
+ description: Ruby client for Modulr Finance API.
140
+ email:
141
+ - aitor@devengo.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".markdownlint.yaml"
147
+ - ".rspec"
148
+ - ".rubocop.yml"
149
+ - ".rubocop_devengo.yml"
150
+ - CODE_OF_CONDUCT.md
151
+ - Gemfile
152
+ - Gemfile.lock
153
+ - LICENSE.txt
154
+ - README.md
155
+ - Rakefile
156
+ - bin/console
157
+ - bin/setup
158
+ - lib/modulr.rb
159
+ - lib/modulr/api/accounts_service.rb
160
+ - lib/modulr/api/service.rb
161
+ - lib/modulr/api/services.rb
162
+ - lib/modulr/auth/signature.rb
163
+ - lib/modulr/client.rb
164
+ - lib/modulr/resources/accounts/account.rb
165
+ - lib/modulr/resources/accounts/identifier.rb
166
+ - lib/modulr/resources/accounts/identifiers.rb
167
+ - lib/modulr/resources/base.rb
168
+ - lib/modulr/resources/collection.rb
169
+ - lib/modulr/version.rb
170
+ - modulr.gemspec
171
+ - sig/modulr.rbs
172
+ homepage: https://github.com/devengoapp/modulr-ruby
173
+ licenses:
174
+ - MIT
175
+ metadata:
176
+ homepage_uri: https://github.com/devengoapp/modulr-ruby
177
+ source_code_uri: https://github.com/devengoapp/modulr-ruby
178
+ changelog_uri: https://github.com/devengoapp/modulr-ruby/blob/master/CHANGELOG.md
179
+ rubygems_mfa_required: 'true'
180
+ post_install_message:
181
+ rdoc_options: []
182
+ require_paths:
183
+ - lib
184
+ required_ruby_version: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ">="
187
+ - !ruby/object:Gem::Version
188
+ version: 2.7.0
189
+ required_rubygems_version: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ requirements: []
195
+ rubygems_version: 3.3.7
196
+ signing_key:
197
+ specification_version: 4
198
+ summary: Ruby client for Modulr Finance API.
199
+ test_files: []