finapps 1.0.8 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.rspec +1 -2
  4. data/.rubocop.yml +102 -0
  5. data/.ruby-gemset +1 -1
  6. data/.ruby-version +1 -1
  7. data/Rakefile +1 -1
  8. data/finapps.gemspec +10 -10
  9. data/lib/finapps/core_extensions/hash/compact.rb +22 -0
  10. data/lib/finapps/core_extensions/integerable.rb +14 -0
  11. data/lib/finapps/core_extensions/object/blank.rb +145 -0
  12. data/lib/finapps/error.rb +7 -0
  13. data/lib/finapps/hash_constructable.rb +9 -0
  14. data/lib/finapps/middleware/raise_error.rb +46 -0
  15. data/lib/finapps/middleware/tenant_authentication.rb +19 -0
  16. data/lib/finapps/rest/base_client.rb +96 -0
  17. data/lib/finapps/rest/client.rb +11 -199
  18. data/lib/finapps/rest/configuration.rb +55 -0
  19. data/lib/finapps/rest/connection.rb +14 -33
  20. data/lib/finapps/rest/defaults.rb +55 -64
  21. data/lib/finapps/rest/resource.rb +3 -6
  22. data/lib/finapps/rest/resources.rb +11 -6
  23. data/lib/finapps/rest/users.rb +17 -57
  24. data/lib/finapps/utils/loggeable.rb +13 -0
  25. data/lib/finapps/version.rb +1 -1
  26. data/lib/finapps.rb +11 -23
  27. data/lib/tasks/releaser.rake +2 -2
  28. data/spec/middleware/tenant_authentication_spec.rb +29 -0
  29. data/spec/rest/base_client_spec.rb +89 -0
  30. data/spec/rest/client_spec.rb +16 -102
  31. data/spec/rest/configuration_spec.rb +75 -0
  32. data/spec/spec_helper.rb +10 -7
  33. data/spec/support/fake_api.rb +9 -2
  34. data/spec/support/fixtures/error.json +5 -0
  35. data/spec/support/fixtures/relevance_ruleset_names.json +47 -0
  36. metadata +49 -57
  37. data/lib/finapps/middleware/api_token.rb +0 -26
  38. data/lib/finapps/middleware/raise_http_exceptions.rb +0 -92
  39. data/lib/finapps/middleware/response_logger.rb +0 -37
  40. data/lib/finapps/rest/alert.rb +0 -62
  41. data/lib/finapps/rest/alert_definition.rb +0 -40
  42. data/lib/finapps/rest/alert_preferences.rb +0 -40
  43. data/lib/finapps/rest/alert_settings.rb +0 -40
  44. data/lib/finapps/rest/budget_calculation.rb +0 -45
  45. data/lib/finapps/rest/budget_models.rb +0 -42
  46. data/lib/finapps/rest/budgets.rb +0 -103
  47. data/lib/finapps/rest/cashflows.rb +0 -87
  48. data/lib/finapps/rest/categories.rb +0 -21
  49. data/lib/finapps/rest/errors.rb +0 -155
  50. data/lib/finapps/rest/institutions.rb +0 -47
  51. data/lib/finapps/rest/relevance/rulesets.rb +0 -64
  52. data/lib/finapps/rest/transactions.rb +0 -45
  53. data/lib/finapps/rest/user_institutions.rb +0 -138
  54. data/lib/finapps/utils/logging.rb +0 -95
  55. data/lib/finapps/utils/utils.rb +0 -57
  56. data/spec/middleware/api_token_spec.rb +0 -32
  57. data/spec/rest/connection_spec.rb +0 -40
  58. data/spec/rest/users_spec.rb +0 -24
  59. data/spec/utils/logging_spec.rb +0 -28
@@ -1,214 +1,26 @@
1
1
  module FinApps
2
2
  module REST
3
- class Client
3
+ class Client < BaseClient # :nodoc:
4
4
  include FinApps::REST::Defaults
5
- include FinApps::Logging
6
- include FinApps::REST::Connection
7
5
 
8
- attr_reader :config, :company_credentials
9
-
10
- # @param [String] company_identifier
11
- # @param [String] company_token
6
+ # @param [String] tenant_identifier
7
+ # @param [String] tenant_token
12
8
  # @param [Hash] options
