finapps 2.0.4 → 2.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/finapps/middleware/tenant_authentication.rb +1 -1
- data/lib/finapps/rest/client.rb +4 -0
- data/lib/finapps/rest/orders.rb +10 -0
- data/lib/finapps/rest/resources.rb +21 -6
- data/lib/finapps/rest/users.rb +10 -11
- data/lib/finapps/version.rb +1 -1
- data/lib/finapps.rb +1 -0
- data/spec/rest/client_spec.rb +6 -2
- data/spec/rest/orders_spec.rb +19 -0
- data/spec/rest/resources_spec.rb +35 -0
- data/spec/support/fake_api.rb +7 -0
- data/spec/support/fixtures/resource.json +3 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1467952204aa017d2c08fe58cdae31a62b57aa4
|
4
|
+
data.tar.gz: 6e0a321efe02addaf8731dfdff3de8ba59c9cd90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a2a307d85c1e7d4aa958444f7d2e2b790f074f20eee1e2836f21fbb9e61ff13d5ced6fd8522a720ff1575805d94a4199fe83a58fd5e59a2f15c4a7980f65446
|
7
|
+
data.tar.gz: 5c0dd965c386d2e827086ca559d48d394a4bd9b6f4f4e1189e0a65498475baa7daed195211835ca152c45404b32061ec319d9e7f940f9fcaa1e78964676c9b87
|
data/lib/finapps/rest/client.rb
CHANGED
@@ -1,23 +1,38 @@
|
|
1
1
|
module FinApps
|
2
2
|
module REST
|
3
3
|
class Resources # :nodoc:
|
4
|
+
require 'erb'
|
5
|
+
|
4
6
|
attr_reader :client
|
5
7
|
|
6
8
|
# @param [FinApps::REST::Client] client
|
7
9
|
# @return [FinApps::REST::Resources]
|
8
10
|
def initialize(client)
|
11
|
+
raise MissingArgumentsError.new 'Missing argument: client.' if client.blank?
|
9
12
|
@client = client
|
10
13
|
end
|
11
14
|
|
12
|
-
def create(params,
|
13
|
-
|
14
|
-
|
15
|
-
path = Defaults::END_POINTS[endpoint]
|
16
|
-
logger.debug "#{name}##{__method__} => path: #{path} params: #{params}"
|
17
|
-
|
15
|
+
def create(params={}, path=nil)
|
16
|
+
path = self.class.name.split('::').last.downcase if path.nil?
|
17
|
+
logger.debug "#{self.class.name}##{__method__} => path: #{path} params: #{params}"
|
18
18
|
results, error_messages = client.send_request(path, :post, params)
|
19
19
|
[results, error_messages]
|
20
20
|
end
|
21
|
+
|
22
|
+
def show(id, path=nil)
|
23
|
+
if path.nil?
|
24
|
+
path = "#{self.class.name.split('::').last.downcase}/:id".sub ':id', ERB::Util.url_encode(id)
|
25
|
+
end
|
26
|
+
logger.debug "#{self.class.name}##{__method__} => path: #{path}"
|
27
|
+
results, error_messages = client.send_request(path, :get)
|
28
|
+
[results, error_messages]
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def logger
|
34
|
+
client.logger
|
35
|
+
end
|
21
36
|
end
|
22
37
|
end
|
23
38
|
end
|
data/lib/finapps/rest/users.rb
CHANGED
@@ -1,15 +1,20 @@
|
|
1
1
|
module FinApps
|
2
2
|
module REST
|
3
3
|
class Users < FinApps::REST::Resources # :nodoc:
|
4
|
-
|
5
|
-
|
4
|
+
END_POINTS = {
|
5
|
+
list: nil,
|
6
|
+
create: 'users/new',
|
7
|
+
show: 'users/:public_id',
|
8
|
+
update: 'user',
|
9
|
+
destroy: 'users/:public_id'
|
10
|
+
}.freeze
|
6
11
|
|
7
12
|
# @param [String] public_id
|
8
13
|
# @return [FinApps::REST::User, Array<String>]
|
9
14
|
def show(public_id)
|
10
15
|
raise MissingArgumentsError.new 'Missing argument: public_id.' if public_id.blank?
|
11
16
|
|
12
|
-
end_point =
|
17
|
+
end_point = END_POINTS[:show]
|
13
18
|
path = end_point.sub ':public_id', ERB::Util.url_encode(public_id)
|
14
19
|
|
15
20
|
logger.debug "##{__method__} => path: #{path}"
|
@@ -18,19 +23,13 @@ module FinApps
|
|
18
23
|
[results, error_messages]
|
19
24
|
end
|
20
25
|
|
21
|
-
# @param [Hash] params
|
22
|
-
# @return [FinApps::REST::User, Array<String>]
|
23
|
-
def create(params)
|
24
|
-
super(params, :users_create)
|
25
|
-
end
|
26
|
-
|
27
26
|
# @param [Hash] params
|
28
27
|
# @return [Array<String>]
|
29
28
|
def update(params)
|
30
29
|
raise MissingArgumentsError.new 'Missing argument: params.' if params.blank?
|
31
30
|
logger.debug "##{__method__} => params: #{params}"
|
32
31
|
|
33
|
-
end_point =
|
32
|
+
end_point = END_POINTS[:update]
|
34
33
|
path = end_point
|
35
34
|
|
36
35
|
logger.debug "##{__method__} => path: #{path}"
|
@@ -45,7 +44,7 @@ module FinApps
|
|
45
44
|
raise MissingArgumentsError.new 'Missing argument: public_id.' if public_id.blank?
|
46
45
|
logger.debug "##{__method__} => public_id: #{public_id}"
|
47
46
|
|
48
|
-
end_point =
|
47
|
+
end_point = END_POINTS[:delete]
|
49
48
|
logger.debug "##{__method__} => end_point: #{end_point}"
|
50
49
|
|
51
50
|
path = end_point.sub ':public_id', ERB::Util.url_encode(public_id)
|
data/lib/finapps/version.rb
CHANGED
data/lib/finapps.rb
CHANGED
data/spec/rest/client_spec.rb
CHANGED
@@ -12,7 +12,7 @@ RSpec.describe FinApps::REST::Client do
|
|
12
12
|
context 'an instance of Client' do
|
13
13
|
subject { FinApps::REST::Client.new(:company_identifier, :company_token) }
|
14
14
|
|
15
|
-
%i(users).each do |method|
|
15
|
+
%i(users orders).each do |method|
|
16
16
|
it "responds to #{method}" do
|
17
17
|
expect(subject).to respond_to(method)
|
18
18
|
end
|
@@ -22,10 +22,14 @@ RSpec.describe FinApps::REST::Client do
|
|
22
22
|
it { expect(subject.users).to be_an_instance_of(FinApps::REST::Users) }
|
23
23
|
end
|
24
24
|
|
25
|
+
describe '#orders' do
|
26
|
+
it { expect(subject.orders).to be_an_instance_of(FinApps::REST::Orders) }
|
27
|
+
end
|
28
|
+
|
25
29
|
# [:users, :institutions, :user_institutions, :transactions, :categories,
|
26
30
|
# :budget_models, :budget_calculation, :budgets, :cashflows,
|
27
31
|
# :alert, :alert_definition, :alert_preferences, :alert_settings, :rule_sets]
|
28
|
-
|
32
|
+
%i(users orders).each do |method|
|
29
33
|
it "memoizes the result of #{method}" do
|
30
34
|
first = subject.send(method)
|
31
35
|
second = subject.send(method)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
RSpec.describe FinApps::REST::Orders do
|
2
|
+
describe '#show' do
|
3
|
+
let(:client) { FinApps::REST::Client.new :company_identifier, :company_token }
|
4
|
+
|
5
|
+
context 'when missing params' do
|
6
|
+
subject { FinApps::REST::Orders.new(client).show(nil) }
|
7
|
+
it { expect { subject }.to raise_error(FinApps::MissingArgumentsError) }
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'when valid params are provided' do
|
11
|
+
subject { FinApps::REST::Orders.new(client).show(:id) }
|
12
|
+
|
13
|
+
it { expect { subject }.not_to raise_error }
|
14
|
+
it('returns an array') { expect(subject).to be_a(Array) }
|
15
|
+
it('performs a post and returns the response') { expect(subject[0]).to respond_to(:public_id) }
|
16
|
+
it('returns no error messages') { expect(subject[1]).to be_empty }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
RSpec.describe FinApps::REST::Resources do
|
2
|
+
let(:client) { FinApps::REST::Client.new :company_identifier, :company_token }
|
3
|
+
describe '#new' do
|
4
|
+
context 'when client is nil' do
|
5
|
+
subject { FinApps::REST::Resources.new(nil) }
|
6
|
+
it { expect { subject }.to raise_error(FinApps::MissingArgumentsError, 'Missing argument: client.') }
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'when client param is set' do
|
10
|
+
subject { FinApps::REST::Resources.new(client) }
|
11
|
+
it { expect { subject }.not_to raise_error }
|
12
|
+
it('assigns @client') { expect(subject.client).to eq(client) }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#create' do
|
17
|
+
context 'when valid params are provided' do
|
18
|
+
subject { FinApps::REST::Resources.new(client) }
|
19
|
+
it { expect { subject.create }.not_to raise_error }
|
20
|
+
it('returns an array') { expect(subject.create).to be_a(Array) }
|
21
|
+
it('performs a post and returns the response') { expect(subject.create[0]).to respond_to(:public_id) }
|
22
|
+
it('returns no error messages') { expect(subject.create[1]).to be_empty }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#show' do
|
27
|
+
context 'when valid params are provided' do
|
28
|
+
subject { FinApps::REST::Resources.new(client).show(:id) }
|
29
|
+
it { expect { subject }.not_to raise_error }
|
30
|
+
it('returns an array') { expect(subject).to be_a(Array) }
|
31
|
+
it('performs a post and returns the response') { expect(subject[0]).to respond_to(:public_id) }
|
32
|
+
it('returns no error messages') { expect(subject[1]).to be_empty }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/spec/support/fake_api.rb
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
require 'sinatra/base'
|
2
2
|
|
3
3
|
class FakeApi < Sinatra::Base
|
4
|
+
# resource
|
5
|
+
post('/v2/resources') { json_response 201, 'resource.json' }
|
6
|
+
get('/v2/resources/:id') { json_response 200, 'resource.json' }
|
7
|
+
|
8
|
+
# orders
|
9
|
+
get('/v2/orders/:id') { json_response 200, 'resource.json' }
|
10
|
+
|
4
11
|
# users
|
5
12
|
get('/users/:id') { json_response 200, 'user.json' }
|
6
13
|
|
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.
|
4
|
+
version: 2.0.5
|
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-
|
11
|
+
date: 2016-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -261,6 +261,7 @@ files:
|
|
261
261
|
- lib/finapps/rest/configuration.rb
|
262
262
|
- lib/finapps/rest/connection.rb
|
263
263
|
- lib/finapps/rest/defaults.rb
|
264
|
+
- lib/finapps/rest/orders.rb
|
264
265
|
- lib/finapps/rest/resource.rb
|
265
266
|
- lib/finapps/rest/resources.rb
|
266
267
|
- lib/finapps/rest/users.rb
|
@@ -271,10 +272,13 @@ files:
|
|
271
272
|
- spec/rest/base_client_spec.rb
|
272
273
|
- spec/rest/client_spec.rb
|
273
274
|
- spec/rest/configuration_spec.rb
|
275
|
+
- spec/rest/orders_spec.rb
|
276
|
+
- spec/rest/resources_spec.rb
|
274
277
|
- spec/spec_helper.rb
|
275
278
|
- spec/support/fake_api.rb
|
276
279
|
- spec/support/fixtures/error.json
|
277
280
|
- spec/support/fixtures/relevance_ruleset_names.json
|
281
|
+
- spec/support/fixtures/resource.json
|
278
282
|
- spec/support/fixtures/user.json
|
279
283
|
homepage: https://github.com/finapps/ruby-client
|
280
284
|
licenses:
|
@@ -310,6 +314,8 @@ test_files:
|
|
310
314
|
- spec/spec_helper.rb
|
311
315
|
- spec/support/fake_api.rb
|
312
316
|
- spec/middleware/tenant_authentication_spec.rb
|
317
|
+
- spec/rest/resources_spec.rb
|
313
318
|
- spec/rest/client_spec.rb
|
319
|
+
- spec/rest/orders_spec.rb
|
314
320
|
- spec/rest/base_client_spec.rb
|
315
321
|
- spec/rest/configuration_spec.rb
|