bs2_api 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b46010721b6fd642ba8db84aff501d9a29ecf78faacf023c4dc844ff50d58b41
4
- data.tar.gz: '0982876fca9f7c65f23c58286d9f60bcb01217d934287b38505fd21d2000f9c2'
3
+ metadata.gz: 86300aea3210ea0f4a86d34cc062b75ec68e1315520b240c907b2ec0cf79cd62
4
+ data.tar.gz: 3515768ebac73fec3704b59f332b4c2ddd09b71a33866682ea692409653e577f
5
5
  SHA512:
6
- metadata.gz: 6fcee38ab1c4c3c3ada7eb9e2ada3f8090223ad0d28e0797a7494bd8c00bd11a9d828e2ccc545f9ad23278d9ac86b124116f6b604e7cc476ad5aab08cc5c074a
7
- data.tar.gz: 98e9b97e08e256ee31145a404758702dbd40c6a62f12d018fcf1e0f2de9456efb3604d25fe8361b43d004104003d96ba237020b7afa690d1bf11088c8646c7cf
6
+ metadata.gz: b6ff81648836152febb2a1faa2bf1e592c5e8f3a962e25d29782a6dc99dceddb74d906a83bdfe194c95f32c27b8b1ea1c92bde3d8917d4afeda07d23c1043a4e
7
+ data.tar.gz: 4f195c7cc92db0bbddb6680e2cb54113c65350deeedce4c936a9a244b91b233dd703bcc36d86c8b22b574d214ac32732e94ca2f88573ab619a83405e66d42da6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2021-06-15
4
+
5
+ - Entities, Auth, Create Pix Key Payment
6
+
7
+
3
8
  ## [0.1.0] - 2021-06-11
4
9
 
5
10
  - Initial release
data/Gemfile CHANGED
@@ -2,12 +2,17 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- # Specify your gem's dependencies in bs2_api.gemspec
6
5
  gemspec
7
6
 
8
7
  gem "rake", "~> 13.0"
8
+ gem "httparty", "~> 0.18.1"
9
+ gem "activesupport", "~> 6.1", ">= 6.1.3.2"
9
10
 
10
11
  group :test do
11
12
  gem "pry-byebug", "~> 3.9"
12
- gem 'uuid', '~> 2.3', '>= 2.3.9'
13
+ gem "uuid", "~> 2.3", ">= 2.3.9"
14
+ gem "rspec", "~> 3.10"
15
+ gem "webmock", "~> 3.13"
16
+ gem "vcr", "~> 6.0"
17
+ gem "dotenv", "~> 2.7", ">= 2.7.6"
13
18
  end
data/Gemfile.lock CHANGED
@@ -3,7 +3,6 @@ PATH
3
3
  specs:
4
4
  bs2_api (0.2.0)
5
5
  activesupport (~> 6.1, >= 6.1.3.2)
6
- http (~> 4.4)
7
6
 
8
7
  GEM
9
8
  remote: https://rubygems.org/
@@ -22,30 +21,21 @@ GEM
22
21
  crack (0.4.5)
23
22
  rexml
24
23
  diff-lcs (1.4.4)
25
- domain_name (0.5.20190701)
26
- unf (>= 0.0.5, < 1.0.0)
27
24
  dotenv (2.7.6)
28
- ffi (1.15.1)
29
- ffi-compiler (1.0.1)
30
- ffi (>= 1.0.0)
31
- rake
32
25
  hashdiff (1.0.1)
33
- http (4.4.1)
34
- addressable (~> 2.3)
35
- http-cookie (~> 1.0)
36
- http-form_data (~> 2.2)
37
- http-parser (~> 1.2.0)
38
- http-cookie (1.0.4)
39
- domain_name (~> 0.5)
40
- http-form_data (2.3.0)
41
- http-parser (1.2.3)
42
- ffi-compiler (>= 1.0, < 2.0)
26
+ httparty (0.18.1)
27
+ mime-types (~> 3.0)
28
+ multi_xml (>= 0.5.2)
43
29
  i18n (1.8.10)
