figo 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/test_figo.rb CHANGED
@@ -1,16 +1,16 @@
1
1
  #
2
2
  # Copyright (c) 2013 figo GmbH
3
- #
3
+ #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  # of this software and associated documentation files (the "Software"), to deal
6
6
  # in the Software without restriction, including without limitation the rights
7
7
  # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
8
  # copies of the Software, and to permit persons to whom the Software is
9
9
  # furnished to do so, subject to the following conditions:
10
- #
10
+ #
11
11
  # The above copyright notice and this permission notice shall be included in
12
12
  # all copies or substantial portions of the Software.
13
- #
13
+ #
14
14
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
15
  # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
16
  # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -18,59 +18,113 @@
18
18
  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
19
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
20
  # THE SOFTWARE.
21
- #
21
+ #
22
22
 
23
+ require "flt"
23
24
  require "minitest/autorun"
24
25
  require_relative "../lib/figo"
25
26
 
26
27
 
27
28
  class FigoTest < MiniTest::Unit::TestCase
28
29
 
29
- def test_accounts
30
- sut = Figo::Session.new("ASHWLIkouP2O6_bgA2wWReRhletgWKHYjLqDaqb0LFfamim9RjexTo22ujRIP_cjLiRiSyQXyt2kM1eXU2XLFZQ0Hro15HikJQT_eNeT_9XQ")
30
+ def setup
31
+ @sut = Figo::Session.new("ASHWLIkouP2O6_bgA2wWReRhletgWKHYjLqDaqb0LFfamim9RjexTo22ujRIP_cjLiRiSyQXyt2kM1eXU2XLFZQ0Hro15HikJQT_eNeT_9XQ")
32
+ end
31
33
 
32
- sut.accounts
33
- sut.get_account "A1.1"
34
- account = sut.get_account "A1.2"
34
+ def test_accounts
35
+ @sut.accounts
36
+ @sut.get_account "A1.1"
37
+ account = @sut.get_account "A1.2"
35
38
  assert_equal account.account_id, "A1.2"
36
39
 
37
40
  # account sub-resources
38
- balance = sut.get_account("A1.2").balance
41
+ balance = @sut.get_account("A1.2").balance
39
42
  assert balance.balance
40
43
  assert balance.balance_date
41
44
 
42
- transactions = sut.get_account("A1.2").transactions
45
+ transactions = @sut.get_account("A1.2").transactions
43
46
  assert transactions.length > 0
47
+
48
+ payments = @sut.get_account("A1.2").payments
49
+ assert payments.length >= 0
44
50
  end
45
51
 
46
52
  def test_global_transactions
47
- sut = Figo::Session.new("ASHWLIkouP2O6_bgA2wWReRhletgWKHYjLqDaqb0LFfamim9RjexTo22ujRIP_cjLiRiSyQXyt2kM1eXU2XLFZQ0Hro15HikJQT_eNeT_9XQ")
48
- transactions = sut.transactions
49
- self.assert transactions.length > 0
53
+ transactions = @sut.transactions
54
+ assert transactions.length > 0
55
+ end
56
+
57
+ def test_global_payments
58
+ payments = @sut.payments
59
+ assert payments.length >= 0
60
+ end
61
+
62
+ def test_notifications
63
+ notifications = @sut.notifications
64
+ assert notifications.length >= 0
65
+ end
66
+
67
+ def test_missing_handling
68
+ assert_nil @sut.get_account "A1.42"
69
+ end
70
+
71
+ def test_error_handling
72
+ assert_raises(Figo::Error) { @sut.sync_url "http://localhost:3003/", "" }
50
73
  end
51
74
 
52
75
  def test_sync_uri
53
- sut = Figo::Session.new("ASHWLIkouP2O6_bgA2wWReRhletgWKHYjLqDaqb0LFfamim9RjexTo22ujRIP_cjLiRiSyQXyt2kM1eXU2XLFZQ0Hro15HikJQT_eNeT_9XQ")
54
- sut.sync_url("qwe", "qew")
76
+ @sut.sync_url("qwe", "qew")
77
+ end
78
+
79
+ def test_user
80
+ @sut.user
55
81
  end
56
82
 
57
83
  def test_create_update_delete_notification
