finapps 2.0.15 → 2.0.16

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
  SHA1:
3
- metadata.gz: 2242125f25f1a4a899e074d02fcce073bfa609e2
4
- data.tar.gz: c35d6ae1c4d2da1c9915a9d9b13b912949ce450a
3
+ metadata.gz: 7acc8269730e6c9379955eadb06949d765436767
4
+ data.tar.gz: 60954938368277bfd3d29b76ab001c67f71025d9
5
5
  SHA512:
6
- metadata.gz: d6624a26b750c6f7d1c2271961210967bc60caddc75a12bd4f66e8dbef080c4d3ca68a21b6e98fd22bbd3834044ef4bd164cabf0352ec5be42a635dd64734769
7
- data.tar.gz: 6c1504ecf7d72f1b11bf0a601c2bcba4a23185000cfd6e8500ac2581eb84e5f32477d85aed672b3aee5947d80500244189afd8ccfec58fcd1805a903a9fe3927
6
+ metadata.gz: eb7dae092bd33046c5f7f605e92eb4b6f454595a9a8089fbc1543308dafc78166e9fb3fb5c922efe828a38a624f9511cfc1bcb456266a24e3485174badb75740
7
+ data.tar.gz: fcb7e7fd5186a691e8948a67d874bbc090b99f34226a9c9bd7b360d8a3e4289581b8ab29d9693db817fcbcd6d3d771f9fa5bca223347193c7ac621309a0dc919
@@ -39,7 +39,7 @@ module FinApps
39
39
  raise FinApps::MissingArgumentsError.new 'Missing argument: method.' if method.blank?
40
40
 
41
41
  response, error_messages = execute_request(method, params, path)
42
- result = if response.blank?
42
+ result = if empty?(response)
43
43
  nil
44
44
  else
45
45
  block_given? ? yield(response) : response.body
@@ -50,6 +50,10 @@ module FinApps
50
50
 
51
51
  private
52
52
 
53
+ def empty?(response)
54
+ response.blank? || (response.respond_to?(:body) && response.body.blank?)
55
+ end
56
+
53
57
  def execute_request(method, params, path)
54
58
  error_messages = []
55
59
  begin
@@ -21,14 +21,32 @@ module FinApps
21
21
  [results, error_messages]
22
22
  end
23
23
 
24
- def show(id, path=nil)
24
+ def update(params={}, path=nil)
25
+ path = end_point if path.nil?
26
+ logger.debug "#{self.class.name}##{__method__} => path: #{path} params: #{params}"
27
+ results, error_messages = client.send_request(path, :put, params)
28
+ [results, error_messages]
29
+ end
30
+
31
+ def show(id=nil, path=nil)
32
+ raise MissingArgumentsError.new 'Missing argument: id.' if id.nil? && path.nil?
33
+
25
34
  path = "#{end_point}/:id".sub ':id', ERB::Util.url_encode(id) if path.nil?
26
35
  logger.debug "#{self.class.name}##{__method__} => path: #{path}"
27
36
  results, error_messages = client.send_request(path, :get)
28
37
  [results, error_messages]
29
38
  end
30
39
 
31
- private
40
+ def destroy(id=nil, path=nil)
41
+ raise MissingArgumentsError.new 'Missing argument: id.' if id.nil? && path.nil?
42
+
43
+ path = "#{end_point}/:id".sub ':id', ERB::Util.url_encode(id) if path.nil?
44
+ logger.debug "#{self.class.name}##{__method__} => path: #{path}"
45
+ results, error_messages = client.send_request(path, :delete)
46
+ [results, error_messages]
47
+ end
48
+
49
+ protected
32
50
 
33
51
  def logger
34
52
  client.logger
@@ -2,60 +2,32 @@
2
2
  module FinApps
3
3
  module REST
4
4
  class Users < FinApps::REST::Resources # :nodoc:
5
+ require 'erb'
6
+
5
7
  using ObjectExtensions
6
8
  using StringExtensions
7
9
 
8
- END_POINTS = {
9
- list: nil,
10
- create: 'users/new',
11
- show: 'users/:public_id',
12
- update: 'user',
13
- destroy: 'users/:public_id'
14
- }.freeze
15
-
16
10
  # @param [String] public_id
17
11
  # @return [FinApps::REST::User, Array<String>]
18
12
  def show(public_id)
19
13
  raise MissingArgumentsError.new 'Missing argument: public_id.' if public_id.blank?
