stp_client 0.2.1 → 0.3.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: bc5b27b5570c48f3fe21db14b7ebbd0131d89d143c677b9ecb75a4d301923bf1
4
- data.tar.gz: cc579b5ec5d1c93077d1c17d4a6e65f2945f3fbcc741c5937bc576f428114139
3
+ metadata.gz: b35312a692c39818b9fb03f02b10dae9ed44de79d1333b64ef7da23bbdb4e638
4
+ data.tar.gz: 65902abc627a5de9e20e37e213744f0f77c8c44571d8c5000c4a75151a4e5741
5
5
  SHA512:
6
- metadata.gz: 3c613cab091aa0cbf59a5c807fa5d04ba12286e4f7c70e0178b190d7d847bca243a2ff3784c4516af972bb97a2ba9041cf5604dfa49dc800b555a5f2efabda69
7
- data.tar.gz: b757d4944f474c1319cb1c66d5ab7234c269707b386bd0804245fc740edaf073b0c3b5788a4b73aa066508c9c27fe0dfdd58e7cc663fedc9754c973c16a6cd82
6
+ metadata.gz: 675889febf324cfbca754443c114b0c99ca3499142ecf471bbe61588c07adf19e6dc7f8aaf7f4989ba79b126216d4d2790447a6f9c12fe1613b8b785394c58bc
7
+ data.tar.gz: d1f14ac8556e19d1677e34d2c37d98eb6b86c51f88f157e4a2333c2dde26136e1e2e06af4349b26777469fd9b629170107328708f88d5844262268ecb000d92a
data/Gemfile.lock CHANGED
@@ -15,8 +15,12 @@ GEM
15
15
  i18n (>= 0.7, < 2)
16
16
  minitest (~> 5.1)
17
17
  tzinfo (~> 1.1)
18
+ addressable (2.7.0)
19
+ public_suffix (>= 2.0.2, < 5.0)
18
20
  bcrypt (3.1.13)
19
21
  concurrent-ruby (1.1.5)
22
+ crack (0.4.3)
23
+ safe_yaml (~> 1.0.0)
20
24
  crypto_yellowme (0.4.0)
21
25
  activemodel (~> 5.2)
22
26
  activesupport (~> 5.0)
@@ -27,11 +31,13 @@ GEM
27
31
  i18n (>= 1.6, < 1.8)
28
32
  faraday (1.0.0)
29
33
  multipart-post (>= 1.2, < 3)
34
+ hashdiff (1.0.1)
30
35
  i18n (1.7.0)
31
36
  concurrent-ruby (~> 1.0)
32
37
  json (2.3.0)
33
38
  minitest (5.13.0)
34
39
  multipart-post (2.1.1)
40
+ public_suffix (4.0.3)
35
41
  rspec (3.9.0)
36
42
  rspec-core (~> 3.9.0)
37
43
  rspec-expectations (~> 3.9.0)
@@ -45,6 +51,7 @@ GEM
45
51
  diff-lcs (>= 1.2.0, < 2.0)
46
52
  rspec-support (~> 3.9.0)
47
53
  rspec-support (3.9.2)
54
+ safe_yaml (1.0.5)
48
55
  simplecov (0.17.1)
49
56
  docile (~> 1.1)
50
57
  json (>= 1.8, < 3)
@@ -53,6 +60,10 @@ GEM
53
60
  thread_safe (0.3.6)
54
61
  tzinfo (1.2.6)
55
62
  thread_safe (~> 0.1)
63
+ webmock (3.4.2)
64
+ addressable (>= 2.3.6)
65
+ crack (>= 0.3.2)
66
+ hashdiff
56
67
 
57
68
  PLATFORMS
58
69
  ruby
@@ -62,6 +73,7 @@ DEPENDENCIES
62
73
  rspec (~> 3.8)
63
74
  simplecov (~> 0.17)
64
75
  stp_client!
76
+ webmock (~> 3.4.2)
65
77
 
66
78
  BUNDLED WITH
67
79
  2.0.2
data/lib/stp.rb CHANGED
@@ -5,6 +5,7 @@ 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
9
 
9
10
  module STP
10
11
  def self.config
data/lib/stp/account.rb CHANGED
@@ -9,7 +9,7 @@ module STP
9
9
  req.body = account.to_json
10
10
  end
11
11
  hash = JSON.parse(response.body)
12
- hash
12
+ raise STP::STPError.new(hash['message']) unless hash['id'] == 0
13
13
  end
14
14
 
15
15
  def self.delete(account)
@@ -21,7 +21,7 @@ module STP
21
21
  req.body = account.to_json
22
22
  end
23
23
  hash = JSON.parse(response.body)
24
- hash
24
+ raise STP::STPError.new(hash['message']) unless hash['id'] == 0
25
25
  end
26
26
  end
27
27
  end
