juno-sdk 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/juno.rb +19 -0
- data/lib/juno/authorization.rb +43 -0
- data/lib/juno/configuration.rb +46 -0
- data/lib/juno/resource.rb +56 -0
- data/lib/juno/transaction/charges.rb +27 -0
- data/lib/juno/version.rb +5 -0
- data/lib/juno/webhooks.rb +29 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2e1be87c593b5a1575e84f69f01365ec09788af1c5eba92c44dbf9f510b8818f
|
4
|
+
data.tar.gz: 9c0e7d15f76dcaf966b7d2fa1c680f86e4ecce4cbc1147b68696beab24fe5244
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: da974dc5798b77ff1162edd3e29c3ba7ebd0317308d70d8dfc4444dbac64a3c117ffc600fd028fe0e50797dc04dee38f00241819f730fbfef7e27d08243c03e0
|
7
|
+
data.tar.gz: 52b11ec80c91b2ec03fe8d6126ee7abefe852a2e89131fda435c04801d69dbe8441cc9479059c9e7080ab18ec943cd86b3b405e23cd8ac83e347056a4517371e
|
data/lib/juno.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Juno
|
4
|
+
autoload :Authorization, 'juno/authorization.rb'
|
5
|
+
autoload :Configuration, 'juno/configuration.rb'
|
6
|
+
autoload :Transaction, 'juno/charges.rb'
|
7
|
+
autoload :Webhooks, 'juno/webhooks.rb'
|
8
|
+
autoload :Resource, 'juno/resource.rb'
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def configuration
|
12
|
+
@configuration ||= Configuration.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def configure
|
16
|
+
yield(configuration)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'http'
|
4
|
+
|
5
|
+
module Juno
|
6
|
+
class Authorization
|
7
|
+
class << self
|
8
|
+
def token
|
9
|
+
@token ||= access_token
|
10
|
+
end
|
11
|
+
|
12
|
+
def refresh_token
|
13
|
+
@token = access_token
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def access_token
|
19
|
+
url = Juno.configuration.endpoint_for(:authorization)
|
20
|
+
|
21
|
+
response = HTTP.headers(headers).post("#{url}/oauth/token", form: { grant_type: :client_credentials })
|
22
|
+
|
23
|
+
case response.code
|
24
|
+
when 200
|
25
|
+
JSON.parse(response.body.to_s)['access_token']
|
26
|
+
else
|
27
|
+
raise 'Invalid authorization'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def headers
|
32
|
+
credentials = [Juno.configuration.client_id, Juno.configuration.client_secret].map(&:to_s).join(':')
|
33
|
+
|
34
|
+
encoded_credentials = Base64.encode64(credentials).tr("\n", '')
|
35
|
+
|
36
|
+
{
|
37
|
+
'Content-Type' => 'application/x-www-form-urlencoded',
|
38
|
+
'Authorization' => "Basic #{encoded_credentials}"
|
39
|
+
}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
module Juno
|
4
|
+
class Configuration
|
5
|
+
POSSIBLES_ENVIRONMENTS = %i[sandbox production].freeze
|
6
|
+
|
7
|
+
attr_accessor :client_id,
|
8
|
+
:client_secret,
|
9
|
+
:private_token
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@environment = POSSIBLES_ENVIRONMENTS.first
|
13
|
+
end
|
14
|
+
|
15
|
+
def endpoint_for(type)
|
16
|
+
ENDPOINTS.dig(@environment, type)
|
17
|
+
end
|
18
|
+
|
19
|
+
def environment=(environment)
|
20
|
+
raise ArgumentError, "environment #{environment} is not valid" unless valid_environment?(environment)
|
21
|
+
|
22
|
+
@environment = environment
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
ENDPOINTS = {
|
28
|
+
sandbox: {
|
29
|
+
authorization: 'https://sandbox.boletobancario.com/authorization-server',
|
30
|
+
resource: 'https://sandbox.boletobancario.com/api-integration'
|
31
|
+
},
|
32
|
+
production: {
|
33
|
+
authorization: 'https://api.juno.com.br/authorization-server',
|
34
|
+
resource: 'https://api.juno.com.br'
|
35
|
+
}
|
36
|
+
}.freeze
|
37
|
+
|
38
|
+
def base_endpoint
|
39
|
+
ENDPOINTS[@environment]
|
40
|
+
end
|
41
|
+
|
42
|
+
def valid_environment?(environment)
|
43
|
+
POSSIBLES_ENVIRONMENTS.include?(environment.to_sym)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'http'
|
4
|
+
|
5
|
+
module Juno
|
6
|
+
class Resource
|
7
|
+
class << self
|
8
|
+
def post(path, body)
|
9
|
+
req(:post, path, body)
|
10
|
+
end
|
11
|
+
|
12
|
+
def patch(path, body)
|
13
|
+
req(:patch, path, body)
|
14
|
+
end
|
15
|
+
|
16
|
+
def get(path)
|
17
|
+
req(:get, path)
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete(path)
|
21
|
+
req(:delete, path)
|
22
|
+
end
|
23
|
+
|
24
|
+
def put(path, body = {})
|
25
|
+
req(:put, path, body)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def req(method, path, body = {}, fallback = true)
|
31
|
+
res = HTTP.headers(headers).send(method, "#{endpoint}#{path}", json: body)
|
32
|
+
|
33
|
+
if res.code.eql?(401) && fallback
|
34
|
+
Juno::Authorization.refresh_token
|
35
|
+
req(method, path, body, false)
|
36
|
+
else
|
37
|
+
body = res.code.eql?(204) ? '' : JSON.parse(res.body.to_s)
|
38
|
+
{ body: body, code: res.code }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def endpoint
|
43
|
+
Juno.configuration.endpoint_for(:resource)
|
44
|
+
end
|
45
|
+
|
46
|
+
def headers
|
47
|
+
{
|
48
|
+
'Content-Type': 'application/json;charset=UTF-8',
|
49
|
+
'X-Resource-Token': Juno.configuration.private_token,
|
50
|
+
'Authorization': "Bearer #{Juno::Authorization.token}",
|
51
|
+
'X-Api-Version': 2
|
52
|
+
}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Juno
|
4
|
+
class Charges < Juno::Resource
|
5
|
+
class << self
|
6
|
+
def create(body)
|
7
|
+
post('/charges', body)
|
8
|
+
end
|
9
|
+
|
10
|
+
def list
|
11
|
+
get('/charges')
|
12
|
+
end
|
13
|
+
|
14
|
+
def show(id)
|
15
|
+
get("/charges/#{id}")
|
16
|
+
end
|
17
|
+
|
18
|
+
def cancel(id)
|
19
|
+
put("/charges/#{id}/cancelation")
|
20
|
+
end
|
21
|
+
|
22
|
+
def update_split(id)
|
23
|
+
put("/charges/#{id}/split")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/juno/version.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Juno
|
2
|
+
class Webhooks < Juno::Resource
|
3
|
+
class << self
|
4
|
+
def create(body)
|
5
|
+
post('/notifications/webhooks', body)
|
6
|
+
end
|
7
|
+
|
8
|
+
def list
|
9
|
+
get('/notifications/webhooks')
|
10
|
+
end
|
11
|
+
|
12
|
+
def show(id)
|
13
|
+
get("/notifications/webhooks/#{id}")
|
14
|
+
end
|
15
|
+
|
16
|
+
def update(id, body)
|
17
|
+
patch("/notifications/webhooks/#{id}", body)
|
18
|
+
end
|
19
|
+
|
20
|
+
def remove(id)
|
21
|
+
delete("/notifications/webhooks/#{id}")
|
22
|
+
end
|
23
|
+
|
24
|
+
def event_types
|
25
|
+
get('/notifications/event-types')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: juno-sdk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nullbug
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-07-21 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'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: http
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '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: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Juno SDK
|
56
|
+
email:
|
57
|
+
- pedro@nullbug.dev
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- lib/juno.rb
|
63
|
+
- lib/juno/authorization.rb
|
64
|
+
- lib/juno/configuration.rb
|
65
|
+
- lib/juno/resource.rb
|
66
|
+
- lib/juno/transaction/charges.rb
|
67
|
+
- lib/juno/version.rb
|
68
|
+
- lib/juno/webhooks.rb
|
69
|
+
homepage: ''
|
70
|
+
licenses:
|
71
|
+
- MIT
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 2.4.0
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubygems_version: 3.1.2
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: Juno SDK
|
92
|
+
test_files: []
|