finapps 0.14.5.pre → 0.15.0.pre
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 +4 -4
- data/lib/finapps/rest/alert.rb +2 -5
- data/lib/finapps/rest/budgets.rb +97 -0
- data/lib/finapps/rest/client.rb +2 -2
- data/lib/finapps/version.rb +1 -1
- data/lib/finapps.rb +1 -1
- metadata +3 -3
- data/lib/finapps/rest/budget.rb +0 -50
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9f7148284d896dd04a58e18089ace00226d5ad4
|
4
|
+
data.tar.gz: f4e7fe20e55f81774ff535adf4ae90829b8f85cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e7dab72ef0663b55c48077bd94820222c1a4c2459633930d4b1fe6cc7c02059975c7484b4a4bfc09132e879faa2525409ef95cf804f0271ec2823b3f49bae00
|
7
|
+
data.tar.gz: c3d117ae24215b6e9c0c7b4382a1a6ce4133ba552440c765c6a94df1d1ee25dabdc9ccc25c01e544839bcc722c75bad05011065a0de433213a261d37f1df71a0
|
data/lib/finapps/rest/alert.rb
CHANGED
@@ -32,8 +32,8 @@ module FinApps
|
|
32
32
|
|
33
33
|
raise MissingArgumentsError.new 'Missing argument: alert_id.' if alert_id.blank?
|
34
34
|
logger.debug "##{__method__.to_s} => alert_id: #{alert_id.inspect}"
|
35
|
-
raise MissingArgumentsError.new 'Missing argument:
|
36
|
-
logger.debug "##{__method__.to_s} =>
|
35
|
+
raise MissingArgumentsError.new 'Missing argument: read.' if read.blank?
|
36
|
+
logger.debug "##{__method__.to_s} => read: #{read.inspect}"
|
37
37
|
|
38
38
|
end_point = Defaults::END_POINTS[:alert_update]
|
39
39
|
logger.debug "##{__method__.to_s} => end_point: #{end_point}"
|
@@ -54,14 +54,11 @@ module FinApps
|
|
54
54
|
|
55
55
|
raise MissingArgumentsError.new 'Missing argument: alert_id.' if alert_id.blank?
|
56
56
|
logger.debug "##{__method__.to_s} => alert_id: #{alert_id.inspect}"
|
57
|
-
raise MissingArgumentsError.new 'Missing argument: alert_id.' if read.blank?
|
58
|
-
logger.debug "##{__method__.to_s} => alert_id: #{read.inspect}"
|
59
57
|
|
60
58
|
end_point = Defaults::END_POINTS[:alert_delete]
|
61
59
|
logger.debug "##{__method__.to_s} => end_point: #{end_point}"
|
62
60
|
|
63
61
|
path = end_point.sub ':alert_id', ERB::Util.url_encode(alert_id)
|
64
|
-
path = path.sub ':read', ERB::Util.url_encode(read)
|
65
62
|
logger.debug "##{__method__.to_s} => path: #{path}"
|
66
63
|
|
67
64
|
_, error_messages = @client.send(path, :delete)
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module FinApps
|
2
|
+
module REST
|
3
|
+
|
4
|
+
require 'erb'
|
5
|
+
|
6
|
+
class Budgets < 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
|
+
budget = Budget.new({:start_date => start_date, :end_date => end_date, :details => []})
|
21
|
+
|
22
|
+
end_point = Defaults::END_POINTS[:budget_show]
|
23
|
+
logger.debug "##{__method__.to_s} => end_point: #{end_point}"
|
24
|
+
|
25
|
+
path = end_point.sub(':start_date', ERB::Util.url_encode(start_date)).sub(':end_date', ERB::Util.url_encode(end_date))
|
26
|
+
logger.debug "##{__method__.to_s} => path: #{path}"
|
27
|
+
|
28
|
+
result, error_messages = @client.send(path, :get)
|
29
|
+
if result.present? && error_messages.blank?
|
30
|
+
transactions = result.find { |r| r.has_key?('trans') }
|
31
|
+
categories = result.find { |r| r.has_key?('cats') }
|
32
|
+
|
33
|
+
raise 'Category results set for budget is not an array.' unless categories.respond_to?(:each)
|
34
|
+
categories['cats'].each do |c|
|
35
|
+
|
36
|
+
raise 'Unable to locate category id for current category record.' unless c.key?['cat_id']
|
37
|
+
category_id = c['cat_id']
|
38
|
+
|
39
|
+
raise 'Unable to locate budget_amount for current category record.' unless c.key?['budget_amount'] && c.key?['days']
|
40
|
+
raise 'Unable to locate number of days for current category record.' unless c.key?['days']
|
41
|
+
budget_amount = c['budget_amount'].to_f * c['days'].to_i
|
42
|
+
|
43
|
+
raise 'Unable to locate category name for current category record.' unless c.key?['name']
|
44
|
+
category_name = c['name']
|
45
|
+
|
46
|
+
budget.details << BudgetDetail.new({:category_id => category_id,
|
47
|
+
:category_name => category_name,
|
48
|
+
:budget_amount => budget_amount,
|
49
|
+
:expense_amount => expense_amount(category_id, transactions)})
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
logger.debug "##{__method__.to_s} => Completed"
|
55
|
+
return budget, error_messages
|
56
|
+
end
|
57
|
+
|
58
|
+
# @param [Hash] params
|
59
|
+
# @return [Array<Hash>, Array<String>]
|
60
|
+
def update(params={})
|
61
|
+
logger.debug "##{__method__.to_s} => Started"
|
62
|
+
|
63
|
+
raise MissingArgumentsError.new 'Missing argument: params.' if params.blank?
|
64
|
+
|
65
|
+
end_point = Defaults::END_POINTS[:budget_update]
|
66
|
+
logger.debug "##{__method__.to_s} => end_point: #{end_point}"
|
67
|
+
|
68
|
+
budget, error_messages = @client.send(end_point, :put, params)
|
69
|
+
logger.debug "##{__method__.to_s} => Completed"
|
70
|
+
|
71
|
+
return budget, error_messages
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
def expense_amount(category_id, transactions)
|
76
|
+
amount = 0
|
77
|
+
if category_id.present? && transactions.respond_to?(:find)
|
78
|
+
transaction = transactions.find { |t| t['category_id'] == category_id }
|
79
|
+
if transaction.present? && transaction.key?['expense']
|
80
|
+
amount = transaction['expense'].to_f
|
81
|
+
end
|
82
|
+
end
|
83
|
+
amount
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
class Budget < FinApps::REST::Resource
|
89
|
+
attr_accessor :start_date, :end_date, :details
|
90
|
+
end
|
91
|
+
|
92
|
+
class BudgetDetail < FinApps::REST::Resource
|
93
|
+
attr_accessor :category_id, :category_name, :budget_amount, :expense_amount
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
data/lib/finapps/rest/client.rb
CHANGED
@@ -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, :
|
10
|
+
:budget_models, :budget_calculation, :budgets, :cashflow,
|
11
11
|
:alert, :alert_definition, :alert_setting,
|
12
12
|
:rule_sets
|
13
13
|
|
@@ -201,7 +201,7 @@ module FinApps
|
|
201
201
|
@categories ||= FinApps::REST::Categories.new self
|
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
205
|
@cashflow ||= FinApps::REST::Cashflow.new self
|
206
206
|
@alert ||= FinApps::REST::Alert.new self
|
207
207
|
@alert_definition ||= FinApps::REST::AlertDefinition.new self
|
data/lib/finapps/version.rb
CHANGED
data/lib/finapps.rb
CHANGED
@@ -26,7 +26,7 @@ require 'finapps/rest/transactions'
|
|
26
26
|
require 'finapps/rest/categories'
|
27
27
|
require 'finapps/rest/budget_models'
|
28
28
|
require 'finapps/rest/budget_calculation'
|
29
|
-
require 'finapps/rest/
|
29
|
+
require 'finapps/rest/budgets'
|
30
30
|
require 'finapps/rest/cashflow'
|
31
31
|
require 'finapps/rest/alert'
|
32
32
|
require 'finapps/rest/alert_definition'
|
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: 0.
|
4
|
+
version: 0.15.0.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erich Quintero
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -200,9 +200,9 @@ files:
|
|
200
200
|
- lib/finapps/rest/alert.rb
|
201
201
|
- lib/finapps/rest/alert_definition.rb
|
202
202
|
- lib/finapps/rest/alert_setting.rb
|
203
|
-
- lib/finapps/rest/budget.rb
|
204
203
|
- lib/finapps/rest/budget_calculation.rb
|
205
204
|
- lib/finapps/rest/budget_models.rb
|
205
|
+
- lib/finapps/rest/budgets.rb
|
206
206
|
- lib/finapps/rest/cashflow.rb
|
207
207
|
- lib/finapps/rest/categories.rb
|
208
208
|
- lib/finapps/rest/client.rb
|
data/lib/finapps/rest/budget.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
module FinApps
|
2
|
-
module REST
|
3
|
-
|
4
|
-
require 'erb'
|
5
|
-
|
6
|
-
class Budget < 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[:budget_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
|
-
# @param [Hash] params
|
33
|
-
# @return [Array<Hash>, Array<String>]
|
34
|
-
def update(params={})
|
35
|
-
logger.debug "##{__method__.to_s} => Started"
|
36
|
-
|
37
|
-
raise MissingArgumentsError.new 'Missing argument: params.' if params.blank?
|
38
|
-
|
39
|
-
end_point = Defaults::END_POINTS[:budget_update]
|
40
|
-
logger.debug "##{__method__.to_s} => end_point: #{end_point}"
|
41
|
-
|
42
|
-
budget, error_messages = @client.send(end_point, :put, params)
|
43
|
-
logger.debug "##{__method__.to_s} => Completed"
|
44
|
-
|
45
|
-
return budget, error_messages
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|