forked from mdespuits/minty
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds basic support for retrieving mint categories
- Loading branch information
1 parent
4daf02b
commit a0e4c4d
Showing
6 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |