core_pro.rb 0.0.1 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47e1af473fc3afb70990f259b46c112f2afd2a76b0eaee62ff6e23d6a3cc48ed
4
- data.tar.gz: cd00c1b26e77b9e65f5bb2622820622920c803c24ef11154212739df2e88d96e
3
+ metadata.gz: 130b62b258a66f45f4d37795a3d33bce4d57bbc1c0ebcf1238afe2a0e4e2bf90
4
+ data.tar.gz: e5bb0ab3b6da965530a0b5cbe1e8505cc2d1e16ddb3adae4564f6ada38d5201a
5
5
  SHA512:
6
- metadata.gz: c839debe81fa0792059ff1a5ef41443f5d720cd4d31bec182cf700ec85f4c6a20931277d28942bb95578991aaea157a6141e50088e2d1edc71dfd3fdbb42c3dc
7
- data.tar.gz: 73e433fae0e4488ec487396df6de906807c2e5327d27bc727a61256d670efd609b9d663ba0f3bffa6adbf5d2bb8eb383085842f6ac8884689ae283c449750e06
6
+ metadata.gz: b4a3880e631dc4a72d38f58a7f21892e5eba603e0c8c1447e0e8205deac302de3f33a5b473cf0565f14fdd988c614c18a8f30126e8429047834469bcd8d1fe7d
7
+ data.tar.gz: 2e029a79d634de155fb9353d650adab6ca1c245517cb7b6149b65092414feaced0c143c7e412d61db16ce4546c461bc4d00c445cd4a845c5e788d99246ae083d
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # CorePro API SDK
1
+ # Helix by Q2 (ex CorePro) API SDK
2
2
 
