finapps 2.2.13 → 2.2.14

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: 8e5336f7f84372902606d737ef74a07be99b7178
4
- data.tar.gz: b19bc5d2f1833367a6eee7c094ea1a14eab08142
3
+ metadata.gz: cf5f0601a67422163160e5df827d28996565c17a
4
+ data.tar.gz: 3377656058a00af66d5d8a9be2b5bf5f8e40ef05
5
5
  SHA512:
6
- metadata.gz: f756dd81fe95d4fede02dd56e431138ae30a20bf1d244da71d1943ebd766e96b6e095f0bf0b8d1d0ea52a190ce973073bb901db21cd60b6c22486865d8b1d9d0
7
- data.tar.gz: cc6ed19800f26b060440660fa00725fe48f0524e45dcfaceb2a2f2cdc67d262031092becd2c534d1f3ed09ea282fcc9fdc031fc3a3e2bd04330e48a5e9ac2ab1
6
+ metadata.gz: 3a019a8f4a409566a26fa73bee5b928f437b88d20be84d1b18842d48a11dd3c93612b7b4009bb3a344e24838afb0abf1df70812d0103b9eab6bd015a075c1d46
7
+ data.tar.gz: 4ed6c7b2925748098e1182e9ffc59543384f9bc5a07aebcaa313410023b9c8a5399b8570bfef8f6b8de10ea17dbf546f91b2e1e91d1d569cd1fe969aac81585e
@@ -23,6 +23,7 @@ require 'finapps/rest/order_statuses'
23
23
  require 'finapps/rest/password_resets'
24
24
  require 'finapps/rest/operators'
25
25
  require 'finapps/rest/operators_password_resets'
26
+ require 'finapps/utils/query_builder'
26
27
 
27
28
  # require 'finapps/rest/configuration'
28
29
  # require 'finapps/rest/credentials'
@@ -1,12 +1,15 @@
1
1
  # frozen_string_literal: true
2
+ require_relative '../utils/query_builder'
3
+
2
4
  module FinApps
3
5
  module REST
4
6
  class Operators < FinAppsCore::REST::Resources
7
+ include FinApps::Utils::QueryBuilder
8
+
5
9
  def list(params=nil)
6
10
  return super if params.nil?
7
-
8
- path = "#{endpoint}/#{ERB::Util.url_encode(params)}"
9
- super path
11
+ raise FinAppsCore::InvalidArgumentsError.new 'Invalid argument: params' unless params.is_a? Hash
12
+ super build_query_path(end_point, params)
10
13
  end
11
14
 
12
15
  def show(id)
@@ -1,7 +1,11 @@
1
1
  # frozen_string_literal: true
2
+ require_relative '../utils/query_builder'
3
+
2
4
  module FinApps
3
5
  module REST
4
6
  class Orders < FinAppsCore::REST::Resources # :nodoc:
7
+ include FinApps::Utils::QueryBuilder
8
+
5
9
  def show(id)
6
10
  not_blank(id, :id)
7
11
  super
@@ -16,14 +20,12 @@ module FinApps
16
20
  # :page - page number requested
17
21
  # :requested - number of results per page requested
18
22
  # :sort - sort order
19
- # options:
20
- # date - the date of the order
21
- # status - the status of the order
23
+ # :filter - mongo object to filter
22
24
  # descending - append "-" before option for descending sort
23
25
  def list(params=nil) # params hash with optional keys [:page, :sort, :requested]
24
26
  return super if params.nil?
25
27
  raise FinAppsCore::InvalidArgumentsError.new 'Invalid argument: params' unless params.is_a? Hash
26
- super build_path(params)
28
+ super build_query_path(end_point, params)
27
29
  end
28
30
 
29
31
  def update(id, params)
@@ -37,15 +39,6 @@ module FinApps
37
39
 
38
40
  super params, path
39
41
  end
40
-
41
- private
42
-
43
- def build_path(p)
44
- page = p[:page] ? "page=#{ERB::Util.url_encode(p[:page])}" : ''
45
- requested = p[:requested] ? "&requested=#{ERB::Util.url_encode(p[:requested])}" : ''
46
- sort = p[:sort] ? "&sort=#{ERB::Util.url_encode(p[:sort])}" : ''
47
- "#{end_point}?#{page}#{requested}#{sort}"
48
- end
49
42
  end
50
43
  end
51
44
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ module FinApps
3
+ module Utils
4
+ module QueryBuilder
5
+ def build_query_path(root_url, params)
6
+ page = params[:page] ? "page=#{params[:page]}" : ''
7
+ requested = params[:requested] ? "&requested=#{params[:requested]}" : ''
8
+ sort = params[:sort] ? "&sort=#{ERB::Util.url_encode(params[:sort])}" : ''
9
+ filter = params[:filter] ? "&filter=#{ERB::Util.url_encode(params[:filter])}" : ''
10
+ "#{root_url}?#{page}#{requested}#{sort}#{filter}"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module FinApps
3
- VERSION = '2.2.13'
3
+ VERSION = '2.2.14'
4
4
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+ class FakeClass
3
+ include FinApps::Utils::QueryBuilder
4
+ end
5
+
6
+ RSpec.describe FinApps::Utils::QueryBuilder do
7
+ describe '#build_query_path' do
8
+ subject { FakeClass.new }
9
+ let(:end_point) { 'orders' }
10
+
11
+ context 'with full params' do
12
+ let(:params) { {page: '1', requested: '20', sort: '-date', filter: '{"role": "1"}'} }
13
+ it 'returns correct string' do
14
+ correct_string = 'orders?page=1&requested=20&sort=-date&filter=%7B%22role%22%3A%20%221%22%7D'
15
+ expect(subject.build_query_path(end_point, params)).to eq(correct_string)
16
+ end
17
+ end
18
+
19
+ context 'with partial params' do
20
+ let(:params) { {page: '1', filter: '{"role": "1"}'} }
21
+ it 'returns correct string' do
22
+ expect(subject.build_query_path(end_point, params)).to eq('orders?page=1&filter=%7B%22role%22%3A%20%221%22%7D')
23
+ end
24
+ end
25
+ end
26
+ end
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.2.13
4
+ version: 2.2.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erich Quintero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-21 00:00:00.000000000 Z
11
+ date: 2017-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: finapps_core
@@ -249,6 +249,7 @@ files:
249
249
  - lib/finapps/rest/user_institutions_forms.rb
250
250
  - lib/finapps/rest/user_institutions_statuses.rb
251
251
  - lib/finapps/rest/version.rb
252
+ - lib/finapps/utils/query_builder.rb
252
253
  - lib/finapps/version.rb
253
254
  - lib/tasks/releaser.rake
254
255
  - spec/rest/client_spec.rb
@@ -298,6 +299,7 @@ files:
298
299
  - spec/support/fixtures/user_institution_status.json
299
300
  - spec/support/fixtures/user_institutions_list.json
300
301
  - spec/support/fixtures/user_institutions_show.json
302
+ - spec/utils/query_builder_spec.rb
301
303
  homepage: https://github.com/finapps/ruby-client
302
304
  licenses:
303
305
  - MIT
@@ -346,5 +348,6 @@ test_files:
346
348
  - spec/rest/order_statuses_spec.rb
347
349
  - spec/rest/sessions_spec.rb
348
350
  - spec/support/fake_api.rb
351
+ - spec/utils/query_builder_spec.rb
349
352
  - spec/spec_helpers/client.rb
350
353
  - spec/spec_helper.rb