13
9
  # @return [FinApps::REST::Client]
14
- def initialize(company_identifier, company_token, options = {})
15
- @config = DEFAULTS.merge! options
16
- logger_config config
10
+ def initialize(tenant_identifier, tenant_token, logger=nil, options={})
11
+ raise FinApps::MissingArgumentsError.new 'Invalid company_identifier.' if tenant_identifier.blank?
12
+ raise FinApps::MissingArgumentsError.new 'Invalid company_token.' if tenant_token.blank?
17
13
 
18
- @company_credentials = {:company_identifier => company_identifier, :company_token => company_token}
19
- @company_credentials.validate_required_strings!
20
- end
14
+ merged_options = FinApps::REST::Defaults::DEFAULTS.merge options
15
+ merged_options[:tenant_credentials] = {identifier: tenant_identifier,
16
+ token: tenant_token}
21
17
 
22
- def connection
23
- @connection ||= set_up_connection(self.company_credentials, @config)
18
+ super(merged_options, logger)
24
19
  end
25
20
 
26
21
  def users
27
22
  @users ||= FinApps::REST::Users.new self
28
23
  end
29
-
30
- def institutions
31
- @institutions ||= FinApps::REST::Institutions.new self
32
- end
33
-
34
- def user_institutions
35
- @user_institutions ||= FinApps::REST::UserInstitutions.new self
36
- end
37
-
38
- def transactions
39
- @transactions ||= FinApps::REST::Transactions.new self
40
- end
41
-
42
- def categories
43
- @categories ||= FinApps::REST::Categories.new self
44
- end
45
-
46
- def budget_models
47
- @budget_models ||= FinApps::REST::BudgetModels.new self
48
- end
49
-
50
- def budget_calculation
51
- @budget_calculation ||= FinApps::REST::BudgetCalculation.new self
52
- end
53
-
54
- def budgets
55
- @budgets ||= FinApps::REST::Budgets.new self
56
- end
57
-
58
- def cashflows
59
- @cashflows ||= FinApps::REST::Cashflows.new self
60
- end
61
-
62
- def alert
63
- @alert ||= FinApps::REST::Alert.new self
64
- end
65
-
66
- def alert_definition
67
- @alert_definition ||= FinApps::REST::AlertDefinition.new self
68
- end
69
-
70
- def alert_settings
71
- @alert_settings ||= FinApps::REST::AlertSettings.new self
72
- end
73
-
74
- def alert_preferences
75
- @alert_preferences ||= FinApps::REST::AlertPreferences.new self
76
- end
77
-
78
- def rule_sets
79
- @rule_sets ||= FinApps::REST::Relevance::Rulesets.new self
80
- end
81
-
82
- # Performs HTTP GET, POST, UPDATE and DELETE requests.
83
- # You shouldn't need to use this method directly, but it can be useful for debugging.
84
- # Returns a hash obtained from parsing the JSON object in the response body.
85
- #
86
- # @param [String] path
87
- # @param [String] method
88
- # @param [Proc] proc
89
- # @return [Hash,Array<String>]
90
- def send_request(path, method, params = {}, &proc)
91
- raise FinApps::REST::MissingArgumentsError.new 'Missing argument: path.' if path.blank?
92
- raise FinApps::REST::MissingArgumentsError.new 'Missing argument: method.' if method.blank?
93
-
94
- result, error_messages = nil, []
95
-
96
- begin
97
- case method
98
- when :get
99
- response = get(path)
100
- when :post
101
- response = post(path, params)
102
- when :put
103
- response = put(path, params)
104
- when :delete
105
- response = delete(path, params)
106
- else
107
- raise FinApps::REST::InvalidArgumentsError.new "Method not supported: #{method}."
108
- end
109
-
110
- if response.present?
111
- result = block_given? ? proc.call(response) : response.body
112
- else
113
- logger.error "##{__method__} => Null response found. Unable to process it."
114
- end
115
-
116
- rescue FinApps::REST::InvalidArgumentsError => error
117
- raise error
118
- rescue FinApps::REST::Error => error
119
- error_messages = error.error_messages
120
- rescue Faraday::ParsingError => error
121
- error_messages << 'Unable to parse the server response.'
122
- logger.error "##{__method__} => Faraday::ParsingError, #{error.to_s}"
123
- rescue Exception => error
124
- error_messages << 'Unexpected error.'
125
- logger.fatal "##{__method__} => Exception, #{error.to_s}"
126
- logger.fatal error
127
- ensure
128
- logger.debug "##{__method__} => Failed, error_messages: #{error_messages.pretty_inspect}" if error_messages.present?
129
- end
130
-
131
- return result, error_messages
132
- end
133
-
134
- # @param [String] user_identifier
135
- # @param [String] user_token
136
- def user_credentials!(user_identifier, user_token)
137
- {:user_identifier => user_identifier, :user_token => user_token}.validate_required_strings!
138
-
139
- @config[:user_identifier] = user_identifier
140
- @config[:user_token] = user_token
141
-
142
- logger.debug "##{__method__} => Attempting to set user credentials on current connection."
143
- @connection = set_up_connection(company_credentials, config)
144
- end
145
-
146
- private
147
-
148
- # Performs an HTTP GET request.
149
- # Returns a hash obtained from parsing
150
- # the JSON object in the response body.
151
- #
152
- # @param [String] path
153
- # @return [Hash,Array<String>]
154
- def get(path)
155
- raise MissingArgumentsError.new 'Missing argument: path.' if path.blank?
156
-
157
- logger.debug "##{__method__} => GET path:#{path}"
158
- connection.get { |req| req.url path }
159
- end
160
-
161
- # Performs an HTTP POST request.
162
- # Returns a hash obtained from parsing
163
- # the JSON object in the response body.
164
- #
165
- # @param [String] path
166
- # @param [Hash] params
167
- # @return [Hash,Array<String>]
168
- def post(path, params = {})
169
- raise MissingArgumentsError.new 'Missing argument: path.' if path.blank?
170
-
171
- logger.debug "##{__method__} => POST path:#{path} params:#{skip_sensitive_data params }"
172
- connection.post do |req|
173
- req.url path
174
- req.body = params
175
- end
176
- end
177
-
178
- # Performs an HTTP PUT request.
179
- # Returns a hash obtained from parsing
180
- # the JSON object in the response body.
181
- #
182
- # @param [String] path
183
- # @param [Hash] params
184
- # @return [Hash,Array<String>]
185
- def put(path, params = {})
186
- raise MissingArgumentsError.new 'Missing argument: path.' if path.blank?
187
-
188
- logger.debug "##{__method__} => PUT path:#{path} params:#{skip_sensitive_data(params)}"
189
- connection.put do |req|
190
- req.url path
191
- req.body = params
192
- end
193
- end
194
-
195
- # Performs an HTTP DELETE request.
196
- # Returns a hash obtained from parsing
197
- # the JSON object in the response body.
198
- #
199
- # @param [String] path
200
- # @param [Hash] params
201
- # @return [Hash,Array<String>]
202
- def delete(path, params = {})
203
- raise MissingArgumentsError.new 'Missing argument: path.' if path.blank?
204
-
205
- logger.debug "##{__method__} => DELETE path:#{path} params:#{skip_sensitive_data(params)}"
206
- connection.delete do |req|
207
- req.url path
208
- req.body = params
209
- end
210
- end
211
-
212
24
  end
