async-firefly 1.0.0

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.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/lib/async/firefly/about.rb +79 -0
  3. data/lib/async/firefly/accounts.rb +129 -0
  4. data/lib/async/firefly/attachments.rb +53 -0
  5. data/lib/async/firefly/autocomplete.rb +435 -0
  6. data/lib/async/firefly/available_budgets.rb +59 -0
  7. data/lib/async/firefly/bills.rb +107 -0
  8. data/lib/async/firefly/budgets.rb +165 -0
  9. data/lib/async/firefly/categories.rb +63 -0
  10. data/lib/async/firefly/charts.rb +73 -0
  11. data/lib/async/firefly/client.rb +89 -0
  12. data/lib/async/firefly/configurations.rb +62 -0
  13. data/lib/async/firefly/currencies.rb +71 -0
  14. data/lib/async/firefly/data.rb +37 -0
  15. data/lib/async/firefly/error.rb +57 -0
  16. data/lib/async/firefly/escape.rb +9 -0
  17. data/lib/async/firefly/exchange_rates.rb +77 -0
  18. data/lib/async/firefly/insight.rb +185 -0
  19. data/lib/async/firefly/links.rb +69 -0
  20. data/lib/async/firefly/nested.rb +75 -0
  21. data/lib/async/firefly/object_groups.rb +33 -0
  22. data/lib/async/firefly/page.rb +139 -0
  23. data/lib/async/firefly/piggy_banks.rb +153 -0
  24. data/lib/async/firefly/preferences.rb +58 -0
  25. data/lib/async/firefly/recurrences.rb +169 -0
  26. data/lib/async/firefly/redacted.rb +32 -0
  27. data/lib/async/firefly/representation.rb +99 -0
  28. data/lib/async/firefly/rule_groups.rb +55 -0
  29. data/lib/async/firefly/rules.rb +105 -0
  30. data/lib/async/firefly/search.rb +40 -0
  31. data/lib/async/firefly/submit.rb +139 -0
  32. data/lib/async/firefly/summary.rb +45 -0
  33. data/lib/async/firefly/sums.rb +17 -0
  34. data/lib/async/firefly/tags.rb +57 -0
  35. data/lib/async/firefly/transactions.rb +231 -0
  36. data/lib/async/firefly/user_groups.rb +49 -0
  37. data/lib/async/firefly/users.rb +35 -0
  38. data/lib/async/firefly/version.rb +5 -0
  39. data/lib/async/firefly/webhooks.rb +101 -0
  40. data/lib/async/firefly/wrapper.rb +65 -0
  41. data/lib/async/firefly.rb +2 -0
  42. data/license.md +21 -0
  43. data/readme.md +498 -0
  44. metadata +110 -0
