Class: FreeAgent::BankAccountsResource

Inherits:
Resource
  • Object
show all
Defined in:
lib/free_agent/resources/bank_accounts.rb

Instance Attribute Summary

Attributes inherited from Resource

#client

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from FreeAgent::Resource

Instance Method Details

#create(type:, name:, opening_balance:, **params) ⇒ Object



16
17
18
19
20
# File 'lib/free_agent/resources/bank_accounts.rb', line 16

def create(type:, name:, opening_balance:, **params)
  attributes = {type: type, name: name, opening_balance: opening_balance}
  response = post_request("bank_accounts", body: attributes.merge(params))
  BankAccount.new(response.body["bank_account"]) if response.success?
end

#delete(id:) ⇒ Object



27
28
29
30
# File 'lib/free_agent/resources/bank_accounts.rb', line 27

def delete(id:)
  response = delete_request("bank_accounts/#{id}")
  response.success?
end

#list(view: nil) ⇒ Object



4
5
6
7
8
9
# File 'lib/free_agent/resources/bank_accounts.rb', line 4

def list(view: nil)
  url = view.nil? ? "bank_accounts" : "bank_accounts?view=#{view}"

  response = get_request(url)
  Collection.from_response(response, type: BankAccount, key: "bank_accounts")
end

#retrieve(id:) ⇒ Object



11
12
13
14
# File 'lib/free_agent/resources/bank_accounts.rb', line 11

def retrieve(id:)
  response = get_request("bank_accounts/#{id}")
  BankAccount.new(response.body["bank_account"])
end

#update(id:, **params) ⇒ Object



22
23
24
25
# File 'lib/free_agent/resources/bank_accounts.rb', line 22

def update(id:, **params)
  response = put_request("bank_accounts/#{id}", body: params)
  BankAccount.new(response.body["bank_account"]) if response.success?
end