20
-
21
- end_point = END_POINTS[:show]
22
- path = end_point.sub ':public_id', ERB::Util.url_encode(public_id)
23
-
24
- logger.debug "##{__method__} => path: #{path}"
25
-
26
- results, error_messages = client.send_request(path, :get)
27
- [results, error_messages]
14
+ super public_id
28
15
  end
29
16
 
30
17
  # @param [Hash] params
31
18
  # @return [Array<String>]
32
- def update(params)
19
+ def update(public_id, params)
20
+ raise MissingArgumentsError.new 'Missing argument: public_id.' if public_id.blank?
33
21
  raise MissingArgumentsError.new 'Missing argument: params.' if params.blank?
34
- logger.debug "##{__method__} => params: #{params}"
35
-
36
- end_point = END_POINTS[:update]
37
- path = end_point
38
22
 
39
- logger.debug "##{__method__} => path: #{path}"
40
-
41
- results, error_messages = client.send_request(path, :put, params.compact)
42
- [results, error_messages]
23
+ path = "#{end_point}/#{ERB::Util.url_encode(public_id)}#{'/password' if password_update?(params)}"
24
+ super params, path
43
25
  end
44
26
 
45
- # @param [String] public_id
46
- # @return [Array<String>]
47
- def delete(public_id)
48
- raise MissingArgumentsError.new 'Missing argument: public_id.' if public_id.blank?
49
- logger.debug "##{__method__} => public_id: #{public_id}"
50
-
51
- end_point = END_POINTS[:delete]
52
- logger.debug "##{__method__} => end_point: #{end_point}"
53
-
54
- path = end_point.sub ':public_id', ERB::Util.url_encode(public_id)
55
- logger.debug "##{__method__} => path: #{path}"
27
+ private
56
28
 
57
- results, error_messages = client.send_request(path, :delete)
58
- [results, error_messages]
29
+ def password_update?(params)
30
+ params.key?(:password) && params.key?(:password_confirm)
59
31
  end
60
32
  end
61
33
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module FinApps
3
- VERSION = '2.0.15'
3
+ VERSION = '2.0.16'
4
4
  end
@@ -25,7 +25,7 @@ RSpec.describe FinApps::REST::OrderTokens, 'initialized with valid FinApps::Clie
25
25
 
26
26
  it { expect { show }.not_to raise_error }
27
27
  it('results is nil') { expect(results).to be_nil }
28
- it('error messages array is populated') { expect(error_messages.first).to eq('resource not found') }
28
+ it('error messages array is populated') { expect(error_messages.first.downcase).to eq('resource not found') }
29
29
  end
30
30
  end
31
31
  end
@@ -21,11 +21,21 @@ RSpec.describe FinApps::REST::Resources do
21
21
 
22
22
  describe '#create' do
23
23
  context 'when valid params are provided' do
24
- subject { FinApps::REST::Resources.new(client) }
25
- it { expect { subject.create }.not_to raise_error }
26
- it('returns an array') { expect(subject.create).to be_a(Array) }
27
- it('performs a post and returns the response') { expect(subject.create[0]).to respond_to(:public_id) }
28
- it('returns no error messages') { expect(subject.create[1]).to be_empty }
24
+ subject { FinApps::REST::Resources.new(client).create }
25
+ it { expect { subject }.not_to raise_error }
26
+ it('returns an array') { expect(subject).to be_a(Array) }
27
+ it('performs a post and returns the response') { expect(subject[0]).to respond_to(:public_id) }
28
+ it('returns no error messages') { expect(subject[1]).to be_empty }
29
+ end
30
+ end
31
+
32
+ describe '#update' do
33
+ context 'when valid params are provided' do
34
+ subject { FinApps::REST::Resources.new(client).update }
35
+ it { expect { subject }.not_to raise_error }
36
+ it('returns an array') { expect(subject).to be_a(Array) }
37
+ it('performs a put and returns the response') { expect(subject[0]).to respond_to(:public_id) }
38
+ it('returns no error messages') { expect(subject[1]).to be_empty }
29
39
  end
30
40
  end
31
41
 
@@ -34,7 +44,17 @@ RSpec.describe FinApps::REST::Resources do
34
44
  subject { FinApps::REST::Resources.new(client).show(:id) }
35
45
  it { expect { subject }.not_to raise_error }
36
46
  it('returns an array') { expect(subject).to be_a(Array) }