44
30
  concurrent-ruby (~> 1.0)
45
31
  macaddr (1.7.2)
46
32
  systemu (~> 2.6.5)
47
33
  method_source (1.0.0)
34
+ mime-types (3.3.1)
35
+ mime-types-data (~> 3.2015)
36
+ mime-types-data (3.2021.0225)
48
37
  minitest (5.14.4)
38
+ multi_xml (0.6.0)
49
39
  pry (0.13.1)
50
40
  coderay (~> 1.1)
51
41
  method_source (~> 1.0)
@@ -71,9 +61,6 @@ GEM
71
61
  systemu (2.6.5)
72
62
  tzinfo (2.0.4)
73
63
  concurrent-ruby (~> 1.0)
74
- unf (0.1.4)
75
- unf_ext
76
- unf_ext (0.0.7.7)
77
64
  uuid (2.3.9)
78
65
  macaddr (~> 1.0)
79
66
  vcr (6.0.0)
@@ -87,8 +74,10 @@ PLATFORMS
87
74
  x86_64-linux
88
75
 
89
76
  DEPENDENCIES
77
+ activesupport (~> 6.1, >= 6.1.3.2)
90
78
  bs2_api!
91
79
  dotenv (~> 2.7, >= 2.7.6)
80
+ httparty (~> 0.18.1)
92
81
  pry-byebug (~> 3.9)
93
82
  rake (~> 13.0)
94
83
  rspec (~> 3.10)
data/bs2_api.gemspec CHANGED
@@ -26,11 +26,5 @@ Gem::Specification.new do |spec|
26
26
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
27
  spec.require_paths = ["lib"]
28
28
 
29
- spec.add_development_dependency "rspec", "~> 3.10"
30
- spec.add_development_dependency "webmock", "~> 3.13"
31
- spec.add_development_dependency "vcr", "~> 6.0"
32
- spec.add_development_dependency "dotenv", "~> 2.7", ">= 2.7.6"
33
-
34
- spec.add_dependency "http", "~> 4.4"
35
29
  spec.add_dependency "activesupport", "~> 6.1", ">= 6.1.3.2"
36
30
  end
data/lib/bs2_api.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  # frozen_string_literal: true
2
+ require 'httparty'
3
+ require "active_support/core_ext/hash/indifferent_access"
2
4
 
3
5
  require 'bs2_api/version'
4
6
  require 'bs2_api/configuration'
@@ -27,8 +29,6 @@ require 'bs2_api/request/auth'
27
29
 
28
30
  require 'bs2_api/util/bank_service'
29
31
 
30
- require "active_support/core_ext/hash/indifferent_access"
31
-
32
32
  module Bs2Api