213
25
  end
214
- end
26
+ end
@@ -0,0 +1,55 @@
1
+ module FinApps
2
+ module REST
3
+ class Configuration # :nodoc:
4
+ include FinApps::HashConstructable
5
+
6
+ using CoreExtensions::Integerable
7
+
8
+ RUBY = "#{RUBY_ENGINE}/#{RUBY_PLATFORM} #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}".freeze
9
+ HEADERS = {
10
+ accept: 'application/json',
11
+ user_agent: "finapps-ruby/#{FinApps::VERSION} (#{RUBY})"
12
+ }.freeze
13
+
14
+ attr_accessor :host, :timeout, :tenant_credentials, :user_credentials, :url,
15
+ :proxy_addr, :proxy_port, :proxy_user, :proxy_pass,
16
+ :retry_limit, :log_level
17
+
18
+ def initialize(options)
19
+ super(options, FinApps::REST::Defaults::DEFAULTS)
20
+ validate
21
+ @url = "#{host}/v#{FinApps::REST::Defaults::API_VERSION}/"
22
+ end
23
+
24
+ def connection_options
25
+ {url: url,
26
+ request: {open_timeout: timeout, timeout: timeout},
27
+ headers: {accept: HEADERS[:accept], user_agent: HEADERS[:user_agent]}}
28
+ end
29
+
30
+ def valid_user_credentials?
31
+ valid_credentials? user_credentials
32
+ end
33
+
34
+ private
35
+
36
+ def validate
37
+ raise FinApps::MissingArgumentsError.new 'Missing tenant_credentials.' unless valid_tenant_credentials?
38
+ raise FinApps::InvalidArgumentsError.new "Invalid argument. {host: #{host}}" unless valid_host?
39
+ raise FinApps::InvalidArgumentsError.new "Invalid argument. {timeout: #{timeout}}" unless timeout.integer?
40
+ end
41
+
42
+ def valid_tenant_credentials?
43
+ valid_credentials? tenant_credentials
44
+ end
45
+
46
+ def valid_credentials?(h)
47
+ h.is_a?(Hash) && %i(identifier token).all? {|x| h.key? x } && h.values.all?(&:present?)
48
+ end
49
+
50
+ def valid_host?
51
+ host.start_with?('http://', 'https://')
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,50 +1,31 @@
1
- require 'pp'
2
-
3
1
  module FinApps