37
- it('performs a post and returns the response') { expect(subject[0]).to respond_to(:public_id) }
47
+ it('performs a get and returns the response') { expect(subject[0]).to respond_to(:public_id) }
48
+ it('returns no error messages') { expect(subject[1]).to be_empty }
49
+ end
50
+ end
51
+
52
+ describe '#destroy' do
53
+ context 'when valid params are provided' do
54
+ subject { FinApps::REST::Resources.new(client).destroy(:id) }
55
+ it { expect { subject }.not_to raise_error }
56
+ it('returns an array') { expect(subject).to be_a(Array) }
57
+ it('performs a delete and returns an empty response') { expect(subject[0]).to be_nil }
38
58
  it('returns no error messages') { expect(subject[1]).to be_empty }
39
59
  end
40
60
  end
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+ RSpec.describe FinApps::REST::Users, 'initialized with valid FinApps::Client object' do
3
+ missing_public_id = 'Missing argument: public_id.'
4
+ client = FinApps::REST::Client.new :company_identifier, :company_token
5
+
6
+ describe '#show' do
7
+ subject(:users) { FinApps::REST::Users.new(client) }
8
+
9
+ context 'when missing public_id' do
10
+ it { expect { subject.show(nil) }.to raise_error(FinApps::MissingArgumentsError, missing_public_id) }
11
+ end
12
+
13
+ context 'for valid public_id' do
14
+ let(:show) { subject.show(:valid_public_id) }
15
+ let(:results) { show[0] }
16
+ let(:error_messages) { show[1] }
17
+
18
+ it { expect { show }.not_to raise_error }
19
+ it('results is a Hashie::Rash') { expect(results).to be_a(Hashie::Rash) }
20
+ it('performs a get and returns the response') { expect(results).to respond_to(:public_id) }
21
+ it('error_messages array is empty') { expect(error_messages).to eq([]) }
22
+ end
23
+
24
+ context 'for invalid token' do
25
+ let(:show) { subject.show(:invalid_public_id) }
26
+ let(:results) { show[0] }
27
+ let(:error_messages) { show[1] }
28
+
29
+ it { expect { show }.not_to raise_error }
30
+ it('results is nil') { expect(results).to be_nil }
31
+ it('error messages array is populated') { expect(error_messages.first.downcase).to eq('resource not found') }
32
+ end
33
+ end
34
+
35
+ describe '#update' do
36
+ subject(:users) { FinApps::REST::Users.new(client) }
37
+
38
+ context 'when missing public_id' do
39
+ it { expect { subject.update(nil, {}) }.to raise_error(FinApps::MissingArgumentsError, missing_public_id) }
40
+ end
41
+
42
+ context 'when updating user details' do
43
+ context 'for valid public_id' do
44
+ let(:update) { subject.update(:valid_public_id, postal_code: '33021') }
45
+ let(:results) { update[0] }
46
+ let(:error_messages) { update[1] }
47
+
48
+ it { expect { update }.not_to raise_error }
49
+ it('results is nil') { expect(results).to be_nil }
50
+ it('error_messages array is empty') { expect(error_messages).to eq([]) }
51
+ end
52
+
53
+ context 'for invalid public_id' do
54
+ # no point testing this context unless this api bug is solved: https://github.com/finapps/api/issues/209
55
+ end
56
+ end
57
+
58
+ context 'when updating password' do
59
+ context 'for valid public_id' do
60
+ let(:update) { subject.update(:valid_public_id, password: 'Aa123456!', password_confirm: 'Aa123456!') }
61
+ let(:results) { update[0] }
62
+ let(:error_messages) { update[1] }
63
+
64
+ it { expect { update }.not_to raise_error }
65
+ it('results is a Hashie::Rash') { expect(results).to be_a(Hashie::Rash) }
66
+ it('the public_id is on the results') { expect(results).to respond_to(:public_id) }
67
+ it('the new token is on the results') { expect(results).to respond_to(:token) }
68
+ it('error_messages array is empty') { expect(error_messages).to eq([]) }
69
+ end
70
+
71
+ context 'for invalid public_id' do
72
+ let(:update) { subject.update(:invalid_public_id, password: 'Aa123456!', password_confirm: 'Aa123456!') }
73
+ let(:results) { update[0] }
74
+ let(:error_messages) { update[1] }
75
+
76
+ it { expect { update }.not_to raise_error }
77
+ it('results is nil') { expect(results).to be_nil }
78
+ it('error messages array is populated') { expect(error_messages.first.downcase).to eq('resource not found') }
79
+ end
80
+ end
81
+ end
82
+ end
@@ -6,14 +6,20 @@ class FakeApi < Sinatra::Base
6
6
  # resource