@@ -0,0 +1,4 @@
1
+ module STP
2
+ class STPError < StandardError
3
+ end
4
+ end
data/lib/stp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module STP
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -1,27 +1,28 @@
1
1
  require 'rspec'
2
2
  require 'simplecov'
3
3
  require 'faker'
4
+ require 'webmock/rspec'
4
5
 
5
6
  require 'stp'
6
7
 
7
8
  STP.config do |c|
8
- c.api_uri = 'xxxxx'
9
+ c.api_uri = 'https://demo_url.com:8080/'
9
10
  c.private_key = %q(
10
- -----BEGIN RSA PRIVATE KEY-----
11
- MIICXgIBAAKBgQDO6dcS4k8Sz//09ISLLCIqHjCYNpHUbtauyu4+N3bvTOxgyX9R
12
- fC9hQ0HyL6VjcAoY67BNF1gvLPTRB0ijwMPpl2uEyv2y1pPwxmDoH4dH0aoRrWUW
13
- zSejnfVn4NoHIchiu8umIofDFuGb/cIDnVBikKNFBTf6HxPePUW2p35Q9wIDAQAB
14
- AoGBAJm4jqmf6mEumJkyw/nlauhhj3a2K/dn9STc7MzaRgkY3BA4AtfV7BlVb3vv
15
- O+85QLcs+sj7S++YdbWJtMS7pI/jYQPEiR2pQ9aHx/Hacor92Oi7zEzn6QLr/VKA
16
- K2qPAiRicPItrY4zWkrEwmwX0SBUPjAD3Ffjf8T6cETE8puxAkEA7aijTnkK8FzM
17
- TxXDl6UMxSwjcJeP/vJcN+im+aphliIGJykL1kcXT5B9R3OUyqsbySgmjsG2yNEm
18
- psCEd/rZKQJBAN7hxnVGAeVl1q2NWgL+lCgvgwaoPqE2NzcFsIxs5EOpKXn0fZuR
19
- oH7l09Giv61NmdNAJT1oMxdLVQ9QJ1UNfR8CQQC9ACr3Yk2vv6z/i+hjte/E8ogw
20
- p2ftsaJjGBOKY9R9yAsqo3r1as4ACYGIDEQdNRzAybx4NVf+tk5NuLbgj86ZAkEA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
+ 9bIAmsKrvYVL4B40Nb3jPNXCKm8zRqFu//WX/G1uy5Q6nQ==
25
+ -----END RSA PRIVATE KEY-----
25
26
  )
26
27
  c.private_key_password = '12345678'
27
28
  c.company = 'xxxxx'
@@ -2,8 +2,7 @@ require 'support/stp_test_helpers'
2
2
 
3
3
  RSpec.describe STP::Account do
4
4
  subject do
5
- response = STP::Account.create(account_obj)
6
- response
5
+ STP::Account.create(account_obj)
7
6
  end
8
7
 
9
8
  describe 'account create' do
@@ -32,18 +31,14 @@ RSpec.describe STP::Account do
32
31
  account.phone = Faker::PhoneNumber.phone_number
33
32
  account
34
33
  end
35
-
34
+
36
35
  before do
37
- allow(STP::Account).to receive(:create).
38
- and_return(STPTestHelpers::ACCOUNT_CREATE_MOCK_SUCCESS())
36
+ stub_request(:put, "#{STP.api_uri}/cuentaModule/fisica").to_return(
37
+ body: JSON.dump(STPTestHelpers::ACCOUNT_CREATE_MOCK_SUCCESS()), status: 200
38
+ )
39
39
  end
40
40
 
41
- it do
42
- response = subject
43
- expect(response['id']).not_to be_nil
44
- expect(response['id']).to be 0
45
- expect(response['descripcionError']).to be_nil
46
- end
41
+ it { expect{subject}.not_to raise_error }
47
42
  end
48
43
 
49
44
  context 'with minimal data' do
@@ -54,18 +49,14 @@ RSpec.describe STP::Account do
54
49
  account.rfc = 'RFCURP'
55
50
  account
56
51
  end
57
-
52
+
58
53
  before do
59
- allow(STP::Account).to receive(:create).
60
- and_return(STPTestHelpers::ACCOUNT_CREATE_MOCK_SUCCESS())
54
+ stub_request(:put, "#{STP.api_uri}/cuentaModule/fisica").to_return(
55
+ body: JSON.dump(STPTestHelpers::ACCOUNT_CREATE_MOCK_SUCCESS()), status: 200
56
+ )
61
57
  end
62
58
 
63
- it do
64
- response = subject
65
- expect(response['id']).not_to be_nil
66
- expect(response['id']).to be 0
67
- expect(response['descripcionError']).to be_nil
68
- end
59
+ it { expect{subject}.not_to raise_error }
69
60
  end
70
61
  end
71
62
 
@@ -94,14 +85,14 @@ RSpec.describe STP::Account do
94
85
  account.phone = Faker::PhoneNumber.phone_number
