mintkit 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -18,7 +18,30 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ Command line:
22
+
23
+ ``` shell
24
+ mintkit --help
25
+ ```
26
+
27
+ Ruby API:
28
+
29
+ ```ruby
30
+ client = Mintkit::Client.new(username,password)
31
+
32
+ # refresh your account
33
+ client.refresh #refresh the accounts (it doesn't block yet while refreshing)
34
+
35
+ # dump all accounts and transactions
36
+ puts client.accounts #print out the accounts
37
+ puts client.transactions #print out all your transactions
38
+
39
+ # or use iterators (works for accounts as well)
40
+ client.transactions do |t|
41
+ puts "#{t[:account]} #{t[:amount]} #{t[:description]} #{t[:date]}"
42
+ end
43
+
44
+ ```
22
45
 
23
46
  ## Contributing
24
47
 
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'mintkit'
4
+ require 'trollop'
5
+ require 'io/console'
6
+
7
+
8
+ Signal.trap("PIPE", "EXIT")
9
+
10
+ ############################3
11
+ # Main functions
12
+ #
13
+
14
+ def refresh(client)
15
+ client.refresh
16
+
17
+ puts "Account is currently refreshing. It might take a minute or two"
18
+
19
+ end
20
+
21
+ def accounts(client)
22
+ client.accounts do |a|
23
+ puts "%-10s %10s %s" % [a[:account_type],a[:value],a[:name][0..27]]
24
+ end
25
+
26
+ end
27
+
28
+ def transactions(client)
29
+ client.transactions do |t|
30
+ sign = "-"
31
+ sign = "" if t[:type] == "credit"
32
+ puts "%-11s %1s%-9s %s" % [ t[:date].strftime("%-m/%-d/%Y"), sign, t[:amount], t[:description]]
33
+ #puts "#{t[:date]} #{t[:amount]} \t#{t[:description]}"
34
+ end
35
+
36
+ end
37
+
38
+ #############################3
39
+ # Options, etc
40
+
41
+ opts = Trollop::options do
42
+ version Mintkit::VERSION
43
+ banner <<-EOS
44
+ Mintkit provides a simple interface to Mint.com. Not affiliated with Mint.com or Intuit. Your mileage may vary.
45
+
46
+ Usage:
47
+ mintkit [options] command
48
+
49
+ where command is one of:
50
+ refresh :refreshes your accounts
51
+ accounts :lists your accounts and balances
52
+ transactions :lists your transactions
53
+
54
+ and options are:
55
+ EOS
56
+
57
+ opt :username, "Mint.com username", :type => :string
58
+ opt :password, "Mint.com password", :type => :string
59
+ end
60
+
61
+ username = opts.username
62
+ password = opts.password
63
+
64
+ command = ARGV.shift
65
+ args = ARGV.join(' ')
66
+
67
+ unless command
68
+ puts "Error: no command specified. Try \"mintkit --help\""
69
+ exit
70
+ end
71
+
72
+ unless username
73
+ print "Mint.com username: "
74
+ username = $stdin.gets.chomp
75
+ end
76
+
77
+ unless password
78
+ print "Mint.com password: "
79
+ password = STDIN.noecho(&:gets)
80
+ print "\n"
81
+ end
82
+
83
+
84
+ #############################3
85
+ #
86
+ # create the client and call the appropriate function
87
+
88
+
89
+ client = Mintkit::Client.new(username,password)
90
+
91
+ case
92
+ when command == 'refresh'
93
+ refresh(client)
94
+
95
+ when command == 'accounts'
96
+ accounts(client)
97
+
98
+ when command == 'transactions'
99
+ transactions(client)
100
+ else
101
+ puts "No such command: #{command}"
102
+ end
@@ -10,14 +10,15 @@ module Mintkit
10
10
  @username = username
11
11
  @password = password
12
12
  @token = nil
13
+ @agent = Mechanize.new{|a| a.ssl_version, a.verify_mode = 'SSLv3', OpenSSL::SSL::VERIFY_NONE}
14
+ login
13
15
 
14
16
  end
15
17
 
16
18
  # login to my account
17
19
  # get all the transactions
18
20
  def transactions
19
- agent = login
20
- raw_transactions = agent.get("https://wwws.mint.com/transactionDownload.event?").body
21
+ raw_transactions = @agent.get("https://wwws.mint.com/transactionDownload.event?").body
21
22
 
22
23
  transos = []
23
24
 
@@ -38,38 +39,59 @@ module Mintkit
38
39
  }
39
40
  transos << transaction
40
41
 
42
+ if block_given?
43
+ yield transaction
44
+ end
45
+
41
46
  end
42
47
 
43
-
44
48
  end
45
- logout(agent)
46
49
  transos
47
50
 
48
51
  end
49
52
 
50
53
  def accounts
51
- agent = login
52
- page = agent.get('https://wwws.mint.com/overview.event')
53
-
54
+ page = @agent.get('https://wwws.mint.com/overview.event')
54
55
 
