zspay 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1aac14f56e09d57e0571f4693044c020d617f4d857c34bc7f01b508532a36e82
4
+ data.tar.gz: a4b5ecbd3292bdf40f8279ad2dbc7ec50f30e8cb244f6f6b022ffffda6bf1517
5
+ SHA512:
6
+ metadata.gz: a33ca0bdd26dbbcb622bc3f618f2d757670a0c18f95deb5cf3adc6a52a4ca8fca65af04f4bfdbcc7f41e93f0cdfca06748bf626c7e1ab19028f3dc783ebd266c
7
+ data.tar.gz: afea2070c867ec49b5015db4adb00692bab9e95ab88b260cb26b5c6393ab65708084e33c7d26e051f8bd4aaeb09ed74b744c3a8c8b177c7fe7923c6f3174ac2d
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zspay
4
+ class Configuration
5
+ class << self
6
+ attr_accessor :token
7
+
8
+ def endpoint
9
+ 'https://api.zsystems.com.br'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zspay
4
+ class Resource
5
+ class << self
6
+ def post(path, payload = {}, body: 'json')
7
+ req(:post, path, payload, body: body)
8
+ end
9
+
10
+ def patch(path, payload)
11
+ req(:patch, path, payload)
12
+ end
13
+
14
+ def get(path)
15
+ req(:get, path)
16
+ end
17
+
18
+ def delete(path)
19
+ req(:delete, path)
20
+ end
21
+
22
+ def put(path, payload = {})
23
+ req(:put, path, payload)
24
+ end
25
+
26
+ private
27
+
28
+ def req(method, path, payload = {}, body: 'json')
29
+ send("req_#{body}", method, path, payload)
30
+ end
31
+
32
+ def req_json(method, path, payload)
33
+ res = HTTP.headers(headers).send(method, "#{endpoint}#{path}", json: payload)
34
+
35
+ parse_body(res)
36
+ end
37
+
38
+ def req_form(method, path, payload)
39
+ payload = HTTP::FormData::Multipart.new(payload)
40
+ res = HTTP.headers(headers).send(method, "#{endpoint}#{path}", form: payload)
41
+ parse_body(res)
42
+ end
43
+
44
+ def parse_body(response)
45
+ if success_request?(response)
46
+ json = JSON.parse(response.body.to_s, object_class: OpenStruct)
47
+ json.message = JSON.parse(json.message.gsub(/^\d+ - /, ''), object_class: OpenStruct) unless json.success
48
+
49
+ json
50
+ else
51
+ error_log = Logger.new(STDERR)
52
+ error_log.error("Error while making Zspay request" \
53
+ " to: #{response.uri}" \
54
+ " body: #{response.body}" \
55
+ " status: #{response.code}")
56
+
57
+ OpenStruct.new({ success: false, message: 'An error occurred while making the request' })
58
+ end
59
+ end
60
+
61
+ def endpoint
62
+ Zspay::Configuration.endpoint
63
+ end
64
+
65
+ def headers
66
+ {
67
+ 'Authorization': "Bearer #{Zspay::Configuration.token}"
68
+ }
69
+ end
70
+
71
+ def success_request?(response)
72
+ response.code.to_s =~ /2../
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zspay
4
+ class BankAccount < Zspay::Resource
5
+ class << self
6
+ def index
7
+ get('/estabelecimentos/contas_bancarias')
8
+ end
9
+
10
+ def create(account)
11
+ post('/estabelecimentos/contas_bancarias', account)
12
+ end
13
+
14
+ def active(account_id)
15
+ post("/estabelecimentos/contas_bancarias/#{account_id}/ativar")
16
+ end
17
+
18
+ def destroy(establishment_id, account_id)
19
+ delete("/estabelecimentos/#{establishment_id}/contas_bancarias/#{account_id}/excluir")
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zspay
4
+ class Client < Zspay::Resource
5
+ class << self
6
+ def create(client)
7
+ post('/clientes', client)
8
+ end
9
+
10
+ def create_card(client_id, card)
11
+ post("/clientes/#{client_id}/cartoes", card)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zspay
4
+ class Establishments < Zspay::Resource
5
+ class << self
6
+ def index
7
+ get('/estabelecimentos/filhos')
8
+ end
9
+
10
+ def create(establishment)
11
+ post('/estabelecimentos', establishment, body: 'form')
12
+ end
13
+
14
+ def active(establishment_id)
15
+ post("/estabelecimentos/#{establishment_id}/habilitar")
16
+ end
17
+
18
+ def disable(establishment_id)
19
+ delete("/estabelecimentos/#{establishment_id}")
20
+ end
21
+
22
+ def token(establishment_id)
23
+ get("/estabelecimentos/#{establishment_id}/token")
24
+ end
25
+
26
+ def balance(establishment_id)
27
+ get("/estabelecimentos/#{establishment_id}/saldo")
28
+ end
29
+
30
+ def search_by_document(document)
31
+ get("/estabelecimentos/por_documento/#{document}")
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zspay
4
+ class Sale < Zspay::Resource
5
+ class << self
6
+ def create(sale)
7
+ post('/vendas', sale)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zspay/resources/bank_account'
4
+ require 'zspay/resources/client'
5
+ require 'zspay/resources/establishments'
6
+ require 'zspay/resources/sale'
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zspay
4
+ VERSION = '0.1.0'
5
+ end
data/lib/zspay.rb ADDED
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'http'
4
+ require 'byebug'
5
+ require 'logger'
6
+ require 'active_support/hash_with_indifferent_access'
7
+
8
+ require 'zspay/configuration'
9
+
10
+ require 'zspay/resource'
11
+ require 'zspay/resources'
12
+
13
+ module Zspay
14
+ class << self
15
+ def configuration
16
+ @configuration ||= Configuration.new
17
+ end
18
+
19
+ def configure
20
+ yield(configuration)
21
+ end
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zspay
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nullbug
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-12-20 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: '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: byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: ZSPAY
56
+ email:
57
+ - pedro@nullbug.dev
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/zspay.rb
63
+ - lib/zspay/configuration.rb
64
+ - lib/zspay/resource.rb
65
+ - lib/zspay/resources.rb
66
+ - lib/zspay/resources/bank_account.rb
67
+ - lib/zspay/resources/client.rb
68
+ - lib/zspay/resources/establishments.rb
69
+ - lib/zspay/resources/sale.rb
70
+ - lib/zspay/version.rb
71
+ homepage: ''
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 2.4.0
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubygems_version: 3.2.22
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: ZSPAY
94
+ test_files: []