kobana 0.1.0
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 +7 -0
- data/CHANGELOG.md +7 -0
- data/LICENSE +21 -0
- data/README.md +131 -0
- data/Rakefile +12 -0
- data/lib/kobana_ruby_client/base.rb +61 -0
- data/lib/kobana_ruby_client/configuration.rb +12 -0
- data/lib/kobana_ruby_client/resources/charge/bank_billet.rb +23 -0
- data/lib/kobana_ruby_client/resources/charge/pix.rb +17 -0
- data/lib/kobana_ruby_client/resources/resource_operations.rb +31 -0
- data/lib/kobana_ruby_client/version.rb +5 -0
- data/lib/kobana_ruby_client.rb +30 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 334079d4826a8bdd4f675cb5ffe61441d2e96ff16c7843ba29297f9f10516014
|
4
|
+
data.tar.gz: b38d41b3fa4af6b6db02170c41b79ad5cc0ae5f6163ca10b4f09db6bcd896933
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e4f171a71676fa12cfc86cf4d7d1215465e53ecedabe3367462e147fd548469339e2f333252acd7737f1c7b6e27482a6a29eaac4e0b0d240e2e1c13af46bd4b0
|
7
|
+
data.tar.gz: 867c12e536ce5766ebac00f7788b802b19d4f6276a18f50425ecfa60b1fb64d7014a4a70385bcd6479b30515c1ee255721da1e24d9d0135455b43c699a317067
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2023 Kobana
|
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/README.md
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
## KobanaRubyClient - Ruby Client for Kobana Services
|
4
|
+
|
5
|
+
This Ruby gem provides a convenient method to interact with the Kobana APP, simplifying operations with charges and bank billets.
|
6
|
+
|
7
|
+
This is BETA and can change anytimes.
|
8
|
+
Use with caution.
|
9
|
+
|
10
|
+
### Prerequisites
|
11
|
+
|
12
|
+
- Ruby version >= 3.2
|
13
|
+
- Access to the Kobana API and a valid API key
|
14
|
+
|
15
|
+
### Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'kobana_ruby_client'
|
21
|
+
```
|
22
|
+
|
23
|
+
Then execute:
|
24
|
+
|
25
|
+
```bash
|
26
|
+
$ bundle install
|
27
|
+
```
|
28
|
+
|
29
|
+
Or install it yourself as:
|
30
|
+
|
31
|
+
```bash
|
32
|
+
$ gem install kobana_ruby_client
|
33
|
+
```
|
34
|
+
|
35
|
+
### Configuration
|
36
|
+
|
37
|
+
Configure your API key by creating an initializer in your Rails project:
|
38
|
+
|
39
|
+
`config/initializers/kobana_ruby_client.rb`
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
KobanaRubyClient.api_key = 'YOUR_API_KEY_HERE'
|
43
|
+
```
|
44
|
+
|
45
|
+
Replace `'YOUR_API_KEY_HERE'` with your actual API key.
|
46
|
+
|
47
|
+
### Usage
|
48
|
+
|
49
|
+
To use this gem:
|
50
|
+
|
51
|
+
#### **Configuration**
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
KobanaRubyClient.configure do |config|
|
55
|
+
config.api_token = 'YOUR_API_KEY'
|
56
|
+
config.environment = :sandbox # you can specify the environment as :development, :sandbox, or :production
|
57
|
+
config.api_version = :v1 #or :v2
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
#### **Charges**
|
62
|
+
|
63
|
+
##### Creating a Charge
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
charge_data = {
|
67
|
+
'amount' => 100.50,
|
68
|
+
'payer' => {
|
69
|
+
'document_number' => '1234567890',
|
70
|
+
'name' => 'John Doe'
|
71
|
+
},
|
72
|
+
'pix_account_id' => 1,
|
73
|
+
'expire_at' => '2023-12-31',
|
74
|
+
'message' => 'Thanks for your purchase!',
|
75
|
+
'additional_info' => {
|
76
|
+
'Chave' => 'Value'
|
77
|
+
},
|
78
|
+
'custom_data' => '{"order_id": "12345"}'
|
79
|
+
}
|
80
|
+
|
81
|
+
charge = KobanaRubyClient::Resources::Charge::Pix.new
|
82
|
+
result = charge.create(charge_data)
|
83
|
+
puts result
|
84
|
+
```
|
85
|
+
|
86
|
+
##### Fetching a Charge
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
charge_id = 1 # Replace with your charge ID
|
90
|
+
charge = KobanaRubyClient::Resources::Charge::Pix.new
|
91
|
+
result = charge.find(charge_id)
|
92
|
+
puts result
|
93
|
+
```
|
94
|
+
|
95
|
+
##### Listing All Charges
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
charge = KobanaRubyClient::Resources::Charge::Pix.new
|
99
|
+
params = { status: ["opened", "overdue"], page: 2 }
|
100
|
+
results = charge.index(params)
|
101
|
+
puts result
|
102
|
+
```
|
103
|
+
|
104
|
+
#### **Bank Billets**
|
105
|
+
|
106
|
+
##### Creating a Bank Billet
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
bank_billet_data = { ... }
|
110
|
+
|
111
|
+
bank_billet = KobanaRubyClient::Resources::BankBillet::BankBillet.new
|
112
|
+
result = bank_billet.create(bank_billet_data)
|
113
|
+
puts result
|
114
|
+
```
|
115
|
+
|
116
|
+
##### Fetching a Bank Billet
|
117
|
+
|
118
|
+
```ruby
|
119
|
+
bank_billet_id = 1 # Replace with your charge ID
|
120
|
+
bank_billet = KobanaRubyClient::Resources::BankBillet::BankBillet.new
|
121
|
+
result = bank_billet.find(bank_billet_id)
|
122
|
+
puts result
|
123
|
+
```
|
124
|
+
|
125
|
+
##### Listing All Bank Billets
|
126
|
+
|
127
|
+
```ruby
|
128
|
+
bank_billet = KobanaRubyClient::Resources::BankBillet::BankBillet.new
|
129
|
+
result = bank_billet.index
|
130
|
+
puts result
|
131
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "faraday"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
module KobanaRubyClient
|
7
|
+
class Base
|
8
|
+
attr_reader :base_url, :custom_headers
|
9
|
+
|
10
|
+
BASE_URI = {
|
11
|
+
v2: {
|
12
|
+
sandbox: "https://api-sandbox.kobana.com.br/v2",
|
13
|
+
production: "https://api.kobana.com.br/v2",
|
14
|
+
development: "http://localhost:5000/api/v2"
|
15
|
+
},
|
16
|
+
v1: {
|
17
|
+
sandbox: "https://api-sandbox.kobana.com.br/v1",
|
18
|
+
production: "https://api.kobana.com.br/v1",
|
19
|
+
development: "http://localhost:5000/api/v1"
|
20
|
+
}
|
21
|
+
}.freeze
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
config = KobanaRubyClient.configuration
|
25
|
+
|
26
|
+
@api_key = config.api_token
|
27
|
+
@base_url = BASE_URI[config.api_version][config.environment]
|
28
|
+
@custom_headers = config.custom_headers
|
29
|
+
@debug = config.debug
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def default_headers
|
35
|
+
{
|
36
|
+
"Authorization" => "Bearer #{@api_key}",
|
37
|
+
"Content-Type" => "application/json"
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def connection
|
42
|
+
headers = default_headers.merge(@custom_headers)
|
43
|
+
Faraday.new(url: @base_url) do |faraday|
|
44
|
+
faraday.request :url_encoded
|
45
|
+
faraday.adapter Faraday.default_adapter
|
46
|
+
faraday.headers = headers
|
47
|
+
faraday.response :logger if @debug
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def parse_response(response)
|
52
|
+
body_parsed = JSON.parse(response.body, symbolize_names: true)
|
53
|
+
|
54
|
+
if body_parsed.is_a?(Array) || !body_parsed.key?(:data)
|
55
|
+
{ status: response.status, data: body_parsed }
|
56
|
+
else
|
57
|
+
body_parsed
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KobanaRubyClient
|
4
|
+
module Resources
|
5
|
+
module Charge
|
6
|
+
class BankBillet < Base
|
7
|
+
include ResourceOperations
|
8
|
+
|
9
|
+
@resource_endpoint = "bank_billets"
|
10
|
+
|
11
|
+
class << self
|
12
|
+
attr_reader :resource_endpoint
|
13
|
+
end
|
14
|
+
|
15
|
+
def cancel(resource_id)
|
16
|
+
url = "#{base_url}/#{endpoint}/#{resource_id}/cancel"
|
17
|
+
response = connection.put(url)
|
18
|
+
{ status: response.status, data: {} }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KobanaRubyClient
|
4
|
+
module Resources
|
5
|
+
module Charge
|
6
|
+
class Pix < Base
|
7
|
+
include ResourceOperations
|
8
|
+
|
9
|
+
@resource_endpoint = "charge/pix"
|
10
|
+
|
11
|
+
class << self
|
12
|
+
attr_reader :resource_endpoint
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KobanaRubyClient
|
4
|
+
module Resources
|
5
|
+
module ResourceOperations
|
6
|
+
def index(params = {})
|
7
|
+
url = "#{base_url}/#{endpoint}"
|
8
|
+
response = connection.get(url, params)
|
9
|
+
parse_response(response)
|
10
|
+
end
|
11
|
+
|
12
|
+
def create(data)
|
13
|
+
url = "#{base_url}/#{endpoint}"
|
14
|
+
response = connection.post(url, data.to_json)
|
15
|
+
parse_response(response)
|
16
|
+
end
|
17
|
+
|
18
|
+
def find(resource_id)
|
19
|
+
url = "#{base_url}/#{endpoint}/#{resource_id}"
|
20
|
+
response = connection.get(url)
|
21
|
+
parse_response(response)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def endpoint
|
27
|
+
self.class.resource_endpoint
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "faraday"
|
4
|
+
require "json"
|
5
|
+
require "kobana_ruby_client/configuration"
|
6
|
+
|
7
|
+
module KobanaRubyClient
|
8
|
+
class << self
|
9
|
+
attr_writer :configuration
|
10
|
+
|
11
|
+
def configuration
|
12
|
+
@configuration ||= Configuration.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def configure
|
16
|
+
yield(configuration) if block_given?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
autoload :Base, "kobana_ruby_client/base"
|
21
|
+
autoload :Version, "kobana_ruby_client/version"
|
22
|
+
|
23
|
+
module Resources
|
24
|
+
autoload :ResourceOperations, "kobana_ruby_client/resources/resource_operations"
|
25
|
+
module Charge
|
26
|
+
autoload :Pix, "kobana_ruby_client/resources/charge/pix"
|
27
|
+
autoload :BankBillet, "kobana_ruby_client/resources/charge/bank_billet"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kobana
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kivanio Barbosa
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-01-03 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.4'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '3.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.4'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: json
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
description: Kobana API Client
|
48
|
+
email:
|
49
|
+
- kivanio@gmail.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- CHANGELOG.md
|
55
|
+
- LICENSE
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- lib/kobana_ruby_client.rb
|
59
|
+
- lib/kobana_ruby_client/base.rb
|
60
|
+
- lib/kobana_ruby_client/configuration.rb
|
61
|
+
- lib/kobana_ruby_client/resources/charge/bank_billet.rb
|
62
|
+
- lib/kobana_ruby_client/resources/charge/pix.rb
|
63
|
+
- lib/kobana_ruby_client/resources/resource_operations.rb
|
64
|
+
- lib/kobana_ruby_client/version.rb
|
65
|
+
homepage: https://www.kobana.com.br/
|
66
|
+
licenses: []
|
67
|
+
metadata:
|
68
|
+
homepage_uri: https://github.com/universokobana/kobana-ruby-client
|
69
|
+
changelog_uri: https://github.com/universokobana/kobana-ruby-client/releases
|
70
|
+
source_code_uri: https://github.com/universokobana/kobana-ruby-client
|
71
|
+
bug_tracker_uri: https://github.com/universokobana/kobana-ruby-client/issues
|
72
|
+
documentation_uri: https://github.com/universokobana/kobana-ruby-client/wiki
|
73
|
+
rubygems_mfa_required: 'true'
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.2.6
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubygems_version: 3.5.23
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: Kobana API Client
|
93
|
+
test_files: []
|