Skip to content

Commit 75404ee

Browse files
committed
add much stuff
1 parent fc93d57 commit 75404ee

30 files changed

+375
-50
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@
1616
/tmp
1717

1818
.ruby-gemset
19+
20+
# Ignore application configuration
21+
/config/application.yml

Bowerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
asset "select2"

Gemfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@ gem 'rails', '4.0.4'
66
# Use postgresql as the database for Active Record
77
gem 'pg'
88

9+
# View template language
10+
gem 'haml'
11+
912
# Use SCSS for stylesheets
1013
gem 'sass-rails', '~> 4.0.2'
1114

15+
# Javascript Dependency Management
16+
gem 'bower-rails'
17+
1218
# Use Uglifier as compressor for JavaScript assets
1319
gem 'uglifier', '>= 1.3.0'
1420

@@ -27,8 +33,18 @@ gem 'turbolinks'
2733
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
2834
gem 'jbuilder', '~> 1.2'
2935

36+
# Mint API
3037
gem 'mint-api', git: "git@github.com:whoward/mint-api.git"
3138

39+
# Cron tasks
40+
gem 'whenever'
41+
42+
# ActiveRecord Hierarchies
43+
gem 'acts_as_tree'
44+
45+
# application configuration
46+
gem 'figaro'
47+
3248
# Use ActiveModel has_secure_password
3349
# gem 'bcrypt', '~> 3.1.7'
3450

Gemfile.lock

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
GIT
22
remote: git@github.com:whoward/mint-api.git
3-
revision: 2701208f94dbea68e709a6e35f924ba6f46c8777
3+
revision: 5cd71284eeef761e6db34d326948a617ac1e3f4e
44
specs:
55
mint-api (1.0.0)
66
activesupport (>= 3.0.0)
@@ -35,8 +35,11 @@ GEM
3535
multi_json (~> 1.3)
3636
thread_safe (~> 0.1)
3737
tzinfo (~> 0.3.37)
38+
acts_as_tree (1.5.0)
39+
activerecord (>= 3.0.0)
3840
arel (4.0.2)
3941
atomic (1.1.15)
42+
bower-rails (0.7.1)
4043
builder (3.1.4)
4144
childprocess (0.5.1)
4245
ffi (~> 1.0, >= 1.0.11)
@@ -51,6 +54,11 @@ GEM
5154
erubis (2.7.0)
5255
execjs (2.0.2)
5356
ffi (1.9.3)
57+
figaro (0.7.0)
58+
bundler (~> 1.0)
59+
rails (>= 3, < 5)
60+
haml (4.0.5)
61+
tilt
5462
hike (1.2.3)
5563
i18n (0.6.9)
5664
jbuilder (1.5.3)
@@ -121,12 +129,19 @@ GEM
121129
execjs (>= 0.3.0)
122130
json (>= 1.8.0)
123131
websocket (1.0.7)
132+
whenever (0.9.2)
133+
activesupport (>= 2.3.4)
134+
chronic (>= 0.6.3)
124135

125136
PLATFORMS
126137
ruby
127138

128139
DEPENDENCIES
140+
acts_as_tree
141+
bower-rails
129142
coffee-rails (~> 4.0.0)
143+
figaro
144+
haml
130145
jbuilder (~> 1.2)
131146
jquery-rails
132147
mint-api!
@@ -135,3 +150,4 @@ DEPENDENCIES
135150
sass-rails (~> 4.0.2)
136151
turbolinks
137152
uglifier (>= 1.3.0)
153+
whenever
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
class DashboardController < ApplicationController
3+
end

app/models/account.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Account < ActiveRecord::Base
2+
has_many :transactions
3+
end

app/models/category.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
class Category < ActiveRecord::Base
3+
acts_as_tree
4+
has_many :transactions
5+
end

app/models/expense.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Expense < Transaction
2+
3+
end

app/models/income.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Income < Transaction
2+
3+
end

app/models/mint_account.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class MintAccount < ActiveRecord::Base
2+
has_many :mint_transactions, foreign_key: "account_id", primary_key: "mint_id"
3+
4+
scope :imported -> { where("imported_id is not null") }
5+
scope :not_imported, -> { where(imported_id: nil) }
6+
end

app/models/mint_transaction.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class MintTransaction < ActiveRecord::Base
2+
belongs_to :mint_account, class_name: "MintAccount", foreign_key: "account_id", primary_key: "mint_id"
3+
4+
scope :imported -> { where("imported_id is not null") }
5+
scope :not_imported, -> { where(imported_id: nil) }
6+
end

app/models/transaction.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Transaction < ActiveRecord::Base
2+
belongs_to :account
3+
belongs_to :category
4+
5+
end

app/models/transfer_from.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
class TransferFrom < Expense
3+
has_one :to, class_name: "TransferTo", foreign_key: "transfer_id"
4+
5+
def from
6+
self
7+
end
8+
end

app/models/transfer_to.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
class TransferTo < Income
3+
has_one :from, class_name: "TransferFrom", foreign_key: "transfer_id"
4+
5+
def to
6+
self
7+
end
8+
end