4
2
  module REST
5
- module Connection
6
- include FinApps::REST::Defaults
7
-
8
- # @param [Hash] company_credentials
9
- # @param [Hash] config
10
- # @return [Faraday::Connection]
11
- def set_up_connection(company_credentials, config)
12
- host_url = config[:host].blank? ? DEFAULTS[:host] : config[:host]
13
- raise InvalidArgumentsError.new "Invalid argument: host_url: #{host_url}" unless host_url.start_with?('http://', 'https://')
14
-
15
- base_url = "#{host_url}/v#{API_VERSION}"
16
- timeout = config[:timeout].blank? ? DEFAULTS[:timeout] : config[:timeout]
3
+ module Connection # :nodoc:
4
+ module_function
17
5
 
18
- Faraday.new(:url => base_url,
19
- :request => {
20
- :open_timeout => timeout,
21
- :timeout => timeout},
22
- :headers => {
23
- :accept => HEADERS[:accept],
24
- :user_agent => HEADERS[:user_agent]}) do |conn|
6
+ def faraday(config, logger)
7
+ Faraday.new(config.connection_options) do |conn|
8
+ # tenant level authentication
9
+ conn.use FinApps::Middleware::TenantAuthentication, config.tenant_credentials
25
10
 
26
- # add basic authentication header if user credentials were provided
27
- user_identifier = config[:user_identifier]
28
- user_token = config[:user_token]
29
- conn.request :basic_auth, user_identifier, user_token unless user_identifier.blank? || user_token.blank?
30
-
31
- # company level authentication
32
- conn.use FinApps::Middleware::ApiToken, company_credentials
11
+ # user level authentication
12
+ if config.valid_user_credentials?
13
+ conn.request :basic_auth, config.user_credentials[:identifier], config.user_credentials[:token]
14
+ end
33
15
 
34
16
  conn.request :json
35
17
  conn.request :retry
36
18
  conn.request :multipart
37
19
  conn.request :url_encoded
38
- conn.use FinApps::Middleware::RaiseHttpExceptions
20
+ conn.use FinApps::Middleware::RaiseError
39
21
  conn.response :rashify
40
- conn.response :json, :content_type => /\bjson$/
41
- conn.use FinApps::Middleware::ResponseLogger
22
+ conn.response :json, content_type: /\bjson$/
23
+ conn.response :logger, logger # , bodies: true
42
24
 
43
25
  # Adapter (ensure that the adapter is always last.)
44
26
  conn.adapter :typhoeus
45
27
  end
46
28
  end
47
-
48
29
  end
49
30
  end
50
- end
31
+ end
@@ -1,89 +1,80 @@
1
1
  module FinApps
2
2
  module REST
3
3
  module Defaults
4
-
5
- API_VERSION = '1'
6
-
7
- HEADERS = {
8
- :accept => 'application/json',
9
- :user_agent => "finapps-ruby/#{FinApps::VERSION} (#{RUBY_ENGINE}/#{RUBY_PLATFORM} #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL})"
10
- }.freeze
4
+ API_VERSION = '2'.freeze
11
5
 
