freeagentrb 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.env.example +1 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +51 -0
- data/LICENSE.txt +21 -0
- data/README.md +34 -0
- data/Rakefile +4 -0
- data/bin/console +22 -0
- data/bin/setup +8 -0
- data/freeagentrb.gemspec +34 -0
- data/lib/free_agent/client.rb +100 -0
- data/lib/free_agent/collection.rb +27 -0
- data/lib/free_agent/error.rb +4 -0
- data/lib/free_agent/object.rb +25 -0
- data/lib/free_agent/objects/attachment.rb +4 -0
- data/lib/free_agent/objects/bank_account.rb +4 -0
- data/lib/free_agent/objects/bank_transaction.rb +4 -0
- data/lib/free_agent/objects/bank_transaction_explanation.rb +4 -0
- data/lib/free_agent/objects/bill.rb +4 -0
- data/lib/free_agent/objects/company.rb +4 -0
- data/lib/free_agent/objects/contact.rb +4 -0
- data/lib/free_agent/objects/credit_note.rb +4 -0
- data/lib/free_agent/objects/estimate.rb +4 -0
- data/lib/free_agent/objects/estimate_item.rb +4 -0
- data/lib/free_agent/objects/invoice.rb +4 -0
- data/lib/free_agent/objects/project.rb +4 -0
- data/lib/free_agent/objects/task.rb +4 -0
- data/lib/free_agent/objects/timeslip.rb +4 -0
- data/lib/free_agent/objects/user.rb +4 -0
- data/lib/free_agent/resource.rb +60 -0
- data/lib/free_agent/resources/attachments.rb +15 -0
- data/lib/free_agent/resources/bank_accounts.rb +33 -0
- data/lib/free_agent/resources/bank_transaction_explanations.rb +29 -0
- data/lib/free_agent/resources/bank_transactions.rb +37 -0
- data/lib/free_agent/resources/bills.rb +42 -0
- data/lib/free_agent/resources/company.rb +10 -0
- data/lib/free_agent/resources/contacts.rb +32 -0
- data/lib/free_agent/resources/credit_notes.rb +74 -0
- data/lib/free_agent/resources/estimate_items.rb +22 -0
- data/lib/free_agent/resources/estimates.rb +79 -0
- data/lib/free_agent/resources/invoices.rb +89 -0
- data/lib/free_agent/resources/projects.rb +37 -0
- data/lib/free_agent/resources/tasks.rb +37 -0
- data/lib/free_agent/resources/timeslips.rb +47 -0
- data/lib/free_agent/resources/users.rb +42 -0
- data/lib/free_agent/version.rb +3 -0
- data/lib/free_agent.rb +48 -0
- data/lib/freeagentrb.rb +1 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b570455fe0bf3cdc90330ad013a8f878f3c48405116d2033932ebc2db86bbb0f
|
4
|
+
data.tar.gz: ca6b9f1bc67606328cddabfb1261beb77ec482c054214f58f0635041119c164e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8d6349663051511f41b43b2312e01529549a13c5a36bbee06855ce3e1f10abe6c9eaff4002e847f1e3b706d9164bc7ba85278e23f82ac0d7ece82d4c81d858b6
|
7
|
+
data.tar.gz: b03dd9e7852da63914f12ad3a6b0e93ebd22d2dff80f865b8810739ecc4cb6df2900cb4e8a0ae7e6563f9ac7a2c93fc7c140e6ae2622f4eee5db867492a0521f
|
data/.env.example
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ACCESS_TOKEN=
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
freeagentrb (0.1.0)
|
5
|
+
faraday (~> 1.7)
|
6
|
+
faraday-multipart (~> 1.0)
|
7
|
+
faraday_middleware (~> 1.1)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
dotenv (2.7.6)
|
13
|
+
faraday (1.9.3)
|
14
|
+
faraday-em_http (~> 1.0)
|
15
|
+
faraday-em_synchrony (~> 1.0)
|
16
|
+
faraday-excon (~> 1.1)
|
17
|
+
faraday-httpclient (~> 1.0)
|
18
|
+
faraday-multipart (~> 1.0)
|
19
|
+
faraday-net_http (~> 1.0)
|
20
|
+
faraday-net_http_persistent (~> 1.0)
|
21
|
+
faraday-patron (~> 1.0)
|
22
|
+
faraday-rack (~> 1.0)
|
23
|
+
faraday-retry (~> 1.0)
|
24
|
+
ruby2_keywords (>= 0.0.4)
|
25
|
+
faraday-em_http (1.0.0)
|
26
|
+
faraday-em_synchrony (1.0.0)
|
27
|
+
faraday-excon (1.1.0)
|
28
|
+
faraday-httpclient (1.0.1)
|
29
|
+
faraday-multipart (1.0.3)
|
30
|
+
multipart-post (>= 1.2, < 3)
|
31
|
+
faraday-net_http (1.0.1)
|
32
|
+
faraday-net_http_persistent (1.2.0)
|
33
|
+
faraday-patron (1.0.0)
|
34
|
+
faraday-rack (1.0.0)
|
35
|
+
faraday-retry (1.0.3)
|
36
|
+
faraday_middleware (1.2.0)
|
37
|
+
faraday (~> 1.0)
|
38
|
+
multipart-post (2.1.1)
|
39
|
+
rake (13.0.6)
|
40
|
+
ruby2_keywords (0.0.5)
|
41
|
+
|
42
|
+
PLATFORMS
|
43
|
+
x86_64-linux
|
44
|
+
|
45
|
+
DEPENDENCIES
|
46
|
+
dotenv
|
47
|
+
freeagentrb!
|
48
|
+
rake (~> 13.0)
|
49
|
+
|
50
|
+
BUNDLED WITH
|
51
|
+
2.2.33
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Dean Perry
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# FreeAgentRB
|
2
|
+
|
3
|
+
**This library is a work in progress**
|
4
|
+
|
5
|
+
FreeAgentRB is a Ruby library for interacting with the FreeAgent v2 API.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem "freeagentrb"
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
### Set Client Details
|
18
|
+
|
19
|
+
Firstly you'll need to set an Access Token, which would be created from OAuth.
|
20
|
+
See [this page](https://dev.freeagent.com/docs/quick_start) for more info.
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
@client = FreeAgent::Client.new(access_token: "", sandbox: true)
|
24
|
+
```
|
25
|
+
|
26
|
+
### Bank Accounts
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
@client.bank_accounts.list
|
30
|
+
@client.bank_accounts.list(view: "paypal_accounts")
|
31
|
+
@client.bank_accounts.retrieve(id: "12345")
|
32
|
+
@client.bank_accounts.create type: "StandardBankAccount", name: "My Account", opening_balance: "10"
|
33
|
+
@client.bank_accounts.update id: "12345", name: "My Other Account"
|
34
|
+
```
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "free_agent"
|
6
|
+
|
7
|
+
# Load environment variables from .env file
|
8
|
+
require 'dotenv/load'
|
9
|
+
|
10
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
11
|
+
# with your gem easier. You can also use a different console, if you like.
|
12
|
+
|
13
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
14
|
+
# require "pry"
|
15
|
+
# Pry.start
|
16
|
+
|
17
|
+
# @access_token = Igdb::AccessToken.new(client_id: ENV["CLIENT_ID"], client_secret: ENV["CLIENT_SECRET"])
|
18
|
+
|
19
|
+
@client = FreeAgent::Client.new(access_token: ENV["ACCESS_TOKEN"], sandbox: true)
|
20
|
+
|
21
|
+
require "irb"
|
22
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/freeagentrb.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/free_agent/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "freeagentrb"
|
7
|
+
spec.version = FreeAgent::VERSION
|
8
|
+
spec.authors = ["Dean Perry"]
|
9
|
+
spec.email = ["dean@deanpcmad.com"]
|
10
|
+
|
11
|
+
spec.summary = "A Ruby library for interacting with the FreeAgent v2 API"
|
12
|
+
spec.homepage = "https://deanpcmad.com"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = ">= 2.6.0"
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
# spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
18
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
24
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
25
|
+
end
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_dependency "faraday", "~> 1.7"
|
32
|
+
spec.add_dependency "faraday_middleware", "~> 1.1"
|
33
|
+
spec.add_dependency "faraday-multipart", "~> 1.0"
|
34
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module FreeAgent
|
2
|
+
class Client
|
3
|
+
BASE_URL = "https://api.freeagent.com/v2"
|
4
|
+
SANDBOX_BASE_URL = "https://api.sandbox.freeagent.com/v2"
|
5
|
+
|
6
|
+
attr_reader :access_token, :sandbox, :adapter
|
7
|
+
|
8
|
+
def initialize(access_token:, sandbox: false, adapter: Faraday.default_adapter, stubs: nil)
|
9
|
+
@access_token = access_token
|
10
|
+
@sandbox = sandbox
|
11
|
+
@adapter = adapter
|
12
|
+
|
13
|
+
# Test stubs for requests
|
14
|
+
@stubs = stubs
|
15
|
+
end
|
16
|
+
|
17
|
+
def company
|
18
|
+
CompanyResource.new(self)
|
19
|
+
end
|
20
|
+
|
21
|
+
def contacts
|
22
|
+
ContactsResource.new(self)
|
23
|
+
end
|
24
|
+
|
25
|
+
def bank_accounts
|
26
|
+
BankAccountsResource.new(self)
|
27
|
+
end
|
28
|
+
|
29
|
+
def bank_transactions
|
30
|
+
BankTransactionsResource.new(self)
|
31
|
+
end
|
32
|
+
|
33
|
+
def bank_transaction_explanations
|
34
|
+
BankTransactionExplanationsResource.new(self)
|
35
|
+
end
|
36
|
+
|
37
|
+
def projects
|
38
|
+
ProjectsResource.new(self)
|
39
|
+
end
|
40
|
+
|
41
|
+
def tasks
|
42
|
+
TasksResource.new(self)
|
43
|
+
end
|
44
|
+
|
45
|
+
def timeslips
|
46
|
+
TimeslipsResource.new(self)
|
47
|
+
end
|
48
|
+
|
49
|
+
def users
|
50
|
+
UsersResource.new(self)
|
51
|
+
end
|
52
|
+
|
53
|
+
def attachments
|
54
|
+
AttachmentsResource.new(self)
|
55
|
+
end
|
56
|
+
|
57
|
+
def invoices
|
58
|
+
InvoicesResource.new(self)
|
59
|
+
end
|
60
|
+
|
61
|
+
def estimates
|
62
|
+
EstimatesResource.new(self)
|
63
|
+
end
|
64
|
+
|
65
|
+
def estimate_items
|
66
|
+
EstimateItemsResource.new(self)
|
67
|
+
end
|
68
|
+
|
69
|
+
def credit_notes
|
70
|
+
CreditNotesResource.new(self)
|
71
|
+
end
|
72
|
+
|
73
|
+
def bills
|
74
|
+
BillsResource.new(self)
|
75
|
+
end
|
76
|
+
|
77
|
+
def connection
|
78
|
+
url = (sandbox == true ? SANDBOX_BASE_URL : BASE_URL)
|
79
|
+
@connection ||= Faraday.new(url) do |conn|
|
80
|
+
conn.request :authorization, :Bearer, access_token
|
81
|
+
conn.request :json
|
82
|
+
|
83
|
+
conn.response :dates
|
84
|
+
conn.response :json, content_type: "application/json"
|
85
|
+
|
86
|
+
conn.adapter adapter, @stubs
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# Uses Faraday Multipart (lostisland/faraday-multipart)
|
91
|
+
def connection_upload
|
92
|
+
url = (sandbox == true ? SANDBOX_BASE_URL : BASE_URL)
|
93
|
+
@connection ||= Faraday.new(url) do |conn|
|
94
|
+
conn.request :authorization, :Bearer, access_token
|
95
|
+
conn.request :multipart
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module FreeAgent
|
2
|
+
class Collection
|
3
|
+
attr_reader :data, :total
|
4
|
+
|
5
|
+
def self.from_response(response, type:, key: nil)
|
6
|
+
body = response.body
|
7
|
+
|
8
|
+
if key.is_a?(String)
|
9
|
+
data = body[key].map { |attrs| type.new(attrs) }
|
10
|
+
else
|
11
|
+
data = body.map { |attrs| type.new(attrs) }
|
12
|
+
end
|
13
|
+
|
14
|
+
total = response.headers["X-total-count"]
|
15
|
+
|
16
|
+
new(
|
17
|
+
data: data,
|
18
|
+
total: total
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(data:, total:)
|
23
|
+
@data = data
|
24
|
+
@total = total
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "ostruct"
|
2
|
+
|
3
|
+
module FreeAgent
|
4
|
+
class Object < OpenStruct
|
5
|
+
def initialize(attributes)
|
6
|
+
super to_ostruct(attributes)
|
7
|
+
|
8
|
+
# The FreeAgent API doesn't send an ID so generate it from the URL
|
9
|
+
if attributes["url"]
|
10
|
+
number = attributes["url"].match(/\d{2,}/)
|
11
|
+
self.id = number[0] unless number.nil?
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_ostruct(obj)
|
16
|
+
if obj.is_a?(Hash)
|
17
|
+
OpenStruct.new(obj.map { |key, val| [key, to_ostruct(val)] }.to_h)
|
18
|
+
elsif obj.is_a?(Array)
|
19
|
+
obj.map { |o| to_ostruct(o) }
|
20
|
+
else # Assumed to be a primitive value
|
21
|
+
obj
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module FreeAgent
|
2
|
+
class Resource
|
3
|
+
attr_reader :client
|
4
|
+
|
5
|
+
def initialize(client)
|
6
|
+
@client = client
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def get_request(url, params: {}, headers: {})
|
12
|
+
handle_response client.connection.get(url, params, headers)
|
13
|
+
end
|
14
|
+
|
15
|
+
def post_request(url, body:, headers: {})
|
16
|
+
handle_response client.connection.post(url, body, headers)
|
17
|
+
end
|
18
|
+
|
19
|
+
def patch_request(url, body:, headers: {})
|
20
|
+
handle_response client.connection.patch(url, body, headers)
|
21
|
+
end
|
22
|
+
|
23
|
+
def put_request(url, body:, headers: {})
|
24
|
+
handle_response client.connection.put(url, body, headers)
|
25
|
+
end
|
26
|
+
|
27
|
+
def delete_request(url, params: {}, headers: {})
|
28
|
+
handle_response client.connection.delete(url, params, headers)
|
29
|
+
end
|
30
|
+
|
31
|
+
def handle_response(response)
|
32
|
+
case response.status
|
33
|
+
when 400
|
34
|
+
raise Error, "Error 400: Your request was malformed. '#{response.body["errors"]["error"]["message"]}'"
|
35
|
+
when 401
|
36
|
+
raise Error, "Error 401: You did not supply valid authentication credentials. '#{response.body["errors"]["error"]["message"]}'"
|
37
|
+
when 403
|
38
|
+
raise Error, "Error 403: You are not allowed to perform that action. '#{response.body["errors"]["error"]["message"]}'"
|
39
|
+
when 404
|
40
|
+
raise Error, "Error 404: No results were found for your request. '#{response.body["errors"]["error"]["message"]}'"
|
41
|
+
when 409
|
42
|
+
raise Error, "Error 409: Your request was a conflict. '#{response.body["errors"]["error"]["message"]}'"
|
43
|
+
when 422
|
44
|
+
if response.body["errors"].is_a? Array
|
45
|
+
raise Error, "Error 422: Unprocessable Entity. '#{response.body["errors"].map {|e| e['message']}.join(" & ")}'"
|
46
|
+
else
|
47
|
+
raise Error, "Error 422: Unprocessable Entity. '#{response.body["errors"]["error"]["message"]}'"
|
48
|
+
end
|
49
|
+
when 429
|
50
|
+
raise Error, "Error 429: Your request exceeded the API rate limit. '#{response.body["errors"]["error"]["message"]}'"
|
51
|
+
when 500
|
52
|
+
raise Error, "Error 500: We were unable to perform the request due to server-side problems. '#{response.body["errors"]["error"]["message"]}'"
|
53
|
+
when 503
|
54
|
+
raise Error, "Error 503: You have been rate limited for sending more than 20 requests per second. '#{response.body["errors"]["error"]["message"]}'"
|
55
|
+
end
|
56
|
+
|
57
|
+
response
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module FreeAgent
|
2
|
+
class AttachmentsResource < Resource
|
3
|
+
|
4
|
+
def retrieve(id:)
|
5
|
+
response = get_request("attachments/#{id}")
|
6
|
+
Attachment.new(response.body["attachment"])
|
7
|
+
end
|
8
|
+
|
9
|
+
def delete(id:)
|
10
|
+
response = delete_request("attachments/#{id}")
|
11
|
+
response.success?
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module FreeAgent
|
2
|
+
class BankAccountsResource < Resource
|
3
|
+
|
4
|
+
def list(view: nil)
|
5
|
+
url = view.nil? ? "bank_accounts" : "bank_accounts?view=#{view}"
|
6
|
+
|
7
|
+
response = get_request(url)
|
8
|
+
Collection.from_response(response, type: BankAccount, key: "bank_accounts")
|
9
|
+
end
|
10
|
+
|
11
|
+
def retrieve(id:)
|
12
|
+
response = get_request("bank_accounts/#{id}")
|
13
|
+
BankAccount.new(response.body["bank_account"])
|
14
|
+
end
|
15
|
+
|
16
|
+
def create(type:, name:, opening_balance:, **params)
|
17
|
+
attributes = {type: type, name: name, opening_balance: opening_balance}
|
18
|
+
response = post_request("bank_accounts", body: attributes.merge(params))
|
19
|
+
BankAccount.new(response.body["bank_account"]) if response.success?
|
20
|
+
end
|
21
|
+
|
22
|
+
def update(id:, **params)
|
23
|
+
response = put_request("bank_accounts/#{id}", body: params)
|
24
|
+
BankAccount.new(response.body["bank_account"]) if response.success?
|
25
|
+
end
|
26
|
+
|
27
|
+
def delete(id:)
|
28
|
+
response = delete_request("bank_accounts/#{id}")
|
29
|
+
response.success?
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module FreeAgent
|
2
|
+
class BankTransactionExplanationsResource < Resource
|
3
|
+
|
4
|
+
def list(bank_account:, **params)
|
5
|
+
attributes = {bank_account: bank_account}
|
6
|
+
|
7
|
+
response = get_request("bank_transaction_explanations", params: attributes.merge(params))
|
8
|
+
Collection.from_response(response, type: BankTransactionExplanation, key: "bank_transaction_explanations")
|
9
|
+
end
|
10
|
+
|
11
|
+
def retrieve(id:)
|
12
|
+
response = get_request("bank_transaction_explanations/#{id}")
|
13
|
+
BankTransactionExplanation.new(response.body["bank_transaction_explanation"])
|
14
|
+
end
|
15
|
+
|
16
|
+
# Commented out as it needs more work
|
17
|
+
# def create(**params)
|
18
|
+
# raise "bank_account or bank_transaction is required" unless !params[:bank_account].nil? || !params[:bank_transaction].nil?
|
19
|
+
# response = post_request("bank_transaction_explanations", body: params)
|
20
|
+
# response.body
|
21
|
+
# end
|
22
|
+
|
23
|
+
def delete(id:)
|
24
|
+
response = delete_request("bank_transaction_explanations/#{id}")
|
25
|
+
response.success?
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module FreeAgent
|
2
|
+
class BankTransactionsResource < Resource
|
3
|
+
|
4
|
+
def list(bank_account:, **params)
|
5
|
+
attributes = {bank_account: bank_account}
|
6
|
+
|
7
|
+
response = get_request("bank_transactions", params: attributes.merge(params))
|
8
|
+
Collection.from_response(response, type: BankTransaction, key: "bank_transactions")
|
9
|
+
end
|
10
|
+
|
11
|
+
def retrieve(id:)
|
12
|
+
response = get_request("bank_transactions/#{id}")
|
13
|
+
BankTransaction.new(response.body["bank_transaction"])
|
14
|
+
end
|
15
|
+
|
16
|
+
# Statement should be an array of transactions
|
17
|
+
def create(bank_account:, statement:)
|
18
|
+
response = post_request("bank_transactions/statement?bank_account=#{bank_account}", body: {statement: statement})
|
19
|
+
response.success?
|
20
|
+
end
|
21
|
+
|
22
|
+
def upload(bank_account:, statement:)
|
23
|
+
# This method uses Faraday Multipart (lostisland/faraday-multipart)
|
24
|
+
payload = {}
|
25
|
+
payload[:statement] = Faraday::Multipart::FilePart.new(statement, 'text/x-ruby')
|
26
|
+
|
27
|
+
response = client.connection_upload.post "bank_transactions/statement?bank_account=#{bank_account}", payload
|
28
|
+
response.success?
|
29
|
+
end
|
30
|
+
|
31
|
+
def delete(id:)
|
32
|
+
response = delete_request("bank_transactions/#{id}")
|
33
|
+
response.success?
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|