EGP_Rates 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/egp_rates.rb +9 -0
- data/lib/egp_rates/aaib.rb +5 -6
- data/lib/egp_rates/al_ahli_bank_of_kuwait.rb +61 -0
- data/lib/egp_rates/al_baraka_bank.rb +84 -0
- data/lib/egp_rates/bank.rb +36 -0
- data/lib/egp_rates/banque_du_caire.rb +66 -0
- data/lib/egp_rates/banque_misr.rb +69 -0
- data/lib/egp_rates/cae.rb +62 -0
- data/lib/egp_rates/cbe.rb +1 -20
- data/lib/egp_rates/cib.rb +2 -1
- data/lib/egp_rates/midb.rb +60 -0
- data/lib/egp_rates/nbe.rb +1 -2
- data/lib/egp_rates/saib.rb +62 -0
- data/lib/egp_rates/suez_canal_bank.rb +80 -0
- data/lib/egp_rates/ube.rb +59 -0
- data/spec/cassettes/AlAhliBankOfKuwait.yml +1379 -0
- data/spec/cassettes/AlBarakaBank.yml +308 -0
- data/spec/cassettes/BanqueDuCaire.yml +1475 -0
- data/spec/cassettes/BanqueMisr.yml +1327 -0
- data/spec/cassettes/CAE.yml +6098 -0
- data/spec/cassettes/MIDB.yml +507 -0
- data/spec/cassettes/SAIB.yml +567 -0
- data/spec/cassettes/SuezCanalBank.yml +1399 -0
- data/spec/cassettes/UBE.yml +69 -0
- data/spec/egp_rates/aaib_spec.rb +4 -4
- data/spec/egp_rates/al_ahli_bank_of_kuwait_spec.rb +76 -0
- data/spec/egp_rates/al_baraka_bank_spec.rb +89 -0
- data/spec/egp_rates/banque_du_caire_spec.rb +111 -0
- data/spec/egp_rates/banque_misr_spec.rb +119 -0
- data/spec/egp_rates/cae_spec.rb +93 -0
- data/spec/egp_rates/cbe_spec.rb +4 -4
- data/spec/egp_rates/cib_spec.rb +3 -3
- data/spec/egp_rates/midb_spec.rb +73 -0
- data/spec/egp_rates/nbe_spec.rb +3 -3
- data/spec/egp_rates/saib_spec.rb +77 -0
- data/spec/egp_rates/suez_canal_bank_spec.rb +102 -0
- data/spec/egp_rates/ube_spec.rb +71 -0
- data/spec/egp_rates_spec.rb +2 -0
- metadata +30 -3
@@ -0,0 +1,69 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://www.theubeg.com/fxRate
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
Host:
|
17
|
+
- www.theubeg.com
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: OK
|
22
|
+
headers:
|
23
|
+
Date:
|
24
|
+
- Sun, 20 Nov 2016 13:57:57 GMT
|
25
|
+
X-Frame-Options:
|
26
|
+
- DENY
|
27
|
+
- DENY
|
28
|
+
X-Content-Type-Options:
|
29
|
+
- nosniff
|
30
|
+
Pragma:
|
31
|
+
- No-cache
|
32
|
+
Cache-Control:
|
33
|
+
- No-cache
|
34
|
+
Content-Type:
|
35
|
+
- text/html; charset=UTF-8
|
36
|
+
Content-Language:
|
37
|
+
- en-US
|
38
|
+
Expires:
|
39
|
+
- Thu, 01 Dec 1994 16:00:00 GMT
|
40
|
+
Set-Cookie:
|
41
|
+
- JSESSIONID=0000voczDUbV3fcD4U5sPp2RMVa:-1; Path=/; HttpOnly
|
42
|
+
- citrix_ns_id=19/ahqMZs4qUxMp6BEbdtb53ERE0001; Domain=.theubeg.com; Path=/;
|
43
|
+
HttpOnly
|
44
|
+
- citrix_ns_id_.theubeg.com_%2F_wat=AAAAAAW0yxX6J1T8zu9wlCVd4qiIVspcF0PH4JuomAyWcs7iAw6yo88sPnalguQM9cIIl_vrw3HpPwHijHwrX1GgKiPo&;
|
45
|
+
Domain=.theubeg.com; Path=/; HttpOnly
|
46
|
+
Transfer-Encoding:
|
47
|
+
- chunked
|
48
|
+
body:
|
49
|
+
encoding: UTF-8
|
50
|
+
string: "\r\n\r\n<span class=\"normal\">Exchange Rates </span>\r\n <span>20
|
51
|
+
November 2016</span>\r\n <span class=\"normal\"><a href=\"#\" onclick=\"return
|
52
|
+
switchToService(2);\"><font size=\"4\">Funds</font></a></span>\r\n<table class=\"rates\"
|
53
|
+
style=\"width: 100%;height: 90%\">\r\n\t<tr>\r\n\t\t<th>Currency Name</th>\r\n\t\t<th>Code</th>\r\n\t\t<th>Buy
|
54
|
+
Rate</th>\r\n\t\t<th>Sell Rate</th>\r\n\t</tr>\r\n\t\r\n\t<tr>\r\n\t\t\r\n\t\t<td
|
55
|
+
style=\"text-align: left;\">U.S. Dollar</td>\r\n\t\t\r\n\t\t\t\t\t\t\t\t\t\t\r\n\t\t<td>USD</td>\r\n\t\t<td
|
56
|
+
style=\"text-align: right;\">17.28</td>\r\n\t\t<td style=\"text-align: right;\">17.55</td>\r\n\t</tr>\r\n\t\r\n\t<tr>\r\n\t\t\r\n\t\t<td
|
57
|
+
style=\"text-align: left;\">Euro</td>\r\n\t\t\r\n\t\t\t\t\t\t\t\t\t\t\r\n\t\t<td>EUR</td>\r\n\t\t<td
|
58
|
+
style=\"text-align: right;\">18.265</td>\r\n\t\t<td style=\"text-align: right;\">18.6644</td>\r\n\t</tr>\r\n\t\r\n\t<tr>\r\n\t\t\r\n\t\t<td
|
59
|
+
style=\"text-align: left;\">Sterling Pound</td>\r\n\t\t\r\n\t\t\t\t\t\t\t\t\t\t\r\n\t\t<td>GBP</td>\r\n\t\t<td
|
60
|
+
style=\"text-align: right;\">21.346</td>\r\n\t\t<td style=\"text-align: right;\">21.662</td>\r\n\t</tr>\r\n\t\r\n\t<tr>\r\n\t\t\r\n\t\t<td
|
61
|
+
style=\"text-align: left;\">Saudi Riyal</td>\r\n\t\t\r\n\t\t\t\t\t\t\t\t\t\t\r\n\t\t<td>SAR</td>\r\n\t\t<td
|
62
|
+
style=\"text-align: right;\">4.5836</td>\r\n\t\t<td style=\"text-align: right;\">4.6798</td>\r\n\t</tr>\r\n\t\r\n\t<tr>\r\n\t\t\r\n\t\t<td
|
63
|
+
style=\"text-align: left;\">Kuwaiti Dinar</td>\r\n\t\t\r\n\t\t\t\t\t\t\t\t\t\t\r\n\t\t<td>KWD</td>\r\n\t\t<td
|
64
|
+
style=\"text-align: right;\">56.6929</td>\r\n\t\t<td style=\"text-align: right;\">57.5599</td>\r\n\t</tr>\r\n\t\r\n\t<tr>\r\n\t\t\r\n\t\t<td
|
65
|
+
style=\"text-align: left;\">U.A.E. Dirham</td>\r\n\t\t\r\n\t\t\t\t\t\t\t\t\t\t\r\n\t\t<td>AED</td>\r\n\t\t<td
|
66
|
+
style=\"text-align: right;\">4.7046</td>\r\n\t\t<td style=\"text-align: right;\">4.778</td>\r\n\t</tr>\r\n\t\r\n</table>"
|
67
|
+
http_version:
|
68
|
+
recorded_at: Sun, 20 Nov 2016 13:57:59 GMT
|
69
|
+
recorded_with: VCR 3.0.3
|
data/spec/egp_rates/aaib_spec.rb
CHANGED
@@ -15,7 +15,7 @@ describe EGPRates::AAIB do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
describe '#exchange_rates'
|
18
|
+
describe '#exchange_rates' do
|
19
19
|
it 'calls #parse with #raw_exchange_rates' do
|
20
20
|
expect(bank).to receive(:raw_exchange_rates)
|
21
21
|
expect(bank).to receive(:parse)
|
@@ -44,7 +44,7 @@ describe EGPRates::AAIB do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
describe '#currency_symbol' do
|
47
|
-
%
|
47
|
+
%W(#{'US DOLLAR'} EURO STERLING SWISS SAUDI KUWAITI DIRHAM)\
|
48
48
|
.each do |currency|
|
49
49
|
it "returns currency :SYM for #{currency}" do
|
50
50
|
symbols = %i(USD EUR GBP CHF SAR KWD AED)
|
@@ -62,7 +62,7 @@ describe EGPRates::AAIB do
|
|
62
62
|
let(:raw_data) { bank.send(:raw_exchange_rates) }
|
63
63
|
|
64
64
|
it 'returns sell: hash of selling prices' do
|
65
|
-
expect(bank.send(:parse, raw_data)[:sell]).to
|
65
|
+
expect(bank.send(:parse, raw_data)[:sell]).to match(
|
66
66
|
AED: 4.3697,
|
67
67
|
CHF: 16.3259,
|
68
68
|
EUR: 17.5314,
|
@@ -74,7 +74,7 @@ describe EGPRates::AAIB do
|
|
74
74
|
end
|
75
75
|
|
76
76
|
it 'returns buy: hash of buying prices' do
|
77
|
-
expect(bank.send(:parse, raw_data)[:buy]).to
|
77
|
+
expect(bank.send(:parse, raw_data)[:buy]).to match(
|
78
78
|
AED: 4.3043,
|
79
79
|
CHF: 16.0687,
|
80
80
|
EUR: 17.2213,
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
describe EGPRates::AlAhliBankOfKuwait do
|
3
|
+
subject(:bank) { described_class.new }
|
4
|
+
|
5
|
+
it 'Live Testing', :live do
|
6
|
+
expect(bank.exchange_rates).to include(:buy, :sell)
|
7
|
+
expect(bank.exchange_rates[:buy].size).to eq 8
|
8
|
+
expect(bank.exchange_rates[:sell].size).to eq 8
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '.new' do
|
12
|
+
it 'initialize instance variables' do
|
13
|
+
expect(bank.sym).to eq :AlAhliBankOfKuwait
|
14
|
+
expect(bank.instance_variable_get(:@uri)).to be_a URI
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#exchange_rates' do
|
19
|
+
it 'calls #parse with #raw_exchange_rates' do
|
20
|
+
expect(bank).to receive(:raw_exchange_rates)
|
21
|
+
expect(bank).to receive(:parse)
|
22
|
+
bank.exchange_rates
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#raw_exchange_rates' do
|
27
|
+
it 'raises ResponseError unless Net::HTTPSuccess', :no_vcr do
|
28
|
+
stub_request(:get, /.*piraeusbank.*/).to_return(body: '', status: 500)
|
29
|
+
expect { bank.send(:raw_exchange_rates) }.to raise_error\
|
30
|
+
EGPRates::ResponseError, '500'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'raises ResponseError if HTML structure changed', :no_vcr do
|
34
|
+
stub_request(:get, /.*piraeusbank.*/).to_return(body: '', status: 200)
|
35
|
+
expect { bank.send(:raw_exchange_rates) }.to raise_error\
|
36
|
+
EGPRates::ResponseError, 'Unknown HTML'
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'returns <#Enumerator::Lazy> of 8 rows',
|
40
|
+
vcr: { cassette_name: :AlAhliBankOfKuwait } do
|
41
|
+
lazy_enumerator = bank.send(:raw_exchange_rates)
|
42
|
+
expect(lazy_enumerator).to be_a Enumerator::Lazy
|
43
|
+
expect(lazy_enumerator.size).to eq 8
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#parse', vcr: { cassette_name: :AlAhliBankOfKuwait } do
|
48
|
+
let(:raw_data) { bank.send(:raw_exchange_rates) }
|
49
|
+
|
50
|
+
it 'returns sell: hash of selling prices' do
|
51
|
+
expect(bank.send(:parse, raw_data)[:sell]).to match(
|
52
|
+
AED: 4.5063,
|
53
|
+
CHF: 16.3959,
|
54
|
+
EUR: 17.5281,
|
55
|
+
GBP: 20.4359,
|
56
|
+
JPY: 0.1492,
|
57
|
+
KWD: 54.3746,
|
58
|
+
SAR: 4.4138,
|
59
|
+
USD: 16.55
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'returns buy: hash of buying prices' do
|
64
|
+
expect(bank.send(:parse, raw_data)[:buy]).to match(
|
65
|
+
AED: 4.3965,
|
66
|
+
CHF: 15.9838,
|
67
|
+
EUR: 17.0948,
|
68
|
+
GBP: 19.9339,
|
69
|
+
JPY: 0.1455,
|
70
|
+
KWD: 53.0604,
|
71
|
+
SAR: 4.3071,
|
72
|
+
USD: 16.15
|
73
|
+
)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
describe EGPRates::AlBarakaBank do
|
3
|
+
subject(:bank) { described_class.new }
|
4
|
+
|
5
|
+
it 'Live Testing', :live do
|
6
|
+
expect(bank.exchange_rates).to include(:buy, :sell)
|
7
|
+
expect(bank.exchange_rates[:buy].size).to eq 7
|
8
|
+
expect(bank.exchange_rates[:sell].size).to eq 7
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '.new' do
|
12
|
+
it 'initialize instance variables' do
|
13
|
+
expect(bank.sym).to eq :AlBarakaBank
|
14
|
+
expect(bank.instance_variable_get(:@uri)).to be_a URI
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#exchange_rates' do
|
19
|
+
it 'calls #parse with #raw_exchange_rates' do
|
20
|
+
expect(bank).to receive(:raw_exchange_rates)
|
21
|
+
expect(bank).to receive(:parse)
|
22
|
+
bank.exchange_rates
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#raw_exchange_rates' do
|
27
|
+
it 'raises ResponseError unless Net::HTTPSuccess', :no_vcr do
|
28
|
+
stub_request(:get, /.*albaraka.*/).to_return(body: '', status: 500)
|
29
|
+
expect { bank.send(:raw_exchange_rates) }.to raise_error\
|
30
|
+
EGPRates::ResponseError, '500'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'raises ResponseError if HTML structure changed', :no_vcr do
|
34
|
+
stub_request(:get, /.*albaraka.*/).to_return(body: '', status: 200)
|
35
|
+
expect { bank.send(:raw_exchange_rates) }.to raise_error\
|
36
|
+
EGPRates::ResponseError, 'Unknown HTML'
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'returns <#Enumerator::Lazy> of 7 rows',
|
40
|
+
vcr: { cassette_name: :AlBarakaBank } do
|
41
|
+
lazy_enumerator = bank.send(:raw_exchange_rates)
|
42
|
+
expect(lazy_enumerator).to be_a Enumerator::Lazy
|
43
|
+
expect(lazy_enumerator.size).to eq 7
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#currency_symbol' do
|
48
|
+
%w(USD EURO GBP CHF JPY SAR BHD)\
|
49
|
+
.each do |currency|
|
50
|
+
it "returns currency :SYM for #{currency}" do
|
51
|
+
symbols = %i(USD EUR GBP CHF JPY SAR BHD)
|
52
|
+
expect(symbols).to include(bank.send(:currency_symbol, currency))
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'raises ResponseError when Unknown Currency' do
|
57
|
+
expect { bank.send(:currency_symbol, 'Egyptian pound') }.to raise_error\
|
58
|
+
EGPRates::ResponseError, 'Unknown currency Egyptian pound'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#parse', vcr: { cassette_name: :AlBarakaBank } do
|
63
|
+
let(:raw_data) { bank.send(:raw_exchange_rates) }
|
64
|
+
|
65
|
+
it 'returns sell: hash of selling prices' do
|
66
|
+
expect(bank.send(:parse, raw_data)[:sell]).to match(
|
67
|
+
BHD: 44.1132,
|
68
|
+
CHF: 16.6453,
|
69
|
+
EUR: 17.8711,
|
70
|
+
GBP: 20.7983,
|
71
|
+
JPY: 15.3206,
|
72
|
+
SAR: 4.4326,
|
73
|
+
USD: 16.500
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'returns buy: hash of buying prices' do
|
78
|
+
expect(bank.send(:parse, raw_data)[:buy]).to match(
|
79
|
+
BHD: 41.7382,
|
80
|
+
CHF: 15.6272,
|
81
|
+
EUR: 16.7232,
|
82
|
+
GBP: 19.5306,
|
83
|
+
JPY: 14.3099,
|
84
|
+
SAR: 4.1259,
|
85
|
+
USD: 15.960
|
86
|
+
)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
describe EGPRates::BanqueDuCaire do
|
3
|
+
subject(:bank) { described_class.new }
|
4
|
+
|
5
|
+
it 'Live Testing', :live do
|
6
|
+
expect(bank.exchange_rates).to include(:buy, :sell)
|
7
|
+
expect(bank.exchange_rates[:buy].size).to eq 17
|
8
|
+
expect(bank.exchange_rates[:sell].size).to eq 17
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '.new' do
|
12
|
+
it 'initialize instance variables' do
|
13
|
+
expect(bank.sym).to eq :BanqueDuCaire
|
14
|
+
expect(bank.instance_variable_get(:@uri)).to be_a URI
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#exchange_rates' do
|
19
|
+
it 'calls #parse with #raw_exchange_rates' do
|
20
|
+
expect(bank).to receive(:raw_exchange_rates)
|
21
|
+
expect(bank).to receive(:parse)
|
22
|
+
bank.exchange_rates
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#raw_exchange_rates' do
|
27
|
+
it 'raises ResponseError unless Net::HTTPSuccess', :no_vcr do
|
28
|
+
stub_request(:get, /.*banqueducaire.*/).to_return(body: '', status: 500)
|
29
|
+
expect { bank.send(:raw_exchange_rates) }.to raise_error\
|
30
|
+
EGPRates::ResponseError, '500'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'raises ResponseError if HTML structure changed', :no_vcr do
|
34
|
+
stub_request(:get, /.*banqueducaire.*/).to_return(body: '', status: 200)
|
35
|
+
expect { bank.send(:raw_exchange_rates) }.to raise_error\
|
36
|
+
EGPRates::ResponseError, 'Unknown HTML'
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'returns <#Enumerator::Lazy> of 17 rows',
|
40
|
+
vcr: { cassette_name: :BanqueDuCaire } do
|
41
|
+
lazy_enumerator = bank.send(:raw_exchange_rates)
|
42
|
+
expect(lazy_enumerator).to be_a Enumerator::Lazy
|
43
|
+
expect(lazy_enumerator.size).to eq 17
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#currency_symbol' do
|
48
|
+
%W(#{'US DOLLAR'} AUSTRALIAN BAHRAIN BRITISH CANADIAN DANISH EMIRATES EURO
|
49
|
+
JAPANESE JORDANIAN NORWEGIAN OMANI QATAR SAUDI KUWAITI SWISS SWEDISH)
|
50
|
+
.each do |currency|
|
51
|
+
it "returns currency :SYM for #{currency}" do
|
52
|
+
symbols = %i(USD AUD BHD GBP CAD DKK AED EUR CHF SEK JPY JOD NOK OMR QAR
|
53
|
+
SAR KWD)
|
54
|
+
expect(symbols).to include(bank.send(:currency_symbol, currency))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'raises ResponseError when Unknown Currency' do
|
59
|
+
expect { bank.send(:currency_symbol, 'EGYPTIAN POUND') }.to raise_error\
|
60
|
+
EGPRates::ResponseError, 'Unknown currency EGYPTIAN POUND'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#parse', vcr: { cassette_name: :BanqueDuCaire } do
|
65
|
+
let(:raw_data) { bank.send(:raw_exchange_rates) }
|
66
|
+
|
67
|
+
it 'returns sell: hash of selling prices' do
|
68
|
+
expect(bank.send(:parse, raw_data)[:sell]).to match(
|
69
|
+
AED: 4.4248,
|
70
|
+
AUD: 12.3971,
|
71
|
+
BHD: 43.139,
|
72
|
+
CAD: 12.0818,
|
73
|
+
CHF: 16.5378,
|
74
|
+
DKK: 2.3854,
|
75
|
+
EUR: 17.7499,
|
76
|
+
GBP: 20.5936,
|
77
|
+
JOD: 22.952,
|
78
|
+
JPY: 15.3302,
|
79
|
+
KWD: 53.662,
|
80
|
+
NOK: 1.9477,
|
81
|
+
OMR: 42.219,
|
82
|
+
QAR: 4.464,
|
83
|
+
SAR: 4.3351,
|
84
|
+
SEK: 1.8017,
|
85
|
+
USD: 16.25
|
86
|
+
)
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'returns buy: hash of buying prices' do
|
90
|
+
expect(bank.send(:parse, raw_data)[:buy]).to match(
|
91
|
+
AED: 4.174,
|
92
|
+
AUD: 11.5417,
|
93
|
+
BHD: 39.359,
|
94
|
+
CAD: 11.3309,
|
95
|
+
CHF: 15.5129,
|
96
|
+
DKK: 2.2338,
|
97
|
+
EUR: 16.6194,
|
98
|
+
GBP: 19.2197,
|
99
|
+
JOD: 21.394,
|
100
|
+
JPY: 14.3552,
|
101
|
+
KWD: 48.862,
|
102
|
+
NOK: 1.819,
|
103
|
+
OMR: 38.375,
|
104
|
+
QAR: 4.194,
|
105
|
+
SAR: 4.0501,
|
106
|
+
SEK: 1.6843,
|
107
|
+
USD: 15.35
|
108
|
+
)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
describe EGPRates::BanqueMisr do
|
3
|
+
subject(:bank) { described_class.new }
|
4
|
+
|
5
|
+
it 'Live Testing', :live do
|
6
|
+
expect(bank.exchange_rates).to include(:buy, :sell)
|
7
|
+
expect(bank.exchange_rates[:buy].size).to eq 17
|
8
|
+
expect(bank.exchange_rates[:sell].size).to eq 17
|
9
|
+
expect(bank.exchange_rates[:buy].keys).to include(
|
10
|
+
:USD, :AUD, :BHD, :GBP, :CAD, :DKK, :AED, :EUR, :CHF, :SEK,
|
11
|
+
:JPY, :JOD, :NOK, :OMR, :QAR, :SAR, :KWD
|
12
|
+
)
|
13
|
+
expect(bank.exchange_rates[:sell].keys).to include(
|
14
|
+
:USD, :AUD, :BHD, :GBP, :CAD, :DKK, :AED, :EUR, :CHF, :SEK,
|
15
|
+
:JPY, :JOD, :NOK, :OMR, :QAR, :SAR, :KWD
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '.new' do
|
20
|
+
it 'initialize instance variables' do
|
21
|
+
expect(bank.sym).to eq :BanqueMisr
|
22
|
+
expect(bank.instance_variable_get(:@uri)).to be_a URI
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#exchange_rates' do
|
27
|
+
it 'calls #parse with #raw_exchange_rates' do
|
28
|
+
expect(bank).to receive(:raw_exchange_rates)
|
29
|
+
expect(bank).to receive(:parse)
|
30
|
+
bank.exchange_rates
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#raw_exchange_rates' do
|
35
|
+
it 'raises ResponseError unless Net::HTTPSuccess', :no_vcr do
|
36
|
+
stub_request(:get, /.*banquemisr.*/).to_return(body: '', status: 500)
|
37
|
+
expect { bank.send(:raw_exchange_rates) }.to raise_error\
|
38
|
+
EGPRates::ResponseError, '500'
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'raises ResponseError if HTML structure changed', :no_vcr do
|
42
|
+
stub_request(:get, /.*banquemisr.*/).to_return(body: '', status: 200)
|
43
|
+
expect { bank.send(:raw_exchange_rates) }.to raise_error\
|
44
|
+
EGPRates::ResponseError, 'Unknown HTML'
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'returns <#Enumerator::Lazy> of 17 rows',
|
48
|
+
vcr: { cassette_name: :BanqueMisr } do
|
49
|
+
lazy_enumerator = bank.send(:raw_exchange_rates)
|
50
|
+
expect(lazy_enumerator).to be_a Enumerator::Lazy
|
51
|
+
expect(lazy_enumerator.size).to eq 17
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#currency_symbol' do
|
56
|
+
%W(#{'UAE DIRHAM'} AUSTRALIA BAHRAIN CANADA SWEDISH DENMARK EURO JAPAN SWISS
|
57
|
+
#{'GB POUND'} JORDANIAN KUWAIT NORWAY OMAN QATARI SAUDI #{'US DOLLAR'})
|
58
|
+
.each do |currency|
|
59
|
+
it "returns currency :SYM for #{currency}" do
|
60
|
+
symbols = %i(USD AUD BHD GBP CAD DKK AED EUR CHF SEK JPY JOD NOK OMR QAR
|
61
|
+
SAR KWD)
|
62
|
+
expect(symbols).to include(bank.send(:currency_symbol, currency))
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'raises ResponseError when Unknown Currency' do
|
67
|
+
expect { bank.send(:currency_symbol, 'EGYPTIAN POUND') }.to raise_error\
|
68
|
+
EGPRates::ResponseError, 'Unknown currency EGYPTIAN POUND'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '#parse', vcr: { cassette_name: :BanqueMisr } do
|
73
|
+
let(:raw_data) { bank.send(:raw_exchange_rates) }
|
74
|
+
|
75
|
+
it 'returns sell: hash of selling prices' do
|
76
|
+
expect(bank.send(:parse, raw_data)[:sell]).to match(
|
77
|
+
AED: 4.3294,
|
78
|
+
AUD: 12.1317,
|
79
|
+
BHD: 42.1928,
|
80
|
+
CAD: 11.8178,
|
81
|
+
CHF: 1.7622,
|
82
|
+
DKK: 2.334,
|
83
|
+
EUR: 17.3698,
|
84
|
+
GBP: 20.1527,
|
85
|
+
JOD: 22.4478,
|
86
|
+
JPY: 14.9963,
|
87
|
+
KWD: 52.534,
|
88
|
+
NOK: 1.9046,
|
89
|
+
OMR: 41.3147,
|
90
|
+
QAR: 4.3677,
|
91
|
+
SAR: 4.24,
|
92
|
+
SEK: 16.1754,
|
93
|
+
USD: 15.91
|
94
|
+
)
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'returns buy: hash of buying prices' do
|
98
|
+
expect(bank.send(:parse, raw_data)[:buy]).to match(
|
99
|
+
AED: 4.179,
|
100
|
+
AUD: 11.5524,
|
101
|
+
BHD: 40.6957,
|
102
|
+
CAD: 11.3309,
|
103
|
+
CHF: 1.6843,
|
104
|
+
DKK: 2.2338,
|
105
|
+
EUR: 16.6256,
|
106
|
+
GBP: 19.2289,
|
107
|
+
JOD: 21.6594,
|
108
|
+
JPY: 14.3552,
|
109
|
+
KWD: 50.5599,
|
110
|
+
NOK: 1.819,
|
111
|
+
OMR: 39.8339,
|
112
|
+
QAR: 4.2154,
|
113
|
+
SAR: 4.0927,
|
114
|
+
SEK: 15.5129,
|
115
|
+
USD: 15.35
|
116
|
+
)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|