finapps 0.15.2.pre → 0.16.0.pre

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: 221dace01dc937a32d9e2c5f7f6f6055e4256f07
4
- data.tar.gz: ec44bba21c568e39ba7f2ad3032de9a4fc47d67e
3
+ metadata.gz: fb3b3440f5bca209610fcf02bbc8e0bac6f92ca6
4
+ data.tar.gz: 799674cd7b7444eeef4b05d5856cf442b90c65d8
5
5
  SHA512:
6
- metadata.gz: 38716ba06d21b39137079daa0e4488dae4f7afe95f7d01cc28e3b5028bb0bbbd0a4e670d7363da3befee325bf6c266923820a36ab5b5fd111cb3b8b05b0954e5
7
- data.tar.gz: d5a77305abbdb03169a083b42d765354976ac83e7a907f433cec9e8b0939188fe3f3db974afa498763b97d0d15eb8d1cb2085b30d24edf43cffa28405df70d59
6
+ metadata.gz: d287bb0bd73efd04435de7374b8293d03bc2507caaec0926b696dcfbc47a5231e4f6517cdcbd30edcdeb01f2e74c238eeea18f2496e4740da5c7a3083e64cd54
7
+ data.tar.gz: d3176f06cf949c9d010963e63f70b469cfe14f5d9475ba9771d10b9c7602d9c70450fa327c0f1d4aa2919376089b67a9822f28ae5891c867fc898b9457a0a5a7
data/bin/finapps CHANGED
@@ -3,5 +3,6 @@ require 'finapps/cli/common'
3
3
  require 'finapps/cli/users'
4
4
  require 'finapps/cli/institutions'
5
5
  require 'finapps/cli/budgets'
6
+ require 'finapps/cli/cashflows'
6
7
 
7
8
  FinApps::CLI.start
@@ -0,0 +1,37 @@
1
+ require 'thor'
2
+ require 'finapps'
3
+ require 'pp'
4
+
5
+ module FinApps
6
+ class CLI < Thor
7
+
8
+ desc 'cashflows', 'show'
9
+
10
+ def cashflows_show
11
+
12
+ begin
13
+
14
+ user_identifier = '53d17daf-909d-45d2-6fb6-d43b74d364cb'
15
+ user_token = '4JZmhcHVf3ODRJ9TMKF7N/1sHDY3M5Q49A9ToAy+TDE='
16
+
17
+ client.user_credentials!(user_identifier, user_token)
18
+ budget, error_messages = client.cashflows.show('2015-01-01T00:00:00Z', '2015-01-31T00:00:00Z')
19
+ if budget.present?
20
+ puts
21
+ puts 'cashflow results:'
22
+ pp budget
23
+ else
24
+ puts
25
+ puts 'unable to get cashflow'
26
+ error_messages.each { |m| puts m } if error_messages.present?
27
+ end
28
+ puts
29
+
30
+ rescue StandardError => error
31
+ rescue_standard_error(error)
32
+ end
33
+
34
+ end
35
+
36
+ end
37
+ end
@@ -27,42 +27,14 @@ module FinApps
27
27
 
28
28
  result, error_messages = @client.send(path, :get)
29
29
  if result.present? && error_messages.blank?
