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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae51d63eabbc06265ec732daaabdca386e3b1b79
4
- data.tar.gz: 616025325958098e835789d0f39c9cbdf223a115
3
+ metadata.gz: c1467952204aa017d2c08fe58cdae31a62b57aa4
4
+ data.tar.gz: 6e0a321efe02addaf8731dfdff3de8ba59c9cd90
5
5
  SHA512:
6
- metadata.gz: e36a7872196a1ea55ee82f37cbf999f1ffce1c1954a2ae7742d24dda678f3a6913d7e9ed6c26d18c004a4ca0fbb49c369714cd618e7d6e2f74da4be7b2e6831a
7
- data.tar.gz: e0c3104cd52a91e73952fca3a021aa457e62ed70d50ef4c5340e0c9416bd744238dd72210e49cb6d40852b3482094ec993305247705154b8466a4c499961f798
6
+ metadata.gz: 4a2a307d85c1e7d4aa958444f7d2e2b790f074f20eee1e2836f21fbb9e61ff13d5ced6fd8522a720ff1575805d94a4199fe83a58fd5e59a2f15c4a7980f65446
7
+ data.tar.gz: 5c0dd965c386d2e827086ca559d48d394a4bd9b6f4f4e1189e0a65498475baa7daed195211835ca152c45404b32061ec319d9e7f940f9fcaa1e78964676c9b87
@@ -7,7 +7,7 @@ module FinApps
7
7
 
8
8
  def initialize(app, options={})
9
9
  super(app)
10
- @header_value = "#{options[:identifier].strip}=#{options[:token].strip}"
10
+ @header_value = "#{options[:identifier].to_s.strip}=#{options[:token].to_s.strip}"
11
11
  end
12
12
 
13
13
  def call(env)
@@ -21,6 +21,10 @@ module FinApps
21
21
  def users
22
22
  @users ||= FinApps::REST::Users.new self
23
23
  end
24
+
25
+ def orders
26
+ @orders ||= FinApps::REST::Orders.new self
27
+ end
24
28
  end
25
29
  end
26
30
  end
@@ -0,0 +1,10 @@
1
+ module FinApps
2
+ module REST
3
+ class Orders < FinApps::REST::Resources # :nodoc:
4
+ def show(id)
5
+ raise MissingArgumentsError.new 'Missing argument: params.' if id.blank?
6
+ super
7
+ end
8
+ end
9
+ end
10
+ end
@@ -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, endpoint)
13
- raise MissingArgumentsError.new 'Missing argument: params.' if params.blank?
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
@@ -1,15 +1,20 @@
1
1
  module FinApps
2
2
  module REST
3
3
  class Users < FinApps::REST::Resources # :nodoc:
4
- require 'erb'
5
- include FinApps::REST::Defaults
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 = Defaults::END_POINTS[:users_show]
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 = Defaults::END_POINTS[:users_update]
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 = Defaults::END_POINTS[:users_delete]
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)
@@ -1,3 +1,3 @@
1
1
  module FinApps
2
- VERSION = '2.0.4'.freeze
2
+ VERSION = '2.0.5'.freeze
3
3
  end
data/lib/finapps.rb CHANGED
@@ -20,6 +20,7 @@ require 'finapps/rest/resource'
20
20
  require 'finapps/rest/resources'
21
21
 
22
22
  require 'finapps/rest/users'
23
+ require 'finapps/rest/orders'
23
24
 
24
25
  require 'finapps/rest/configuration'
25
26
  require 'finapps/rest/connection'
@@ -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
- [:users].each do |method|
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
@@ -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
 
@@ -0,0 +1,3 @@
1
+ {
2
+ "public_id":"83e6c55a-9883-40bb-45f9-fc70d70731c9"
3
+ }
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
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-07 00:00:00.000000000 Z
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