58
- sut = Figo::Session.new("ASHWLIkouP2O6_bgA2wWReRhletgWKHYjLqDaqb0LFfamim9RjexTo22ujRIP_cjLiRiSyQXyt2kM1eXU2XLFZQ0Hro15HikJQT_eNeT_9XQ")
59
-
60
- notification = sut.add_notification(observe_key="/rest/transactions", notify_uri="http://figo.me/test", state="qwe")
61
- assert_equal notification.observe_key, "/rest/transactions"
62
- assert_equal notification.notify_uri, "http://figo.me/test"
63
- assert_equal notification.state, "qwe"
64
-
65
- notification.state = "asd"
66
- sut.modify_notification(notification)
67
-
68
- notification = sut.get_notification(notification.notification_id)
69
- assert_equal notification.observe_key, "/rest/transactions"
70
- assert_equal notification.notify_uri, "http://figo.me/test"
71
- assert_equal notification.state, "asd"
72
-
73
- sut.remove_notification(notification)
74
- assert_equal sut.get_notification(notification.notification_id), nil
84
+ added_notification = @sut.add_notification(Figo::Notification.new(@sut, {:observe_key => "/rest/transactions", :notify_uri => "http://figo.me/test", :state => "qwe"}))
85
+ refute_nil added_notification.notification_id
86
+ assert_equal added_notification.observe_key, "/rest/transactions"
87
+ assert_equal added_notification.notify_uri, "http://figo.me/test"
88
+ assert_equal added_notification.state, "qwe"
89
+
90
+ added_notification.state = "asd"
91
+ modified_notification = @sut.modify_notification(added_notification)
92
+ assert_equal modified_notification.notification_id, added_notification.notification_id
93
+ assert_equal modified_notification.observe_key, "/rest/transactions"
94
+ assert_equal modified_notification.notify_uri, "http://figo.me/test"
95
+ assert_equal modified_notification.state, "asd"
96
+
97
+ retrieved_notification = @sut.get_notification(modified_notification.notification_id)
98
+ assert_equal retrieved_notification.notification_id, added_notification.notification_id
99
+ assert_equal retrieved_notification.observe_key, "/rest/transactions"
100
+ assert_equal retrieved_notification.notify_uri, "http://figo.me/test"
101
+ assert_equal retrieved_notification.state, "asd"
102
+
103
+ @sut.remove_notification(retrieved_notification)
104
+ assert_nil @sut.get_notification(added_notification.notification_id)
105
+ end
106
+
107
+ def test_create_update_delete_payment
108
+ added_payment = @sut.add_payment(Figo::Payment.new(@sut, {:account_id => "A1.1", :type => "Transfer", :account_number => "4711951501", :bank_code => "90090042", :name => "figo", :purpose => "Thanks for all the fish.", :amount => 0.89}))
109
+ refute_nil added_payment.payment_id
110
+ assert_equal added_payment.account_id, "A1.1"
111
+ assert_equal added_payment.bank_name, "Demobank"
112
+ assert_equal added_payment.amount, 0.89
113
+
114
+ added_payment.amount = 2.39
115
+ modified_payment = @sut.modify_payment(added_payment)
116
+ assert_equal modified_payment.payment_id, added_payment.payment_id
117
+ assert_equal modified_payment.account_id, "A1.1"
118
+ assert_equal modified_payment.bank_name, "Demobank"
119
+ assert_equal modified_payment.amount, 2.39
120
+
121
+ retrieved_payment = @sut.get_payment(modified_payment.account_id, modified_payment.payment_id)
122
+ assert_equal retrieved_payment.payment_id, added_payment.payment_id
123
+ assert_equal retrieved_payment.account_id, "A1.1"
124
+ assert_equal retrieved_payment.bank_name, "Demobank"
125
+ assert_equal retrieved_payment.amount, 2.39
126
+
127
+ @sut.remove_payment(retrieved_payment)
128
+ assert_nil @sut.get_payment(modified_payment.account_id, modified_payment.payment_id)
75
129
  end
76
130
  end