3
- Ruby SDK for working with [CorePro](https://docs.corepro.io)
3
+ Ruby SDK for working with [Helix Q2](https://docs.helix.q2.com)
4
4
 
5
5
  ## Installation
6
6
 
@@ -20,7 +20,7 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- A subset of the CorePro resources are provided with this SDK:
23
+ A subset of the Helix/CorePro resources are provided with this SDK:
24
24
 
25
25
  * `CorePro::Program`
26
26
  * `CorePro::Customer`
@@ -34,6 +34,7 @@ These resources have implemented the following methods to allow API operations:
34
34
  * `#find`
35
35
  * `#create`
36
36
  * `#onboard(kyc_vendor)` (only for `CorePro::Customer`)
37
+ * `#by_tag` (only for `CorePro::Transaction`)
37
38
 
38
39
  Here's an example on how to create a customer, an account,
39
40
  and initiate a transfer:
@@ -66,10 +67,16 @@ transfer = CorePro::Transfer.create(
66
67
  )
67
68
 
68
69
  transactions = CorePro::Transaction.all(
69
- customerId,
70
- accountId,
71
- '2021-12-21',
72
- '2021-12-22'
70
+ [
71
+ customerId,
72
+ accountId,
73
+ '2021-12-21',
74
+ '2021-12-22'
75
+ ],
76
+ {
77
+ pageNumber: 0,
78
+ pageSize: 200
79
+ }
73
80
  )
74
81
  ```
75
82
 
@@ -77,9 +84,9 @@ transactions = CorePro::Transaction.all(
77
84
 
78
85
  The API keys will be loaded from your environment variables:
79
86
 
80
- * `COREPRO_KEY`
81
- * `COREPRO_SECRET`
82
- * `COREPRO_ENDPOINT` defaults to `https://api.corepro.io`
87
+ * `HELIX_KEY`
88
+ * `HELIX_SECRET`
89
+ * `HELIX_ENDPOINT` defaults to `https://api.helix.q2.com`
83
90
 
84
91
  ## Development
85
92
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CorePro
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.4'
5
5
  end
data/lib/core_pro.rb CHANGED
@@ -8,9 +8,16 @@ module CorePro
8
8
  class Resource < OpenStruct
9
9
  extend HTTP::RestClient::DSL
10
10
 
11
- endpoint(ENV['COREPRO_ENDPOINT'] || 'https://api.corepro.io')
12
11
  content_type 'application/json'
13
- basic_auth(user: ENV['COREPRO_KEY'], pass: ENV['COREPRO_SECRET'])
12
+ endpoint(
13
+ ENV['COREPRO_ENDPOINT'] ||
14
+ ENV['HELIX_ENDPOINT'] ||
15
+ 'https://api.helix.q2.com'
16
+ )
17
+ basic_auth(
18
+ user: ENV['COREPRO_KEY'] || ENV['HELIX_KEY'],
19
+ pass: ENV['COREPRO_SECRET'] || ENV['HELIX_SECRET']
20
+ )
14
21
 
15
22
  # Resource collection finder, uses the default limit
16
23
  #
@@ -43,8 +50,8 @@ module CorePro
43
50
  # @param id [String] resource indentifier
44
51
  # @param params [Hash] request parameters to pass to the endpoint as JSON.
45
52
  # @return [Object] instance
46
- def self.update(id, params = {})
47
- objectify(request(:patch, uri(:update, id), json: params))
53
+ def self.update(params = {})
54
+ objectify(request(:post, uri(:update), json: params))
48
55
  end
49
56
 
50
57
  # Resource constructor wrapper
@@ -52,11 +59,11 @@ module CorePro
52
59
  # @param payload [Hash] response payload to build a resource.
53
60
  # @return [Object] instance or a list of instances.
54
61
  def self.objectify(payload)
55
- if payload['data'].is_a?(Array)
62
+ if payload.is_a?(Hash) && payload['data'].is_a?(Array)
56
63
  return payload['data'].map { |data| new(data) }
57
64
  end
58
65
 
59
- return new(payload['data']) if payload['data'].is_a?(Hash)
66
+ return new(payload['data']) if payload&.fetch('data', nil).is_a?(Hash)
60
67
 
61
68
  payload
62
69
  end
@@ -84,7 +91,7 @@ module CorePro
84
91
  #
85
92
  # @return [String]
86
93
  def self.extract_error(response, parsed_response)
87
- parsed_response['errors'] || super(response, parsed_response)
94
+ parsed_response&.fetch('errors', nil) || super(response, parsed_response)
88
95
  end
89
96
 
90
97
  # Validate error response
@@ -96,7 +103,8 @@ module CorePro
96
103
  #
97
104
  # @return [TrueClass] if status code is not a successful standard value
98
105
  def self.error_response?(response, parsed_response)
99
- !(200..299).cover?(response.code) && parsed_response['errors'].any?
106
+ errors = parsed_response&.fetch('errors', nil) || []
107
+ !(200..299).cover?(response.code) || errors.any?
100
108
  end
101
109
  end
102
110
 
@@ -145,5 +153,14 @@ module CorePro
145
153
  # Transaction endpoint resource
146
154
  class Transaction < Resource
147
155
  path '/transaction'
156
+
157
+ # By-tag finder method
158
+ #
159
+ # @param id_or_ids [String] resource indentifiers
160
+ # @param params [Hash] URI parameters to pass to the endpoint.
161
+ # @return [Object] instance
162
+ def self.by_tag(*id_or_ids)
163
+ objectify(request(:get, uri(:getByTag, *id_or_ids)))
164
+ end
148
165
  end
149
166
  end
@@ -75,6 +75,53 @@ RSpec.describe CorePro::Resource do
75
75
  end
76
76
  end
77
77
 
78
+ describe '#update for customer', vcr: 'core_pro' do
79
+ it do
80
+ customer = CorePro::Customer.update(
81
+ customerId: 12_345,
82
+ firstName: 'James',
83
+ lastName: 'Bond',
84
+ isSubjectToBackupWithholding: false,
85
+ isOptedInToBankCommunication: false,
86
+ birthDate: '1987-07-27',
87
+ taxId: '498931947',
88
+ emailAddress: 'stas@startuplandia.io',
89
+ phones: [
90
+ {
91
+ number: '+16502530000',
92
+ phoneType: 'Mobile'
93
+ }
94
+ ],
95
+ addresses: [
96
+ addressLine1: '4017 Buffalo Ave',
97
+ addressType: 'Residence',
98
+ city: 'Buffalo',
99
+ country: 'US',
100
+ postalCode: '94043',
101
+ state: 'NY'
102
+ ]
103
+ )
104
+
105
+ expect(customer.firstName).to eq('James')
106
+ expect(customer.lastName).to eq('Bond')
107
+ expect(customer.customerId).to eq(12_345)
108
+ end
109
+ end
110
+
111
+ describe '#update with errors for customer', vcr: 'core_pro_errors' do
112
+ it do
113
+ expect do
114
+ CorePro::Customer.update(
115
+ customerId: 12_345,
116
+ firstName: 'James'
117
+ )
118
+ end.to raise_error(
119
+ HTTP::RestClient::ResponseError,
120
+ /used during the ID Verification process is not allowed/
121
+ )
122
+ end
123
+ end
124
+
78
125
  describe '#create with errors', vcr: 'core_pro_errors' do
79
126
  let(:new_customer) do
80
127
  CorePro::Customer.create(
@@ -131,4 +178,11 @@ RSpec.describe CorePro::Resource do
131
178
  expect(new_account).to be_a(CorePro::Account)
132
179
  end
133
180
  end
181
+
182
+ describe '#error_response?', vcr: 'core_pro_errors' do
183
+ it do
184
+ expect { CorePro::Account.all }
185
+ .to raise_error(HTTP::RestClient::ResponseError, '502 Bad Gateway')
186
+ end
187
+ end
134
188
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: core_pro.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stas SUȘCOV
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-22 00:00:00.000000000 Z
11
+ date: 2022-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http-rest_client
@@ -168,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
168
  - !ruby/object:Gem::Version
169
169
  version: '0'
170
170
  requirements: []
171
- rubygems_version: 3.2.22
171
+ rubygems_version: 3.3.3
172
172
  signing_key:
173
173
  specification_version: 4
174
174
  summary: CorePro Ruby SDK