basis_theory 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +11 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +106 -0
- data/LICENSE.txt +21 -0
- data/README.md +159 -0
- data/Rakefile +8 -0
- data/basis_theory.gemspec +30 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/basis_theory/client.rb +40 -0
- data/lib/basis_theory/collection.rb +26 -0
- data/lib/basis_theory/error.rb +6 -0
- data/lib/basis_theory/object.rb +22 -0
- data/lib/basis_theory/objects/application.rb +6 -0
- data/lib/basis_theory/objects/atomic_bank.rb +6 -0
- data/lib/basis_theory/objects/token.rb +6 -0
- data/lib/basis_theory/resource.rb +58 -0
- data/lib/basis_theory/resources/application_resource.rb +14 -0
- data/lib/basis_theory/resources/atomic_bank_resource.rb +26 -0
- data/lib/basis_theory/resources/token_resource.rb +31 -0
- data/lib/basis_theory/version.rb +5 -0
- data/lib/basis_theory.rb +21 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8cb36e8ea25ccb9b9cac48e6532bc040ce6d15d7123e85cd24978470327a586c
|
4
|
+
data.tar.gz: 652a21b9efb13227d4eeb7c00b5009ce7a235a36daf49b51438748f3fc77d342
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7d8120c588ec74a89a204bc89a35673977480ff9d6de550808b0347bda2fa0f9a32720e53769e2d7c340208769aedc1b287a589120ad955c55bd6fcd7ae6887d
|
7
|
+
data.tar.gz: 61584eef9e72b6e18555bd7696e4960ee16ffe0c2e1db305e90091ef1c29801f5b23a61ab10f2f4bbc0c683391ac313a539c3ad739b01c98f6a9303a1b1a021e
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.1.1
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in basis_theory.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem 'debug'
|
9
|
+
gem 'dotenv'
|
10
|
+
gem 'rake', '~> 13.0'
|
11
|
+
gem 'rspec', '~> 3.0'
|
12
|
+
gem 'rubocop', '~> 1.7'
|
13
|
+
gem 'vcr'
|
14
|
+
gem 'webmock'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
basis_theory (0.1.0)
|
5
|
+
faraday (~> 1.8)
|
6
|
+
faraday_middleware (~> 1.1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.8.0)
|
12
|
+
public_suffix (>= 2.0.2, < 5.0)
|
13
|
+
ast (2.4.2)
|
14
|
+
crack (0.4.5)
|
15
|
+
rexml
|
16
|
+
debug (1.1.0)
|
17
|
+
irb
|
18
|
+
reline (>= 0.2.7)
|
19
|
+
diff-lcs (1.4.4)
|
20
|
+
dotenv (2.7.6)
|
21
|
+
faraday (1.8.0)
|
22
|
+
faraday-em_http (~> 1.0)
|
23
|
+
faraday-em_synchrony (~> 1.0)
|
24
|
+
faraday-excon (~> 1.1)
|
25
|
+
faraday-httpclient (~> 1.0.1)
|
26
|
+
faraday-net_http (~> 1.0)
|
27
|
+
faraday-net_http_persistent (~> 1.1)
|
28
|
+
faraday-patron (~> 1.0)
|
29
|
+
faraday-rack (~> 1.0)
|
30
|
+
multipart-post (>= 1.2, < 3)
|
31
|
+
ruby2_keywords (>= 0.0.4)
|
32
|
+
faraday-em_http (1.0.0)
|
33
|
+
faraday-em_synchrony (1.0.0)
|
34
|
+
faraday-excon (1.1.0)
|
35
|
+
faraday-httpclient (1.0.1)
|
36
|
+
faraday-net_http (1.0.1)
|
37
|
+
faraday-net_http_persistent (1.2.0)
|
38
|
+
faraday-patron (1.0.0)
|
39
|
+
faraday-rack (1.0.0)
|
40
|
+
faraday_middleware (1.1.0)
|
41
|
+
faraday (~> 1.0)
|
42
|
+
hashdiff (1.0.1)
|
43
|
+
io-console (0.5.9)
|
44
|
+
irb (1.3.7)
|
45
|
+
reline (>= 0.2.7)
|
46
|
+
multipart-post (2.1.1)
|
47
|
+
parallel (1.20.1)
|
48
|
+
parser (3.0.2.0)
|
49
|
+
ast (~> 2.4.1)
|
50
|
+
public_suffix (4.0.6)
|
51
|
+
rainbow (3.0.0)
|
52
|
+
rake (13.0.6)
|
53
|
+
regexp_parser (2.1.1)
|
54
|
+
reline (0.2.7)
|
55
|
+
io-console (~> 0.5)
|
56
|
+
rexml (3.2.5)
|
57
|
+
rspec (3.10.0)
|
58
|
+
rspec-core (~> 3.10.0)
|
59
|
+
rspec-expectations (~> 3.10.0)
|
60
|
+
rspec-mocks (~> 3.10.0)
|
61
|
+
rspec-core (3.10.1)
|
62
|
+
rspec-support (~> 3.10.0)
|
63
|
+
rspec-expectations (3.10.1)
|
64
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
65
|
+
rspec-support (~> 3.10.0)
|
66
|
+
rspec-mocks (3.10.2)
|
67
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
68
|
+
rspec-support (~> 3.10.0)
|
69
|
+
rspec-support (3.10.2)
|
70
|
+
rubocop (1.20.0)
|
71
|
+
parallel (~> 1.10)
|
72
|
+
parser (>= 3.0.0.0)
|
73
|
+
rainbow (>= 2.2.2, < 4.0)
|
74
|
+
regexp_parser (>= 1.8, < 3.0)
|
75
|
+
rexml
|
76
|
+
rubocop-ast (>= 1.9.1, < 2.0)
|
77
|
+
ruby-progressbar (~> 1.7)
|
78
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
79
|
+
rubocop-ast (1.11.0)
|
80
|
+
parser (>= 3.0.1.1)
|
81
|
+
ruby-progressbar (1.11.0)
|
82
|
+
ruby2_keywords (0.0.5)
|
83
|
+
unicode-display_width (2.0.0)
|
84
|
+
vcr (6.0.0)
|
85
|
+
webmock (3.14.0)
|
86
|
+
addressable (>= 2.8.0)
|
87
|
+
crack (>= 0.3.2)
|
88
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
89
|
+
|
90
|
+
PLATFORMS
|
91
|
+
arm64-darwin-20
|
92
|
+
arm64-darwin-21
|
93
|
+
x86_64-linux
|
94
|
+
|
95
|
+
DEPENDENCIES
|
96
|
+
basis_theory!
|
97
|
+
debug
|
98
|
+
dotenv
|
99
|
+
rake (~> 13.0)
|
100
|
+
rspec (~> 3.0)
|
101
|
+
rubocop (~> 1.7)
|
102
|
+
vcr
|
103
|
+
webmock
|
104
|
+
|
105
|
+
BUNDLED WITH
|
106
|
+
2.3.10
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Scott Olsen
|
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,159 @@
|
|
1
|
+
# BasisTheory API Rubygem
|
2
|
+
|
3
|
+
[![Build Status](https://github.com/scottolsen/basis_theory/workflows/Tests/badge.svg)](https://github.com/scottolsen/basis_theory/actions)
|
4
|
+
|
5
|
+
Rubygem for [Basis Theory](https://basistheory.com/). API docs can be found [here.](https://docs.basistheory.com/api-reference/#introduction)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'basis_theory'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install basis_theory
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Grab an API Key from an Application you created.
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
client = BasisTheory::Client.new(api_key: 'YOUR_API_KEY')
|
29
|
+
```
|
30
|
+
|
31
|
+
### Applications
|
32
|
+
|
33
|
+
#### List Applications
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
applications = client.applications.list # => BasisTheory::Collection
|
37
|
+
|
38
|
+
application = applications.data.first # => BasisTheory::Application
|
39
|
+
|
40
|
+
application.type # => 'server_to_server'
|
41
|
+
```
|
42
|
+
|
43
|
+
#### Create an Application
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
application = client.applications.create(name: 'My Example App', type: 'server_to_server')
|
47
|
+
|
48
|
+
application.type # => 'server_to_server'
|
49
|
+
```
|
50
|
+
|
51
|
+
### Tokens
|
52
|
+
|
53
|
+
#### List Tokens
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
tokens = client.tokens.list # => BasisTheory::Collection
|
57
|
+
|
58
|
+
token = tokens.data.first # => BasisTheory::Token
|
59
|
+
|
60
|
+
token.type # => 'token'
|
61
|
+
token.data # => 'encrypted_data'
|
62
|
+
```
|
63
|
+
|
64
|
+
#### Create an Token
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
token = client.tokens.create(data: 'some_data_to_encrypt')
|
68
|
+
|
69
|
+
token.type # => 'token'
|
70
|
+
```
|
71
|
+
|
72
|
+
#### Find Token
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
token = client.tokens.find('your_token_id') # => BasisTheory::Collection
|
76
|
+
|
77
|
+
token.type # => 'token'
|
78
|
+
token.data # => 'your_encrypted_data'
|
79
|
+
```
|
80
|
+
|
81
|
+
#### Decrypt Token
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
token = client.tokens.decrypt('your_token_id') # => BasisTheory::Collection
|
85
|
+
|
86
|
+
token.type # => 'token'
|
87
|
+
token.data # => 'your_decrypted_data'
|
88
|
+
```
|
89
|
+
|
90
|
+
#### Delete Token
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
client.tokens.delete('your_token_id') # => BasisTheory::Collection
|
94
|
+
```
|
95
|
+
### Atomic Banks
|
96
|
+
|
97
|
+
#### List Atomic Banks
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
atomic_banks = client.atomic_banks.list # => BasisTheory::Collection
|
101
|
+
|
102
|
+
atomic_bank = atomic_banks.data.first # => BasisTheory::AtomicBank
|
103
|
+
|
104
|
+
atomic_bank.type # => 'bank'
|
105
|
+
atomic_bank.bank.routing_number # => '021000021'
|
106
|
+
```
|
107
|
+
|
108
|
+
#### Create an Atomic Bank
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
atomic_bank = client.atomic_banks.create(
|
112
|
+
bank: {
|
113
|
+
routing_number: '021000021',
|
114
|
+
account_number: '1234567890'
|
115
|
+
}
|
116
|
+
)
|
117
|
+
|
118
|
+
atomic_bank.type # => 'bank'
|
119
|
+
atomic_bank.bank.routing_number # => '021000021'
|
120
|
+
```
|
121
|
+
|
122
|
+
#### Find Atomic Bank
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
atomic_bank = client.atomic_banks.find('your_atomic_bank_id') # => BasisTheory::Collection
|
126
|
+
|
127
|
+
atomic_bank.type # => 'bank'
|
128
|
+
atomic_bank.bank.routing_number # => '021000021'
|
129
|
+
atomic_bank.bank.account_number # => 'XXXXX67890'
|
130
|
+
```
|
131
|
+
|
132
|
+
#### Decrypt Atomic Bank
|
133
|
+
|
134
|
+
```ruby
|
135
|
+
atomic_bank = client.atomic_banks.decrypt('your_atomic_bank_id') # => BasisTheory::Collection
|
136
|
+
|
137
|
+
atomic_bank.type # => 'bank'
|
138
|
+
atomic_bank.bank.account_number # => '1234567890'
|
139
|
+
```
|
140
|
+
|
141
|
+
#### Delete Atomic Bank
|
142
|
+
|
143
|
+
```ruby
|
144
|
+
client.atomic_banks.delete('your_atomic_bank_id') # => BasisTheory::Collection
|
145
|
+
```
|
146
|
+
|
147
|
+
## Development
|
148
|
+
|
149
|
+
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.
|
150
|
+
|
151
|
+
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).
|
152
|
+
|
153
|
+
## Contributing
|
154
|
+
|
155
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/scottolsen/basis_theory.
|
156
|
+
|
157
|
+
## License
|
158
|
+
|
159
|
+
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,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/basis_theory/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'basis_theory'
|
7
|
+
spec.version = BasisTheory::VERSION
|
8
|
+
spec.authors = ['Scott Olsen']
|
9
|
+
spec.email = ['solsen300@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'Ruby gem for the Basis Theory API.'
|
12
|
+
spec.description = 'Ruby gem for the Basis Theory API. API docs can be found here: https://docs.basistheory.com/api-reference/#introduction'
|
13
|
+
spec.homepage = 'https://github.com/scottolsen/basis_theory'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.required_ruby_version = '>= 2.6.0'
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
21
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
22
|
+
end
|
23
|
+
end
|
24
|
+
spec.bindir = 'exe'
|
25
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ['lib']
|
27
|
+
|
28
|
+
spec.add_dependency 'faraday', '~> 1.8'
|
29
|
+
spec.add_dependency 'faraday_middleware', '~> 1.1'
|
30
|
+
end
|
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 'basis_theory'
|
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,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
module BasisTheory
|
6
|
+
class Client
|
7
|
+
BASE_URL = 'https://api.basistheory.com/'
|
8
|
+
|
9
|
+
attr_reader :api_key, :adapter
|
10
|
+
|
11
|
+
def initialize(api_key:, adapter: Faraday.default_adapter)
|
12
|
+
@api_key = api_key
|
13
|
+
@adapter = adapter
|
14
|
+
end
|
15
|
+
|
16
|
+
def applications
|
17
|
+
ApplicationResource.new(self)
|
18
|
+
end
|
19
|
+
|
20
|
+
def atomic_banks
|
21
|
+
AtomicBankResource.new(self)
|
22
|
+
end
|
23
|
+
|
24
|
+
def tokens
|
25
|
+
TokenResource.new(self)
|
26
|
+
end
|
27
|
+
|
28
|
+
def connection
|
29
|
+
@connection ||= Faraday.new(BASE_URL) do |conn|
|
30
|
+
# conn.response :logger, ::Logger.new(STDOUT), body: true, bodies: { request: true, response: true }
|
31
|
+
conn.headers['X-API-KEY'] = api_key
|
32
|
+
conn.headers['Content-Type'] = 'application/json'
|
33
|
+
|
34
|
+
conn.response :json, content_type: 'application/json'
|
35
|
+
|
36
|
+
conn.adapter adapter
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BasisTheory
|
4
|
+
class Collection
|
5
|
+
attr_reader :data, :total_items, :page_number, :page_size, :total_pages
|
6
|
+
|
7
|
+
def self.from_response(response, type:)
|
8
|
+
body = response.body
|
9
|
+
new(
|
10
|
+
data: body['data'].map { |attrs| type.new(attrs) },
|
11
|
+
total_items: body.dig('pagination', 'total_items'),
|
12
|
+
page_number: body.dig('pagination', 'page_number'),
|
13
|
+
page_size: body.dig('pagination', 'page_size'),
|
14
|
+
total_pages: body.dig('pagination', 'total_pages')
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(data:, total_items:, page_number:, page_size:, total_pages:)
|
19
|
+
@data = data
|
20
|
+
@total_items = total_items
|
21
|
+
@page_number = page_number
|
22
|
+
@page_size = page_size
|
23
|
+
@total_pages = total_pages
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
module BasisTheory
|
6
|
+
class Object < OpenStruct
|
7
|
+
def initialize(attributes)
|
8
|
+
super to_ostruct(attributes)
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_ostruct(obj)
|
12
|
+
case obj
|
13
|
+
when Hash
|
14
|
+
OpenStruct.new(obj.transform_values { |val| to_ostruct(val) })
|
15
|
+
when Array
|
16
|
+
obj.map { |o| to_ostruct(o) }
|
17
|
+
else
|
18
|
+
obj
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module BasisTheory
|
6
|
+
class Resource
|
7
|
+
attr_reader :client
|
8
|
+
|
9
|
+
def initialize(client)
|
10
|
+
@client = client
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def get_request(url, params: {}, headers: {})
|
16
|
+
handle_response client.connection.get(url, params, headers)
|
17
|
+
end
|
18
|
+
|
19
|
+
def post_request(url, body:, headers: {})
|
20
|
+
handle_response client.connection.post(url, body.to_json, headers)
|
21
|
+
end
|
22
|
+
|
23
|
+
def patch_request(url, body:, headers: {})
|
24
|
+
handle_response client.connection.patch(url, body, headers)
|
25
|
+
end
|
26
|
+
|
27
|
+
def put_request(url, body:, headers: {})
|
28
|
+
handle_response client.connection.put(url, body, headers)
|
29
|
+
end
|
30
|
+
|
31
|
+
def delete_request(url, params: {}, headers: {})
|
32
|
+
handle_response client.connection.delete(url, params, headers)
|
33
|
+
end
|
34
|
+
|
35
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength
|
36
|
+
def handle_response(response)
|
37
|
+
case response.status
|
38
|
+
when 400
|
39
|
+
raise Error, "Invalid request body. #{response.body['error']}"
|
40
|
+
when 401
|
41
|
+
raise Error, "A missing or invalid X-API-KEY was provided. #{response.body['error']}"
|
42
|
+
when 403
|
43
|
+
raise Error, "The provided X-API-KEY does not have the required permissions. #{response.body['error']}"
|
44
|
+
when 404
|
45
|
+
raise Error, "Request entity was not found. #{response.body['error']}"
|
46
|
+
when 422
|
47
|
+
raise Error, "Request does not satisfy requirements for processing. #{response.body['error']}"
|
48
|
+
when 429
|
49
|
+
raise Error, "Request has been rate limited. #{response.body['error']}"
|
50
|
+
when 500
|
51
|
+
raise Error, "Something went wrong on Basis Theory's side. #{response.body['error']}"
|
52
|
+
end
|
53
|
+
|
54
|
+
response
|
55
|
+
end
|
56
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BasisTheory
|
4
|
+
class ApplicationResource < Resource
|
5
|
+
def list(**params)
|
6
|
+
response = get_request('applications', params: params)
|
7
|
+
Collection.from_response(response, type: Application)
|
8
|
+
end
|
9
|
+
|
10
|
+
def create(**attributes)
|
11
|
+
Application.new(post_request('applications', body: attributes).body)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BasisTheory
|
4
|
+
class AtomicBankResource < Resource
|
5
|
+
def list(**params)
|
6
|
+
response = get_request('atomic/banks', params: params)
|
7
|
+
Collection.from_response(response, type: AtomicBank)
|
8
|
+
end
|
9
|
+
|
10
|
+
def create(**attributes)
|
11
|
+
AtomicBank.new(post_request('atomic/banks', body: attributes).body)
|
12
|
+
end
|
13
|
+
|
14
|
+
def find(id)
|
15
|
+
AtomicBank.new(get_request("atomic/banks/#{id}").body)
|
16
|
+
end
|
17
|
+
|
18
|
+
def decrypt(id)
|
19
|
+
AtomicBank.new(get_request("atomic/banks/#{id}/decrypt").body)
|
20
|
+
end
|
21
|
+
|
22
|
+
def delete(id)
|
23
|
+
delete_request("atomic/banks/#{id}")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BasisTheory
|
4
|
+
class TokenResource < Resource
|
5
|
+
def list(**params)
|
6
|
+
response = get_request('tokens', params: params)
|
7
|
+
Collection.from_response(response, type: Token)
|
8
|
+
end
|
9
|
+
|
10
|
+
def list_decrypted(**params)
|
11
|
+
response = get_request('tokens/decrypt', params: params)
|
12
|
+
Collection.from_response(response, type: Token)
|
13
|
+
end
|
14
|
+
|
15
|
+
def create(**attributes)
|
16
|
+
Token.new(post_request('tokens', body: attributes).body)
|
17
|
+
end
|
18
|
+
|
19
|
+
def find(id)
|
20
|
+
Token.new(get_request("tokens/#{id}").body)
|
21
|
+
end
|
22
|
+
|
23
|
+
def decrypt(id)
|
24
|
+
Token.new(get_request("tokens/#{id}/decrypt").body)
|
25
|
+
end
|
26
|
+
|
27
|
+
def delete(id)
|
28
|
+
delete_request("tokens/#{id}")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/basis_theory.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'faraday'
|
4
|
+
require 'faraday_middleware'
|
5
|
+
require 'basis_theory/version'
|
6
|
+
|
7
|
+
module BasisTheory
|
8
|
+
autoload :Client, 'basis_theory/client'
|
9
|
+
autoload :Collection, 'basis_theory/collection'
|
10
|
+
autoload :Error, 'basis_theory/error'
|
11
|
+
autoload :Resource, 'basis_theory/resource'
|
12
|
+
autoload :Object, 'basis_theory/object'
|
13
|
+
|
14
|
+
autoload :ApplicationResource, 'basis_theory/resources/application_resource'
|
15
|
+
autoload :AtomicBankResource, 'basis_theory/resources/atomic_bank_resource'
|
16
|
+
autoload :TokenResource, 'basis_theory/resources/token_resource'
|
17
|
+
|
18
|
+
autoload :Application, 'basis_theory/objects/application'
|
19
|
+
autoload :AtomicBank, 'basis_theory/objects/atomic_bank'
|
20
|
+
autoload :Token, 'basis_theory/objects/token'
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: basis_theory
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Scott Olsen
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-03-26 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.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
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.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.1'
|
41
|
+
description: 'Ruby gem for the Basis Theory API. API docs can be found here: https://docs.basistheory.com/api-reference/#introduction'
|
42
|
+
email:
|
43
|
+
- solsen300@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".rspec"
|
49
|
+
- ".rubocop.yml"
|
50
|
+
- ".ruby-version"
|
51
|
+
- CHANGELOG.md
|
52
|
+
- Gemfile
|
53
|
+
- Gemfile.lock
|
54
|
+
- LICENSE.txt
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- basis_theory.gemspec
|
58
|
+
- bin/console
|
59
|
+
- bin/setup
|
60
|
+
- lib/basis_theory.rb
|
61
|
+
- lib/basis_theory/client.rb
|
62
|
+
- lib/basis_theory/collection.rb
|
63
|
+
- lib/basis_theory/error.rb
|
64
|
+
- lib/basis_theory/object.rb
|
65
|
+
- lib/basis_theory/objects/application.rb
|
66
|
+
- lib/basis_theory/objects/atomic_bank.rb
|
67
|
+
- lib/basis_theory/objects/token.rb
|
68
|
+
- lib/basis_theory/resource.rb
|
69
|
+
- lib/basis_theory/resources/application_resource.rb
|
70
|
+
- lib/basis_theory/resources/atomic_bank_resource.rb
|
71
|
+
- lib/basis_theory/resources/token_resource.rb
|
72
|
+
- lib/basis_theory/version.rb
|
73
|
+
homepage: https://github.com/scottolsen/basis_theory
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 2.6.0
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubygems_version: 3.3.7
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Ruby gem for the Basis Theory API.
|
96
|
+
test_files: []
|