Class: Mintkit::Client
- Inherits:
-
Object
- Object
- Mintkit::Client
- Defined in:
- lib/mintkit/client.rb
Instance Method Summary collapse
- #accounts ⇒ Object
-
#initialize(username, password) ⇒ Client
constructor
A new instance of Client.
-
#refresh ⇒ Object
force a refresh on my account.
-
#transactions ⇒ Object
login to my account get all the transactions.
Constructor Details
#initialize(username, password) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 16 |
# File 'lib/mintkit/client.rb', line 10 def initialize(username, password) @username, @password = username, password @agent = Mechanize.new{|a| a.ssl_version, a.verify_mode = 'SSLv3', OpenSSL::SSL::VERIFY_NONE} login end |
Instance Method Details
#accounts ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/mintkit/client.rb', line 52 def accounts page = @agent.get('https://wwws.mint.com/overview.event') requeststring = %q#[{"args":{"types":["BANK","CREDIT","INVESTMENT","LOAN","MORTGAGE","OTHER_PROPERTY","REAL_ESTATE","VEHICLE","UNCLASSIFIED"]},"service":"MintAccountService","task":"getAccountsSortedByBalanceDescending","id":"8675309"}]# accounts = JSON.parse(@agent.post("https://wwws.mint.com/bundledServiceController.xevent?token=#{@token}",{"input" => requeststring}).body)["response"]["8675309"]["response"] accountlist = [] accounts.each do |a| account = { :current_balance => a["currentBalance"], :login_status => a["fiLoginUIStatus"], :currency => a["currency"], :id => a["id"], :amount_due => a["dueAmt"], :name => a["name"], :value => a["value"], #:due_date => Date.strptime(a["dueDate"], '%m/%d/%Y'), :last_updated => Time.at(a["lastUpdated"]/1000).to_date, :last_updated_string => a["lastUpdatedInString"], :active => !!a["isActive"], :login_status => a["fiLoginStatus"], :account_type => a["accountType"], :date_added => Time.at(a["addAccountDate"]/1000).to_date } if block_given? yield account end accountlist << account end accountlist end |
#refresh ⇒ Object
force a refresh on my account
90 91 92 93 94 95 96 97 |
# File 'lib/mintkit/client.rb', line 90 def refresh page = @agent.get('https://wwws.mint.com/overview.event') @agent.post("https://wwws.mint.com/refreshFILogins.xevent", {"token"=>@token}) true end |
#transactions ⇒ Object
login to my account get all the transactions
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/mintkit/client.rb', line 20 def transactions raw_transactions = @agent.get("https://wwws.mint.com/transactionDownload.event?").body transos = [] CSV::Converters[:string] = proc do |field| field.encode(ConverterEncoding) rescue field end transos = CSV.parse(raw_transactions, { :headers => true }).map do |row| puts row.inspect { :date => Date.strptime(row['Date'], '%m/%d/%Y'), :description => row['Description'], :original_description => row['Original Description'], :amount => row['Amount'].to_f, :type => row['Transaction Type'], :category => row['Category'], :account => row['Account Name'], :labels => row['Labels'], :notes => row['Notes'], } end if block_given? transos.each do |transaction| yield transaction end end transos end |