@@ -0,0 +1,59 @@
1
+ require_relative "page"
2
+
3
+ module Async
4
+ module Firefly
5
+ class AvailableBudget < Representation
6
+ def created_at = self.attributes[:created_at]
7
+
8
+ def updated_at = self.attributes[:updated_at]
9
+
10
+ def object_has_currency_setting = self.attributes[:object_has_currency_setting]
11
+
12
+ def currency_id = self.attributes[:currency_id]
13
+
14
+ def currency_name = self.attributes[:currency_name]
15
+
16
+ def currency_code = self.attributes[:currency_code]
17
+
18
+ def currency_symbol = self.attributes[:currency_symbol]
19
+
20
+ def currency_decimal_places = self.attributes[:currency_decimal_places]
21
+
22
+ def primary_currency_id = self.attributes[:primary_currency_id]
23
+
24
+ def primary_currency_name = self.attributes[:primary_currency_name]
25
+
26
+ def primary_currency_code = self.attributes[:primary_currency_code]
27
+
28
+ def primary_currency_symbol = self.attributes[:primary_currency_symbol]
29
+
30
+ def primary_currency_decimal_places = self.attributes[:primary_currency_decimal_places]
31
+
32
+ def amount = self.attributes[:amount]
33
+
34
+ def pc_amount = self.attributes[:pc_amount]
35
+
36
+ def start = self.attributes[:start]
37
+
38
+ def end = self.attributes[:end]
39
+
40
+ def spent_in_budgets = self.nested_list(ArrayEntryWithCurrencyAndSum, self.attributes[:spent_in_budgets])
41
+
42
+ def pc_spent_in_budgets = self.nested_list(ArrayEntryWithCurrencyAndSum, self.attributes[:pc_spent_in_budgets])
43
+
44
+ def spent_outside_budgets = self.nested_list(ArrayEntryWithCurrencyAndSum, self.attributes[:spent_outside_budgets])
45
+
46
+ def pc_spent_outside_budgets = self.nested_list(ArrayEntryWithCurrencyAndSum, self.attributes[:pc_spent_outside_budgets])
47
+ end
48
+
49
+ class AvailableBudgetPage < Page
50
+ MEMBER = AvailableBudget
51
+ end
52
+
53
+ module AvailableBudgets
54
+ def available_budgets(**parameters) = Collection.for(self, "v1/available-budgets", AvailableBudgetPage, **parameters)
55
+
56
+ def available_budget(id) = AvailableBudget.new(self.with(path: "v1/available-budgets/" + Firefly.escape(id)))
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,107 @@
1
+ require_relative "page"
2
+
3
+ module Async
4
+ module Firefly
5
+ class Bill < Representation
6
+ def created_at = self.attributes[:created_at]
7
+
8
+ def updated_at = self.attributes[:updated_at]
9
+
10
+ def name = self.attributes[:name]
11
+
12
+ def object_has_currency_setting = self.attributes[:object_has_currency_setting]
13
+
14
+ def currency_id = self.attributes[:currency_id]
15
+
16
+ def currency_name = self.attributes[:currency_name]
17
+
18
+ def currency_code = self.attributes[:currency_code]
19
+
20
+ def currency_symbol = self.attributes[:currency_symbol]
21
+
22
+ def currency_decimal_places = self.attributes[:currency_decimal_places]
23
+
24
+ def primary_currency_id = self.attributes[:primary_currency_id]
25
+
26
+ def primary_currency_name = self.attributes[:primary_currency_name]
27
+
28
+ def primary_currency_code = self.attributes[:primary_currency_code]
29
+
30
+ def primary_currency_symbol = self.attributes[:primary_currency_symbol]
31
+
32
+ def primary_currency_decimal_places = self.attributes[:primary_currency_decimal_places]
33
+
34
+ def amount_min = self.attributes[:amount_min]
35
+
36
+ def pc_amount_min = self.attributes[:pc_amount_min]
37
+
38
+ def amount_max = self.attributes[:amount_max]
39
+
40
+ def pc_amount_max = self.attributes[:pc_amount_max]
41
+
42
+ def amount_avg = self.attributes[:amount_avg]
43
+
44
+ def pc_amount_avg = self.attributes[:pc_amount_avg]
45
+
46
+ def date = self.attributes[:date]
47
+
48
+ def end_date = self.attributes[:end_date]
49
+
50
+ def extension_date = self.attributes[:extension_date]
51
+
52
+ def repeat_freq = self.attributes[:repeat_freq]
53
+
54
+ def skip = self.attributes[:skip]
55
+
56
+ def active = self.attributes[:active]
57
+
58
+ def order = self.attributes[:order]
59
+
60
+ def notes = self.attributes[:notes]
61
+
62
+ def object_group_id = self.attributes[:object_group_id]
63
+
64
+ def object_group_order = self.attributes[:object_group_order]
65
+
66
+ def object_group_title = self.attributes[:object_group_title]
67
+
68
+ def paid_dates = self.attributes[:paid_dates]
69
+
70
+ def pay_dates = self.attributes[:pay_dates]
71
+
72
+ def next_expected_match = self.attributes[:next_expected_match]
73
+
74
+ def next_expected_match_diff = self.attributes[:next_expected_match_diff]
75
+
76
+ def active? = self.active == true
77
+
78
+ def attachments(**parameters) = Collection.for(@resource, "attachments", NestedAttachmentPage, **parameters)
79
+
80
+ def rules(**parameters) = NestedRulePage.new(@resource.with(path: "rules", parameters: parameters))
81
+
82
+ def transactions(**parameters) = Collection.for(@resource, "transactions", NestedTransactionPage, **parameters)
83
+
84
+ def update(payload) = self.submit(Bill, @resource, payload, method: :put)
85
+
86
+ def delete = self.discard(@resource)
87
+ end
88
+
89
+ class BillPage < Page
90
+ MEMBER = Bill
91
+ end
92
+
93
+ module Bills
94
+ def bills(**parameters) = Collection.for(self, "v1/bills", BillPage, **parameters)
95
+
96
+ def bill(id) = Bill.new(self.with(path: "v1/bills/" + Firefly.escape(id)))
97
+
98
+ def create_bill(payload) = self.submit(Bill, self.with(path: "v1/bills"), payload, identify: true)
99
+
100
+ def subscriptions(**parameters) = Collection.for(self, "v1/subscriptions", BillPage, **parameters)
101
+
102
+ def subscription(id) = Bill.new(self.with(path: "v1/subscriptions/" + Firefly.escape(id)))
103
+
104
+ def create_subscription(payload) = self.submit(Bill, self.with(path: "v1/subscriptions"), payload, identify: true)
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,165 @@
1
+ require_relative "page"
2
+
3
+ module Async
4
+ module Firefly
5
+ class Budget < Representation
6
+ def created_at = self.attributes[:created_at]
7
+
8
+ def updated_at = self.attributes[:updated_at]
9
+
10
+ def active = self.attributes[:active]
11
+
12
+ def name = self.attributes[:name]
13
+
14
+ def order = self.attributes[:order]
15
+
16
+ def notes = self.attributes[:notes]
17
+
18
+ def auto_budget_type = self.attributes[:auto_budget_type]
19
+
20
+ def auto_budget_period = self.attributes[:auto_budget_period]
21
+
22
+ def object_group_id = self.attributes[:object_group_id]
23
+
24
+ def object_group_order = self.attributes[:object_group_order]
25
+
26
+ def object_group_title = self.attributes[:object_group_title]
27
+
28
+ def object_has_currency_setting = self.attributes[:object_has_currency_setting]
29
+
30
+ def currency_id = self.attributes[:currency_id]
31
+
32
+ def currency_name = self.attributes[:currency_name]
33
+
34
+ def currency_code = self.attributes[:currency_code]
35
+
36
+ def currency_symbol = self.attributes[:currency_symbol]
37
+
38
+ def currency_decimal_places = self.attributes[:currency_decimal_places]
39
+
40
+ def primary_currency_id = self.attributes[:primary_currency_id]
41
+
42
+ def primary_currency_name = self.attributes[:primary_currency_name]
43
+
44
+ def primary_currency_code = self.attributes[:primary_currency_code]
45
+
46
+ def primary_currency_symbol = self.attributes[:primary_currency_symbol]
47
+
48
+ def primary_currency_decimal_places = self.attributes[:primary_currency_decimal_places]
49
+
50
+ def auto_budget_amount = self.attributes[:auto_budget_amount]
51
+
52
+ def pc_auto_budget_amount = self.attributes[:pc_auto_budget_amount]
53
+
54
+ def spent = self.nested_list(ArrayEntryWithCurrencyAndSum, self.attributes[:spent])
55
+
56
+ def pc_spent = self.nested_list(ArrayEntryWithCurrencyAndSum, self.attributes[:pc_spent])
57
+
58
+ def active? = self.active == true
59
+
60
+ def limits(**parameters) = BudgetLimitPage.new(@resource.with(path: "limits", parameters: parameters))
61
+
62
+ def limit(id) = BudgetLimit.new(@resource.with(path: "limits/" + Firefly.escape(id)))
63
+
64
+ def create_limit(payload) = self.submit(BudgetLimit, @resource.with(path: "limits"), payload, identify: true)
65
+
66
+ def transactions(**parameters) = Collection.for(@resource, "transactions", NestedTransactionPage, **parameters)
67
+
68
+ def attachments(**parameters) = Collection.for(@resource, "attachments", NestedAttachmentPage, **parameters)
69
+
70
+ def update(payload) = self.submit(Budget, @resource, payload, method: :put)
71
+
72
+ def delete = self.discard(@resource)
73
+ end
74
+
75
+ class BudgetPage < Page
76
+ MEMBER = Budget
77
+ end
78
+
79
+ class BudgetLimit < Representation
80
+ def created_at = self.attributes[:created_at]
81
+
82
+ def updated_at = self.attributes[:updated_at]
83
+
84
+ def start = self.attributes[:start]
85
+
86
+ def end = self.attributes[:end]
87
+
88
+ def budget_id = self.attributes[:budget_id]
89
+
90
+ def object_has_currency_setting = self.attributes[:object_has_currency_setting]
91
+
92
+ def currency_id = self.attributes[:currency_id]
93
+
94
+ def currency_name = self.attributes[:currency_name]
95
+
96
+ def currency_code = self.attributes[:currency_code]
97
+
98
+ def currency_symbol = self.attributes[:currency_symbol]
99
+
100
+ def currency_decimal_places = self.attributes[:currency_decimal_places]
101
+
102
+ def primary_currency_id = self.attributes[:primary_currency_id]
103
+
104
+ def primary_currency_name = self.attributes[:primary_currency_name]
105
+
106
+ def primary_currency_code = self.attributes[:primary_currency_code]
107
+
108
+ def primary_currency_symbol = self.attributes[:primary_currency_symbol]
109
+
110
+ def primary_currency_decimal_places = self.attributes[:primary_currency_decimal_places]
111
+
112
+ def amount = self.attributes[:amount]
113
+
114
+ def pc_amount = self.attributes[:pc_amount]
115
+
116
+ def period = self.attributes[:period]
117
+
118
+ def spent = self.nested_list(ArrayEntryWithCurrencyAndSum, self.attributes[:spent])
119
+
120
+ def pc_spent = self.nested_list(ArrayEntryWithCurrencyAndSum, self.attributes[:pc_spent])
121
+
122
+ def notes = self.attributes[:notes]
123
+
124
+ def transactions(**parameters) = Collection.for(@resource, "transactions", BudgetLimitTransactionPage, **parameters)
125
+
126
+ def update(payload) = self.submit(BudgetLimit, @resource, payload, method: :put)
127
+
128
+ def delete = self.discard(@resource)
129
+ end
130
+
131
+ class BudgetLimitPage < Page
132
+ MEMBER = BudgetLimit
133
+ end
134
+
135
+ class BudgetLimitListPage < Page
136
+ MEMBER = BudgetLimit
137
+
138
+ def member_path(record) = "../budgets/" + self.identifier(record, :attributes, :budget_id) + "/limits/" + self.identifier(record, :id)
139
+ end
140
+
141
+ class BudgetLimitTransactionPage < Page
142
+ def member_class = Transaction
143
+
144
+ def member_path(record) = "../../../../../transactions/" + self.identifier(record, :id)
145
+ end
146
+
147
+ class TransactionsWithoutBudgetPage < Page
148
+ def member_class = Transaction
149
+
150
+ def member_path(record) = "../../transactions/" + self.identifier(record, :id)
151
+ end
152
+
153
+ module Budgets
154
+ def budgets(**parameters) = Collection.for(self, "v1/budgets", BudgetPage, **parameters)
155
+
156
+ def budget(id) = Budget.new(self.with(path: "v1/budgets/" + Firefly.escape(id)))
157
+
158
+ def create_budget(payload) = self.submit(Budget, self.with(path: "v1/budgets"), payload, identify: true)
159
+
160
+ def budget_limits(**parameters) = BudgetLimitListPage.new(self.with(path: "v1/budget-limits", parameters: parameters))
161
+
162
+ def transactions_without_budget(**parameters) = Collection.for(self, "v1/budgets/transactions-without-budget", TransactionsWithoutBudgetPage, **parameters)
163
+ end
164
+ end
165
+ end
@@ -0,0 +1,63 @@
1
+ require_relative "page"
2
+
3
+ module Async
4
+ module Firefly
5
+ class Category < Representation
6
+ def created_at = self.attributes[:created_at]
7
+
8
+ def updated_at = self.attributes[:updated_at]
9
+
10
+ def name = self.attributes[:name]
11
+
12
+ def color = self.attributes[:color]
13
+
14
+ def last_activity = self.attributes[:last_activity]
15
+
16
+ def notes = self.attributes[:notes]
17
+
18
+ def object_has_currency_setting = self.attributes[:object_has_currency_setting]
19
+
20
+ def primary_currency_id = self.attributes[:primary_currency_id]
21
+
22
+ def primary_currency_name = self.attributes[:primary_currency_name]
23
+
24
+ def primary_currency_code = self.attributes[:primary_currency_code]
25
+
26
+ def primary_currency_symbol = self.attributes[:primary_currency_symbol]
27
+
28
+ def primary_currency_decimal_places = self.attributes[:primary_currency_decimal_places]
29
+
30
+ def spent = self.nested_list(ArrayEntryWithCurrencyAndSum, self.attributes[:spent])
31
+
32
+ def pc_spent = self.nested_list(ArrayEntryWithCurrencyAndSum, self.attributes[:pc_spent])
33
+
34
+ def earned = self.nested_list(ArrayEntryWithCurrencyAndSum, self.attributes[:earned])
35
+
36
+ def pc_earned = self.nested_list(ArrayEntryWithCurrencyAndSum, self.attributes[:pc_earned])
37
+
38
+ def transferred = self.nested_list(ArrayEntryWithCurrencyAndSum, self.attributes[:transferred])
39
+
40
+ def pc_transferred = self.nested_list(ArrayEntryWithCurrencyAndSum, self.attributes[:pc_transferred])
41
+
42
+ def transactions(**parameters) = Collection.for(@resource, "transactions", NestedTransactionPage, **parameters)
43
+
44
+ def attachments(**parameters) = Collection.for(@resource, "attachments", NestedAttachmentPage, **parameters)
45
+
46
+ def update(payload) = self.submit(Category, @resource, payload, method: :put)
47
+
48
+ def delete = self.discard(@resource)
49
+ end
50
+
51
+ class CategoryPage < Page
52
+ MEMBER = Category
53
+ end
54
+
55
+ module Categories
56
+ def categories(**parameters) = Collection.for(self, "v1/categories", CategoryPage, **parameters)
57
+
58
+ def category(id) = Category.new(self.with(path: "v1/categories/" + Firefly.escape(id)))
59
+
60
+ def create_category(payload) = self.submit(Category, self.with(path: "v1/categories"), payload, identify: true)
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,73 @@
1
+ require_relative "page"
2
+
3
+ module Async
4
+ module Firefly
5
+ class ChartDataPoint < Representation
6
+ def key = self.value[:key]
7
+ end
8
+
9
+ class ChartDataSet < Representation
10
+ def label = self.value[:label]
11
+
12
+ def currency_id = self.value[:currency_id]
13
+
14
+ def currency_name = self.value[:currency_name]
15
+
16
+ def currency_code = self.value[:currency_code]
17
+
18
+ def currency_symbol = self.value[:currency_symbol]
19
+
20
+ def currency_decimal_places = self.value[:currency_decimal_places]
21
+
22
+ def primary_currency_id = self.value[:primary_currency_id]
23
+
24
+ def primary_currency_name = self.value[:primary_currency_name]
25
+
26
+ def primary_currency_code = self.value[:primary_currency_code]
27
+
28
+ def primary_currency_symbol = self.value[:primary_currency_symbol]
29
+
30
+ def primary_currency_decimal_places = self.value[:primary_currency_decimal_places]
31
+
32
+ def date = self.value[:date]
33
+
34
+ def start_date = self.value[:start_date]
35
+
36
+ def end_date = self.value[:end_date]
37
+
38
+ def type = self.value[:type]
39
+
40
+ def period = self.value[:period]
41
+
42
+ def yAxisID = self.value[:yAxisID]
43
+
44
+ def entries = self.value[:entries]
45
+
46
+ def pc_entries = self.value[:pc_entries]
47
+ end
48
+
49
+ class ChartLine < Representation
50
+ include Enumerable
51
+
52
+ def each(&block)
53
+ if block
54
+ self.deconstruct.each{|record| block.call(ChartDataSet.new(@resource, value: record, metadata: self.metadata))}
55
+ else
56
+ self.to_enum(:each)
57
+ end
58
+ end
59
+ end
60
+
61
+ module Charts
62
+ def account_overview_chart(**parameters) = self.fetch(ChartLine, self.with(path: "v1/chart/account/overview", parameters: parameters))
63
+
64
+ def balance_chart(**parameters) = self.fetch(ChartLine, self.with(path: "v1/chart/balance/balance", parameters: parameters))
65
+
66
+ def budget_overview_chart(**parameters) = self.fetch(ChartLine, self.with(path: "v1/chart/budget/overview", parameters: parameters))
67
+
68
+ def budget_overview_with_limits_chart(**parameters) = self.fetch(ChartLine, self.with(path: "v1/chart/budget/overview-with-limits", parameters: parameters))
69
+
70
+ def category_overview_chart(**parameters) = self.fetch(ChartLine, self.with(path: "v1/chart/category/overview", parameters: parameters))
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,89 @@
1
+ require "async/rest/resource"
2
+
3
+ require_relative "about"
4
+ require_relative "accounts"
5
+ require_relative "attachments"
6
+ require_relative "autocomplete"
7
+ require_relative "available_budgets"
8
+ require_relative "bills"
9
+ require_relative "budgets"
10
+ require_relative "categories"
11
+ require_relative "charts"
12
+ require_relative "configurations"
13
+ require_relative "currencies"
14
+ require_relative "data"
15
+ require_relative "error"
16
+ require_relative "exchange_rates"
17
+ require_relative "insight"
18
+ require_relative "links"
19
+ require_relative "nested"
20
+ require_relative "object_groups"
21
+ require_relative "page"
22
+ require_relative "sums"
23
+ require_relative "piggy_banks"
24
+ require_relative "preferences"
25
+ require_relative "recurrences"
26
+ require_relative "rule_groups"
27
+ require_relative "rules"
28
+ require_relative "search"
29
+ require_relative "submit"
30
+ require_relative "summary"
31
+ require_relative "tags"
32
+ require_relative "transactions"
33
+ require_relative "user_groups"
34
+ require_relative "users"
35
+ require_relative "version"
36
+ require_relative "webhooks"
37
+
38
+ module Async
39
+ module Firefly
40
+ class Client < Async::REST::Resource
41
+ ENDPOINT = Async::HTTP::Endpoint.parse(ENV.fetch("FIREFLY_URL", "http://localhost:8080/api/"))
42
+
43
+ USER_AGENT = "async-firefly (https://github.com/n-at-han-k/async-firefly, v" + VERSION + ")"
44
+
45
+ include Submit
46
+
47
+ include About
48
+ include Accounts
49
+ include Attachments
50
+ include Autocomplete
51
+ include AvailableBudgets
52
+ include Bills
53
+ include Budgets
54
+ include Categories
55
+ include Charts
56
+ include Configurations
57
+ include Currencies
58
+ include Data
59
+ include ExchangeRates
60
+ include Insight
61
+ include Links
62
+ include ObjectGroups
63
+ include PiggyBanks
64
+ include Preferences
65
+ include Recurrences
66
+ include RuleGroups
67
+ include Rules
68
+ include Search
69
+ include Summary
70
+ include Tags
71
+ include Transactions
72
+ include UserGroups
73
+ include Users
74
+ include Webhooks
75
+
76
+ def initialize(delegate, reference = ::Protocol::URL::Reference.parse, headers = ::Protocol::HTTP::Headers.new)
77
+ super
78
+
79
+ unless @headers["user-agent"]
80
+ @headers = @headers.merge("user-agent" => USER_AGENT)
81
+ end
82
+ end
83
+
84
+ def authenticated(token)
85
+ self.with(headers: {"authorization" => "Bearer " + token})
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,62 @@
1
+ require_relative "page"
2
+
3
+ module Async
4
+ module Firefly
5
+ class Configuration < Representation
6
+ def title = self.value[:title]
7
+
8
+ def value_attribute = self.value[:value]
9
+
10
+ def editable = self.value[:editable]
11
+ end
12
+
13
+ module Configurations
14
+ def configurations
15
+ resource = self.with(path: "v1/configuration")
16
+
17
+ Configuration.get(resource) do |target, response|
18
+ unless response.success?
19
+ raise Failure.for(response)
20
+ end
21
+
22
+ Array(response.read).map{|item| Configuration.new(target, value: item, metadata: response.headers)}
23
+ end
24
+ end
25
+
26
+ def configuration(name)
27
+ resource = self.with(path: "v1/configuration/" + Firefly.escape(name))
28
+
29
+ Configuration.get(resource) do |target, response|
30
+ unless response.success?
31
+ raise Failure.for(response)
32
+ end
33
+
34
+ self.unwrapped_configuration(target, response)
35
+ end
36
+ end
37
+
38
+ def set_configuration(name, payload)
39
+ resource = self.with(path: "v1/configuration/" + Firefly.escape(name))
40
+
41
+ self.with_retry do
42
+ Configuration.put(resource, payload) do |target, response|
43
+ unless response.success?
44
+ raise Failure.for(response)
45
+ end
46
+
47
+ self.unwrapped_configuration(target, response)
48
+ end
49
+ end
50
+ end
51
+
52
+ def unwrapped_configuration(target, response)
53
+ case response.read
54
+ in {data: Hash => data}
55
+ Configuration.new(target, value: data, metadata: response.headers)
56
+ else
57
+ Configuration.new(target, value: {}, metadata: response.headers)
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,71 @@
1
+ require_relative "page"
2
+
3
+ module Async
4
+ module Firefly
5
+ class Currency < Representation
6
+ def created_at = self.attributes[:created_at]
7
+
8
+ def updated_at = self.attributes[:updated_at]
9
+
10
+ def enabled = self.attributes[:enabled]
11
+
12
+ def primary = self.attributes[:primary]
13
+
14
+ def code = self.attributes[:code]
15
+
16
+ def name = self.attributes[:name]
17
+
18
+ def symbol = self.attributes[:symbol]
19
+
20
+ def decimal_places = self.attributes[:decimal_places]
21
+
22
+ def enabled? = self.enabled == true
23
+
24
+ def primary? = self.primary == true
25
+
26
+ def accounts(**parameters) = Collection.for(@resource, "accounts", NestedAccountPage, **parameters)
27
+
28
+ def available_budgets(**parameters) = Collection.for(@resource, "available-budgets", NestedAvailableBudgetPage, **parameters)
29
+
30
+ def bills(**parameters) = Collection.for(@resource, "bills", NestedBillPage, **parameters)
31
+
32
+ def budget_limits(**parameters) = NestedBudgetLimitPage.new(@resource.with(path: "budget-limits", parameters: parameters))
33
+
34
+ def recurrences(**parameters) = Collection.for(@resource, "recurrences", NestedRecurrencePage, **parameters)
35
+
36
+ def rules(**parameters) = NestedRulePage.new(@resource.with(path: "rules", parameters: parameters))
37
+
38
+ def transactions(**parameters) = Collection.for(@resource, "transactions", NestedTransactionPage, **parameters)
39
+
40
+ def exchange_rates(**parameters) = Collection.for(@resource, "cer", NestedExchangeRatePage, **parameters)
41
+
42
+ def enable = self.submit(Currency, @resource.with(path: "enable"), method: :post, identify: nil)
43
+
44
+ def disable = self.submit(Currency, @resource.with(path: "disable"), method: :post, identify: nil)
45
+
46
+ def make_primary = self.submit(Currency, @resource.with(path: "primary"), method: :post, identify: nil)
47
+
48
+ def update(payload) = self.submit(Currency, @resource, payload, method: :put)
49
+
50
+ def delete = self.discard(@resource)
51
+ end
52
+
53
+ class CurrencyPage < Page
54
+ MEMBER = Currency
55
+
56
+ def member_path(record) = self.identifier(record, :attributes, :code)
57
+ end
58
+
59
+ module Currencies
60
+ def currencies(**parameters) = Collection.for(self, "v1/currencies", CurrencyPage, **parameters)
61
+
62
+ def currency(code) = Currency.new(self.with(path: "v1/currencies/" + Firefly.escape(code)))
63
+
64
+ def create_currency(payload) = self.submit(Currency, self.with(path: "v1/currencies"), payload, identify: :code)
65
+
66
+ def primary_currency = Currency.new(self.with(path: "v1/currencies/primary"))
67
+
68
+ def default_currency = Currency.new(self.with(path: "v1/currencies/default"))
69
+ end
70
+ end
71
+ end