money-hungarian-mnb 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rvmrc +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +20 -0
- data/Gemfile.lock +59 -0
- data/History.txt +7 -0
- data/LICENSE.txt +20 -0
- data/README.md +24 -0
- data/Rakefile +44 -0
- data/VERSION +1 -0
- data/lib/money-hungarian-mnb.rb +1 -0
- data/lib/money/bank/mnb.rb +109 -0
- data/lib/money_hungarian_mnb.rb +1 -0
- data/lib/money_mnb.rb +1 -0
- data/spec/fixtures/currencies.xml +79 -0
- data/spec/fixtures/rates.xml +40 -0
- data/spec/integration/with_money_api_spec.rb +26 -0
- data/spec/integration/with_wsdl_spec.rb +44 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/unit/money_bank_mnb_spec.rb +48 -0
- metadata +148 -0
data/.document
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use ruby-1.9.3@money-mnb
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem 'savon'
|
7
|
+
gem 'money'
|
8
|
+
|
9
|
+
# Add dependencies to develop your gem here.
|
10
|
+
# Include everything needed to run rake, tests, features, etc.
|
11
|
+
group :development do
|
12
|
+
gem "rdoc", "> 3.12"
|
13
|
+
gem "jeweler", "~> 1.8.4"
|
14
|
+
gem 'rake'
|
15
|
+
end
|
16
|
+
|
17
|
+
group :test do
|
18
|
+
gem 'rspec'
|
19
|
+
gem 'rspec-mocks'
|
20
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
akami (1.2.0)
|
5
|
+
gyoku (>= 0.4.0)
|
6
|
+
nokogiri (>= 1.4.0)
|
7
|
+
builder (3.2.0)
|
8
|
+
diff-lcs (1.2.1)
|
9
|
+
git (1.2.5)
|
10
|
+
gyoku (1.0.0)
|
11
|
+
builder (>= 2.1.2)
|
12
|
+
httpi (2.0.2)
|
13
|
+
rack
|
14
|
+
i18n (0.6.1)
|
15
|
+
jeweler (1.8.4)
|
16
|
+
bundler (~> 1.0)
|
17
|
+
git (>= 1.2.5)
|
18
|
+
rake
|
19
|
+
rdoc
|
20
|
+
json (1.7.7)
|
21
|
+
money (5.1.1)
|
22
|
+
i18n (~> 0.6.0)
|
23
|
+
nokogiri (1.5.6)
|
24
|
+
nori (2.0.3)
|
25
|
+
rack (1.5.2)
|
26
|
+
rake (10.0.3)
|
27
|
+
rdoc (4.0.0)
|
28
|
+
json (~> 1.4)
|
29
|
+
rspec (2.13.0)
|
30
|
+
rspec-core (~> 2.13.0)
|
31
|
+
rspec-expectations (~> 2.13.0)
|
32
|
+
rspec-mocks (~> 2.13.0)
|
33
|
+
rspec-core (2.13.0)
|
34
|
+
rspec-expectations (2.13.0)
|
35
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
36
|
+
rspec-mocks (2.13.0)
|
37
|
+
savon (2.1.0)
|
38
|
+
akami (~> 1.2.0)
|
39
|
+
builder (>= 2.1.2)
|
40
|
+
gyoku (~> 1.0.0)
|
41
|
+
httpi (~> 2.0.2)
|
42
|
+
nokogiri (>= 1.4.0)
|
43
|
+
nori (~> 2.0.3)
|
44
|
+
wasabi (~> 3.0.0)
|
45
|
+
wasabi (3.0.0)
|
46
|
+
httpi (~> 2.0)
|
47
|
+
nokogiri (>= 1.4.0)
|
48
|
+
|
49
|
+
PLATFORMS
|
50
|
+
ruby
|
51
|
+
|
52
|
+
DEPENDENCIES
|
53
|
+
jeweler (~> 1.8.4)
|
54
|
+
money
|
55
|
+
rake
|
56
|
+
rdoc (> 3.12)
|
57
|
+
rspec
|
58
|
+
rspec-mocks
|
59
|
+
savon
|
data/History.txt
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Gabor Garami
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# money-hungarian-mnb
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/hron84/money-hungarian-mnb.png?branch=master)](https://travis-ci.org/hron84/money-hungarian-mnb)
|
4
|
+
|
5
|
+
This gem is provides integration for [money gem](https://github.com/RubyMoney/money) with [Hungarian National Bank](http://english.mnb.hu/) (Magyar Nemzeti Bank).
|
6
|
+
|
7
|
+
This library is uses the SOAP web service provided by the bank and supports all currencies what is supported by the bank plus Hungarian Forint. To see the full list
|
8
|
+
of supported currencies please check the [daily exchange rates](http://english.mnb.hu/arfolyamok) page.
|
9
|
+
|
10
|
+
## Contributing to money-hungarian-mnb
|
11
|
+
|
12
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
13
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
14
|
+
* Fork the project.
|
15
|
+
* Start a feature/bugfix branch.
|
16
|
+
* Commit and push until you are happy with your contribution.
|
17
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
18
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
19
|
+
|
20
|
+
## Copyright
|
21
|
+
|
22
|
+
Copyright (c) 2013 Gabor Garami. See LICENSE.txt for
|
23
|
+
further details.
|
24
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
|
6
|
+
begin
|
7
|
+
Bundler.setup(:default, :development)
|
8
|
+
rescue Bundler::BundlerError => e
|
9
|
+
$stderr.puts e.message
|
10
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
11
|
+
exit e.status_code
|
12
|
+
end
|
13
|
+
require 'rake'
|
14
|
+
|
15
|
+
require 'jeweler'
|
16
|
+
Jeweler::Tasks.new do |gem|
|
17
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
18
|
+
gem.name = "money-hungarian-mnb"
|
19
|
+
gem.homepage = "http://github.com/hron84/money-hungarian-mnb"
|
20
|
+
gem.license = "MIT"
|
21
|
+
gem.summary = %Q{Hungarian National Bank integration for Money gem}
|
22
|
+
gem.description = %Q{The gem provides integration for Money gem with webservice provided by Hungarian National Bank}
|
23
|
+
gem.email = "hron@hron.me"
|
24
|
+
gem.authors = ["Gabor Garami"]
|
25
|
+
# dependencies defined in Gemfile
|
26
|
+
end
|
27
|
+
|
28
|
+
Jeweler::RubygemsDotOrgTasks.new
|
29
|
+
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
RSpec::Core::RakeTask.new
|
32
|
+
|
33
|
+
|
34
|
+
task :default => :spec
|
35
|
+
|
36
|
+
require 'rdoc/task'
|
37
|
+
Rake::RDocTask.new do |rdoc|
|
38
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
39
|
+
|
40
|
+
rdoc.rdoc_dir = 'rdoc'
|
41
|
+
rdoc.title = "money-hungarian-mnb #{version}"
|
42
|
+
rdoc.rdoc_files.include('README*')
|
43
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
44
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'money/bank/mnb'
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'savon'
|
2
|
+
|
3
|
+
class Money
|
4
|
+
module Bank
|
5
|
+
class MNB < Money::Bank::VariableExchange
|
6
|
+
WSDL_URL = 'http://www.mnb.hu/arfolyamok.asmx?WSDL'
|
7
|
+
|
8
|
+
VERSION = File.read(File.expand_path('../../../', File.dirname(__FILE__)))
|
9
|
+
|
10
|
+
attr_reader :rates
|
11
|
+
|
12
|
+
def setup
|
13
|
+
HTTPI.log = false
|
14
|
+
@rates = {}
|
15
|
+
end
|
16
|
+
|
17
|
+
def flush_rates
|
18
|
+
mutex.synchronize do
|
19
|
+
@rates = {}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def flush_rate(from, to)
|
24
|
+
key = rate_key_for(from, to)
|
25
|
+
mutex.synchronize do
|
26
|
+
@rates.delete(key)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_rate(from, to)
|
31
|
+
mutex.synchronize do
|
32
|
+
@rates[rate_key_for(from, to)] ||= fetch_rate(from, to)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def fetch_rate(from, to)
|
37
|
+
from, to = Currency.wrap(from).iso_code.to_s, Currency.wrap(to).iso_code.to_s
|
38
|
+
|
39
|
+
# Providing usable error messages
|
40
|
+
raise UnknownRate, "Source currency '#{from}' is not known by this module" unless currencies.include?(from)
|
41
|
+
raise UnknownRate, "Target currency '#{to}' is not known by this module" unless currencies.include?(to)
|
42
|
+
|
43
|
+
rsp = fetch_rates_from_wsdl
|
44
|
+
|
45
|
+
doc = Nokogiri::XML.parse(rsp)
|
46
|
+
|
47
|
+
## Rates are specified in HUF, so we have to lookup both side before convert
|
48
|
+
## If any currency is HUF then it will be constant 1
|
49
|
+
from_rate = from == 'HUF' ? 1 : 0
|
50
|
+
to_rate = to == 'HUF' ? 1 : 0
|
51
|
+
|
52
|
+
doc.css('Rate').each do |rate|
|
53
|
+
curr = rate['curr']
|
54
|
+
next unless [from, to].include?(curr)
|
55
|
+
|
56
|
+
## XXX Bank provides exchange rates in hungarian number notation form!
|
57
|
+
value = rate.text.sub(',', '.').to_f
|
58
|
+
|
59
|
+
unit = rate['unit'].to_i
|
60
|
+
|
61
|
+
if curr == from
|
62
|
+
from_rate = value / unit
|
63
|
+
else
|
64
|
+
to_rate = value / unit
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
from_rate / to_rate
|
69
|
+
end
|
70
|
+
|
71
|
+
def currencies
|
72
|
+
@currencies ||= []
|
73
|
+
return @currencies unless @currencies.empty?
|
74
|
+
|
75
|
+
doc = Nokogiri::XML.parse fetch_currencies_from_wsdl
|
76
|
+
@currencies = doc.css('Curr').collect(&:text)
|
77
|
+
@currencies << 'HUF'
|
78
|
+
|
79
|
+
@currencies
|
80
|
+
end
|
81
|
+
|
82
|
+
def mnb_client
|
83
|
+
@client ||= Savon.client(:wsdl => WSDL_URL, :log => false)
|
84
|
+
end
|
85
|
+
|
86
|
+
def fetch_rates_from_wsdl
|
87
|
+
rsp = mnb_client.call :get_current_exchange_rates
|
88
|
+
|
89
|
+
raise UnknownRate, "Bank returned with an error response" unless rsp.success?
|
90
|
+
|
91
|
+
rsp.body[:get_current_exchange_rates_response][:get_current_exchange_rates_result]
|
92
|
+
end
|
93
|
+
|
94
|
+
def fetch_currencies_from_wsdl
|
95
|
+
rsp = mnb_client.call :get_info
|
96
|
+
|
97
|
+
raise UnknownRate, "Bank returned with an error response" unless rsp.success?
|
98
|
+
|
99
|
+
rsp.body[:get_info_response][:get_info_result]
|
100
|
+
end
|
101
|
+
|
102
|
+
private
|
103
|
+
|
104
|
+
def mutex
|
105
|
+
@mutex ||= Mutex.new
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'money/bank/mnb'
|
data/lib/money_mnb.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'money/bank/mnb'
|
@@ -0,0 +1,79 @@
|
|
1
|
+
<MNBCurrencies>
|
2
|
+
<Currencies>
|
3
|
+
<Curr>ATS</Curr>
|
4
|
+
<Curr>AUD</Curr>
|
5
|
+
<Curr>AUP</Curr>
|
6
|
+
<Curr>BEF</Curr>
|
7
|
+
<Curr>BGL</Curr>
|
8
|
+
<Curr>BGN</Curr>
|
9
|
+
<Curr>BRL</Curr>
|
10
|
+
<Curr>CAD</Curr>
|
11
|
+
<Curr>CHF</Curr>
|
12
|
+
<Curr>CNY</Curr>
|
13
|
+
<Curr>CYN</Curr>
|
14
|
+
<Curr>CZK</Curr>
|
15
|
+
<Curr>CSD</Curr>
|
16
|
+
<Curr>CSK</Curr>
|
17
|
+
<Curr>DDM</Curr>
|
18
|
+
<Curr>DEM</Curr>
|
19
|
+
<Curr>DKK</Curr>
|
20
|
+
<Curr>EEK</Curr>
|
21
|
+
<Curr>EGP</Curr>
|
22
|
+
<Curr>ESP</Curr>
|
23
|
+
<Curr>EUR</Curr>
|
24
|
+
<Curr>FIM</Curr>
|
25
|
+
<Curr>FRF</Curr>
|
26
|
+
<Curr>GBP</Curr>
|
27
|
+
<Curr>GHP</Curr>
|
28
|
+
<Curr>GRD</Curr>
|
29
|
+
<Curr>HKD</Curr>
|
30
|
+
<Curr>HRK</Curr>
|
31
|
+
<Curr>IDR</Curr>
|
32
|
+
<Curr>IEP</Curr>
|
33
|
+
<Curr>ILS</Curr>
|
34
|
+
<Curr>INR</Curr>
|
35
|
+
<Curr>ISK</Curr>
|
36
|
+
<Curr>ITL</Curr>
|
37
|
+
<Curr>JPY</Curr>
|
38
|
+
<Curr>KPW</Curr>
|
39
|
+
<Curr>KRW</Curr>
|
40
|
+
<Curr>KWD</Curr>
|
41
|
+
<Curr>LBP</Curr>
|
42
|
+
<Curr>LTL</Curr>
|
43
|
+
<Curr>LUF</Curr>
|
44
|
+
<Curr>LVL</Curr>
|
45
|
+
<Curr>MNT</Curr>
|
46
|
+
<Curr>MXN</Curr>
|
47
|
+
<Curr>MYR</Curr>
|
48
|
+
<Curr>NLG</Curr>
|
49
|
+
<Curr>NOK</Curr>
|
50
|
+
<Curr>NZD</Curr>
|
51
|
+
<Curr>OAL</Curr>
|
52
|
+
<Curr>OBL</Curr>
|
53
|
+
<Curr>OFR</Curr>
|
54
|
+
<Curr>ORB</Curr>
|
55
|
+
<Curr>PHP</Curr>
|
56
|
+
<Curr>PKR</Curr>
|
57
|
+
<Curr>PLN</Curr>
|
58
|
+
<Curr>PTE</Curr>
|
59
|
+
<Curr>ROL</Curr>
|
60
|
+
<Curr>RON</Curr>
|
61
|
+
<Curr>RSD</Curr>
|
62
|
+
<Curr>RUB</Curr>
|
63
|
+
<Curr>SDP</Curr>
|
64
|
+
<Curr>SEK</Curr>
|
65
|
+
<Curr>SGD</Curr>
|
66
|
+
<Curr>SIT</Curr>
|
67
|
+
<Curr>SKK</Curr>
|
68
|
+
<Curr>SUR</Curr>
|
69
|
+
<Curr>THB</Curr>
|
70
|
+
<Curr>TRY</Curr>
|
71
|
+
<Curr>UAH</Curr>
|
72
|
+
<Curr>USD</Curr>
|
73
|
+
<Curr>VND</Curr>
|
74
|
+
<Curr>XEU</Curr>
|
75
|
+
<Curr>XTR</Curr>
|
76
|
+
<Curr>YUD</Curr>
|
77
|
+
<Curr>ZAR</Curr>
|
78
|
+
</Currencies>
|
79
|
+
</MNBCurrencies>
|
@@ -0,0 +1,40 @@
|
|
1
|
+
<MNBCurrentExchangeRates>
|
2
|
+
<Day date="2013-02-25">
|
3
|
+
<Rate curr="AUD" unit="1">228,76</Rate>
|
4
|
+
<Rate curr="BGN" unit="1">150,41</Rate>
|
5
|
+
<Rate curr="BRL" unit="1">112,56</Rate>
|
6
|
+
<Rate curr="CAD" unit="1">217,06</Rate>
|
7
|
+
<Rate curr="CHF" unit="1">239,68</Rate>
|
8
|
+
<Rate curr="CNY" unit="1">35,65</Rate>
|
9
|
+
<Rate curr="CZK" unit="1">11,52</Rate>
|
10
|
+
<Rate curr="DKK" unit="1">39,44</Rate>
|
11
|
+
<Rate curr="EUR" unit="1">294,17</Rate>
|
12
|
+
<Rate curr="GBP" unit="1">336,5</Rate>
|
13
|
+
<Rate curr="HKD" unit="1">28,65</Rate>
|
14
|
+
<Rate curr="HRK" unit="1">38,77</Rate>
|
15
|
+
<Rate curr="IDR" unit="100">2,29</Rate>
|
16
|
+
<Rate curr="ILS" unit="1">59,76</Rate>
|
17
|
+
<Rate curr="INR" unit="1">4,12</Rate>
|
18
|
+
<Rate curr="ISK" unit="1">1,76</Rate>
|
19
|
+
<Rate curr="JPY" unit="100">236,72</Rate>
|
20
|
+
<Rate curr="KRW" unit="100">20,47</Rate>
|
21
|
+
<Rate curr="LTL" unit="1">85,23</Rate>
|
22
|
+
<Rate curr="LVL" unit="1">420,41</Rate>
|
23
|
+
<Rate curr="MXN" unit="1">17,49</Rate>
|
24
|
+
<Rate curr="MYR" unit="1">71,71</Rate>
|
25
|
+
<Rate curr="NOK" unit="1">39,47</Rate>
|
26
|
+
<Rate curr="NZD" unit="1">186,38</Rate>
|
27
|
+
<Rate curr="PHP" unit="1">5,46</Rate>
|
28
|
+
<Rate curr="PLN" unit="1">70,76</Rate>
|
29
|
+
<Rate curr="RON" unit="1">67,12</Rate>
|
30
|
+
<Rate curr="RSD" unit="1">2,64</Rate>
|
31
|
+
<Rate curr="RUB" unit="1">7,32</Rate>
|
32
|
+
<Rate curr="SEK" unit="1">34,82</Rate>
|
33
|
+
<Rate curr="SGD" unit="1">179,52</Rate>
|
34
|
+
<Rate curr="THB" unit="1">7,45</Rate>
|
35
|
+
<Rate curr="TRY" unit="1">123,46</Rate>
|
36
|
+
<Rate curr="UAH" unit="1">27,3</Rate>
|
37
|
+
<Rate curr="USD" unit="1">222,23</Rate>
|
38
|
+
<Rate curr="ZAR" unit="1">25,08</Rate>
|
39
|
+
</Day>
|
40
|
+
</MNBCurrentExchangeRates>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Money::Bank::MNB do
|
4
|
+
before(:each) do
|
5
|
+
@bank = Money::Bank::MNB.new
|
6
|
+
|
7
|
+
@bank.stub!(:mnb_client).and_return(nil)
|
8
|
+
|
9
|
+
@bank.stub!(:fetch_currencies_from_wsdl).and_return(File.read(FIXTURE_PATH + '/currencies.xml'))
|
10
|
+
@bank.stub!(:fetch_rates_from_wsdl).and_return(File.read(FIXTURE_PATH + '/rates.xml'))
|
11
|
+
|
12
|
+
Money.default_bank = @bank
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'integration with Money api' do
|
16
|
+
it 'should exchanges between USD and CAD' do
|
17
|
+
Money.new(100, 'USD').exchange_to('CAD').fractional.should eq 102
|
18
|
+
Money.new(102, 'CAD').exchange_to('USD').fractional.should eq 99 # rounding
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should exchanges currency with non-default unit' do
|
22
|
+
Money.new(10000, 'IDR').exchange_to('HUF').fractional.should eq 229 # base
|
23
|
+
Money.new(10000, 'IDR').exchange_to('USD').fractional.should eq 1 # another currency
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe Money::Bank::MNB do
|
5
|
+
|
6
|
+
|
7
|
+
before(:all) do
|
8
|
+
@bank = Money::Bank::MNB.new
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'currencies' do
|
12
|
+
it 'should not be blank' do
|
13
|
+
@bank.currencies.should_not be_blank
|
14
|
+
end
|
15
|
+
|
16
|
+
TESTED_CURRENCIES.each do |curr|
|
17
|
+
it "includes #{curr}" do
|
18
|
+
@bank.currencies.should be_include curr
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should not include unknown currency' do
|
23
|
+
@bank.currencies.should_not be_include 'ABC'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'exchange_rates' do
|
28
|
+
it 'should convert from USD to HUF' do
|
29
|
+
rate = @bank.get_rate 'USD', 'HUF'
|
30
|
+
rate.should > 10.0
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should convert from HUF to USD' do
|
34
|
+
rate = @bank.get_rate 'HUF', 'USD'
|
35
|
+
rate.should < 1.0
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should thows an exception for unknown currency' do
|
39
|
+
expect do
|
40
|
+
rate = @bank.get_rate 'ABC', 'HUF'
|
41
|
+
end.to raise_error Money::Currency::UnknownCurrency
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../lib', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
require 'rspec/autorun'
|
4
|
+
require 'money'
|
5
|
+
require 'money/bank/mnb'
|
6
|
+
|
7
|
+
FIXTURE_PATH = File.join(File.dirname(__FILE__), 'fixtures')
|
8
|
+
TESTED_CURRENCIES = %w(ATS AUD AUP BEF BGL BGN BRL CAD CHF CNY CYN CZK CSD CSK DDM DEM DKK EEK EGP ESP EUR FIM FRF GBP GHP GRD HKD HRK IDR IEP ILS INR ISK ITL JPY KPW KRW KWD LBP LTL LUF LVL MNT MXN MYR NLG NOK NZD OAL OBL OFR ORB PHP PKR PLN PTE ROL RON RSD RUB SDP SEK SGD SIT SKK SUR THB TRY UAH USD VND XEU XTR YUD ZAR)
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Money::Bank::MNB do
|
4
|
+
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@bank = Money::Bank::MNB.new
|
8
|
+
|
9
|
+
@bank.stub!(:mnb_client).and_return(nil)
|
10
|
+
|
11
|
+
@bank.stub!(:fetch_currencies_from_wsdl).and_return(File.read(FIXTURE_PATH + '/currencies.xml'))
|
12
|
+
@bank.stub!(:fetch_rates_from_wsdl).and_return(File.read(FIXTURE_PATH + '/rates.xml'))
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'currencies' do
|
16
|
+
it 'should not be blank' do
|
17
|
+
@bank.currencies.should_not be_blank
|
18
|
+
end
|
19
|
+
|
20
|
+
TESTED_CURRENCIES.each do |curr|
|
21
|
+
it "includes #{curr}" do
|
22
|
+
@bank.currencies.should be_include curr
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should not include unknown currency' do
|
27
|
+
@bank.currencies.should_not be_include 'ABC'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'exchange_rates' do
|
32
|
+
it 'should convert from USD to HUF' do
|
33
|
+
rate = @bank.get_rate 'USD', 'HUF'
|
34
|
+
rate.should eq 222.23
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should convert from HUF to USD' do
|
38
|
+
rate = @bank.get_rate 'HUF', 'USD'
|
39
|
+
rate.should eq 1 / 222.23
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should thows an exception for unknown currency' do
|
43
|
+
expect do
|
44
|
+
rate = @bank.get_rate 'ABC', 'HUF'
|
45
|
+
end.to raise_error Money::Currency::UnknownCurrency
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
metadata
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: money-hungarian-mnb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Gabor Garami
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: savon
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: money
|
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'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rdoc
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>'
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.12'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>'
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.12'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: jeweler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.8.4
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.8.4
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rake
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: The gem provides integration for Money gem with webservice provided by
|
95
|
+
Hungarian National Bank
|
96
|
+
email: hron@hron.me
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files:
|
100
|
+
- LICENSE.txt
|
101
|
+
- README.md
|
102
|
+
files:
|
103
|
+
- .document
|
104
|
+
- .rvmrc
|
105
|
+
- .travis.yml
|
106
|
+
- Gemfile
|
107
|
+
- Gemfile.lock
|
108
|
+
- History.txt
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- VERSION
|
113
|
+
- lib/money-hungarian-mnb.rb
|
114
|
+
- lib/money/bank/mnb.rb
|
115
|
+
- lib/money_hungarian_mnb.rb
|
116
|
+
- lib/money_mnb.rb
|
117
|
+
- spec/fixtures/currencies.xml
|
118
|
+
- spec/fixtures/rates.xml
|
119
|
+
- spec/integration/with_money_api_spec.rb
|
120
|
+
- spec/integration/with_wsdl_spec.rb
|
121
|
+
- spec/spec_helper.rb
|
122
|
+
- spec/unit/money_bank_mnb_spec.rb
|
123
|
+
homepage: http://github.com/hron84/money-hungarian-mnb
|
124
|
+
licenses:
|
125
|
+
- MIT
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
none: false
|
132
|
+
requirements:
|
133
|
+
- - ! '>='
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
requirements: []
|
143
|
+
rubyforge_project:
|
144
|
+
rubygems_version: 1.8.25
|
145
|
+
signing_key:
|
146
|
+
specification_version: 3
|
147
|
+
summary: Hungarian National Bank integration for Money gem
|
148
|
+
test_files: []
|