Skip to content

Commit

Permalink
Adds basic support for retrieving mint categories
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusmateus committed Sep 16, 2013
1 parent 4daf02b commit a0e4c4d
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
*.gem
*.rbc
.bundle
.ruby-version
.ruby-gemset
.config
.yardoc
Gemfile.lock
Expand Down
1 change: 1 addition & 0 deletions lib/minty/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require 'minty/cli/default'
require 'minty/cli/login'
require 'minty/cli/accounts'
require 'minty/cli/categories'
require 'minty/cli/refresh'
require 'minty/cli/transactions'
require 'minty/cli/goals'
Expand Down
24 changes: 24 additions & 0 deletions lib/minty/cli/categories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'text-table'

require 'minty/utils'
require 'minty/cli/command'

module Minty
class CLI
class Categories < Command
banner "Usage: minty categories [options]"

def exec
table = Text::Table.new
table.head = ['Root ID', 'ID', 'Name', 'Standard']
client.categories.sort_by { |a| a.name }.each do |category|
table.rows << [category.id, nil, category.name, nil]
category.children.each do |child|
table.rows << [nil, child.id, child.name, child.standard?]
end
end
puts table
end
end
end
end
1 change: 1 addition & 0 deletions lib/minty/cli/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Default
login: Save your Mint.com credentials for other actions
refresh: Refresh your Mint.com accounts
accounts: Display a table of your Mint.com accounts
categories: Display a table of your Mint.com categories
goals: Display your Mint.com goals
transactions: Show Last {{count}} transactions recorded on Mint.com
Expand Down
10 changes: 10 additions & 0 deletions lib/minty/client.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'minty/objects/account'
require 'minty/objects/category'
require 'minty/objects/goal'
require 'minty/objects/transaction'

Expand Down Expand Up @@ -51,6 +52,15 @@ def transactions
}
end

def categories
login do
response_body = agent.get("app/getJsonData.xevent?task=categories").body
parsed_body = ::JSON.parse(response_body)
categories = parsed_body["set"][0]["data"]
Minty::Objects::Category.build(categories)
end
end

def goals
login {
page = agent.get("app/getJsonData.xevent?task=goals&rnd=1378927170581").body
Expand Down
45 changes: 45 additions & 0 deletions lib/minty/objects/category.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# https://wwws.mint.com/app/getJsonData.xevent?task=categories

require 'minty/objects/model'

module Minty
module Objects
class Category < Model
def self.build(json)
json.each_with_object([]) do |category, list|
cat = self.new(category)
children = category['children']
if children
children.each do |child|
cat.children.push self.new(child)
end
end
list.concat [cat]
end
end

attribute :id
attribute :name, 'value'
attribute :level1, 'isL1'
attribute :standard, 'isStandard'

def children
@children ||= []
end

def is_level1?
level1
end

def standard?
standard
end

def to_s
"#<#{self.class.name} id=#{id} name=\"#{name}\" children=#{children}>"
end
alias inspect to_s

end
end
end

0 comments on commit a0e4c4d

Please sign in to comment.