class BlueBank::Account

Attributes

client[R]

Public Class Methods

new(id:, client:, json: nil) click to toggle source
# File lib/blue_bank/account.rb, line 3
def initialize(id:, client:, json: nil)
  @id, @client, @json = id, client, json
end

Public Instance Methods

account_type() click to toggle source
# File lib/blue_bank/account.rb, line 15
def account_type
  json.fetch("accountType")
end
current?() click to toggle source
# File lib/blue_bank/account.rb, line 7
def current?
  account_type == "Standard Current Account"
end
id() click to toggle source
# File lib/blue_bank/account.rb, line 36
def id
  @id ||= json.fetch("id")
end
make_payment(account_number:, sort_code:, reference:, amount:) click to toggle source
# File lib/blue_bank/account.rb, line 19
def make_payment(account_number:, sort_code:, reference:, amount:)
  json = client.post(
    path: "/accounts/#{id}/payments",
    json: {
      "toAccountNumber" => account_number,
      "toSortCode" => sort_code,
      "paymentReference" => reference,
      "paymentAmount" => amount,
    }
  )
  Payment.new(id: json.fetch("id"), account: self, client: client, json: json)
end
savings?() click to toggle source
# File lib/blue_bank/account.rb, line 11
def savings?
  account_type == "Standard Current Account"
end
transactions() click to toggle source
# File lib/blue_bank/account.rb, line 32
def transactions
  client.get("/accounts/#{id}/transactions")
end

Private Instance Methods

json() click to toggle source
# File lib/blue_bank/account.rb, line 42
def json
  @json ||= client.get("/accounts/#{id}").first
end