EGP_Rates 0.1.0 → 0.2.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/aaib.rb +88 -0
- data/lib/egp_rates/cbe.rb +0 -2
- data/lib/egp_rates/cib.rb +76 -0
- data/lib/egp_rates.rb +3 -0
- data/spec/cassettes/AAIB.yml +1509 -0
- data/spec/cassettes/CIB.yml +58 -0
- data/spec/egp_rates/aaib_spec.rb +88 -0
- data/spec/egp_rates/cbe_spec.rb +2 -0
- data/spec/egp_rates/cib_spec.rb +92 -0
- data/spec/egp_rates/nbe_spec.rb +2 -0
- metadata +8 -2
@@ -0,0 +1,58 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: http://www.cibeg.com/_layouts/15/LINKDev.CIB.CurrenciesFunds/FundsCurrencies.aspx/GetCurrencies
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"lang":"en"}'
|
9
|
+
headers:
|
10
|
+
Content-Type:
|
11
|
+
- application/json
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
14
|
+
Accept:
|
15
|
+
- "*/*"
|
16
|
+
User-Agent:
|
17
|
+
- Ruby
|
18
|
+
Host:
|
19
|
+
- www.cibeg.com
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 200
|
23
|
+
message: OK
|
24
|
+
headers:
|
25
|
+
Cache-Control:
|
26
|
+
- private, max-age=0
|
27
|
+
Content-Type:
|
28
|
+
- application/json; charset=utf-8
|
29
|
+
Vary:
|
30
|
+
- Accept-Encoding
|
31
|
+
Server:
|
32
|
+
- ''
|
33
|
+
X-Sharepointhealthscore:
|
34
|
+
- '0'
|
35
|
+
Sprequestguid:
|
36
|
+
- bbcab69d-7775-603d-69e8-36d340f9fb56
|
37
|
+
Request-Id:
|
38
|
+
- bbcab69d-7775-603d-69e8-36d340f9fb56
|
39
|
+
X-Frame-Options:
|
40
|
+
- SAMEORIGIN
|
41
|
+
Sprequestduration:
|
42
|
+
- '16'
|
43
|
+
Spiislatency:
|
44
|
+
- '0'
|
45
|
+
X-Content-Type-Options:
|
46
|
+
- nosniff
|
47
|
+
X-Ms-Invokeapp:
|
48
|
+
- 1; RequireReadOnly
|
49
|
+
Date:
|
50
|
+
- Sat, 12 Nov 2016 21:43:33 GMT
|
51
|
+
Content-Length:
|
52
|
+
- '336'
|
53
|
+
body:
|
54
|
+
encoding: ASCII-8BIT
|
55
|
+
string: '{"d":[{"__type":"LINKDev.CIB.CurrenciesFunds.CIBFund.CurrencyObject","CurrencyID":"USD","BuyRate":15.9,"SellRate":16.05},{"__type":"LINKDev.CIB.CurrenciesFunds.CIBFund.CurrencyObject","CurrencyID":"EUR","BuyRate":17.1904,"SellRate":17.5234},{"__type":"LINKDev.CIB.CurrenciesFunds.CIBFund.CurrencyObject","CurrencyID":"GBP","BuyRate":19.9359,"SellRate":20.292},{"__type":"LINKDev.CIB.CurrenciesFunds.CIBFund.CurrencyObject","CurrencyID":"CHF","BuyRate":16.0433,"SellRate":16.3176},{"__type":"LINKDev.CIB.CurrenciesFunds.CIBFund.CurrencyObject","CurrencyID":"SAR","BuyRate":4.2327,"SellRate":4.281},{"__type":"LINKDev.CIB.CurrenciesFunds.CIBFund.CurrencyObject","CurrencyID":"KWD","BuyRate":52.2074,"SellRate":53.0018}]}'
|
56
|
+
http_version:
|
57
|
+
recorded_at: Sat, 12 Nov 2016 21:48:36 GMT
|
58
|
+
recorded_with: VCR 3.0.3
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
describe EGPRates::AAIB 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 :AAIB
|
14
|
+
expect(bank.instance_variable_get(:@uri)).to be_a URI
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#exchange_rates', vcr: { cassette_name: :AAIB } 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, /.*aaib.*/).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, /.*aaib.*/).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', vcr: { cassette_name: :AAIB } do
|
40
|
+
lazy_enumerator = bank.send(:raw_exchange_rates)
|
41
|
+
expect(lazy_enumerator).to be_a Enumerator::Lazy
|
42
|
+
expect(lazy_enumerator.size).to eq 7
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#currency_symbol' do
|
47
|
+
%w(US EURO STERLING SWISS SAUDI KUWAIT DIRHAM)\
|
48
|
+
.each do |currency|
|
49
|
+
it "returns currency :SYM for #{currency}" do
|
50
|
+
symbols = %i(USD EUR GBP CHF SAR KWD AED)
|
51
|
+
expect(symbols).to include(bank.send(:currency_symbol, currency))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'raises ResponseError when Unknown Currency' do
|
56
|
+
expect { bank.send(:currency_symbol, 'EGYPTIAN POUND') }.to raise_error\
|
57
|
+
EGPRates::ResponseError, 'Unknown currency EGYPTIAN POUND'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#parse', vcr: { cassette_name: :AAIB } do
|
62
|
+
let(:raw_data) { bank.send(:raw_exchange_rates) }
|
63
|
+
|
64
|
+
it 'returns sell: hash of selling prices' do
|
65
|
+
expect(bank.send(:parse, raw_data)[:sell]).to include(
|
66
|
+
AED: 4.3697,
|
67
|
+
CHF: 16.3259,
|
68
|
+
EUR: 17.5314,
|
69
|
+
GBP: 20.3402,
|
70
|
+
KWD: 53.2869,
|
71
|
+
SAR: 4.2797,
|
72
|
+
USD: 16.05
|
73
|
+
)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'returns buy: hash of buying prices' do
|
77
|
+
expect(bank.send(:parse, raw_data)[:buy]).to include(
|
78
|
+
AED: 4.3043,
|
79
|
+
CHF: 16.0687,
|
80
|
+
EUR: 17.2213,
|
81
|
+
GBP: 19.9609,
|
82
|
+
KWD: 52.2056,
|
83
|
+
SAR: 4.2157,
|
84
|
+
USD: 15.9
|
85
|
+
)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/spec/egp_rates/cbe_spec.rb
CHANGED
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
describe EGPRates::CIB 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
|
+
end
|
10
|
+
|
11
|
+
describe '.new' do
|
12
|
+
it 'initialize instance variables' do
|
13
|
+
expect(bank.sym).to eq :CIB
|
14
|
+
expect(bank.instance_variable_get(:@uri)).to be_a URI
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#exchange_rates', vcr: { cassette_name: :CIB } 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(:post, /.*cib.*/).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 JSON respnonse changed', :no_vcr do
|
34
|
+
stub_request(:post, /.*cib.*/).to_return(
|
35
|
+
body: { d: { USD: 1 } }.to_json,
|
36
|
+
status: 200
|
37
|
+
)
|
38
|
+
expect { bank.send(:raw_exchange_rates) }.to raise_error\
|
39
|
+
EGPRates::ResponseError, /Unknown JSON/
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'raises ResponseError if empty JSON respnonse', :no_vcr do
|
43
|
+
stub_request(:post, /.*cib.*/).to_return(body: '"{}"', status: 200)
|
44
|
+
expect { bank.send(:raw_exchange_rates) }.to raise_error\
|
45
|
+
EGPRates::ResponseError, /Unknown JSON/
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'raises ResponseError if malformed JSON respnonse', :no_vcr do
|
49
|
+
stub_request(:post, /.*cib.*/).to_return(body: '{ data', status: 200)
|
50
|
+
expect { bank.send(:raw_exchange_rates) }.to raise_error\
|
51
|
+
EGPRates::ResponseError, /Unknown JSON/
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'raises ResponseError if empty respnonse', :no_vcr do
|
55
|
+
stub_request(:post, /.*cib.*/).to_return(body: '""', status: 200)
|
56
|
+
expect { bank.send(:raw_exchange_rates) }.to raise_error\
|
57
|
+
EGPRates::ResponseError, /Unknown JSON/
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'returns Hash of 6 currencies rates', vcr: { cassette_name: :CIB } do
|
61
|
+
response = bank.send(:raw_exchange_rates)
|
62
|
+
expect(response.size).to eq 1
|
63
|
+
expect(response['d'].size).to eq 6
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#parse', vcr: { cassette_name: :CIB } do
|
68
|
+
let(:raw_data) { bank.send(:raw_exchange_rates) }
|
69
|
+
|
70
|
+
it 'returns sell: hash of selling prices' do
|
71
|
+
expect(bank.send(:parse, raw_data)[:sell]).to include(
|
72
|
+
CHF: 16.3176,
|
73
|
+
EUR: 17.5234,
|
74
|
+
GBP: 20.292,
|
75
|
+
KWD: 53.0018,
|
76
|
+
SAR: 4.281,
|
77
|
+
USD: 16.05
|
78
|
+
)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'returns buy: hash of buying prices' do
|
82
|
+
expect(bank.send(:parse, raw_data)[:buy]).to include(
|
83
|
+
CHF: 16.0433,
|
84
|
+
EUR: 17.1904,
|
85
|
+
GBP: 19.9359,
|
86
|
+
KWD: 52.2074,
|
87
|
+
SAR: 4.2327,
|
88
|
+
USD: 15.9
|
89
|
+
)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
data/spec/egp_rates/nbe_spec.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: 0.
|
4
|
+
version: 0.2.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: 2016-11-
|
11
|
+
date: 2016-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -172,13 +172,19 @@ extensions: []
|
|
172
172
|
extra_rdoc_files: []
|
173
173
|
files:
|
174
174
|
- lib/egp_rates.rb
|
175
|
+
- lib/egp_rates/aaib.rb
|
175
176
|
- lib/egp_rates/bank.rb
|
176
177
|
- lib/egp_rates/cbe.rb
|
178
|
+
- lib/egp_rates/cib.rb
|
177
179
|
- lib/egp_rates/nbe.rb
|
180
|
+
- spec/cassettes/AAIB.yml
|
178
181
|
- spec/cassettes/CBE.yml
|
182
|
+
- spec/cassettes/CIB.yml
|
179
183
|
- spec/cassettes/NBE.yml
|
184
|
+
- spec/egp_rates/aaib_spec.rb
|
180
185
|
- spec/egp_rates/bank_spec.rb
|
181
186
|
- spec/egp_rates/cbe_spec.rb
|
187
|
+
- spec/egp_rates/cib_spec.rb
|
182
188
|
- spec/egp_rates/nbe_spec.rb
|
183
189
|
- spec/egp_rates_spec.rb
|
184
190
|
- spec/spec_helper.rb
|