12
6
  # noinspection SpellCheckingInspection
13
7
  DEFAULTS = {
14
- :host => 'https://api.financialapps.com',
15
- :timeout => 30,
16
- :proxy_addr => nil,
17
- :proxy_port => nil,
18
- :proxy_user => nil,
19
- :proxy_pass => nil,
20
- :retry_limit => 1,
21
- :log_level => Logger::INFO
22
- }
23
-
8
+ host: 'https://dev.financialapps.com',
9
+ timeout: 30,
10
+ proxy_addr: nil,
11
+ proxy_port: nil,
12
+ proxy_user: nil,
13
+ proxy_pass: nil,
14
+ retry_limit: 1,
15
+ log_level: Logger::INFO
16
+ }.freeze
24
17
 
25
18
  END_POINTS = {
26
- :users_create => 'users/new',
27
- :users_update => 'user',
28
- :users_update_password => 'user/password',
29
- :users_delete => 'users/:public_id',
30
- :users_show => 'users/:public_id',
31
- :users_login => 'users/login',
32
-
33
- :relevance_rulesets_list => 'relevance/ruleset/names',
34
- :relevance_rulesets_show => 'relevance/ruleset/:ruleset_name',
35
- :relevance_rulesets_run => 'relevance/run',
19
+ users_create: 'users/new',
20
+ users_update: 'user',
21
+ users_update_password: 'user/password',
22
+ users_delete: 'users/:public_id',
23
+ users_show: 'users/:public_id',
24
+ users_login: 'users/login',
36
25
 
37
- :institutions_list => 'institutions/:search_term/search',
38
- :institutions_form => 'institutions/:site_id/form',
26
+ relevance_rulesets_list: 'relevance/ruleset/names',
27
+ relevance_rulesets_show: 'relevance/ruleset/:ruleset_name',
28
+ relevance_rulesets_run: 'relevance/run',
39
29
 
40
- :user_institutions_list => 'institutions/user',
41
- :user_institutions_add => 'institutions/:site_id/add',
42
- :user_institutions_show => 'institutions/user/:user_institution_id',
43
- :user_institutions_update => 'institutions/user/:user_institution_id/credentials',
44
- :user_institutions_delete => 'institutions/user/:user_institution_id',
45
- :user_institutions_status => 'institutions/user/:user_institution_id/status',
46
- :user_institutions_mfa => 'institutions/user/:user_institution_id/mfa',
47
- :user_institutions_refresh => 'institutions/user/refresh',
48
- :user_institutions_form => 'institutions/user/:user_institution_id/form',
30
+ institutions_list: 'institutions/:search_term/search',
31
+ institutions_form: 'institutions/:site_id/form',
49
32
 
50
- :transactions_show => 'transaction/:transaction_id',
51
- :transactions_list => 'transactions/search',
52
- :transactions_update => 'transactions/edit',
33
+ user_institutions_list: 'institutions/user',
34
+ user_institutions_add: 'institutions/:site_id/add',
35
+ user_institutions_show: 'institutions/user/:user_institution_id',
36
+ user_institutions_update: 'institutions/user/:user_institution_id/credentials',
37
+ user_institutions_delete: 'institutions/user/:user_institution_id',
38
+ user_institutions_status: 'institutions/user/:user_institution_id/status',
39
+ user_institutions_mfa: 'institutions/user/:user_institution_id/mfa',
40
+ user_institutions_refresh: 'institutions/user/refresh',
41
+ user_institutions_form: 'institutions/user/:user_institution_id/form',
53
42
 
54
- :categories_list => 'categories',
55
- :categories_new => 'categories',
56
- :categories_update => 'categories',
57
- :categories_show => 'categories/:category_id',
58
- :categories_delete => 'categories/:category_id',
43
+ transactions_show: 'transaction/:transaction_id',
44
+ transactions_list: 'transactions/search',
45
+ transactions_update: 'transactions/edit',
59
46
 
60
- :budget_models_list => 'budget/templates',
61
- :budget_models_show => 'budget/template/:budget_model_id',
47
+ categories_list: 'categories',
48
+ categories_new: 'categories',
49
+ categories_update: 'categories',
50
+ categories_show: 'categories/:category_id',
51
+ categories_delete: 'categories/:category_id',
62
52
 
63
- :budget_calculation_create => 'budget/template/:budget_model_id/:income',
64
- :budget_calculation_show => 'categories',
53
+ budget_models_list: 'budget/templates',
54
+ budget_models_show: 'budget/template/:budget_model_id',
65
55
 
66
- :budget_update => 'budget',
67
- :budget_show => 'budget/:start_date/:end_date',
56
+ budget_calculation_create: 'budget/template/:budget_model_id/:income',
57
+ budget_calculation_show: 'categories',
68
58
 
69
- :cashflow_show => 'cashflow/:start_date/:end_date',
59
+ budget_update: 'budget',
60
+ budget_show: 'budget/:start_date/:end_date',
70
61
 
71
- :alert_list => 'alerts/:page/:requested/:sort/:asc/:read',
72
- :alert_update => 'alerts/:alert_id/:read',
73
- :alert_delete => 'alerts/:alert_id',
62
+ cashflow_show: 'cashflow/:start_date/:end_date',
74
63
 
75
- :alert_definition_list => 'alerts/definitions',
76
- :alert_definition_show => 'alerts/definitions/:alert_name',
64
+ alert_list: 'alerts/:page/:requested/:sort/:asc/:read',
65
+ alert_update: 'alerts/:alert_id/:read',
66
+ alert_delete: 'alerts/:alert_id',
77
67
 
78
- :alert_settings_show => 'alerts/settings',
79
- :alert_settings_update => 'alerts/settings',
68
+ alert_definition_list: 'alerts/definitions',
69
+ alert_definition_show: 'alerts/definitions/:alert_name',
80
70
 
81
- :alert_preferences_show => 'alerts/preferences',
82
- :alert_preferences_update => 'alerts/preferences'
71
+ alert_settings_show: 'alerts/settings',
72
+ alert_settings_update: 'alerts/settings',
83
73
 
74
+ alert_preferences_show: 'alerts/preferences',
75
+ alert_preferences_update: 'alerts/preferences'
84
76
 
85
77
  }.freeze
