mintkit 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Mintkit
2
2
 
3
- A Mint.com API. Not at all affialiated with or endorsed by mint.com/intuit. Your mileage may vary.
3
+ A Mint.com API. Not at all affiliated with or endorsed by mint.com/intuit. Your mileage may vary.
4
4
 
5
5
  ## Installation
6
6
 
@@ -29,8 +29,8 @@ Ruby API:
29
29
  ```ruby
30
30
  client = Mintkit::Client.new(username,password)
31
31
 
32
- # refresh your account
33
- client.refresh #refresh the accounts (it doesn't block yet while refreshing)
32
+ # tell mint to refresh all your accounts
33
+ client.refresh #(note: it doesn't block yet while refreshing)
34
34
 
35
35
  # dump all accounts and transactions
36
36
  puts client.accounts #print out the accounts
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'mintkit'
4
+ require 'mintkit/error'
4
5
  require 'trollop'
5
6
  require 'io/console'
6
7
 
@@ -86,7 +87,12 @@ end
86
87
  # create the client and call the appropriate function
87
88
 
88
89
 
89
- client = Mintkit::Client.new(username,password)
90
+ begin
91
+ client = Mintkit::Client.new(username,password)
92
+ rescue Mintkit::FailedLogin
93
+ puts "Login failed. Please check that your username/password is correct"
94
+ exit 1
95
+ end
90
96
 
91
97
  case
92
98
  when command == 'refresh'
@@ -1,5 +1,6 @@
1
1
  require "mechanize"
2
2
  require "json"
3
+ require "mintkit/error"
3
4
 
4
5
  module Mintkit
5
6
 
@@ -7,9 +8,7 @@ module Mintkit
7
8
 
8
9
  def initialize(username, password)
9
10
 
10
- @username = username
11
- @password = password
12
- @token = nil
11
+ @username, @password = username, password
13
12
  @agent = Mechanize.new{|a| a.ssl_version, a.verify_mode = 'SSLv3', OpenSSL::SSL::VERIFY_NONE}
14
13
  login
15
14
 
@@ -105,14 +104,9 @@ module Mintkit
105
104
  form.username = @username
106
105
  form.password = @password
107
106
  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
-
115
107
 
108
+ raise FailedLogin unless page.at('input').attributes["value"]
109
+ @token = page.at('input').attributes["value"].value.match(/"token":"([0-9a-zA-Z]*)"/)[1]
116
110
  end
117
111
 
118
112
  def logout
@@ -0,0 +1,4 @@
1
+ module Mintkit
2
+ class FailedLogin < StandardError; end
3
+ class SessionExpired < StandardError; end
4
+ end
@@ -1,3 +1,3 @@
1
1
  module Mintkit
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
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.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -108,6 +108,7 @@ files:
108
108
  - bin/mintkit
109
109
  - lib/mintkit.rb
110
110
  - lib/mintkit/client.rb
111
+ - lib/mintkit/error.rb
111
112
  - lib/mintkit/version.rb
112
113
  - mintkit.gemspec
113
114
  homepage: https://github.com/arscan/mintkit