Skip to content

Commit

Permalink
Support joint accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-schofield committed Feb 12, 2020
1 parent f350c3d commit e484346
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 34 deletions.
24 changes: 9 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,31 @@ GEM
specs:
classy_struct (0.3.2)
colorize (0.8.1)
commander (4.4.0)
highline (~> 1.7.2)
domain_name (0.5.20170404)
commander (4.4.7)
highline (~> 2.0.0)
domain_name (0.5.20180417)
unf (>= 0.0.5, < 1.0.0)
ffi (1.9.18-x64-mingw32)
highline (1.7.8)
ffi (1.11.1-x64-mingw32)
highline (2.0.2)
http-cookie (1.0.3)
domain_name (~> 0.5)
mime-types (3.1)
mime-types (3.2.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mime-types-data (3.2019.0331)
netrc (0.11.0)
omnistruct (1.1.0)
classy_struct (~> 0.3, >= 0.3.2)
qif (1.2.0)
rest-client (2.0.2)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rest-client (2.0.2-x64-mingw32)
ffi (~> 1.9)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.4)
unf_ext (0.0.7.4-x64-mingw32)
unf_ext (0.0.7.6)

PLATFORMS
ruby
x64-mingw32

DEPENDENCIES
Expand All @@ -44,4 +38,4 @@ DEPENDENCIES
rest-client

BUNDLED WITH
1.15.1
1.17.2
2 changes: 1 addition & 1 deletion lib/qif_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def create(path = nil, settled_only: false, account_number: nil)
qif << Qif::Transaction.new(
date: transaction.created,
amount: transaction.amount.to_f / 100,
memo: memo,
memo: transaction.description,
payee: (transaction.merchant ? transaction.merchant.name : nil) || (transaction.is_load ? 'Topup' : 'Unknown')
)

Expand Down
4 changes: 2 additions & 2 deletions lib/transaction_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
require 'rest-client'

class TransactionFetcher
def initialize(access_token, current_account: false)
def initialize(access_token, joint_account: false)
@access_token = access_token
@account_type = current_account ? "uk_retail" : "uk_prepaid"
@account_type = joint_account ? "uk_retail_joint" : "uk_retail"
@account = http_get("/accounts?account_type=#{@account_type}")['accounts'].first
@account_id = @account['id']
end
Expand Down
28 changes: 12 additions & 16 deletions monzo-export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,17 @@
c.option '--since DATE', String, 'The date (YYYY-MM-DD) to start exporting transactions from. Defaults to 2 weeks ago'
c.option '--folder PATH', String, 'The folder to export to. Defaults to ./exports'
c.option '--settled_only', String, 'Only export settled transactions'
c.option '--prepaid_account', String, 'Export transactions from the prepaid account instead of any current accounts'
c.option '--joint_account', String, 'Export transactions from the joint account instead of any personal accounts'
c.option '--config_file FILE', String, 'Optional config filename'
c.action do |args, options|
since = options.since ? Date.parse(options.since).to_time : (Time.now - (60*60*24*14)).to_date
config = options.config_file ? options.config_file : 'config.yml'
access_token = options.access_token || OAuth.new(config).getAccessToken
fetcher = TransactionFetcher.new(access_token, current_account: !options.prepaid_account)
QifCreator.new(fetcher.fetch(since: since)).create(options.folder, settled_only: options.settled_only, account_number: (fetcher.account_number || 'prepaid'))
fetcher = TransactionFetcher.new(access_token, joint_account: options.joint_account)
QifCreator.new(fetcher.fetch(since: since)).create(options.folder, settled_only: options.settled_only, account_number: fetcher.account_number)

if options.current_account
say "Account Number: #{fetcher.account_number}"
say "Sort Code: #{fetcher.sort_code}"
end
say "Account Number: #{fetcher.account_number}"
say "Sort Code: #{fetcher.sort_code}"

say "Balance: £#{fetcher.balance}"
end
Expand All @@ -41,17 +39,15 @@
c.syntax = 'monzo-export balance [options]'
c.summary = 'Show the balance'
c.option '--access_token TOKEN', String, 'Your access token from: https://developers.monzo.com/'
c.option '--prepaid_account', String, 'Export transactions from the prepaid account instead of any current accounts'
c.option '--joint_account', String, 'Export transactions from the joint account instead of any personal accounts'
c.option '--config_file FILE', String, 'Optional config filename'
c.action do |args, options|
config = options.config_file ? options.config_file : 'config.yml'
access_token = options.access_token || OAuth.new(config).getAccessToken
fetcher = TransactionFetcher.new(access_token, current_account: !options.prepaid_account)
fetcher = TransactionFetcher.new(access_token, joint_account: options.joint_account)

if options.current_account
say "Account Number: #{fetcher.account_number}"
say "Sort Code: #{fetcher.sort_code}"
end
say "Account Number: #{fetcher.account_number}"
say "Sort Code: #{fetcher.sort_code}"

say "Balance: £#{fetcher.balance}"
end
Expand All @@ -64,14 +60,14 @@
c.option '--since DATE', String, 'The date (YYYY-MM-DD) to start exporting transactions from. Defaults to 2 weeks ago'
c.option '--folder PATH', String, 'The folder to export to. Defaults to ./exports'
c.option '--settled_only', String, 'Only export settled transactions'
c.option '--prepaid_account', String, 'Export transactions from the prepaid account instead of any current accounts'
c.option '--joint_account', String, 'Export transactions from the joint account instead of any personal accounts'
c.option '--config_file FILE', String, 'Optional config filename'
c.action do |args, options|
since = options.since ? Date.parse(options.since).to_time : (Time.now - (60*60*24*14)).to_date
config = options.config_file ? options.config_file : 'config.yml'
access_token = options.access_token || OAuth.new(config).getAccessToken
fetcher = TransactionFetcher.new(access_token, current_account: !options.prepaid_account)
CsvCreator.new(fetcher.fetch(since: since)).create(options.folder, settled_only: options.settled_only, account_number: (fetcher.account_number || 'prepaid'))
fetcher = TransactionFetcher.new(access_token, joint_account: options.joint_account)
CsvCreator.new(fetcher.fetch(since: since)).create(options.folder, settled_only: options.settled_only, account_number: fetcher.account_number)
end
end

Expand Down

0 comments on commit e484346

Please sign in to comment.