freeagentrb 0.1.4 → 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.
- checksums.yaml +4 -4
- data/.env.example +3 -1
- data/CHANGELOG.md +65 -0
- data/Gemfile +3 -3
- data/Gemfile.lock +78 -61
- data/README.md +747 -3
- data/bin/console +2 -0
- data/bin/fixtures +148 -0
- data/freeagentrb.gemspec +4 -5
- data/lib/free_agent/client.rb +164 -4
- data/lib/free_agent/error_generator.rb +4 -3
- data/lib/free_agent/oauth.rb +48 -0
- data/lib/free_agent/object.rb +113 -17
- data/lib/free_agent/objects/account_lock.rb +4 -0
- data/lib/free_agent/objects/account_manager.rb +4 -0
- data/lib/free_agent/objects/balance_sheet.rb +4 -0
- data/lib/free_agent/objects/bank_feed.rb +4 -0
- data/lib/free_agent/objects/bank_transaction.rb +7 -12
- data/lib/free_agent/objects/bill.rb +1 -0
- data/lib/free_agent/objects/capital_asset.rb +4 -0
- data/lib/free_agent/objects/capital_asset_type.rb +4 -0
- data/lib/free_agent/objects/cashflow.rb +5 -0
- data/lib/free_agent/objects/cis_band.rb +4 -0
- data/lib/free_agent/objects/cis_settings.rb +4 -0
- data/lib/free_agent/objects/corporation_tax_return.rb +5 -0
- data/lib/free_agent/objects/credit_note.rb +1 -0
- data/lib/free_agent/objects/credit_note_reconciliation.rb +5 -0
- data/lib/free_agent/objects/estimate.rb +1 -0
- data/lib/free_agent/objects/expense.rb +5 -0
- data/lib/free_agent/objects/final_accounts_report.rb +4 -0
- data/lib/free_agent/objects/hire_purchase.rb +4 -0
- data/lib/free_agent/objects/invoice.rb +1 -9
- data/lib/free_agent/objects/journal_set.rb +4 -0
- data/lib/free_agent/objects/note.rb +4 -0
- data/lib/free_agent/objects/payroll_period.rb +4 -0
- data/lib/free_agent/objects/payroll_profile.rb +5 -0
- data/lib/free_agent/objects/practice.rb +4 -0
- data/lib/free_agent/objects/practice_client.rb +4 -0
- data/lib/free_agent/objects/price_list_item.rb +5 -0
- data/lib/free_agent/objects/profit_and_loss.rb +6 -0
- data/lib/free_agent/objects/property.rb +4 -0
- data/lib/free_agent/objects/recurring_invoice.rb +5 -0
- data/lib/free_agent/objects/sales_tax_period.rb +4 -0
- data/lib/free_agent/objects/self_assessment_return.rb +4 -0
- data/lib/free_agent/objects/stock_item.rb +5 -0
- data/lib/free_agent/objects/tax_timeline_item.rb +5 -0
- data/lib/free_agent/objects/timeline_item.rb +5 -0
- data/lib/free_agent/objects/transaction.rb +5 -0
- data/lib/free_agent/objects/trial_balance_item.rb +5 -0
- data/lib/free_agent/objects/vat_return.rb +4 -0
- data/lib/free_agent/rate_limiter.rb +67 -0
- data/lib/free_agent/resource.rb +6 -2
- data/lib/free_agent/resources/account_locks.rb +24 -0
- data/lib/free_agent/resources/account_managers.rb +19 -0
- data/lib/free_agent/resources/balance_sheet.rb +15 -0
- data/lib/free_agent/resources/bank_accounts.rb +5 -7
- data/lib/free_agent/resources/bank_feeds.rb +13 -0
- data/lib/free_agent/resources/bank_transaction_explanations.rb +41 -1
- data/lib/free_agent/resources/bank_transactions.rb +1 -1
- data/lib/free_agent/resources/capital_asset_types.rb +28 -0
- data/lib/free_agent/resources/capital_assets.rb +14 -0
- data/lib/free_agent/resources/cashflow.rb +8 -0
- data/lib/free_agent/resources/categories.rb +33 -0
- data/lib/free_agent/resources/cis_bands.rb +8 -0
- data/lib/free_agent/resources/cis_settings.rb +15 -0
- data/lib/free_agent/resources/clients.rb +8 -0
- data/lib/free_agent/resources/company.rb +12 -0
- data/lib/free_agent/resources/contacts.rb +2 -2
- data/lib/free_agent/resources/corporation_tax_returns.rb +34 -0
- data/lib/free_agent/resources/credit_note_reconciliations.rb +31 -0
- data/lib/free_agent/resources/credit_notes.rb +0 -10
- data/lib/free_agent/resources/email_addresses.rb +9 -0
- data/lib/free_agent/resources/estimate_items.rb +3 -4
- data/lib/free_agent/resources/estimates.rb +30 -3
- data/lib/free_agent/resources/expenses.rb +45 -0
- data/lib/free_agent/resources/final_accounts_reports.rb +24 -0
- data/lib/free_agent/resources/hire_purchases.rb +13 -0
- data/lib/free_agent/resources/invoices.rb +22 -0
- data/lib/free_agent/resources/journal_sets.rb +37 -0
- data/lib/free_agent/resources/notes.rb +37 -0
- data/lib/free_agent/resources/payroll.rb +32 -0
- data/lib/free_agent/resources/payroll_profiles.rb +9 -0
- data/lib/free_agent/resources/practice.rb +10 -0
- data/lib/free_agent/resources/price_list_items.rb +30 -0
- data/lib/free_agent/resources/profit_and_loss.rb +10 -0
- data/lib/free_agent/resources/projects.rb +2 -2
- data/lib/free_agent/resources/properties.rb +29 -0
- data/lib/free_agent/resources/recurring_invoices.rb +23 -0
- data/lib/free_agent/resources/sales_tax_periods.rb +37 -0
- data/lib/free_agent/resources/self_assessment_returns.rb +36 -0
- data/lib/free_agent/resources/stock_items.rb +13 -0
- data/lib/free_agent/resources/tasks.rb +5 -4
- data/lib/free_agent/resources/timeslips.rb +20 -3
- data/lib/free_agent/resources/transactions.rb +15 -0
- data/lib/free_agent/resources/trial_balance.rb +13 -0
- data/lib/free_agent/resources/users.rb +3 -3
- data/lib/free_agent/resources/vat_returns.rb +35 -0
- data/lib/free_agent/version.rb +1 -1
- data/lib/free_agent.rb +67 -0
- metadata +83 -24
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module FreeAgent
|
|
2
|
+
class CreditNoteReconciliationsResource < Resource
|
|
3
|
+
def list(**params)
|
|
4
|
+
response = get_request("credit_note_reconciliations", params: params)
|
|
5
|
+
Collection.from_response(response, type: CreditNoteReconciliation)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def retrieve(id:)
|
|
9
|
+
response = get_request("credit_note_reconciliations/#{id}")
|
|
10
|
+
# The docs show this under a plural root, unlike create and update
|
|
11
|
+
CreditNoteReconciliation.new(response.body["credit_note_reconciliation"] || response.body["credit_note_reconciliations"])
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def create(credit_note:, invoice:, gross_value:, **params)
|
|
15
|
+
attributes = { credit_note: credit_note, invoice: invoice, gross_value: gross_value }
|
|
16
|
+
|
|
17
|
+
response = post_request("credit_note_reconciliations", body: { credit_note_reconciliation: attributes.merge(params) })
|
|
18
|
+
CreditNoteReconciliation.new(response.body["credit_note_reconciliation"]) if response.success?
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def update(id:, **params)
|
|
22
|
+
response = put_request("credit_note_reconciliations/#{id}", body: { credit_note_reconciliation: params })
|
|
23
|
+
CreditNoteReconciliation.new(response.body["credit_note_reconciliation"]) if response.success?
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def delete(id:)
|
|
27
|
+
response = delete_request("credit_note_reconciliations/#{id}")
|
|
28
|
+
response.success?
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -33,11 +33,6 @@ module FreeAgent
|
|
|
33
33
|
CreditNote.new(response.body["credit_note"]) if response.success?
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
# def duplicate(id:)
|
|
37
|
-
# response = post_request("invoices/#{id}/duplicate", body: {})
|
|
38
|
-
# Invoice.new(response.body["invoice"]) if response.success?
|
|
39
|
-
# end
|
|
40
|
-
|
|
41
36
|
def update(id:, **params)
|
|
42
37
|
response = put_request("credit_notes/#{id}", body: { credit_note: params })
|
|
43
38
|
CreditNote.new(response.body["credit_note"]) if response.success?
|
|
@@ -63,10 +58,5 @@ module FreeAgent
|
|
|
63
58
|
response = put_request("credit_notes/#{id}/transitions/mark_as_draft", body: {})
|
|
64
59
|
response.success?
|
|
65
60
|
end
|
|
66
|
-
|
|
67
|
-
def mark_as_cancelled(id:)
|
|
68
|
-
response = put_request("credit_notes/#{id}/transitions/mark_as_cancelled", body: {})
|
|
69
|
-
response.success?
|
|
70
|
-
end
|
|
71
61
|
end
|
|
72
62
|
end
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
module FreeAgent
|
|
2
2
|
class EstimateItemsResource < Resource
|
|
3
3
|
def create(estimate:, **params)
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
response = post_request("estimate_items", body: attributes.merge(params))
|
|
4
|
+
# The payload has two root elements: the estimate's URL, and the item
|
|
5
|
+
response = post_request("estimate_items", body: { estimate: estimate, estimate_item: params })
|
|
7
6
|
EstimateItem.new(response.body["estimate_item"]) if response.success?
|
|
8
7
|
end
|
|
9
8
|
|
|
10
9
|
def update(id:, **params)
|
|
11
|
-
response = put_request("estimate_items/#{id}", body: params)
|
|
10
|
+
response = put_request("estimate_items/#{id}", body: { estimate_item: params })
|
|
12
11
|
EstimateItem.new(response.body["estimate_item"]) if response.success?
|
|
13
12
|
end
|
|
14
13
|
|
|
@@ -38,8 +38,14 @@ module FreeAgent
|
|
|
38
38
|
Estimate.new(response.body["estimate"]) if response.success?
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
+
# The copy is a draft dated today, with the next reference in the sequence
|
|
42
|
+
def duplicate(id:)
|
|
43
|
+
response = post_request("estimates/#{id}/duplicate", body: {})
|
|
44
|
+
Estimate.new(response.body["estimate"]) if response.success?
|
|
45
|
+
end
|
|
46
|
+
|
|
41
47
|
def update(id:, **params)
|
|
42
|
-
response = put_request("estimates/#{id}", body: params)
|
|
48
|
+
response = put_request("estimates/#{id}", body: { estimate: params })
|
|
43
49
|
Estimate.new(response.body["estimate"]) if response.success?
|
|
44
50
|
end
|
|
45
51
|
|
|
@@ -55,12 +61,12 @@ module FreeAgent
|
|
|
55
61
|
end
|
|
56
62
|
|
|
57
63
|
def mark_as_sent(id:)
|
|
58
|
-
response = put_request("
|
|
64
|
+
response = put_request("estimates/#{id}/transitions/mark_as_sent", body: {})
|
|
59
65
|
response.success?
|
|
60
66
|
end
|
|
61
67
|
|
|
62
68
|
def mark_as_draft(id:)
|
|
63
|
-
response = put_request("
|
|
69
|
+
response = put_request("estimates/#{id}/transitions/mark_as_draft", body: {})
|
|
64
70
|
response.success?
|
|
65
71
|
end
|
|
66
72
|
|
|
@@ -73,5 +79,26 @@ module FreeAgent
|
|
|
73
79
|
response = put_request("estimates/#{id}/transitions/mark_as_rejected", body: {})
|
|
74
80
|
response.success?
|
|
75
81
|
end
|
|
82
|
+
|
|
83
|
+
def convert_to_invoice(id:)
|
|
84
|
+
response = put_request("estimates/#{id}/transitions/convert_to_invoice", body: {})
|
|
85
|
+
response.success?
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# The text added to the bottom of every new estimate
|
|
89
|
+
def default_additional_text
|
|
90
|
+
response = get_request("estimates/default_additional_text")
|
|
91
|
+
response.body["default_additional_text"]
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def update_default_additional_text(text)
|
|
95
|
+
response = put_request("estimates/default_additional_text", body: { default_additional_text: text })
|
|
96
|
+
response.success?
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def delete_default_additional_text
|
|
100
|
+
response = delete_request("estimates/default_additional_text")
|
|
101
|
+
response.success?
|
|
102
|
+
end
|
|
76
103
|
end
|
|
77
104
|
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
module FreeAgent
|
|
2
|
+
class ExpensesResource < Resource
|
|
3
|
+
def list(**params)
|
|
4
|
+
response = get_request("expenses", params: params)
|
|
5
|
+
Collection.from_response(response, type: Expense)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def list_for_user(user:, **params)
|
|
9
|
+
response = get_request("expenses?user=#{user}", params: params)
|
|
10
|
+
Collection.from_response(response, type: Expense)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def list_for_project(project:, **params)
|
|
14
|
+
response = get_request("expenses?project=#{project}", params: params)
|
|
15
|
+
Collection.from_response(response, type: Expense)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def retrieve(id:)
|
|
19
|
+
response = get_request("expenses/#{id}")
|
|
20
|
+
Expense.new(response.body["expense"])
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def create(user:, category:, dated_on:, **params)
|
|
24
|
+
attributes = { user: user, category: category, dated_on: dated_on }
|
|
25
|
+
|
|
26
|
+
response = post_request("expenses", body: { expense: attributes.merge(params) })
|
|
27
|
+
Expense.new(response.body["expense"]) if response.success?
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def update(id:, **params)
|
|
31
|
+
response = put_request("expenses/#{id}", body: { expense: params })
|
|
32
|
+
Expense.new(response.body["expense"]) if response.success?
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def delete(id:)
|
|
36
|
+
response = delete_request("expenses/#{id}")
|
|
37
|
+
response.success?
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def mileage_settings
|
|
41
|
+
response = get_request("expenses/mileage_settings")
|
|
42
|
+
Object.new(response.body["mileage_settings"])
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module FreeAgent
|
|
2
|
+
class FinalAccountsReportsResource < Resource
|
|
3
|
+
def list(**params)
|
|
4
|
+
response = get_request("final_accounts_reports", params: params)
|
|
5
|
+
Collection.from_response(response, type: FinalAccountsReport)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# Reports are identified by the date their accounting period ends
|
|
9
|
+
def retrieve(period_ends_on:)
|
|
10
|
+
response = get_request("final_accounts_reports/#{period_ends_on}")
|
|
11
|
+
FinalAccountsReport.new(response.body["final_accounts_report"])
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def mark_as_filed(period_ends_on:, **params)
|
|
15
|
+
response = put_request("final_accounts_reports/#{period_ends_on}/mark_as_filed", body: params)
|
|
16
|
+
response.success?
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def mark_as_unfiled(period_ends_on:)
|
|
20
|
+
response = put_request("final_accounts_reports/#{period_ends_on}/mark_as_unfiled", body: {})
|
|
21
|
+
response.success?
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module FreeAgent
|
|
2
|
+
class HirePurchasesResource < Resource
|
|
3
|
+
def list(**params)
|
|
4
|
+
response = get_request("hire_purchases", params: params)
|
|
5
|
+
Collection.from_response(response, type: HirePurchase)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def retrieve(id:)
|
|
9
|
+
response = get_request("hire_purchases/#{id}")
|
|
10
|
+
HirePurchase.new(response.body["hire_purchase"])
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -79,6 +79,28 @@ module FreeAgent
|
|
|
79
79
|
response.success?
|
|
80
80
|
end
|
|
81
81
|
|
|
82
|
+
# Recent activity across all invoices, e.g. overdue and open invoices
|
|
83
|
+
def timeline(**params)
|
|
84
|
+
response = get_request("invoices/timeline", params: params)
|
|
85
|
+
Collection.from_response(response, type: TimelineItem)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# The text added to the bottom of every new invoice
|
|
89
|
+
def default_additional_text
|
|
90
|
+
response = get_request("invoices/default_additional_text")
|
|
91
|
+
response.body["default_additional_text"]
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def update_default_additional_text(text)
|
|
95
|
+
response = put_request("invoices/default_additional_text", body: { default_additional_text: text })
|
|
96
|
+
response.success?
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def delete_default_additional_text
|
|
100
|
+
response = delete_request("invoices/default_additional_text")
|
|
101
|
+
response.success?
|
|
102
|
+
end
|
|
103
|
+
|
|
82
104
|
def direct_debit(id:)
|
|
83
105
|
response = post_request("invoices/#{id}/direct_debit", body: {})
|
|
84
106
|
response.success?
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module FreeAgent
|
|
2
|
+
class JournalSetsResource < Resource
|
|
3
|
+
def list(**params)
|
|
4
|
+
response = get_request("journal_sets", params: params)
|
|
5
|
+
Collection.from_response(response, type: JournalSet)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# A single journal set, with the opening balances for bank accounts and
|
|
9
|
+
# stock items alongside its journal entries
|
|
10
|
+
def opening_balances
|
|
11
|
+
response = get_request("journal_sets/opening_balances")
|
|
12
|
+
JournalSet.new(response.body["journal_set"])
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def retrieve(id:)
|
|
16
|
+
response = get_request("journal_sets/#{id}")
|
|
17
|
+
JournalSet.new(response.body["journal_set"])
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def create(dated_on:, description:, journal_entries:, **params)
|
|
21
|
+
attributes = { dated_on: dated_on, description: description, journal_entries: journal_entries }
|
|
22
|
+
|
|
23
|
+
response = post_request("journal_sets", body: { journal_set: attributes.merge(params) })
|
|
24
|
+
JournalSet.new(response.body["journal_set"]) if response.success?
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def update(id:, **params)
|
|
28
|
+
response = put_request("journal_sets/#{id}", body: { journal_set: params })
|
|
29
|
+
JournalSet.new(response.body["journal_set"]) if response.success?
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def delete(id:)
|
|
33
|
+
response = delete_request("journal_sets/#{id}")
|
|
34
|
+
response.success?
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module FreeAgent
|
|
2
|
+
class NotesResource < Resource
|
|
3
|
+
# The parent is sent in the query string rather than the body, so create
|
|
4
|
+
# takes either contact: or project:
|
|
5
|
+
def list_for_contact(contact:, **params)
|
|
6
|
+
response = get_request("notes", params: params.merge(contact: contact))
|
|
7
|
+
Collection.from_response(response, type: Note)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def list_for_project(project:, **params)
|
|
11
|
+
response = get_request("notes", params: params.merge(project: project))
|
|
12
|
+
Collection.from_response(response, type: Note)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def retrieve(id:)
|
|
16
|
+
response = get_request("notes/#{id}")
|
|
17
|
+
Note.new(response.body["note"])
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def create(note:, contact: nil, project: nil, **params)
|
|
21
|
+
query = { contact: contact, project: project }.compact
|
|
22
|
+
|
|
23
|
+
response = post_request("notes?#{URI.encode_www_form(query)}", body: { note: { note: note }.merge(params) })
|
|
24
|
+
Note.new(response.body["note"]) if response.success?
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def update(id:, **params)
|
|
28
|
+
response = put_request("notes/#{id}", body: { note: params })
|
|
29
|
+
Note.new(response.body["note"]) if response.success?
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def delete(id:)
|
|
33
|
+
response = delete_request("notes/#{id}")
|
|
34
|
+
response.success?
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module FreeAgent
|
|
2
|
+
class PayrollResource < Resource
|
|
3
|
+
# Payroll is organised by tax year, then by period within that year
|
|
4
|
+
def list(year:, **params)
|
|
5
|
+
response = get_request("payroll/#{year}", params: params)
|
|
6
|
+
Collection.from_response(response, type: PayrollPeriod)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
# The PAYE payments due to HMRC for a tax year, each identified by its
|
|
10
|
+
# due_on date
|
|
11
|
+
def payments(year:)
|
|
12
|
+
response = get_request("payroll/#{year}")
|
|
13
|
+
response.body["payments"].map { |attributes| FreeAgent::Object.new(attributes) }
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# The period, with its payslips
|
|
17
|
+
def retrieve(year:, period:)
|
|
18
|
+
response = get_request("payroll/#{year}/#{period}")
|
|
19
|
+
PayrollPeriod.new(response.body["period"])
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def mark_payment_as_paid(year:, payment_date:)
|
|
23
|
+
response = put_request("payroll/#{year}/payments/#{payment_date}/mark_as_paid", body: {})
|
|
24
|
+
response.success?
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def mark_payment_as_unpaid(year:, payment_date:)
|
|
28
|
+
response = put_request("payroll/#{year}/payments/#{payment_date}/mark_as_unpaid", body: {})
|
|
29
|
+
response.success?
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
module FreeAgent
|
|
2
|
+
class PayrollProfilesResource < Resource
|
|
3
|
+
# Pass user: to fetch the profiles for a single user
|
|
4
|
+
def list(year:, **params)
|
|
5
|
+
response = get_request("payroll_profiles/#{year}", params: params)
|
|
6
|
+
Collection.from_response(response, type: PayrollProfile)
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module FreeAgent
|
|
2
|
+
class PriceListItemsResource < Resource
|
|
3
|
+
def list(**params)
|
|
4
|
+
response = get_request("price_list_items", params: params)
|
|
5
|
+
Collection.from_response(response, type: PriceListItem)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def retrieve(id:)
|
|
9
|
+
response = get_request("price_list_items/#{id}")
|
|
10
|
+
PriceListItem.new(response.body["price_list_item"])
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def create(code:, quantity:, item_type:, description:, price:, **params)
|
|
14
|
+
attributes = { code: code, quantity: quantity, item_type: item_type, description: description, price: price }
|
|
15
|
+
|
|
16
|
+
response = post_request("price_list_items", body: { price_list_item: attributes.merge(params) })
|
|
17
|
+
PriceListItem.new(response.body["price_list_item"]) if response.success?
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def update(id:, **params)
|
|
21
|
+
response = put_request("price_list_items/#{id}", body: { price_list_item: params })
|
|
22
|
+
PriceListItem.new(response.body["price_list_item"]) if response.success?
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def delete(id:)
|
|
26
|
+
response = delete_request("price_list_items/#{id}")
|
|
27
|
+
response.success?
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
module FreeAgent
|
|
2
|
+
class ProfitAndLossResource < Resource
|
|
3
|
+
# Defaults to the current accounting year to date. Pass from_date and
|
|
4
|
+
# to_date, or accounting_period (e.g. "2022/23"), for another period.
|
|
5
|
+
def summary(**params)
|
|
6
|
+
response = get_request("accounting/profit_and_loss/summary", params: params)
|
|
7
|
+
ProfitAndLoss.new(response.body["profit_and_loss_summary"])
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -18,12 +18,12 @@ module FreeAgent
|
|
|
18
18
|
def create(contact:, name:, status:, currency:, budget_units:, **params)
|
|
19
19
|
attributes = { contact: contact, name: name, status: status, currency: currency, budget_units: budget_units }
|
|
20
20
|
|
|
21
|
-
response = post_request("projects", body: attributes.merge(params))
|
|
21
|
+
response = post_request("projects", body: { project: attributes.merge(params) })
|
|
22
22
|
Project.new(response.body["project"]) if response.success?
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def update(id:, **params)
|
|
26
|
-
response = put_request("projects/#{id}", body: params)
|
|
26
|
+
response = put_request("projects/#{id}", body: { project: params })
|
|
27
27
|
Project.new(response.body["project"]) if response.success?
|
|
28
28
|
end
|
|
29
29
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module FreeAgent
|
|
2
|
+
class PropertiesResource < Resource
|
|
3
|
+
# UkUnincorporatedLandlord companies only
|
|
4
|
+
def list(**params)
|
|
5
|
+
response = get_request("properties", params: params)
|
|
6
|
+
Collection.from_response(response, type: Property)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def retrieve(id:)
|
|
10
|
+
response = get_request("properties/#{id}")
|
|
11
|
+
Property.new(response.body["property"])
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def create(**params)
|
|
15
|
+
response = post_request("properties", body: { property: params })
|
|
16
|
+
Property.new(response.body["property"]) if response.success?
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def update(id:, **params)
|
|
20
|
+
response = put_request("properties/#{id}", body: { property: params })
|
|
21
|
+
Property.new(response.body["property"]) if response.success?
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def delete(id:)
|
|
25
|
+
response = delete_request("properties/#{id}")
|
|
26
|
+
response.success?
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module FreeAgent
|
|
2
|
+
class RecurringInvoicesResource < Resource
|
|
3
|
+
def list(**params)
|
|
4
|
+
response = get_request("recurring_invoices", params: params)
|
|
5
|
+
Collection.from_response(response, type: RecurringInvoice)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def list_for_contact(contact:, **params)
|
|
9
|
+
response = get_request("recurring_invoices?contact=#{contact}", params: params)
|
|
10
|
+
Collection.from_response(response, type: RecurringInvoice)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def list_for_project(project:, **params)
|
|
14
|
+
response = get_request("recurring_invoices?project=#{project}", params: params)
|
|
15
|
+
Collection.from_response(response, type: RecurringInvoice)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def retrieve(id:)
|
|
19
|
+
response = get_request("recurring_invoices/#{id}")
|
|
20
|
+
RecurringInvoice.new(response.body["recurring_invoice"])
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module FreeAgent
|
|
2
|
+
class SalesTaxPeriodsResource < Resource
|
|
3
|
+
# US and Universal companies only
|
|
4
|
+
def list(**params)
|
|
5
|
+
response = get_request("sales_tax_periods", params: params)
|
|
6
|
+
Collection.from_response(response, type: SalesTaxPeriod)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def retrieve(id:)
|
|
10
|
+
response = get_request("sales_tax_periods/#{id}")
|
|
11
|
+
SalesTaxPeriod.new(response.body["sales_tax_period"])
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def create(sales_tax_name:, sales_tax_registration_status:, sales_tax_rate_1:, sales_tax_is_value_added:, effective_date:, **params)
|
|
15
|
+
attributes = {
|
|
16
|
+
sales_tax_name: sales_tax_name,
|
|
17
|
+
sales_tax_registration_status: sales_tax_registration_status,
|
|
18
|
+
sales_tax_rate_1: sales_tax_rate_1,
|
|
19
|
+
sales_tax_is_value_added: sales_tax_is_value_added,
|
|
20
|
+
effective_date: effective_date
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
response = post_request("sales_tax_periods", body: { sales_tax_period: attributes.merge(params) })
|
|
24
|
+
SalesTaxPeriod.new(response.body["sales_tax_period"]) if response.success?
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def update(id:, **params)
|
|
28
|
+
response = put_request("sales_tax_periods/#{id}", body: { sales_tax_period: params })
|
|
29
|
+
SalesTaxPeriod.new(response.body["sales_tax_period"]) if response.success?
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def delete(id:)
|
|
33
|
+
response = delete_request("sales_tax_periods/#{id}")
|
|
34
|
+
response.success?
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module FreeAgent
|
|
2
|
+
class SelfAssessmentReturnsResource < Resource
|
|
3
|
+
# Nested under a user, and identified by the date the period ends.
|
|
4
|
+
# FreeAgent's docs call these Income Tax Returns.
|
|
5
|
+
def list(user_id:, **params)
|
|
6
|
+
response = get_request("users/#{user_id}/self_assessment_returns", params: params)
|
|
7
|
+
Collection.from_response(response, type: SelfAssessmentReturn)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def retrieve(user_id:, period_ends_on:)
|
|
11
|
+
response = get_request("users/#{user_id}/self_assessment_returns/#{period_ends_on}")
|
|
12
|
+
SelfAssessmentReturn.new(response.body["self_assessment_return"])
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def mark_as_filed(user_id:, period_ends_on:, **params)
|
|
16
|
+
response = put_request("users/#{user_id}/self_assessment_returns/#{period_ends_on}/mark_as_filed", body: params)
|
|
17
|
+
response.success?
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def mark_as_unfiled(user_id:, period_ends_on:)
|
|
21
|
+
response = put_request("users/#{user_id}/self_assessment_returns/#{period_ends_on}/mark_as_unfiled", body: {})
|
|
22
|
+
response.success?
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# A return can have several payments, each identified by its due_on date
|
|
26
|
+
def mark_payment_as_paid(user_id:, period_ends_on:, payment_date:)
|
|
27
|
+
response = put_request("users/#{user_id}/self_assessment_returns/#{period_ends_on}/payments/#{payment_date}/mark_as_paid", body: {})
|
|
28
|
+
response.success?
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def mark_payment_as_unpaid(user_id:, period_ends_on:, payment_date:)
|
|
32
|
+
response = put_request("users/#{user_id}/self_assessment_returns/#{period_ends_on}/payments/#{payment_date}/mark_as_unpaid", body: {})
|
|
33
|
+
response.success?
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module FreeAgent
|
|
2
|
+
class StockItemsResource < Resource
|
|
3
|
+
def list(**params)
|
|
4
|
+
response = get_request("stock_items", params: params)
|
|
5
|
+
Collection.from_response(response, type: StockItem)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def retrieve(id:)
|
|
9
|
+
response = get_request("stock_items/#{id}")
|
|
10
|
+
StockItem.new(response.body["stock_item"])
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -15,15 +15,16 @@ module FreeAgent
|
|
|
15
15
|
Task.new(response.body["task"])
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
def create(project:, name:,
|
|
19
|
-
attributes = {
|
|
18
|
+
def create(project:, name:, **params)
|
|
19
|
+
attributes = { name: name }
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
# The project is passed in the query string rather than the payload
|
|
22
|
+
response = post_request("tasks?project=#{project}", body: { task: attributes.merge(params) })
|
|
22
23
|
Task.new(response.body["task"]) if response.success?
|
|
23
24
|
end
|
|
24
25
|
|
|
25
26
|
def update(id:, **params)
|
|
26
|
-
response = put_request("tasks/#{id}", body: params)
|
|
27
|
+
response = put_request("tasks/#{id}", body: { task: params })
|
|
27
28
|
Task.new(response.body["task"]) if response.success?
|
|
28
29
|
end
|
|
29
30
|
|
|
@@ -25,15 +25,22 @@ module FreeAgent
|
|
|
25
25
|
Timeslip.new(response.body["timeslip"])
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
def create(task:, user:, project:, dated_on:, hours:,
|
|
28
|
+
def create(task:, user:, project:, dated_on:, hours:, **params)
|
|
29
29
|
attributes = { task: task, user: user, project: project, dated_on: dated_on, hours: hours }
|
|
30
30
|
|
|
31
|
-
response = post_request("timeslips", body: attributes.merge(params))
|
|
31
|
+
response = post_request("timeslips", body: { timeslip: attributes.merge(params) })
|
|
32
32
|
Timeslip.new(response.body["timeslip"]) if response.success?
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
+
# Creates several timeslips in one request. Each is a hash of the same
|
|
36
|
+
# attributes create takes.
|
|
37
|
+
def create_many(timeslips:)
|
|
38
|
+
response = post_request("timeslips", body: { timeslips: timeslips })
|
|
39
|
+
response.success?
|
|
40
|
+
end
|
|
41
|
+
|
|
35
42
|
def update(id:, **params)
|
|
36
|
-
response = put_request("timeslips/#{id}", body: params)
|
|
43
|
+
response = put_request("timeslips/#{id}", body: { timeslip: params })
|
|
37
44
|
Timeslip.new(response.body["timeslip"]) if response.success?
|
|
38
45
|
end
|
|
39
46
|
|
|
@@ -41,5 +48,15 @@ module FreeAgent
|
|
|
41
48
|
response = delete_request("timeslips/#{id}")
|
|
42
49
|
response.success?
|
|
43
50
|
end
|
|
51
|
+
|
|
52
|
+
def start_timer(id:)
|
|
53
|
+
response = post_request("timeslips/#{id}/timer", body: {})
|
|
54
|
+
Timeslip.new(response.body["timeslip"]) if response.success?
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def stop_timer(id:)
|
|
58
|
+
response = delete_request("timeslips/#{id}/timer")
|
|
59
|
+
response.success?
|
|
60
|
+
end
|
|
44
61
|
end
|
|
45
62
|
end
|