33
33
  ENDPOINT = {
34
34
  production: 'https://api.bs2.com:8443',
@@ -1,27 +1,23 @@
1
- # frozen_string_literal: true
2
-
3
1
  module Bs2Api
4
2
  module Payment
5
3
  class Base
6
4
  def call
7
- response = HTTP.auth("Bearer #{bearer_token}")
8
- .headers(headers)
9
- .post(
10
- url,
11
- json: payload
12
- )
13
-
14
- raise Bs2Api::Errors::BadRequest, response.body.to_s if !response.status.created?
15
-
16
- Bs2Api::Entities::Payment.from_response(response.parse)
5
+ response = post_request
6
+
7
+ raise Bs2Api::Errors::BadRequest, parse_error(response) if !response.created?
8
+ Bs2Api::Entities::Payment.from_response(response)
17
9
  end
18
10
 
19
11
  private
12
+ def post_request
13
+ HTTParty.post(url, headers: headers, body: payload.to_json)
14
+ end
15
+
20
16
  def headers
21
17
  {
22
18
  "Content-Type": "application/json",
23
19
  "Accept": "application/json",
24
- "Accept-Encoding": "gzip,deflate"
20
+ "Authorization": "Bearer #{bearer_token}"
25
21
  }
26
22
  end
27
23
 
@@ -29,15 +25,26 @@ module Bs2Api
29
25
  Bs2Api::Request::Auth.token
30
26
  end
31
27
 
28
+ def parse_error(response)
29
+ hash = JSON.parse(response.body)
30
+ message = "#{response.code}: "
31
+
32
+ if hash.is_a?(Array)
33
+ message << hash[0]["descricao"]
34
+ elsif hash.key?("error_description")
35
+ message << hash["error_description"]
36
+ else
37
+ message << hash.to_s
38
+ end
39
+
40
+ message
41
+ end
42
+
32
43
  def payload
33
- no_method_error
44
+ raise NoMethodError, "Missing #{__method__} to #{self.class}"
34
45
  end
35
46
 
36
47
  def url
37
- no_method_error
38
- end
39
-
40
- def no_method_error
41
48
  raise NoMethodError, "Missing #{__method__} to #{self.class}"
42
49
  end
43
50
  end
@@ -9,22 +9,23 @@ module Bs2Api
9
9
 
10
10
  response = create_session
11
11
 
12
- raise Bs2Api::Errors::Unauthorized, response.parse["error_description"] if response.status.unauthorized?
13
- raise Bs2Api::Errors::BadRequest, response.parse["error_description"] if response.status.bad_request?
14
- raise Bs2Api::Errors::ServerError, response.body.to_s if !response.status.success?
12
+ raise Bs2Api::Errors::Unauthorized, response["error_description"] if response.unauthorized?
13
+ raise Bs2Api::Errors::BadRequest, response["error_description"] if response.bad_request?
14
+ raise Bs2Api::Errors::ServerError, response.body if !response.success?
15
15
 
16
- response.parse["access_token"]
16
+ response["access_token"]
17
17
  end
18
18
 
19
19
  private
20
20
  def create_session
21
- HTTP.basic_auth(
22
- user: Bs2Api.configuration.client_id,
23
- pass: Bs2Api.configuration.client_secret
24
- ).post(
21
+ HTTParty.post(
25
22
  auth_url,
26
- body: body,
27
- headers: headers
23
+ headers: headers,
24
+ body: body,
25
+ basic_auth: {
26
+ username: Bs2Api.configuration.client_id,
27
+ password: Bs2Api.configuration.client_secret
28
+ }
28
29
  )
29
30
  end
30
31
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bs2Api
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
metadata CHANGED
@@ -1,91 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bs2_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kim Pastro
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-15 00:00:00.000000000 Z
11
+ date: 2021-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rspec
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '3.10'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '3.10'
27
- - !ruby/object:Gem::Dependency
28
- name: webmock
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '3.13'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '3.13'
41
- - !ruby/object:Gem::Dependency
42
- name: vcr
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '6.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '6.0'
55
- - !ruby/object:Gem::Dependency
56
- name: dotenv
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '2.7'
62
- - - ">="
63
- - !ruby/object:Gem::Version
64
- version: 2.7.6
65
- type: :development
66
- prerelease: false
67
- version_requirements: !ruby/object:Gem::Requirement
68
- requirements:
69
- - - "~>"
70
- - !ruby/object:Gem::Version
71
- version: '2.7'
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- version: 2.7.6
75
- - !ruby/object:Gem::Dependency
76
- name: http
77
- requirement: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - "~>"
80
- - !ruby/object:Gem::Version
81
- version: '4.4'
82
- type: :runtime
83
- prerelease: false
84
- version_requirements: !ruby/object:Gem::Requirement
85
- requirements:
86
- - - "~>"
87
- - !ruby/object:Gem::Version
88
- version: '4.4'
89
13
  - !ruby/object:Gem::Dependency
90
14
  name: activesupport
91
15
  requirement: !ruby/object:Gem::Requirement