data/web_demo/app.rb ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'sinatra'
3
+ require_relative '../lib/figo'
4
+
5
+ CLIENT_ID = "CaESKmC8MAhNpDe5rvmWnSkRE_7pkkVIIgMwclgzGcQY"
6
+ CLIENT_SECRET = "STdzfv0GXtEj_bwYn7AgCVszN1kKq5BdgEIKOM_fzybQ"
7
+ connection = Figo::Connection.new(CLIENT_ID, CLIENT_SECRET, "http://localhost:3000/callback")
8
+
9
+ configure do
10
+ enable :sessions
11
+ set :port, 3000
12
+ end
13
+
14
+ get '/callback*' do
15
+ if params['state'] != "qweqwe"
16
+ logger.info "qwe"
17
+ raise Exception.new("Bogus redirect, wrong state")
18
+ end
19
+
20
+ token_hash = connection.obtain_access_token(params['code'])
21
+ request.session['figo_token'] = token_hash['access_token']
22
+
23
+ redirect to('/')
24
+ end
25
+
26
+ get '/logout' do
27
+ request.session['figo_token'] = nil
28
+ redirect to('/')
29
+ end
30
+
31
+ before '/' do
32
+ logger.info request.path_info
33
+ unless session[:figo_token] or request.path_info == "/callback" then
34
+ redirect to(connection.login_url("qweqwe", "accounts=ro transactions=ro balance=ro user=ro"))
35
+ end
36
+ end
37
+
38
+ get '/:account_id' do | account_id |
39
+ session = Figo::Session.new(request.session['figo_token'])
40
+ @accounts = session.accounts
41
+ @current_account = session.get_account(account_id)
42
+ @transactions = @current_account.transactions
43
+ @user = session.user
44
+
45
+ erb :index
46
+ end
47
+
48
+ get '/' do
49
+ session = Figo::Session.new(request.session['figo_token'])
50
+ @accounts = session.accounts
51
+ @current_account = nil
52
+ @transactions = session.transactions
53
+ @user = session.user
54
+
55
+ erb :index
56
+ end
@@ -0,0 +1 @@
1
+ body { padding-top: 70px; }
Binary file
@@ -0,0 +1,41 @@
1
+ <div class="container-fluid" role="main">
2
+ <h1><%= @current_account.nil? ? "Unified Inbox" : @current_account.name %></h1>
3
+
4
+ <% if @current_account %>
5
+ <div class="panel panel-default">
6
+ <div class="panel-heading">Account Details</div>
7
+ <div class="panel-body">
8
+ <ul class="list-group">
9
+ <li class="list-group-item">Owner: <%= @current_account.owner %></li>
10
+ <li class="list-group-item">Account Number: <%= @current_account.account_number %></li>
11
+ <li class="list-group-item">Bank Code: <%= @current_account.bank_code %></li>
12
+ <li class="list-group-item">IBAN: <%= @current_account.iban %></li>
13
+ <li class="list-group-item">Balance: <%= @current_account.balance.balance %> <%= @current_account.currency %></li>
14
+ </ul>
15
+ </div>
16
+ </div>
17
+ <% end %>
18
+
19
+ <table class="table table-hover table-condensed">
20
+ <thead><tr>
21
+ <th>Date</th>
22
+ <th>Name</th>
23
+ <th>Account Number</th>
24
+ <th>Purpose</th>
25
+ <th style="text-align: right;">Amount</th>
26
+ </tr></thead>
27
+ <tbody>
28
+ <% if @transactions %>
29
+ <% @transactions.each do |transaction| %>
30
+ <tr>
31
+ <td><%= transaction.value_date %></td>
32
+ <td><%= transaction.name %></td>
33
+ <td><%= transaction.account_number %></td>
34
+ <td><%= transaction.purpose %></td>
35
+ <td style="text-align: right; <% if transaction.amount < 0 %>color: red;<% end %>"><%= transaction.amount %></td>
36
+ </tr>
37
+ <% end %>
38
+ <% end %>
39
+ </tbody>
40
+ </table>
41
+ </div>
@@ -0,0 +1,53 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>figo web banking</title>
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+
7
+ <!-- Bootstrap -->
8
+ <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
9
+
10
+ <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
11
+ <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
12
+ <!--[if lt IE 9]>
13
+ <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
14
+ <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
15
+ <![endif]-->
16
+
17
+ <link href="/favicon.ico" rel="shortcut icon" />
18
+ <link href="/banking.css" rel="stylesheet" media="screen" />
19
+
20
+ </head>
21
+ <body>
22
+ <div class="container">
23
+ <div class="navbar navbar-default" role="navigation">
24
+ <div class="navbar-header">
25
+ <a class="navbar-brand" href="/">figo web banking</a>
26
+ </div>
27
+ <div class="navbar-collapse collapse">
28
+ <ul class="nav navbar-nav">
29
+ <li <% if @current_account.nil? %> class="active"<% end %>><a href="/">Unified Inbox</a></li>
30
+ <% @accounts.each do |account| %>
31
+ <li <% if !@current_account.nil? and @current_account.account_id == account.account_id %>class="active" <% end %>><a href="/<%= account.account_id %>"><%= account.name %></a></li>
32
+ <% end %>
33
+ </ul>
34
+ <p class="navbar-text navbar-right">Signed in as <a href="/logout" class="navbar-link"><%= @user.email %></a></p>
35
+ </div><!--/.nav-collapse -->
36
+ </div>
37
+
38
+ <div>
39
+ <%if @error then %>
40
+ <div class="alert alert-error"><%=@error%></div>
41
+ <% end %>
42
+ <%= yield %>
43
+ </div>
44
+
45
+ </div>
46
+
47
+
48
+ <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
49
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
50
+ <!-- Include all compiled plugins (below), or include individual files as needed -->
51
+ <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
52
+ </body>
53
+ </html>
metadata CHANGED
@@ -1,48 +1,46 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: figo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Richter
8
- - Michael Haller
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-04-10 00:00:00.000000000 Z
11
+ date: 2014-07-11 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: flt
16
15
  requirement: !ruby/object:Gem::Requirement