95
86
  account
96
87
  end
97
-
88
+
98
89
  before do
99
- allow(STP::Account).to receive(:create).
100
- and_return(STPTestHelpers::ACCOUNT_CREATE_MOCK_ERROR(-2))
90
+ stub_request(:put, "#{STP.api_uri}/cuentaModule/fisica").to_return(
91
+ body: JSON.dump(STPTestHelpers::ACCOUNT_CREATE_MOCK_ERROR(1)), status: 200
92
+ )
101
93
  end
102
94
 
103
- it { expect(subject['id']).to eq -2 }
104
- it { expect(subject['descripcionError']).not_to be_nil }
95
+ it { expect {subject}.to raise_error(STP::STPError) }
105
96
  end
106
97
  end
107
98
  end
@@ -2,8 +2,7 @@ require 'support/stp_test_helpers'
2
2
 
3
3
  RSpec.describe STP::Account do
4
4
  subject do
5
- response = STP::Account.delete(account_obj)
6
- response
5
+ STP::Account.delete(account_obj)
7
6
  end
8
7
 
9
8
  describe 'account delete' do
@@ -38,12 +37,18 @@ RSpec.describe STP::Account do
38
37
  and_return(STPTestHelpers::ACCOUNT_DELETE_MOCK_SUCCESS())
39
38
  end
40
39
 
41
- it do
42
- response = subject
43
- expect(response['id']).not_to be_nil
44
- expect(response['id']).to be 0
45
- expect(response['descripcionError']).to be_nil
40
+ before do
41
+ allow(STP::Account).to receive(:create).
42
+ and_return(STPTestHelpers::ACCOUNT_DELETE_MOCK_SUCCESS())
43
+ end
44
+
45
+ before do
46
+ stub_request(:delete, "#{STP.api_uri}/cuentaModule/fisica").to_return(
47
+ body: JSON.dump(STPTestHelpers::ACCOUNT_DELETE_MOCK_SUCCESS()), status: 200
48
+ )
46
49
  end
50
+
51
+ it { expect{subject}.not_to raise_error }
47
52
  end
48
53
 
49
54
  context 'with minimal data' do
@@ -54,18 +59,14 @@ RSpec.describe STP::Account do
54
59
  account.rfc = 'RFCURP'
55
60
  account
56
61
  end
57
-
62
+
58
63
  before do
59
- allow(STP::Account).to receive(:delete).
60
- and_return(STPTestHelpers::ACCOUNT_DELETE_MOCK_SUCCESS())
64
+ stub_request(:delete, "#{STP.api_uri}/cuentaModule/fisica").to_return(
65
+ body: JSON.dump(STPTestHelpers::ACCOUNT_DELETE_MOCK_SUCCESS()), status: 200
66
+ )
61
67
  end
62
68
 
63
- it do
64
- response = subject
65
- expect(response['id']).not_to be_nil
66
- expect(response['id']).to be 0
67
- expect(response['descripcionError']).to be_nil
68
- end
69
+ it { expect{subject}.not_to raise_error }
69
70
  end
70
71
  end
71
72
 
@@ -94,14 +95,14 @@ RSpec.describe STP::Account do
94
95
  account.phone = Faker::PhoneNumber.phone_number
95
96
  account
96
97
  end
97
-
98
+
98
99
  before do
99
- allow(STP::Account).to receive(:delete).
100
- and_return(STPTestHelpers::ACCOUNT_DELETE_MOCK_ERROR(-2))
100
+ stub_request(:delete, "#{STP.api_uri}/cuentaModule/fisica").to_return(
101
+ body: JSON.dump(STPTestHelpers::ACCOUNT_DELETE_MOCK_ERROR(-2)), status: 200
102
+ )
101
103
  end
102
104
 
103
- it { expect(subject['id']).to eq -2 }
104
- it { expect(subject['descripcionError']).not_to be_nil }
105
+ it { expect {subject}.to raise_error(STP::STPError) }
105
106
  end
106
107
  end
107
108
  end
data/stp_client.gemspec CHANGED
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "rspec", "~> 3.8"
25
25
  spec.add_development_dependency "faker", "~> 2.0"
26
26
  spec.add_development_dependency "simplecov", "~> 0.17"
27
+ spec.add_development_dependency "webmock", "~> 3.4.2"
27
28
  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.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yellowme
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.17'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 3.4.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 3.4.2
83
97
  description: STP Client is a lib for consuming STP services
84
98
  email: hola@yellowme.mx
85
99
  executables: []
@@ -96,6 +110,7 @@ files:
96
110
  - lib/stp.rb
97
111
  - lib/stp/account.rb
98
112
  - lib/stp/payment_order.rb
113
+ - lib/stp/stp_error.rb
99
114
  - lib/stp/structs/account.rb
100
115
  - lib/stp/structs/payment_order.rb
101
116
  - lib/stp/version.rb