55
56
  requeststring = %q#[{"args":{"types":["BANK","CREDIT","INVESTMENT","LOAN","MORTGAGE","OTHER_PROPERTY","REAL_ESTATE","VEHICLE","UNCLASSIFIED"]},"service":"MintAccountService","task":"getAccountsSortedByBalanceDescending","id":"8675309"}]#
56
57
 
57
- accounts = JSON.parse(agent.post("https://wwws.mint.com/bundledServiceController.xevent?token=#{@token}",{"input" => requeststring}).body)["response"]["8675309"]["response"]
58
+ accounts = JSON.parse(@agent.post("https://wwws.mint.com/bundledServiceController.xevent?token=#{@token}",{"input" => requeststring}).body)["response"]["8675309"]["response"]
59
+
60
+ accountlist = []
61
+ accounts.each do |a|
62
+ account = {
63
+ :current_balance => a["currentBalance"],
64
+ :login_status => a["fiLoginUIStatus"],
65
+ :currency => a["currency"],
66
+ :id => a["id"],
67
+ :amount_due => a["dueAmt"],
68
+ :name => a["name"],
69
+ :value => a["value"],
70
+ #:due_date => Date.strptime(a["dueDate"], '%m/%d/%Y'),
71
+ :last_updated => Time.at(a["lastUpdated"]/1000).to_date,
72
+ :last_updated_string => a["lastUpdatedInString"],
73
+ :active => !!a["isActive"],
74
+ :login_status => a["fiLoginStatus"],
75
+ :account_type => a["accountType"],
76
+ :date_added => Time.at(a["addAccountDate"]/1000).to_date
77
+ }
78
+
79
+ if block_given?
80
+ yield account
81
+ end
58
82
 
59
- logout(agent)
60
-
61
- accounts
83
+ accountlist << account
84
+
85
+ end
86
+ accountlist
62
87
 
63
88
  end
64
89
 
65
90
  # force a refresh on my account
66
91
  def refresh
67
- agent = login
68
- page = agent.get('https://wwws.mint.com/overview.event')
69
-
70
- agent.post("https://wwws.mint.com/refreshFILogins.xevent", {"token"=>@token})
92
+ page = @agent.get('https://wwws.mint.com/overview.event')
71
93
 
72
- logout(agent)
94
+ @agent.post("https://wwws.mint.com/refreshFILogins.xevent", {"token"=>@token})
73
95
 
74
96
  true
75
97
 
@@ -78,19 +100,23 @@ module Mintkit
78
100
 
79
101
  def login
80
102
 
81
- agent = Mechanize.new{|a| a.ssl_version, a.verify_mode = 'SSLv3', OpenSSL::SSL::VERIFY_NONE}
82
- page = agent.get('https://wwws.mint.com/login.event')
103
+ page = @agent.get('https://wwws.mint.com/login.event')
83
104
  form = page.forms[2]
84
105
  form.username = @username
85
106
  form.password = @password
86
- page = agent.submit(form,form.buttons.first)
87
- @token = page.at('input').attributes["value"].value.match(/"token":"([0-9a-zA-Z]*)"/)[1]
88
- agent
107
+ page = @agent.submit(form,form.buttons.first)
108
+ if page.at('input').attributes["value"]
109
+ @token = page.at('input').attributes["value"].value.match(/"token":"([0-9a-zA-Z]*)"/)[1]
110
+ true
111
+ else
112
+ false
113
+ end
114
+
89
115
 
90
116
  end
91
117
 
92
- def logout(agent)
93
- agent.get('https://wwws.mint.com/logout.event?task=explicit')
118
+ def logout
119
+ @agent.get('https://wwws.mint.com/logout.event?task=explicit')
94
120
  true
95
121
  end
96
122
 
@@ -1,3 +1,3 @@
1
1
  module Mintkit
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -18,7 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "mechanize"
21
+ spec.add_runtime_dependency "mechanize"
22
+ spec.add_runtime_dependency "trollop"
22
23
 
23
24
  spec.add_development_dependency "bundler", "~> 1.3"
24
25
  spec.add_development_dependency "rake"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mintkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-06 00:00:00.000000000 Z
12
+ date: 2013-06-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mechanize
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: trollop
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: bundler
32
48
  requirement: !ruby/object:Gem::Requirement
@@ -79,7 +95,8 @@ description: Ruby API for mint.com. Not at all affiliated with or endorsed by m
79
95
  mileage may vary.
80
96
  email:
81
97
  - robscanlon@gmail.com
82
- executables: []
98
+ executables:
99
+ - mintkit
83
100
  extensions: []
84
101
  extra_rdoc_files: []
85
102
  files:
@@ -88,6 +105,7 @@ files:
88
105
  - LICENSE.txt
89
106
  - README.md
90
107
  - Rakefile
108
+ - bin/mintkit
91
109
  - lib/mintkit.rb
92
110
  - lib/mintkit/client.rb
93
111
  - lib/mintkit/version.rb