stp_client 0.3.0 → 0.4.0

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: b35312a692c39818b9fb03f02b10dae9ed44de79d1333b64ef7da23bbdb4e638
4
- data.tar.gz: 65902abc627a5de9e20e37e213744f0f77c8c44571d8c5000c4a75151a4e5741
3
+ metadata.gz: 5daa60f12ce66c0757768630a8851208f4e16a6f57b769c75da532820c5daff8
4
+ data.tar.gz: 8af7bade911342be87701c0eefd401858663631f1c1a90287e6ec0f6f22c310b
5
5
  SHA512:
6
- metadata.gz: 675889febf324cfbca754443c114b0c99ca3499142ecf471bbe61588c07adf19e6dc7f8aaf7f4989ba79b126216d4d2790447a6f9c12fe1613b8b785394c58bc
7
- data.tar.gz: d1f14ac8556e19d1677e34d2c37d98eb6b86c51f88f157e4a2333c2dde26136e1e2e06af4349b26777469fd9b629170107328708f88d5844262268ecb000d92a
6
+ metadata.gz: 2b65070385c57e1258d2b8df82704d12e9f9b616e3db201f81410431eb51c7a27ca436c4856138de2e64bcea22827811cadae64e4d5f24bb8d4d7eddc4db7e64
7
+ data.tar.gz: d4edc29c1ddb34da6db3d22ee91183753547e84aef5df64e2077aa5ee465ea4031b76d2f828e6e8bf49415207cb152ec39d93b5899f6df8c61b4ed9568401f74
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stp_client (0.2.1)
4
+ stp_client (0.3.0)
5
5
  crypto_yellowme (~> 0.4)
6
6
  faraday (~> 1.0)
7
7
 
@@ -35,7 +35,7 @@ GEM
35
35
  i18n (1.7.0)
36
36
  concurrent-ruby (~> 1.0)
37
37
  json (2.3.0)
38
- minitest (5.13.0)
38
+ minitest (5.14.0)
39
39
  multipart-post (2.1.1)
40
40
  public_suffix (4.0.3)
41
41
  rspec (3.9.0)
data/lib/stp/account.rb CHANGED
@@ -8,8 +8,10 @@ module STP
8
8
  req.headers['Content-Type'] = 'application/json'
9
9
  req.body = account.to_json
10
10
  end
11
+ puts response.body if STP.verbose
11
12
  hash = JSON.parse(response.body)
12
- raise STP::STPError.new(hash['message']) unless hash['id'] == 0
13
+ raise STP::Errors::AccountAlreadyExists.new(hash['id'], hash['message']) if hash['id'] == 1 && hash['message'] == "Cuenta Duplicada"
14
+ raise STP::Errors::STPError.new(hash['id'], hash['message']) unless hash['id'] == 0
13
15
  end
14
16
 
15
17
  def self.delete(account)
@@ -20,8 +22,9 @@ module STP
20
22
  req.headers['Content-Type'] = 'application/json'
21
23
  req.body = account.to_json
22
24
  end
25
+ puts response.body if STP.verbose
23
26
  hash = JSON.parse(response.body)
24
- raise STP::STPError.new(hash['message']) unless hash['id'] == 0
27
+ raise STP::Errors::STPError.new(hash['id'], hash['message']) unless hash['id'] == 0
25
28
  end
26
29
  end
27
30
  end
@@ -0,0 +1,6 @@
1
+ module STP
2
+ module Errors
3
+ class AccountAlreadyExists < STPError
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,18 @@
1
+ module STP
2
+ module Errors
3
+ class STPError < StandardError
4
+ def initialize(code = nil, message = nil)
5
+ @code = code
6
+ @message = message
7
+ end
8
+
9
+ def to_h
10
+ { code: @code, message: @message }
11
+ end
12
+
13
+ def to_s
14
+ to_h.to_s
15
+ end
16
+ end
17
+ end
18
+ end
data/lib/stp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module STP
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
data/lib/stp.rb CHANGED
@@ -5,7 +5,8 @@ require 'stp/structs/account'
5
5
  require 'stp/structs/payment_order'
6
6
  require 'stp/account'
7
7
  require 'stp/payment_order'
8
- require 'stp/stp_error'
8
+ require 'stp/errors/stp_error'
9
+ require 'stp/errors/account_already_exists'
9
10
 
10
11
  module STP
11
12
  def self.config
@@ -43,4 +44,12 @@ module STP
43
44
  def self.company
44
45
  @company
45
46
  end
47
+
48
+ def self.verbose
49
+ @verbose
50
+ end
51
+
52
+ def self.verbose=(verbose)
53
+ @verbose = verbose
54
+ end
46
55
  end
@@ -92,7 +92,7 @@ RSpec.describe STP::Account do
92
92
  )
93
93
  end
94
94
 
95
- it { expect {subject}.to raise_error(STP::STPError) }
95
+ it { expect {subject}.to raise_error(STP::Errors::STPError) }
96
96
  end
97
97
  end
98
98
  end
@@ -102,7 +102,7 @@ RSpec.describe STP::Account do
102
102
  )
103
103
  end
104
104
 
105
- it { expect {subject}.to raise_error(STP::STPError) }
105
+ it { expect {subject}.to raise_error(STP::Errors::STPError) }
106
106
  end
107
107
  end
108
108
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stp_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yellowme
@@ -109,8 +109,9 @@ files:
109
109
  - Rakefile
110
110
  - lib/stp.rb
111
111
  - lib/stp/account.rb
112
+ - lib/stp/errors/account_already_exists.rb
113
+ - lib/stp/errors/stp_error.rb
112
114
  - lib/stp/payment_order.rb
113
- - lib/stp/stp_error.rb
114
115
  - lib/stp/structs/account.rb
115
116
  - lib/stp/structs/payment_order.rb
116
117
  - lib/stp/version.rb
data/lib/stp/stp_error.rb DELETED
@@ -1,4 +0,0 @@
1
- module STP
2
- class STPError < StandardError
3
- end
4
- end