7
7
  post('/v2/resources') { json_response 201, 'resource.json' }
8
8
  get('/v2/resources/:id') { json_response 200, 'resource.json' }
9
+ put('/v2/resources') { json_response 201, 'resource.json' }
10
+ delete('/v2/resources/:id') { status 202 }
9
11
 
10
12
  # orders
11
- post('/v2/orders/invalid_token') { json_response 404, 'order_token_invalid.json' }
12
13
  post('/v2/orders/valid_token') { json_response 200, 'order_token.json' }
14
+ post('/v2/orders/invalid_token') { json_response 404, 'resource_not_found.json' }
13
15
  get('/v2/orders/:id') { json_response 200, 'resource.json' }
14
16
 
15
17
  # users
16
- get('/users/:id') { json_response 200, 'user.json' }
18
+ get('/v2/users/valid_public_id') { json_response 200, 'user.json' }
19
+ get('/v2/users/invalid_public_id') { json_response 404, 'resource_not_found.json' }
20
+ put('/v2/users/valid_public_id') { status 204 }
21
+ put('/v2/users/valid_public_id/password'){ json_response 200, 'user.json'}
22
+ put('/v2/users/invalid_public_id/password'){ json_response 404, 'resource_not_found.json' }
17
23
 
18
24
  # relevance
19
25
  get('/v2/relevance/ruleset/names') { json_response 200, 'relevance_ruleset_names.json' }
@@ -0,0 +1,5 @@
1
+ {
2
+ "messages": [
3
+ "Resource not found"
4
+ ]
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "messages": [
3
+ "Invalid User Identifier or Credentials"
4
+ ]
5
+ }
@@ -1,8 +1,9 @@
1
1
  {
2
- "public_id":"83e6c55a-9883-40bb-45f9-fc70d70731c9",
3
- "first_name":"Erich",
4
- "last_name":"{\"phone_number\":\"3052224444\", \"first_name\":\"John\", \"last_name\":\"Smith\", \"savings_plan_id\":1}",
5
- "email":"erich.1440775160085@example.com",
6
- "postal_code":"00000",
7
- "token":"XkI8MORAlR5m2DvF+QuSkrWGsVrBfZUI3mRToYzZ494="
2
+ "public_id": "8dc3bf36-571a-48cd-707a-2e9a9850c4ae",
3
+ "first_name": "John",
4
+ "last_name": "Smith",
5
+ "email": "j.smith@financialapps.com",
6
+ "memo": "",
7
+ "postal_code": "33021",
8
+ "token": "n4Q57JdnE2v1kbvFagLCZEhPG7t2mWQfvs4zWkDpGKg="
8
9
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: finapps
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.15
4
+ version: 2.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erich Quintero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-22 00:00:00.000000000 Z
11
+ date: 2016-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -280,13 +280,15 @@ files:
280
280
  - spec/rest/order_tokens_spec.rb
281
281
  - spec/rest/orders_spec.rb
282
282
  - spec/rest/resources_spec.rb
283
+ - spec/rest/users_spec.rb
283
284
  - spec/spec_helper.rb
284
285
  - spec/support/fake_api.rb
285
286
  - spec/support/fixtures/error.json
286
287
  - spec/support/fixtures/order_token.json
287
- - spec/support/fixtures/order_token_invalid.json
288
288
  - spec/support/fixtures/relevance_ruleset_names.json
289
289
  - spec/support/fixtures/resource.json
290
+ - spec/support/fixtures/resource_not_found.json
291
+ - spec/support/fixtures/unauthorized.json
290
292
  - spec/support/fixtures/user.json
291
293
  homepage: https://github.com/finapps/ruby-client
292
294
  licenses:
@@ -331,5 +333,6 @@ test_files:
331
333
  - spec/rest/order_tokens_spec.rb
332
334
  - spec/rest/orders_spec.rb
333
335
  - spec/rest/resources_spec.rb
336
+ - spec/rest/users_spec.rb
334
337
  - spec/spec_helper.rb
335
338
  - spec/support/fake_api.rb
@@ -1,5 +0,0 @@
1
- {
2
- "messages": [
3
- "resource not found"
4
- ]
5
- }