30
- transactions = result.find { |r| r.has_key?('trans') }
31
- transactions = transactions['trans'] if transactions.present?
32
- logger.debug transactions.pretty_inspect
33
-
34
- categories = result.find { |r| r.has_key?('cats') }
35
- logger.debug categories.pretty_inspect
36
-
37
- raise 'Category results set for budget is not an array.' unless categories.respond_to?(:each)
38
- categories['cats'].each do |c|
39
- logger.debug "---------------------------------------------"
40
- raise 'Unable to locate category id for current category record.' unless c.key?('cat_id')
41
- category_id = c['cat_id']
42
- logger.debug "category_id: #{category_id}"
43
-
44
- raise 'Unable to locate category name for current category record.' unless c.key?('name')
45
- category_name = c['name']
46
- logger.debug "category_name: #{category_name}"
47
-
48
- raise 'Unable to locate budget_amount for current category record.' unless c.key?('budget_amount')
49
- budget_amount = c['budget_amount']
50
- logger.debug "daily_budget_amount: #{budget_amount}"
51
-
52
- raise 'Unable to locate number of days for current category record.' unless c.key?('days')
53
- days = c['days']
54
- logger.debug "days: #{days}"
55
-
56
- date_range_budget_amount = budget_amount.to_f * days.to_i
57
- logger.debug "budget_amount for #{days} days: #{date_range_budget_amount}"
58
-
59
- budget.details << BudgetDetail.new({:category_id => category_id,
60
- :category_name => category_name,
61
- :budget_amount => date_range_budget_amount,
62
- :expense_amount => expense_amount(category_id, transactions)})
63
- end
64
- end
30
+ categories = result_categories(result)
31
+ raise 'Category results-set for budget is not an array.' unless categories.respond_to?(:each)
32
+
33
+ transactions = result_transactions(result)
34
+ categories.each { |category| budget.details << result_category_to_budget_detail(category, transactions) }
65
35
 
36
+ logger.debug budget.pretty_inspect
37
+ end
66
38
 
67
39
  logger.debug "##{__method__.to_s} => Completed"
68
40
  return budget, error_messages
@@ -85,6 +57,41 @@ module FinApps
85
57
  end
86
58
 
87
59
  private
60
+
61
+ def result_categories(result)
62
+ extract_array(result, 'cats')
63
+ end
64
+
65
+ def result_category_to_budget_detail(category, transactions)
66
+ raise 'Unable to locate category id for current category record.' unless category.key?('cat_id')
67
+ category_id = category['cat_id']
68
+
69
+ raise 'Unable to locate category name for current category record.' unless category.key?('name')
70
+ category_name = category['name']
71
+
72
+ raise 'Unable to locate budget_amount for current category record.' unless category.key?('budget_amount')
73
+ budget_amount = category['budget_amount']
74
+
75
+ raise 'Unable to locate number of days for current category record.' unless category.key?('days')
76
+ days = category['days']
77
+
78
+ date_range_budget_amount = budget_amount.to_f * days.to_i
79
+
80
+ BudgetDetail.new({:category_id => category_id,
81
+ :category_name => category_name,
82
+ :budget_amount => date_range_budget_amount,
83
+ :expense_amount => expense_amount(category_id, transactions)})
84
+ end
85
+
86
+ def result_transactions(result)
87
+ extract_array(result, 'trans')
88
+ end
89
+
90
+ def extract_array(result, array_identifier)
91
+ array_container = result.find { |r| r.has_key?(array_identifier) }
92
+ array_container.present? ? array_container[array_identifier] : nil
93
+ end
94
+
88
95
  def expense_amount(category_id, transactions = [])
89
96
  amount = 0
90
97
  if category_id.present? && transactions.respond_to?(:find)
