blnk 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 05e768b805f7c2e8f061d334fd923afcf82fcc3945bf0c5a3ac844815403fd3f
4
+ data.tar.gz: 2edddcd8e0227f1183f05d488a7aec58b22cdef9d157e4479fb7e8ca9026aad7
5
+ SHA512:
6
+ metadata.gz: d8084904b5d4210b9c4e0c8b5a7f7bc8d107fca56ff3669e0d01376cbe5360a644e52b490c677b86baa9672ddb04ba417f4fc4c5ab6c7a6170f381d133558b3b
7
+ data.tar.gz: 54bf131a6080c1af282d581c24395cf99ec28c7a26fab84cc09c77d1337f19e1be5600907454470edff6017ac6dd3d1a7b4234da8def6c3700ecd527feee0370
data/.rubocop.yml ADDED
@@ -0,0 +1,262 @@
1
+ # The behavior of RuboCop can be controlled via the .rubocop.yml
2
+ # configuration file. It makes it possible to enable/disable
3
+ # certain cops (checks) and to alter their behavior if they accept
4
+ # any parameters. The file can be placed either in your home
5
+ # directory or in some project directory.
6
+ #
7
+ # RuboCop will start looking for the configuration file in the directory
8
+ # where the inspected file is and continue its way up to the root directory.
9
+ #
10
+ # See https://docs.rubocop.org/rubocop/configuration
11
+
12
+ # require:
13
+ # - rubocop-rails
14
+ # # - rubocop/cop/internal_affairs
15
+ # # - rubocop-performance
16
+ # - rubocop-rspec
17
+ # - rubocop-rspec_rails
18
+ # # - rubocop-rake
19
+
20
+ AllCops:
21
+ NewCops: enable
22
+ Exclude:
23
+ - 'vendor/**/*'
24
+ - 'spec/fixtures/**/*'
25
+ - 'tmp/**/*'
26
+ - '.git/**/*'
27
+ - 'bin/*'
28
+ TargetRubyVersion: 3.3.1
29
+
30
+ Metrics/BlockLength:
31
+ Exclude:
32
+ - 'Rakefile'
33
+ - 'config/routes.rb'
34
+ - '**/*.rake'
35
+ - 'spec/**/*.rb'
36
+
37
+ Lint/MissingSuper:
38
+ Exclude:
39
+ - 'app/services/**/*'
40
+
41
+ Style/Encoding:
42
+ Enabled: false
43
+
44
+ Layout/LineLength:
45
+ Max: 99
46
+
47
+ Style/OpenStructUse:
48
+ Enabled: false
49
+
50
+ Documentation:
51
+ Enabled: false
52
+
53
+
54
+ # This is the configuration used to check the rubocop source code.
55
+
56
+ # inherit_from: .rubocop_todo.yml
57
+ # require:
58
+ # - rubocop-rails
59
+ # - rubocop/cop/internal_affairs
60
+ # - rubocop-performance
61
+ # - rubocop-rspec
62
+ # - rubocop-rake
63
+
64
+ # AllCops:
65
+ # NewCops: enable
66
+ # Exclude:
67
+ # - 'vendor/**/*'
68
+ # - 'spec/fixtures/**/*'
69
+ # - 'tmp/**/*'
70
+ # - '.git/**/*'
71
+ # - 'bin/*'
72
+ # TargetRubyVersion: 2.7
73
+ # SuggestExtensions: false
74
+
75
+ # Naming/PredicateName:
76
+ # # Method define macros for dynamically generated method.
77
+ # MethodDefinitionMacros:
78
+ # - define_method
79
+ # - define_singleton_method
80
+ # - def_node_matcher
81
+ # - def_node_search
82
+
83
+ # Style/AccessorGrouping:
84
+ # Exclude:
85
+ # - lib/rubocop/formatter/base_formatter.rb
86
+ # - lib/rubocop/cop/offense.rb
87
+
88
+ # Style/FormatStringToken:
89
+ # # Because we parse a lot of source codes from strings. Percent arrays
90
+ # # look like unannotated format string tokens to this cop.
91
+ # Exclude:
92
+ # - spec/**/*
93
+
94
+ # Style/IpAddresses:
95
+ # # The test for this cop includes strings that would cause offenses
96
+ # Exclude:
97
+ # - spec/rubocop/cop/style/ip_addresses_spec.rb
98
+
99
+ # Layout/EndOfLine:
100
+ # EnforcedStyle: lf
101
+
102
+ # Layout/ClassStructure:
103
+ # Enabled: true
104
+
105
+ # Layout/RedundantLineBreak:
106
+ # Enabled: true
107
+
108
+ # Layout/TrailingWhitespace:
109
+ # AllowInHeredoc: false
110
+
111
+ # Lint/AmbiguousBlockAssociation:
112
+ # Exclude:
113
+ # - 'spec/**/*.rb'
114
+
115
+ # Layout/HashAlignment:
116
+ # EnforcedHashRocketStyle:
117
+ # - key
118
+ # - table
119
+ # EnforcedColonStyle:
120
+ # - key
121
+ # - table
122
+
123
+ # Layout/LineLength:
124
+ # Max: 100
125
+ # AllowedPatterns:
126
+ # - !ruby/regexp /\A +(it|describe|context|shared_examples|include_examples|it_behaves_like) ["']/
127
+
128
+ # Lint/InterpolationCheck:
129
+ # Exclude:
130
+ # - 'spec/**/*.rb'
131
+
132
+ # Lint/UselessAccessModifier:
133
+ # MethodCreatingMethods:
134
+ # - 'def_matcher'
135
+ # - 'def_node_matcher'
136
+
137
+ # Lint/EmptyFile:
138
+ # Exclude:
139
+ # # This file is intentionally empty to catch rubocop cops failing on empty files.
140
+ # - spec/rubocop/intentionally_empty_file.rb
141
+
142
+ # Metrics/BlockLength:
143
+ # Exclude:
144
+ # - 'Rakefile'
145
+ # - '**/*.rake'
146
+ # - 'spec/**/*.rb'
147
+
148
+ # Metrics/ClassLength:
149
+ # Exclude:
150
+ # - lib/rubocop/config_obsoletion.rb
151
+ # - lib/rubocop/options.rb
152
+
153
+ # Metrics/ModuleLength:
154
+ # Exclude:
155
+ # - 'spec/**/*.rb'
156
+
157
+ # Naming/InclusiveLanguage:
158
+ # Enabled: true
159
+ # CheckStrings: true
160
+ # FlaggedTerms:
161
+ # ' a offense':
162
+ # Suggestions:
163
+ # - an offense
164
+ # auto-correct:
165
+ # Suggestions:
166
+ # - autocorrect
167
+ # auto_correct:
168
+ # Suggestions:
169
+ # - autocorrect
170
+ # behaviour:
171
+ # Suggestions:
172
+ # - behavior
173
+ # offence:
174
+ # Suggestions:
175
+ # - offense
176
+ # 'does not registers':
177
+ # Suggestions:
178
+ # - does not register
179
+ # 'register no offense':
180
+ # Suggestions:
181
+ # - registers no offense
182
+ # Exclude:
183
+ # - lib/rubocop/cop/naming/inclusive_language.rb
184
+ # - lib/rubocop/cop/mixin/auto_corrector.rb
185
+ # - spec/rubocop/cop/naming/inclusive_language_spec.rb
186
+
187
+ # RSpec:
188
+ # Language:
189
+ # Expectations:
190
+ # - expect_autocorrect_options_for_autocorrect
191
+ # - expect_autocorrect_options_for_autocorrect_all
192
+ # - expect_autocorrect_options_for_fix_layout
193
+ # - expect_correction
194
+ # - expect_feature_loader
195
+ # - expect_no_offenses
196
+ # - expect_offense
197
+
198
+ # RSpec/PredicateMatcher:
199
+ # EnforcedStyle: explicit
200
+
201
+ # RSpec/FilePath:
202
+ # Enabled: false
203
+
204
+ # RSpec/SpecFilePathFormat:
205
+ # CustomTransform:
206
+ # GitHubActionsFormatter: github_actions_formatter
207
+ # JUnitFormatter: junit_formatter
208
+ # RedundantLetRuboCopConfigNew: redundant_let_rubocop_config_new
209
+ # Exclude:
210
+ # - spec/rubocop/cop/mixin/enforce_superclass_spec.rb
211
+
212
+ # RSpec/MessageSpies:
213
+ # EnforcedStyle: receive
214
+
215
+ # RSpec/NestedGroups:
216
+ # Max: 7
217
+
218
+ # RSpec/MultipleMemoizedHelpers:
219
+ # Enabled: false
220
+
221
+ # Performance/CollectionLiteralInLoop:
222
+ # Exclude:
223
+ # - 'Rakefile'
224
+ # - 'spec/**/*.rb'
225
+
226
+ # Performance/EndWith:
227
+ # SafeMultiline: false
228
+
229
+ # Performance/StartWith:
230
+ # SafeMultiline: false
231
+
232
+ # RSpec/StubbedMock:
233
+ # Enabled: false
234
+
235
+ # InternalAffairs/ExampleDescription:
236
+ # Include:
237
+ # - 'spec/rubocop/cop/**/*.rb'
238
+
239
+ # InternalAffairs/ExampleHeredocDelimiter:
240
+ # Include:
241
+ # - 'spec/rubocop/cop/**/*.rb'
242
+
243
+ # InternalAffairs/UndefinedConfig:
244
+ # Include:
245
+ # - 'lib/rubocop/cop/**/*.rb'
246
+ # Exclude:
247
+ # - 'lib/rubocop/cop/correctors/**/*.rb'
248
+ # - 'lib/rubocop/cop/mixin/**/*.rb'
249
+
250
+ # InternalAffairs/StyleDetectedApiUse:
251
+ # Exclude:
252
+ # - 'lib/rubocop/cop/mixin/percent_array.rb'
253
+
254
+ # InternalAffairs/NumblockHandler:
255
+ # Exclude:
256
+ # - 'lib/rubocop/cop/internal_affairs/*.rb'
257
+
258
+ # Gemspec/DependencyVersion:
259
+ # Enabled: true
260
+
261
+ # Style/RequireOrder:
262
+ # Enabled: true
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-06-24
4
+
5
+ - Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Antonio Roberto Silva
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,77 @@
1
+ # This gem is under development, don't use in production
2
+
3
+ # Blnk
4
+
5
+ Easy way to use the blnkfinance.com API in ruby
6
+
7
+ ## Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add blnk
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install blnk
16
+
17
+ ## Usage
18
+
19
+ TODO:
20
+ - [x] Create Ledger
21
+ - [x] Find Ledger
22
+ - [x] List Ledgers
23
+ - [ ] Search Ledgers
24
+ - [x] Create Balances
25
+ - [x] Find Balance
26
+ - [ ] Search Balances
27
+ - [ ] Create Transaction
28
+ - [ ] Find Transaction
29
+ - [ ] Search Transactions
30
+
31
+ ## Usage
32
+
33
+ ```ruby
34
+ require 'blnk'
35
+
36
+ # client config
37
+
38
+ Blnk.address = '192.168.2.7:5001'
39
+ Blnk.secret_token = 'your_strong_secret_key'
40
+ Blnk.search_api_key = Blnk.secret_token
41
+
42
+ # ledgers integration
43
+
44
+ ledger = Blnk::Ledger.create(name: 'foobar')
45
+ ledger = Blnk::Ledger.find 'ledger_id'
46
+ ledgers = Blnk::Ledger.all
47
+
48
+ # search not implemented yet
49
+ ledgers = Blnk::Ledger.search(
50
+ q: 'USD',
51
+ filter_by: 'balances > 1400',
52
+ sort_by: 'created_at:desc',
53
+ page: 1,
54
+ per_page: 50
55
+ )
56
+
57
+
58
+ # Balance integrations
59
+ balance = Blnk::Balance.find 'balance_id'
60
+ balance = Blnk::Balance.create(ledger_id: 'ledger_id', currency: 'USD')
61
+
62
+ ```
63
+
64
+
65
+ ## Development
66
+
67
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
68
+
69
+ 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).
70
+
71
+ ## Contributing
72
+
73
+ Bug reports and pull requests are welcome on GitHub at https://github.com/devton/blnk-ruby
74
+
75
+ ## License
76
+
77
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'minitest/test_task'
5
+
6
+ Minitest::TestTask.create(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.warning = false
10
+ t.test_globs = ['./test/**/test_*.rb']
11
+ end
12
+
13
+ require 'rubocop/rake_task'
14
+
15
+ RuboCop::RakeTask.new
16
+
17
+ task default: %i[test rubocop]
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Blnk
4
+ # Balance representation
5
+ class Balance < Resourceable
6
+ def self.resource_name = :balances
7
+
8
+ def persisted? = !balance_id.nil?
9
+ def body_data = { ledger_id:, currency: }
10
+ end
11
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Blnk
4
+ # HTTP Client to do the requests to blnk server
5
+ module Client
6
+ def client
7
+ ::HTTP.headers(
8
+ 'X-Blnk-Key': Blnk.secret_token,
9
+ 'Content-Type': 'application/json',
10
+ accept: 'application/json'
11
+ )
12
+ end
13
+
14
+ def get_request(path:, params: nil)
15
+ client.get(base_uri(path:), params:)
16
+ end
17
+
18
+ def put_request(path:, body:)
19
+ client.put(base_uri(path:), json: body)
20
+ end
21
+
22
+ def post_request(path:, body:)
23
+ client.post(base_uri(path:), json: body)
24
+ end
25
+
26
+ def base_uri(path:, uri: Blnk.address)
27
+ uri = URI(uri)
28
+ uri.path = path if path
29
+ uri
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Blnk
4
+ # Ledger representation
5
+ class Ledger < Resourceable
6
+ def self.resource_name = :ledgers
7
+
8
+ def persisted? = !ledger_id.nil?
9
+ def body_data = { name:, meta_data: }
10
+ end
11
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Blnk
4
+ # Resoureable module that bring some tweaks for basic REST api integration
5
+ class Resourceable < OpenStruct
6
+ include Client
7
+
8
+ def self.resource_name = raise NotImplementedError
9
+
10
+ def self.find(id)
11
+ response = new.get_request(path: "/#{resource_name}/#{id}")
12
+ return response unless response.status.success?
13
+
14
+ new response.parse
15
+ end
16
+
17
+ def self.all
18
+ response = new.get_request(path: "/#{resource_name}")
19
+ return response unless response.status.success?
20
+
21
+ response.parse.map do |r|
22
+ new r
23
+ end
24
+ end
25
+
26
+ def self.create(*)
27
+ response = new.post_request(
28
+ path: "/#{resource_name}",
29
+ body: new(*).body_data
30
+ )
31
+ return response unless response.status.success?
32
+
33
+ new(response.parse)
34
+ end
35
+
36
+ def persisted? = raise NotImplementedError
37
+ def body_data = raise NotImplementedError
38
+ end
39
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Blnk
4
+ VERSION = '0.1.1'
5
+ end
data/lib/blnk.rb ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'http'
4
+ require 'ostruct'
5
+ require_relative 'blnk/version'
6
+ require_relative 'blnk/client'
7
+ require_relative 'blnk/resourceable'
8
+ require_relative 'blnk/ledger'
9
+ require_relative 'blnk/balance'
10
+
11
+ module Blnk
12
+ class Error < StandardError; end
13
+
14
+ class << self
15
+ attr_accessor :address, :secret_token, :search_api_key
16
+ end
17
+
18
+ self.address = ENV.fetch('BLNK_ADDRESS', nil)
19
+ self.secret_token = ENV.fetch('BLNK_SECRET_TOKEN', nil)
20
+ self.search_api_key = ENV.fetch('BLNK_SEARCH_API_KEY', nil)
21
+ end
data/sig/blnk.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Blnk
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blnk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Antonio Roberto Silva
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-06-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: http
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.2.0
27
+ description: Ruby SDK to connect and interact with BLNK Ledger
28
+ email:
29
+ - forevertonny@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rubocop.yml"
35
+ - CHANGELOG.md
36
+ - LICENSE.txt
37
+ - README.md
38
+ - Rakefile
39
+ - lib/blnk.rb
40
+ - lib/blnk/balance.rb
41
+ - lib/blnk/client.rb
42
+ - lib/blnk/ledger.rb
43
+ - lib/blnk/resourceable.rb
44
+ - lib/blnk/version.rb
45
+ - sig/blnk.rbs
46
+ homepage: https://blnkledger.com/
47
+ licenses:
48
+ - MIT
49
+ metadata:
50
+ homepage_uri: https://blnkledger.com/
51
+ source_code_uri: https://github.com/devton/blnk-ruby
52
+ rubygems_mfa_required: 'true'
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 3.3.1
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubygems_version: 3.5.9
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Ruby SDK to connect and interact with BLNK Ledger
72
+ test_files: []