app/services/import_service.rb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
require 'mint/client'
2+
3+
class ImportService
4+
ImportError = Class.new(StandardError)
5+
6+
def initialize(logger: Mint::NullLogger)
7+
@logger = logger
8+
end
9+
10+
def call
11+
begin
12+
client.go_login!
13+
client.go_transactions!
14+
15+
client.accounts.each do |acc|
16+
MintAccount.find_or_initialize_by(mint_id: acc.id) do |a|
17+
a.name = acc.name
18+
end.save
19+
end
20+
21+
client.transactions.each do |txn|
22+
MintTransaction.find_or_initialize_by(mint_id: txn.id) do |t|
23+
t.date = txn.date
24+
t.description = txn.description
25+
t.category = txn.category
26+
t.cents = txn.cents
27+
t.expense = txn.is_expense
28+
t.account = txn.account
29+
t.account_id = txn.account_id
30+
t.notes = txn.notes
31+
end.save
32+
end
33+
rescue StandardError => error
34+
raise ImportError.new(error.message)
35+
ensure
36+
client.shutdown!
37+
end
38+
end
39+
40+
private
41+
attr_reader :logger
42+
43+
def client
44+
@client ||= Mint::Client.new(Figaro.env.mint_username, Figaro.env.mint_password, logger: logger)
45+
end
46+
47+
end

app/services/review_service.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
class ReviewService
3+
4+
def initialize(handler)
5+
@handler = handler
6+
end
7+
8+
def call
9+
MintAccount.not_imported.find_each do |mint|
10+
Account.transaction do
11+
acc = Account.create(name: mint.name)
12+
mint.update_attribute :imported_id, acc.id
13+
end
14+
end
15+
16+
MintTransaction.not_imported.find_each do |mint|
17+
txn = Transaction.new do |t|
18+
t.date = mint.date
19+
t.date = mint.date
20+
t.description = mint.description
21+
t.category = mint.category
22+
t.cents = mint.cents
23+
t.expense = mint.is_expense
24+
t.account = mint.account
25+
t.account_id = mint.account_id
26+
t.notes = mint.notes
27+
end
28+
29+
handler.verify_transaction(mint, txn)
30+
31+
Transaction.transaction do
32+
txn.save!
33+
mint.update_attribute :imported_id, txn.id
34+
end
35+
end
36+
end
37+
38+
private
39+
attr_reader :handler
40+
41+
end

bower.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"lib": {
3+
"name": "bower-rails generated lib assets",
4+
"dependencies": {
5+
// "threex" : "git@github.com:rharriso/threex.git",
6+
// "gsvpano.js" : "https://github.com/rharriso/GSVPano.js/blob/master/src/GSVPano.js"
7+
}
8+
},
9+
"vendor": {
10+
"name": "bower-rails generated vendor assets",
11+
"dependencies": {
12+
// "three.js" : "https://raw.github.com/mrdoob/three.js/master/build/three.js"
13+
}
14+
}
15+
}

config/database.yml

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,15 @@
1-
# PostgreSQL. Versions 8.2 and up are supported.
2-
#
3-
# Install the pg driver:
4-
# gem install pg
5-
# On OS X with Homebrew:
6-
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
7-
# On OS X with MacPorts:
8-
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
9-
# On Windows:
10-
# gem install pg
11-
# Choose the win32 build.
12-
# Install PostgreSQL and put its /bin directory on your path.
13-
#
14-
# Configure Using Gemfile
15-
# gem 'pg'
16-
#
171
development:
182
adapter: postgresql
193
encoding: unicode
20-
database: mint-app_development
4+
database: mint_development
215
pool: 5
22-
username: mint-app
6+
username: will
237
password:
248

25-
# Connect on a TCP socket. Omitted by default since the client uses a
26-
# domain socket that doesn't need configuration. Windows does not have
27-
# domain sockets, so uncomment these lines.
28-
#host: localhost
29-
30-
# The TCP port the server listens on. Defaults to 5432.
31-
# If your server runs on a different port number, change accordingly.
32-
#port: 5432
33-
34-
# Schema search path. The server defaults to $user,public
35-
#schema_search_path: myapp,sharedapp,public
36-
37-
# Minimum log levels, in increasing order:
38-
# debug5, debug4, debug3, debug2, debug1,
39-
# log, notice, warning, error, fatal, and panic
40-
# Defaults to warning.
41-
#min_messages: notice
42-
43-
# Warning: The database defined as "test" will be erased and
44-
# re-generated from your development database when you run "rake".
45-
# Do not set this db to the same as development or production.
469
test:
4710
adapter: postgresql
4811
encoding: unicode
49-
database: mint-app_test
50-
pool: 5
51-
username: mint-app
52-
password:
53-
54-
production:
55-
adapter: postgresql
56-
encoding: unicode
57-
database: mint-app_production
12+
database: mint_test
5813
pool: 5
59-
username: mint-app
14+
username: will
6015
password:

config/initializers/bower_rails.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
BowerRails.configure do |bower_rails|
2+
# Uncomment this line if you want `rake bower:resolve` task to be run
3+
# automatically before the `rake assets:precompile` task.
4+
5+
# bower_rails.resolve_before_precompile = true
6+
end

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
MintApp::Application.routes.draw do
2+
root to: 'dashboard#show'
3+
24
# The priority is based upon order of creation: first created -> highest priority.
35
# See how all your routes lay out with "rake routes".
46

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class CreateMintAccounts < ActiveRecord::Migration
2+
def change
3+
create_table :mint_accounts do |t|
4+
t.integer :mint_id
5+
t.integer :imported_id
6+
t.string :name
7+
8+
t.timestamps
9+
end
10+
end
11+
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class CreateMintTransactions < ActiveRecord::Migration
2+
def change
3+
create_table :mint_transactions do |t|
4+
t.integer :mint_id
5+
t.integer :imported_id
6+
t.date :date
7+
t.string :description
8+
t.string :category
9+
t.integer :cents
10+
t.boolean :expense
11+
t.string :account
12+
t.integer :account_id
13+
t.string :notes
14+
15+
t.timestamps
16+
end
17+
end
18+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class CreateCategories < ActiveRecord::Migration
2+
def change
3+
create_table :categories do |t|
4+
t.integer :parent_id
5+
t.string :name
6+
7+
t.timestamps
8+
end
9+
end
10+
end

0 commit comments

Comments
 (0)