86
-
87
78
  end
88
79
  end
89
- end
80
+ end
@@ -1,14 +1,11 @@
1
1
  module FinApps
2
2
  module REST
3
- class Resource
4
- include FinApps::Logging
5
-
3
+ class Resource # :nodoc:
6
4
  # @param [Hash] hash
7
5
  def initialize(hash)
8
- hash.each { |k, v| instance_variable_set("@#{k}", v) unless v.nil? } if hash.present?
6
+ hash.each {|k, v| instance_variable_set("@#{k}", v) unless v.nil? } if hash.present?
9
7
  self
10
8
  end
11
-
12
9
  end
13
10
  end
14
- end
11
+ end
@@ -1,10 +1,6 @@
1
1
  module FinApps
2
2
  module REST
3
- class Resources
4
-
5
- include FinApps::REST::Defaults
6
- include FinApps::Logging
7
-
3
+ class Resources # :nodoc:
8
4
  attr_reader :client
9
5
 
10
6
  # @param [FinApps::REST::Client] client
@@ -13,6 +9,15 @@ module FinApps
13
9
  @client = client
14
10
  end
15
11
 
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
+
18
+ results, error_messages = client.send_request(path, :post, params)
19
+ [results, error_messages]
20
+ end
16
21
  end
17
22
  end
18
- end
23
+ end
@@ -1,76 +1,42 @@
1
1
  module FinApps
2
2
  module REST
3
-
4
- require 'erb'
5
-
6
- class Users < FinApps::REST::Resources
7
- include FinApps::Logging
3
+ class Users < FinApps::REST::Resources # :nodoc:
4
+ require 'erb'
8
5
  include FinApps::REST::Defaults
9
6
 
10
7
  # @param [String] public_id
11
8
  # @return [FinApps::REST::User, Array<String>]
12
9
  def show(public_id)
13
10
  raise MissingArgumentsError.new 'Missing argument: public_id.' if public_id.blank?
14
- logger.debug "##{__method__} => public_id: #{public_id}"
15
11
 
16
12
  end_point = Defaults::END_POINTS[:users_show]