17
16
  requirements:
18
- - - '>='
17
+ - - ! '>='
19
18
  - !ruby/object:Gem::Version
20
19
  version: '0'
21
20
  type: :runtime
22
21
  prerelease: false
23
22
  version_requirements: !ruby/object:Gem::Requirement
24
23
  requirements:
25
- - - '>='
24
+ - - ! '>='
26
25
  - !ruby/object:Gem::Version
27
26
  version: '0'
28
27
  - !ruby/object:Gem::Dependency
29
28
  name: net-http-persistent
30
29
  requirement: !ruby/object:Gem::Requirement
31
30
  requirements:
32
- - - '>='
31
+ - - ! '>='
33
32
  - !ruby/object:Gem::Version
34
33
  version: '0'
35
34
  type: :runtime
36
35
  prerelease: false
37
36
  version_requirements: !ruby/object:Gem::Requirement
38
37
  requirements:
39
- - - '>='
38
+ - - ! '>='
40
39
  - !ruby/object:Gem::Version
41
40
  version: '0'
42
- description: Library to easily use the API of http://www.figo.me
41
+ description: Library to easily use the API of http://figo.io
43
42
  email:
44
43
  - stefan.richter@figo.me
45
- - michael.haller@figo.me
46
44
  executables: []
47
45
  extensions: []
48
46
  extra_rdoc_files: []
@@ -52,11 +50,17 @@ files:
52
50
  - Gemfile
53
51
  - README.md
54
52
  - Rakefile
53
+ - console_demo.rb
55
54
  - figo.gemspec
56
55
  - lib/cacert.pem
57
56
  - lib/figo.rb
58
57
  - lib/models.rb
59
58
  - test/test_figo.rb
59
+ - web_demo/app.rb
60
+ - web_demo/public/banking.css
61
+ - web_demo/public/favicon.ico
62
+ - web_demo/views/index.erb
63
+ - web_demo/views/layout.erb
60
64
  homepage: https://github.com/figo-connect/ruby-figo
61
65
  licenses:
62
66
  - MIT
@@ -67,19 +71,18 @@ require_paths:
67
71
  - lib
68
72
  required_ruby_version: !ruby/object:Gem::Requirement
69
73
  requirements:
70
- - - '>='
74
+ - - ! '>='
71
75
  - !ruby/object:Gem::Version
72
76
  version: '0'
73
77
  required_rubygems_version: !ruby/object:Gem::Requirement
74
78
  requirements:
75
- - - '>='
79
+ - - ! '>='
76
80
  - !ruby/object:Gem::Version
77
81
  version: '0'
78
82
  requirements: []
79
83
  rubyforge_project:
80
- rubygems_version: 2.1.11
84
+ rubygems_version: 2.2.2
81
85
  signing_key:
82
86
  specification_version: 4
83
87
  summary: API wrapper for figo Connect.
84
- test_files:
85
- - test/test_figo.rb
88
+ test_files: []