@@ -0,0 +1,97 @@
1
+ module FinApps
2
+ module REST
3
+
4
+ require 'erb'
5
+
6
+ class Cashflows < FinApps::REST::Resources
7
+ include FinApps::REST::Defaults
8
+
9
+ # @param [Date] start_date
10
+ # @param [Date] end_date
11
+ # @return [Hash, Array<String>]
12
+ def show(start_date, end_date)
13
+ logger.debug "##{__method__.to_s} => Started"
14
+
15
+ raise MissingArgumentsError.new 'Missing argument: start_date.' if start_date.blank?
16
+ logger.debug "##{__method__.to_s} => start_date: #{start_date}"
17
+ raise MissingArgumentsError.new 'Missing argument: end_date.' if end_date.blank?
18
+ logger.debug "##{__method__.to_s} => end_date: #{end_date}"
19
+
20
+ cashflow = Cashflow.new({:start_date => start_date,
21
+ :end_date => end_date,
22
+ :total_inflow_amount => 0,
23
+ :total_outflow_amount => 0,
24
+ :total_leftover_amount => 0,
25
+ :details => []})
26
+
27
+ end_point = Defaults::END_POINTS[:cashflow_show]
28
+ logger.debug "##{__method__.to_s} => end_point: #{end_point}"
29
+
30
+ path = end_point.sub(':start_date', ERB::Util.url_encode(start_date)).sub(':end_date', ERB::Util.url_encode(end_date))
31
+ logger.debug "##{__method__.to_s} => path: #{path}"
32
+
33
+ result, error_messages = @client.send(path, :get)
34
+ if result.present? && error_messages.blank?
35
+
36
+ summary = extract_value(result, 'summary')
37
+ raise 'Summary result-set for cashflow is not present.' if summary.nil?
38
+ raise 'Summary result-set for cashflow is not a hash.' unless summary.respond_to?(:key?)
39
+
40
+ raise 'Total in-flow value for cashflow is not present.' unless summary.key?('inflow')
41
+ cashflow.total_inflow_amount = summary['inflow']
42
+
43
+ raise 'Total out-flow value for cashflow is not present.' unless summary.key?('outflow')
44
+ cashflow.total_outflow_amount = summary['outflow']
45
+
46
+ raise 'Total left-over value for cashflow is not present.' unless summary.key?('diff')
47
+ cashflow.total_leftover_amount = summary['diff']
48
+
49
+ categories = extract_value(result, 'details')
50
+ raise 'Category results-set for cashflow is not an array.' unless categories.respond_to?(:each)
51
+
52
+ categories.each { |category| cashflow.details << result_category_to_cashflow_detail(category) }
53
+ end
54
+
55
+ logger.debug "##{__method__.to_s} => Completed"
56
+ return cashflow, error_messages
57
+ end
58
+
59
+ private
60
+
61
+ def extract_value(result, array_identifier)
62
+ array_container = result.find { |r| r.has_key?(array_identifier) }
63
+ array_container.present? ? array_container[array_identifier] : nil
64
+ end
65
+
66
+ def result_category_to_cashflow_detail(category)
67
+ raise 'Unable to locate category id for current category record.' unless category.key?('cat')
68
+ category_id = category['cat']
69
+
70
+ raise 'Unable to locate inflow amount for current category record.' unless category.key?('inflow')
71
+ inflow_amount = category['inflow']
72
+
73
+ raise 'Unable to locate outflow amount for current category record.' unless category.key?('outflow')
74
+ outflow_amount = category['outflow']
75
+
76
+ raise 'Unable to locate left over amount for current category record.' unless category.key?('diff')
77
+ leftover_amount = category['diff']
78
+
79
+ BudgetDetail.new({:category_id => category_id,
80
+ :inflow_amount => inflow_amount,
81
+ :outflow_amount => outflow_amount,
82
+ :leftover_amount => leftover_amount})
83
+ end
84
+
85
+ end
86
+
87
+ class Cashflow < FinApps::REST::Resource
88
+ attr_accessor :start_date, :end_date,
89
+ :total_inflow_amount, :total_outflow_amount, :total_leftover_amount, :details
90
+ end
91
+
92
+ class CashflowDetail < FinApps::REST::Resource
93
+ attr_accessor :category_id, :inflow_amount, :outflow_amount, :leftover_amount
94
+ end
95
+
96
+ end
97
+ end
@@ -7,7 +7,7 @@ module FinApps
7
7
 
8
8
  attr_reader :connection, :users, :institutions, :user_institutions,
9
9
  :transactions, :categories,
10
- :budget_models, :budget_calculation, :budgets, :cashflow,
10
+ :budget_models, :budget_calculation, :budgets, :cashflows,
11
11
  :alert, :alert_definition, :alert_setting,