17
- logger.debug "##{__method__} => end_point: #{end_point}"
18
-
19
13
  path = end_point.sub ':public_id', ERB::Util.url_encode(public_id)
14
+
20
15
  logger.debug "##{__method__} => path: #{path}"
21
16
 
22
- user, error_messages = client.send_request(path, :get) { |r| User.new(r.body) }
23
- return user, error_messages
17
+ results, error_messages = client.send_request(path, :get)
18
+ [results, error_messages]
24
19
  end
25
20
 
26
21
  # @param [Hash] params
27
22
  # @return [FinApps::REST::User, Array<String>]
28
- def create(params = {})
29
- raise MissingArgumentsError.new 'Missing argument: params.' if params.blank?
30
- logger.debug "##{__method__} => params: #{skip_sensitive_data params}"
31
-
32
- end_point = Defaults::END_POINTS[:users_create]
33
- logger.debug "##{__method__} => end_point: #{end_point}"
34
-
35
- user, error_messages = client.send_request(end_point, :post, params) { |r| User.new(r.body) }
36
- return user, error_messages
23
+ def create(params)
24
+ super(params, :users_create)
37
25
  end
38
26
 
39
27
  # @param [Hash] params
40
28
  # @return [Array<String>]
41
- def update(params = {})
42
- logger.debug "##{__method__} => params: #{skip_sensitive_data params}"
43
-
44
- path = Defaults::END_POINTS[:users_update]
45
- logger.debug "##{__method__} => path: #{path}"
29
+ def update(params)
30
+ raise MissingArgumentsError.new 'Missing argument: params.' if params.blank?
31
+ logger.debug "##{__method__} => params: #{params}"
46
32
 
47
- _, error_messages = client.send_request(path, :put, params.compact)
48
- error_messages
49
- end
33
+ end_point = Defaults::END_POINTS[:users_update]
34
+ path = end_point
50
35
 
51
- # @param [Hash] params
52
- # @return [FinApps::REST::User, Array<String>]
53
- def update_password(params = {})
54
- logger.debug "##{__method__} => params: #{skip_sensitive_data params}"
55
-
56
- path = Defaults::END_POINTS[:users_update_password]
57
36
  logger.debug "##{__method__} => path: #{path}"
58
37
 
59
- user, error_messages = client.send_request(path, :put, params.compact) { |r| User.new(r.body) }
60
- return user, error_messages
61
- end
62
-
63
- # @param [Hash] params
64
- # @return [FinApps::REST::User, Array<String>]
65
- def login(params = {})
66
- raise MissingArgumentsError.new 'Missing argument: params.' if params.blank?
67
- logger.debug "##{__method__} => params: #{skip_sensitive_data params}"
68
-
69
- end_point = Defaults::END_POINTS[:users_login]
70
- logger.debug "##{__method__} => end_point: #{end_point}"
71
-
72
- user, error_messages = client.send_request(end_point, :post, params) { |r| User.new(r.body) }
73
- return user, error_messages
38
+ results, error_messages = client.send_request(path, :put, params.compact)
39
+ [results, error_messages]
74
40
  end
75
41
 
76
42
  # @param [String] public_id
@@ -85,15 +51,9 @@ module FinApps
85
51
  path = end_point.sub ':public_id', ERB::Util.url_encode(public_id)
86
52
  logger.debug "##{__method__} => path: #{path}"
87
53
 
88
- _, error_messages = client.send_request(path, :delete)
89
- error_messages
54
+ results, error_messages = client.send_request(path, :delete)
55
+ [results, error_messages]
90
56
  end
91
-
92
57
  end
93
-
94
- class User < FinApps::REST::Resource
95
- attr_accessor :public_id, :token, :email, :first_name, :last_name, :postal_code
96
- end
97
-
98
58
  end
99
- end
59
+ end
@@ -0,0 +1,13 @@
1
+ module FinApps
2
+ module Utils
3
+ # Adds logging capabilities when included into other classes
4
+ module Loggeable
5
+ def logger
6
+ @logger ||= begin
7
+ require 'logger'
8
+ ::Logger.new(STDOUT)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module FinApps
2
- VERSION = '1.0.8'
2
+ VERSION = '2.0.2'.freeze
3
3
  end