EGP_Rates 1.0.7 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/egp_rates/bank.rb +4 -4
- data/lib/egp_rates/faisal_bank.rb +5 -25
- data/lib/egp_rates.rb +0 -1
- data/spec/cassettes/FaisalBank.gz +0 -0
- data/spec/egp_rates/faisal_bank_spec.rb +30 -30
- data/spec/egp_rates_spec.rb +3 -3
- data/spec/spec_helper.rb +1 -0
- metadata +2 -4
- data/lib/egp_rates/saib.rb +0 -60
- data/spec/egp_rates/saib_spec.rb +0 -77
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e976dae1eab58fd31f597eea3578ccc57e7d3f8
|
4
|
+
data.tar.gz: a6dc1a5e24a3f346c2b76c94a9ccbcc7579e09a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e923542f46a4232deb29b55c8c8945453cb2682851e70cbfb9162964f5cfc1d168996f597f71d63a2bf27b8c19c0eb81ddbf178fbde38a56d93a318358f1106
|
7
|
+
data.tar.gz: 102830270b29082b200f8a5f909351ac82fa392387691768d685215809af46e58640f34012cda9578b5bdc450d52d4ff67585e994a0500802ccf2957b8b29991
|
data/lib/egp_rates/bank.rb
CHANGED
@@ -33,21 +33,21 @@ module EGPRates
|
|
33
33
|
when /UAE|EMIRATES|Dirham|AED/i then :AED
|
34
34
|
when /Australian/i then :AUD
|
35
35
|
when /Bahrain|BHD/i then :BHD
|
36
|
-
when /Canadian/i
|
36
|
+
when /Canadian|CANAD\. Dollar/i then :CAD
|
37
37
|
when /Swiss|CHF/i then :CHF
|
38
38
|
when /Chinese/ then :CNY
|
39
39
|
when /Danish/i then :DKK
|
40
40
|
when /Euro|EUR/i then :EUR
|
41
|
-
when /British|
|
41
|
+
when /British|Sterl.|GBP/i then :GBP
|
42
42
|
when /Jordanian/i then :JOD
|
43
43
|
when /Japanese|JPY|YEN/i then :JPY
|
44
44
|
when /Kuwait/i then :KWD
|
45
|
-
when /Norwegian
|
45
|
+
when /Norwegian|NORWEG\./i then :NOK
|
46
46
|
when /Omani/i then :OMR
|
47
47
|
when /Qatar/i then :QAR
|
48
48
|
when /SAR|Saudi/i then :SAR
|
49
49
|
when /Swidish|Swedish/i then :SEK
|
50
|
-
when /
|
50
|
+
when /U(\.)?S(\.)? Dollar|USD/i then :USD
|
51
51
|
else fail ResponseError, "Unknown currency #{currency}"
|
52
52
|
end
|
53
53
|
end
|
@@ -4,7 +4,7 @@ module EGPRates
|
|
4
4
|
class FaisalBank < EGPRates::Bank
|
5
5
|
def initialize
|
6
6
|
@sym = :FaisalBank
|
7
|
-
@uri = URI.parse('
|
7
|
+
@uri = URI.parse('https://online.faisalbank.com.eg/IB/.FIBUserServices/currencyXRate.do?op=getCurrencyExchangeRates&LangID=2')
|
8
8
|
end
|
9
9
|
|
10
10
|
# @return [Hash] of exchange rates for selling and buying
|
@@ -26,30 +26,10 @@ module EGPRates
|
|
26
26
|
# ...
|
27
27
|
# ]
|
28
28
|
def raw_exchange_rates
|
29
|
-
table_rows = Oga.parse_html(response.body).css('.
|
30
|
-
#
|
31
|
-
fail ResponseError, 'Unknown HTML' unless table_rows&.size == 13
|
32
|
-
table_rows.
|
33
|
-
cell.to_a.drop(2).map(&:text).map(&:strip)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
# Parse the #raw_exchange_rates returned in response
|
38
|
-
# @param [Array] of the raw_data scraped
|
39
|
-
# @return [Hash] of exchange rates for selling and buying
|
40
|
-
# {
|
41
|
-
# { sell: { SYM: rate }, { SYM: rate }, ... },
|
42
|
-
# { buy: { SYM: rate }, { SYM: rate }, ... }
|
43
|
-
# }
|
44
|
-
def parse(raw_data)
|
45
|
-
raw_data.each_with_object(sell: {}, buy: {}) do |row, result|
|
46
|
-
sell_rate = row[5].to_f
|
47
|
-
buy_rate = row[3].to_f
|
48
|
-
currency = row[1].to_sym
|
49
|
-
|
50
|
-
result[:sell][currency] = sell_rate
|
51
|
-
result[:buy][currency] = buy_rate
|
52
|
-
end
|
29
|
+
table_rows = Oga.parse_html(response.body).css('.Action-Table td')
|
30
|
+
# each currency of the 13 provided in 5 table data
|
31
|
+
fail ResponseError, 'Unknown HTML' unless table_rows&.size == 13 * 5
|
32
|
+
table_rows.map(&:text).map(&:strip).each_slice(5)
|
53
33
|
end
|
54
34
|
end
|
55
35
|
end
|
data/lib/egp_rates.rb
CHANGED
@@ -15,7 +15,6 @@ require 'egp_rates/banque_du_caire'
|
|
15
15
|
require 'egp_rates/suez_canal_bank'
|
16
16
|
require 'egp_rates/al_baraka_bank'
|
17
17
|
require 'egp_rates/al_ahli_bank_of_kuwait'
|
18
|
-
require 'egp_rates/saib'
|
19
18
|
require 'egp_rates/midb'
|
20
19
|
require 'egp_rates/ube'
|
21
20
|
require 'egp_rates/cae'
|
Binary file
|
@@ -36,11 +36,11 @@ describe EGPRates::FaisalBank do
|
|
36
36
|
EGPRates::ResponseError, 'Unknown HTML'
|
37
37
|
end
|
38
38
|
|
39
|
-
it 'returns <#Enumerator::Lazy> of
|
39
|
+
it 'returns <#Enumerator::Lazy> of 13 rows',
|
40
40
|
vcr: { cassette_name: :FaisalBank } do
|
41
|
-
|
42
|
-
expect(
|
43
|
-
expect(
|
41
|
+
enumerator = bank.send(:raw_exchange_rates)
|
42
|
+
expect(enumerator).to be_an Enumerator
|
43
|
+
expect(enumerator.size).to eq 13
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -49,37 +49,37 @@ describe EGPRates::FaisalBank do
|
|
49
49
|
|
50
50
|
it 'returns sell: hash of selling prices' do
|
51
51
|
expect(bank.send(:parse, raw_data)[:sell]).to match(
|
52
|
-
AED: 4.
|
53
|
-
CAD:
|
54
|
-
CHF:
|
55
|
-
DKK: 2.
|
56
|
-
EUR:
|
57
|
-
GBP:
|
58
|
-
JPY: 0.
|
59
|
-
KWD:
|
60
|
-
NOK:
|
61
|
-
QAR: 4.
|
62
|
-
SAR: 4.
|
63
|
-
SEK: 1.
|
64
|
-
USD:
|
52
|
+
AED: 4.2884,
|
53
|
+
CAD: 12.0616,
|
54
|
+
CHF: 15.7092,
|
55
|
+
DKK: 2.2495,
|
56
|
+
EUR: 16.7218,
|
57
|
+
GBP: 19.7899,
|
58
|
+
JPY: 0.140688,
|
59
|
+
KWD: 51.6902,
|
60
|
+
NOK: 1.8928,
|
61
|
+
QAR: 4.3251,
|
62
|
+
SAR: 4.2216,
|
63
|
+
SEK: 1.757,
|
64
|
+
USD: 15.75
|
65
65
|
)
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'returns buy: hash of buying prices' do
|
69
69
|
expect(bank.send(:parse, raw_data)[:buy]).to match(
|
70
|
-
AED: 4.
|
71
|
-
CAD:
|
72
|
-
CHF:
|
73
|
-
DKK: 2.
|
74
|
-
EUR:
|
75
|
-
GBP:
|
76
|
-
JPY: 0.
|
77
|
-
KWD:
|
78
|
-
NOK:
|
79
|
-
QAR: 4.
|
80
|
-
SAR: 4.
|
81
|
-
SEK: 1.
|
82
|
-
USD:
|
70
|
+
AED: 4.2611,
|
71
|
+
CAD: 11.932,
|
72
|
+
CHF: 15.5273,
|
73
|
+
DKK: 2.2224,
|
74
|
+
EUR: 16.5233,
|
75
|
+
GBP: 19.4796,
|
76
|
+
JPY: 0.139148,
|
77
|
+
KWD: 51.2409,
|
78
|
+
NOK: 1.8679,
|
79
|
+
QAR: 4.2983,
|
80
|
+
SAR: 4.151,
|
81
|
+
SEK: 1.7316,
|
82
|
+
USD: 15.65
|
83
83
|
)
|
84
84
|
end
|
85
85
|
end
|
data/spec/egp_rates_spec.rb
CHANGED
@@ -6,10 +6,10 @@ describe EGPRates do
|
|
6
6
|
let(:bank) { double(EGPRates::Bank) }
|
7
7
|
|
8
8
|
it 'calls #exchange_rates on all Bank Classes' do
|
9
|
-
expect(described_class).to receive(:const_get).exactly(
|
9
|
+
expect(described_class).to receive(:const_get).exactly(19).times
|
10
10
|
.and_return bank
|
11
|
-
expect(bank).to receive(:new).exactly(
|
12
|
-
expect(bank).to receive(:exchange_rates).exactly(
|
11
|
+
expect(bank).to receive(:new).exactly(19).times.and_return bank
|
12
|
+
expect(bank).to receive(:exchange_rates).exactly(19).times
|
13
13
|
|
14
14
|
described_class.exchange_rates
|
15
15
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: EGP_Rates
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ahmed Abdel-Razzak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -190,7 +190,6 @@ files:
|
|
190
190
|
- lib/egp_rates/midb.rb
|
191
191
|
- lib/egp_rates/nbe.rb
|
192
192
|
- lib/egp_rates/nbg.rb
|
193
|
-
- lib/egp_rates/saib.rb
|
194
193
|
- lib/egp_rates/suez_canal_bank.rb
|
195
194
|
- lib/egp_rates/ube.rb
|
196
195
|
- spec/cassettes/AAIB.gz
|
@@ -231,7 +230,6 @@ files:
|
|
231
230
|
- spec/egp_rates/midb_spec.rb
|
232
231
|
- spec/egp_rates/nbe_spec.rb
|
233
232
|
- spec/egp_rates/nbg_spec.rb
|
234
|
-
- spec/egp_rates/saib_spec.rb
|
235
233
|
- spec/egp_rates/suez_canal_bank_spec.rb
|
236
234
|
- spec/egp_rates/ube_spec.rb
|
237
235
|
- spec/egp_rates_spec.rb
|
data/lib/egp_rates/saib.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module EGPRates
|
3
|
-
# Société Arabe Internationale de Banque (SAIB)
|
4
|
-
class SAIB < EGPRates::Bank
|
5
|
-
def initialize
|
6
|
-
@sym = :SAIB
|
7
|
-
@uri = URI.parse('http://www.saib.com.eg/foreign-currencies/')
|
8
|
-
end
|
9
|
-
|
10
|
-
# @return [Hash] of exchange rates for selling and buying
|
11
|
-
# {
|
12
|
-
# { sell: { SYM: rate }, { SYM: rate }, ... },
|
13
|
-
# { buy: { SYM: rate }, { SYM: rate }, ... }
|
14
|
-
# }
|
15
|
-
def exchange_rates
|
16
|
-
@exchange_rates ||= parse(raw_exchange_rates)
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
# Send the request to the URL and retrun raw data of the response
|
22
|
-
# @return [Enumerator::Lazy] with the table row in HTML that evaluates to
|
23
|
-
# [
|
24
|
-
# [
|
25
|
-
# "\n", "USD", "\n", "1605.00", "\n", "1675.00", "\n"
|
26
|
-
# ], [
|
27
|
-
# \n", "\xC2\xA0EUR", "\n", "1698", "\n", "1773", "\n
|
28
|
-
# ]
|
29
|
-
# ...
|
30
|
-
# ]
|
31
|
-
#
|
32
|
-
def raw_exchange_rates
|
33
|
-
table_rows = Oga.parse_html(response.body).css('.cont table tbody tr')
|
34
|
-
# SAIB porvide 6 currencies on the home page but with header
|
35
|
-
# and an empty row in the end
|
36
|
-
fail ResponseError, 'Unknown HTML' unless table_rows&.size == 8
|
37
|
-
table_rows.lazy.drop(1).take(6).map(&:children).map do |cell|
|
38
|
-
cell.map(&:text)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
# Parse the #raw_exchange_rates returned in response
|
43
|
-
# @param [Array] of the raw_data scraped
|
44
|
-
# @return [Hash] of exchange rates for selling and buying
|
45
|
-
# {
|
46
|
-
# { sell: { SYM: rate }, { SYM: rate }, ... },
|
47
|
-
# { buy: { SYM: rate }, { SYM: rate }, ... }
|
48
|
-
# }
|
49
|
-
def parse(raw_data)
|
50
|
-
raw_data.each_with_object(sell: {}, buy: {}) do |row, result|
|
51
|
-
sell_rate = (row[5].to_f / 100).round(4)
|
52
|
-
buy_rate = (row[3].to_f / 100).round(4)
|
53
|
-
currency = row[1].gsub(/\xC2\xA0/n, '').to_sym
|
54
|
-
|
55
|
-
result[:sell][currency] = sell_rate
|
56
|
-
result[:buy][currency] = buy_rate
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
data/spec/egp_rates/saib_spec.rb
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
describe EGPRates::SAIB 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 6
|
8
|
-
expect(bank.exchange_rates[:sell].size).to eq 6
|
9
|
-
expect(bank.exchange_rates[:buy].keys).to include(
|
10
|
-
:CHF, :EUR, :GBP, :KWD, :SAR, :USD
|
11
|
-
)
|
12
|
-
expect(bank.exchange_rates[:sell].keys).to include(
|
13
|
-
:CHF, :EUR, :GBP, :KWD, :SAR, :USD
|
14
|
-
)
|
15
|
-
end
|
16
|
-
|
17
|
-
describe '.new' do
|
18
|
-
it 'initialize instance variables' do
|
19
|
-
expect(bank.sym).to eq :SAIB
|
20
|
-
expect(bank.instance_variable_get(:@uri)).to be_a URI
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe '#exchange_rates' do
|
25
|
-
it 'calls #parse with #raw_exchange_rates' do
|
26
|
-
expect(bank).to receive(:raw_exchange_rates)
|
27
|
-
expect(bank).to receive(:parse)
|
28
|
-
bank.exchange_rates
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe '#raw_exchange_rates' do
|
33
|
-
it 'raises ResponseError unless Net::HTTPSuccess', :no_vcr do
|
34
|
-
stub_request(:get, /.*saib.*/).to_return(body: '', status: 500)
|
35
|
-
expect { bank.send(:raw_exchange_rates) }.to raise_error\
|
36
|
-
EGPRates::ResponseError, '500'
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'raises ResponseError if HTML structure changed', :no_vcr do
|
40
|
-
stub_request(:get, /.*saib.*/).to_return(body: '', status: 200)
|
41
|
-
expect { bank.send(:raw_exchange_rates) }.to raise_error\
|
42
|
-
EGPRates::ResponseError, 'Unknown HTML'
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'returns <#Enumerator::Lazy> of 6 rows', vcr: { cassette_name: :SAIB } do
|
46
|
-
lazy_enumerator = bank.send(:raw_exchange_rates)
|
47
|
-
expect(lazy_enumerator).to be_a Enumerator::Lazy
|
48
|
-
expect(lazy_enumerator.size).to eq 6
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe '#parse', vcr: { cassette_name: :SAIB } do
|
53
|
-
let(:raw_data) { bank.send(:raw_exchange_rates) }
|
54
|
-
|
55
|
-
it 'returns sell: hash of selling prices' do
|
56
|
-
expect(bank.send(:parse, raw_data)[:sell]).to match(
|
57
|
-
CHF: 17.98,
|
58
|
-
EUR: 19.4,
|
59
|
-
GBP: 22.95,
|
60
|
-
KWD: 59.5,
|
61
|
-
SAR: 4.83,
|
62
|
-
USD: 18.15
|
63
|
-
)
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'returns buy: hash of buying prices' do
|
67
|
-
expect(bank.send(:parse, raw_data)[:buy]).to match(
|
68
|
-
CHF: 17.53,
|
69
|
-
EUR: 18.91,
|
70
|
-
GBP: 22.31,
|
71
|
-
KWD: 58.22,
|
72
|
-
SAR: 4.73,
|
73
|
-
USD: 17.75
|
74
|
-
)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|