12
12
  :rule_sets
13
13
 
@@ -202,7 +202,7 @@ module FinApps
202
202
  @budget_models ||= FinApps::REST::BudgetModels.new self
203
203
  @budget_calculation ||= FinApps::REST::BudgetCalculation.new self
204
204
  @budgets ||= FinApps::REST::Budgets.new self
205
- @cashflow ||= FinApps::REST::Cashflow.new self
205
+ @cashflows ||= FinApps::REST::Cashflows.new self
206
206
  @alert ||= FinApps::REST::Alert.new self
207
207
  @alert_definition ||= FinApps::REST::AlertDefinition.new self
208
208
  @alert_setting ||= FinApps::REST::AlertSetting.new self
@@ -1,3 +1,3 @@
1
1
  module FinApps
2
- VERSION = '0.15.2.pre'
2
+ VERSION = '0.16.0.pre'
3
3
  end
data/lib/finapps.rb CHANGED
@@ -27,7 +27,7 @@ require 'finapps/rest/categories'
27
27
  require 'finapps/rest/budget_models'
28
28
  require 'finapps/rest/budget_calculation'
29
29
  require 'finapps/rest/budgets'
30
- require 'finapps/rest/cashflow'
30
+ require 'finapps/rest/cashflows'
31
31
  require 'finapps/rest/alert'
32
32
  require 'finapps/rest/alert_definition'
33
33
  require 'finapps/rest/alert_setting'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: finapps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.2.pre
4
+ version: 0.16.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erich Quintero
@@ -192,6 +192,7 @@ files:
192
192
  - finapps.gemspec
193
193
  - lib/finapps.rb
194
194
  - lib/finapps/cli/budgets.rb
195
+ - lib/finapps/cli/cashflows.rb
195
196
  - lib/finapps/cli/common.rb
196
197
  - lib/finapps/cli/institutions.rb
197
198
  - lib/finapps/cli/users.rb
@@ -204,7 +205,7 @@ files:
204
205
  - lib/finapps/rest/budget_calculation.rb
205
206
  - lib/finapps/rest/budget_models.rb
206
207
  - lib/finapps/rest/budgets.rb
207
- - lib/finapps/rest/cashflow.rb
208
+ - lib/finapps/rest/cashflows.rb
208
209
  - lib/finapps/rest/categories.rb
209
210
  - lib/finapps/rest/client.rb
210
211
  - lib/finapps/rest/connection.rb
@@ -1,34 +0,0 @@
1
- module FinApps
2
- module REST
3
-
4
- require 'erb'
5
-
6
- class Cashflow < FinApps::REST::Resources
7
- include FinApps::REST::Defaults
8
-
9
- # @param [Date] start_date
10
- # @param [Date] end_date
11
- # @return [Hash, Array<String>]
12
- def show(start_date, end_date)
13
- logger.debug "##{__method__.to_s} => Started"
14
-
15
- raise MissingArgumentsError.new 'Missing argument: start_date.' if start_date.blank?
16
- logger.debug "##{__method__.to_s} => start_date: #{start_date}"
17
- raise MissingArgumentsError.new 'Missing argument: end_date.' if end_date.blank?
18
- logger.debug "##{__method__.to_s} => end_date: #{end_date}"
19
-
20
- end_point = Defaults::END_POINTS[:cashflow_show]
21
- logger.debug "##{__method__.to_s} => end_point: #{end_point}"
22
-
23
- path = end_point.sub(':start_date', ERB::Util.url_encode(start_date)).sub(':end_date', ERB::Util.url_encode(end_date))
24
- logger.debug "##{__method__.to_s} => path: #{path}"
25
-
26
- budget, error_messages = @client.send(path, :get)
27
-
28
- logger.debug "##{__method__.to_s} => Completed"
29
- return budget, error_messages
30
- end
31
-
32
- end
33
- end
34
- end