cbr_currency 1.0.1
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 +7 -0
- data/.gitignore +2 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +75 -0
- data/LICENSE.txt +21 -0
- data/README.md +83 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/cbr_currency.gemspec +27 -0
- data/lib/cbr_currency.rb +24 -0
- data/lib/cbr_currency/configuration.rb +10 -0
- data/lib/cbr_currency/currency.rb +20 -0
- data/lib/cbr_currency/fetcher.rb +55 -0
- data/lib/cbr_currency/version.rb +3 -0
- metadata +118 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 97a3957e82823767137c63cc6ccdb499f13c7540
|
|
4
|
+
data.tar.gz: 04c23787857ae4104780c7f6bf21f451aced20e5
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 7b88f036be117164d1af9148f436630d6948d9109b5357f550f7bdb569dade479b0c83d981ba2e629c49c8e2d4bbc4cbe13a7e7f314df1f05f22d838e469e7f4
|
|
7
|
+
data.tar.gz: 6854558367f27080b8bfb54e9dc2024585e7153f6d6bcc294361a02b700bd2272df423fd8e03127ecbb30a066b2dc6561f3217da64de038b30e1144c86868d32
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2.2.1
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
cbr_currency (0.1.0)
|
|
5
|
+
logging
|
|
6
|
+
nokogiri
|
|
7
|
+
|
|
8
|
+
GEM
|
|
9
|
+
remote: https://rubygems.org/
|
|
10
|
+
specs:
|
|
11
|
+
addressable (2.3.8)
|
|
12
|
+
byebug (4.0.5)
|
|
13
|
+
columnize (= 0.9.0)
|
|
14
|
+
coderay (1.1.0)
|
|
15
|
+
columnize (0.9.0)
|
|
16
|
+
crack (0.4.2)
|
|
17
|
+
safe_yaml (~> 1.0.0)
|
|
18
|
+
diff-lcs (1.2.5)
|
|
19
|
+
docile (1.1.5)
|
|
20
|
+
json (1.8.3)
|
|
21
|
+
little-plugger (1.1.3)
|
|
22
|
+
logging (2.0.0)
|
|
23
|
+
little-plugger (~> 1.1)
|
|
24
|
+
multi_json (~> 1.10)
|
|
25
|
+
method_source (0.8.2)
|
|
26
|
+
mini_portile (0.6.2)
|
|
27
|
+
multi_json (1.11.2)
|
|
28
|
+
nokogiri (1.6.6.2)
|
|
29
|
+
mini_portile (~> 0.6.0)
|
|
30
|
+
pry (0.10.1)
|
|
31
|
+
coderay (~> 1.1.0)
|
|
32
|
+
method_source (~> 0.8.1)
|
|
33
|
+
slop (~> 3.4)
|
|
34
|
+
pry-byebug (3.1.0)
|
|
35
|
+
byebug (~> 4.0)
|
|
36
|
+
pry (~> 0.10)
|
|
37
|
+
rake (10.4.2)
|
|
38
|
+
rspec (3.3.0)
|
|
39
|
+
rspec-core (~> 3.3.0)
|
|
40
|
+
rspec-expectations (~> 3.3.0)
|
|
41
|
+
rspec-mocks (~> 3.3.0)
|
|
42
|
+
rspec-core (3.3.1)
|
|
43
|
+
rspec-support (~> 3.3.0)
|
|
44
|
+
rspec-expectations (3.3.0)
|
|
45
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
46
|
+
rspec-support (~> 3.3.0)
|
|
47
|
+
rspec-mocks (3.3.1)
|
|
48
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
49
|
+
rspec-support (~> 3.3.0)
|
|
50
|
+
rspec-support (3.3.0)
|
|
51
|
+
safe_yaml (1.0.4)
|
|
52
|
+
simplecov (0.10.0)
|
|
53
|
+
docile (~> 1.1.0)
|
|
54
|
+
json (~> 1.8)
|
|
55
|
+
simplecov-html (~> 0.10.0)
|
|
56
|
+
simplecov-html (0.10.0)
|
|
57
|
+
slop (3.6.0)
|
|
58
|
+
webmock (1.21.0)
|
|
59
|
+
addressable (>= 2.3.6)
|
|
60
|
+
crack (>= 0.3.2)
|
|
61
|
+
|
|
62
|
+
PLATFORMS
|
|
63
|
+
ruby
|
|
64
|
+
|
|
65
|
+
DEPENDENCIES
|
|
66
|
+
bundler (~> 1.10)
|
|
67
|
+
cbr_currency!
|
|
68
|
+
pry-byebug
|
|
69
|
+
rake (~> 10.0)
|
|
70
|
+
rspec
|
|
71
|
+
simplecov
|
|
72
|
+
webmock
|
|
73
|
+
|
|
74
|
+
BUNDLED WITH
|
|
75
|
+
1.10.5
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015 Petrova Y
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# CbrCurrency
|
|
2
|
+
|
|
3
|
+
Гем тащит курсы валют с [API ЦБ](http://www.cbr.ru/scripts/XML_daily.asp)
|
|
4
|
+
|
|
5
|
+
## Установка
|
|
6
|
+
|
|
7
|
+
В Gemfile:
|
|
8
|
+
|
|
9
|
+
gem 'cbr_currency'
|
|
10
|
+
|
|
11
|
+
Или вручную:
|
|
12
|
+
|
|
13
|
+
$ gem install cbr_currency
|
|
14
|
+
|
|
15
|
+
## Как пользоваться
|
|
16
|
+
|
|
17
|
+
CbrCurrency.call
|
|
18
|
+
|
|
19
|
+
Вернет коллекцию:
|
|
20
|
+
|
|
21
|
+
[
|
|
22
|
+
#<CbrCurrency::Currency:0x007fee0ca436c8 @code=:aud, @rate=42.4964, @title="Австралийский доллар", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
23
|
+
#<CbrCurrency::Currency:0x007fee0ca42d40 @code=:azn, @rate=54.5745, @title="Азербайджанский манат", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
24
|
+
#<CbrCurrency::Currency:0x007fee0ca42868 @code=:gbp, @rate=89.8108, @title="Фунт стерлингов Соединенного королевства", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
25
|
+
#<CbrCurrency::Currency:0x007fee0ca42368 @code=:amd, @rate=0.12002700000000001, @title="Армянских драмов", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
26
|
+
#<CbrCurrency::Currency:0x007fee0ca41e68 @code=:byr, @rate=0.00376734, @title="Белорусских рублей", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
27
|
+
#<CbrCurrency::Currency:0x007fee0ca41990 @code=:bgn, @rate=32.2162, @title="Болгарский лев", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
28
|
+
#<CbrCurrency::Currency:0x007fee0ca41328 @code=:brl, @rate=17.8047, @title="Бразильский реал", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
29
|
+
#<CbrCurrency::Currency:0x007fee0ca40e28 @code=:huf, @rate=0.20408400000000002, @title="Венгерских форинтов", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
30
|
+
#<CbrCurrency::Currency:0x007fee0ca40838 @code=:dkk, @rate=8.44503, @title="Датских крон", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
31
|
+
#<CbrCurrency::Currency:0x007fee0ca403d8 @code=:usd, @rate=57.3578, @title="Доллар США", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
32
|
+
#<CbrCurrency::Currency:0x007fee0ca408b0 @code=:eur, @rate=62.933, @title="Евро", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
33
|
+
#<CbrCurrency::Currency:0x007fee0ca3be50 @code=:inr, @rate=0.9006489999999999, @title="Индийских рупий", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
34
|
+
#<CbrCurrency::Currency:0x007fee0ca3b7c0 @code=:kzt, @rate=0.306628, @title="Казахстанских тенге", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
35
|
+
#<CbrCurrency::Currency:0x007fee0ca3ae38 @code=:cad, @rate=44.186, @title="Канадский доллар", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
36
|
+
#<CbrCurrency::Currency:0x007fee0ca3a758 @code=:kgs, @rate=0.915906, @title="Киргизских сомов", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
37
|
+
#<CbrCurrency::Currency:0x007fee0ca3a028 @code=:cny, @rate=9.23681, @title="Китайских юаней", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
38
|
+
#<CbrCurrency::Currency:0x007fee0ca39948 @code=:mdl, @rate=3.01091, @title="Молдавских леев", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
39
|
+
#<CbrCurrency::Currency:0x007fee0ca39380 @code=:nok, @rate=7.0343100000000005, @title="Норвежских крон", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
40
|
+
#<CbrCurrency::Currency:0x007fee0ca38ef8 @code=:pln, @rate=15.2633, @title="Польский злотый", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
41
|
+
#<CbrCurrency::Currency:0x007fee0ca38ac0 @code=:ron, @rate=14.2483, @title="Новый румынский лей", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
42
|
+
#<CbrCurrency::Currency:0x007fee0ca386b0 @code=:xdr, @rate=79.9017, @title="СДР (специальные права заимствования)", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
43
|
+
#<CbrCurrency::Currency:0x007fee0ca38200 @code=:sgd, @rate=41.9773, @title="Сингапурский доллар", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
44
|
+
#<CbrCurrency::Currency:0x007fee0ca39ec0 @code=:tjs, @rate=9.156740000000001, @title="Таджикских сомони", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
45
|
+
#<CbrCurrency::Currency:0x007fee0ca33e30 @code=:try, @rate=21.0657, @title="Турецкая лира", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
46
|
+
#<CbrCurrency::Currency:0x007fee0ca339d0 @code=:tmt, @rate=16.3983, @title="Новый туркменский манат", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
47
|
+
#<CbrCurrency::Currency:0x007fee0ca33480 @code=:uzs, @rate=0.0223182, @title="Узбекских сумов", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
48
|
+
#<CbrCurrency::Currency:0x007fee0ca32fd0 @code=:uah, @rate=2.59479, @title="Украинских гривен", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
49
|
+
#<CbrCurrency::Currency:0x007fee0ca32a80 @code=:czk, @rate=2.3301, @title="Чешских крон", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
50
|
+
#<CbrCurrency::Currency:0x007fee0ca325a8 @code=:sek, @rate=6.6945, @title="Шведских крон", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
51
|
+
#<CbrCurrency::Currency:0x007fee0ca32080 @code=:chf, @rate=60.1109, @title="Швейцарский франк", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
52
|
+
#<CbrCurrency::Currency:0x007fee0ca31bd0 @code=:zar, @rate=4.6228, @title="Южноафриканских рэндов", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
53
|
+
#<CbrCurrency::Currency:0x007fee0ca31630 @code=:krw, @rate=0.049388100000000004, @title="Вон Республики Корея", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>,
|
|
54
|
+
#<CbrCurrency::Currency:0x007fee0ca31180 @code=:jpy, @rate=0.46332900000000005, @title="Японских иен", @date=#<Date: 2015-07-24 ((2457228j,0s,0n),+0s,2299161j)>>]
|
|
55
|
+
|
|
56
|
+
`@rate` - это то, сколько надо заплатить рублей за 1 единицу иностранной валюты. Например, 1 евро стоит 62.39р, а 1 Вон Республики Корея стоит около 0.04р.
|
|
57
|
+
|
|
58
|
+
## Конфигурация
|
|
59
|
+
|
|
60
|
+
CbrCurrency.configure |config| do
|
|
61
|
+
config.cbr_uri = "www.example.com"
|
|
62
|
+
config.logger = mylogger
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
Ожидается, что по адресу `cbr_uri` будет xml вида
|
|
66
|
+
|
|
67
|
+
<ValCurs Date="24.07.2015" name="Foreign Currency Market">
|
|
68
|
+
<Valute ID="R01010">
|
|
69
|
+
<NumCode>036</NumCode>
|
|
70
|
+
<CharCode>AUD</CharCode>
|
|
71
|
+
<Nominal>1</Nominal>
|
|
72
|
+
<Name>Австралийский доллар</Name>
|
|
73
|
+
<Value>42,4964</Value>
|
|
74
|
+
</Valute>
|
|
75
|
+
</ValCurs>
|
|
76
|
+
|
|
77
|
+
По дефолту `cbr_uri = "http://www.cbr.ru/scripts/XML_daily.asp"`.
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
## License
|
|
81
|
+
|
|
82
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
|
83
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "cbr_currency"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'cbr_currency/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "cbr_currency"
|
|
8
|
+
spec.version = CbrCurrency::VERSION
|
|
9
|
+
spec.authors = ["Yana Petrova"]
|
|
10
|
+
spec.email = ["y.petrova@rambler-co.ru"]
|
|
11
|
+
|
|
12
|
+
spec.summary = "Fetches currency from CBR"
|
|
13
|
+
spec.description = "Fetches currency from CBR"
|
|
14
|
+
spec.homepage = "https://github.com/rambler-digital-solutions/cbr_currencies"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
18
|
+
spec.bindir = "exe"
|
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
20
|
+
spec.require_paths = ["lib"]
|
|
21
|
+
|
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
24
|
+
|
|
25
|
+
spec.add_dependency "nokogiri"
|
|
26
|
+
spec.add_dependency "logging"
|
|
27
|
+
end
|
data/lib/cbr_currency.rb
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'logging'
|
|
2
|
+
require 'cbr_currency/version'
|
|
3
|
+
require 'cbr_currency/fetcher'
|
|
4
|
+
require 'cbr_currency/currency'
|
|
5
|
+
require 'cbr_currency/configuration'
|
|
6
|
+
|
|
7
|
+
module CbrCurrency
|
|
8
|
+
class << self
|
|
9
|
+
attr_writer :configuration
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.configure
|
|
13
|
+
yield configuration
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.configuration
|
|
17
|
+
@configuration ||= Configuration.new
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.call
|
|
21
|
+
fetcher = CbrCurrency::Fetcher.new
|
|
22
|
+
fetcher.call
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module CbrCurrency
|
|
2
|
+
class Currency
|
|
3
|
+
attr_accessor :code, :rate, :title, :date
|
|
4
|
+
|
|
5
|
+
def initialize(code:, cost:, title:, amount: 1, date:)
|
|
6
|
+
raise ArgumentError.new("some of params (code, cost, title, amount) is nil") unless code && cost && title && date
|
|
7
|
+
|
|
8
|
+
@code = code.downcase.to_sym
|
|
9
|
+
@rate = normalize_rate cost, amount
|
|
10
|
+
@title = title
|
|
11
|
+
@date = Date.parse(date)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
def normalize_rate(cost, amount)
|
|
17
|
+
cost.gsub(',', '.').to_f / amount.to_f
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require 'nokogiri'
|
|
2
|
+
|
|
3
|
+
module CbrCurrency
|
|
4
|
+
class Fetcher
|
|
5
|
+
def call
|
|
6
|
+
xml = fetch_xml CbrCurrency.configuration.cbr_uri
|
|
7
|
+
return unless xml
|
|
8
|
+
|
|
9
|
+
currencies = fetch_currencies xml
|
|
10
|
+
normalized = currencies.map { |currency| extract_currency currency }
|
|
11
|
+
entities = normalized.map { |currency| Currency.new currency }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
def fetch_xml(uri)
|
|
17
|
+
uri = URI(uri)
|
|
18
|
+
file = Net::HTTP.get uri
|
|
19
|
+
|
|
20
|
+
Nokogiri::XML file
|
|
21
|
+
rescue *exceptions => e
|
|
22
|
+
CbrCurrency.configuration.logger.warn e
|
|
23
|
+
|
|
24
|
+
nil
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def fetch_currencies(xml)
|
|
28
|
+
xml.xpath("//Valute")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def extract_currency(xml)
|
|
32
|
+
code = xml.xpath("CharCode")
|
|
33
|
+
cost = xml.xpath("Value")
|
|
34
|
+
title = xml.xpath("Name")
|
|
35
|
+
amount = xml.xpath("Nominal")
|
|
36
|
+
date = xml.xpath("//ValCurs").attr("Date")
|
|
37
|
+
|
|
38
|
+
raise ArgumentError.new("incorrect xml structure") unless code && cost && title && amount && date
|
|
39
|
+
|
|
40
|
+
{
|
|
41
|
+
code: code.text,
|
|
42
|
+
cost: cost.text,
|
|
43
|
+
title: title.text,
|
|
44
|
+
amount: amount.text,
|
|
45
|
+
date: date.value
|
|
46
|
+
}
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def exceptions
|
|
50
|
+
[Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, Errno::ECONNREFUSED, EOFError,
|
|
51
|
+
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError,
|
|
52
|
+
Nokogiri::XML::SyntaxError]
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: cbr_currency
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Yana Petrova
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-07-28 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.10'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.10'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: nokogiri
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: logging
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
description: Fetches currency from CBR
|
|
70
|
+
email:
|
|
71
|
+
- y.petrova@rambler-co.ru
|
|
72
|
+
executables: []
|
|
73
|
+
extensions: []
|
|
74
|
+
extra_rdoc_files: []
|
|
75
|
+
files:
|
|
76
|
+
- ".gitignore"
|
|
77
|
+
- ".rspec"
|
|
78
|
+
- ".ruby-version"
|
|
79
|
+
- ".travis.yml"
|
|
80
|
+
- Gemfile
|
|
81
|
+
- Gemfile.lock
|
|
82
|
+
- LICENSE.txt
|
|
83
|
+
- README.md
|
|
84
|
+
- Rakefile
|
|
85
|
+
- bin/console
|
|
86
|
+
- bin/setup
|
|
87
|
+
- cbr_currency.gemspec
|
|
88
|
+
- lib/cbr_currency.rb
|
|
89
|
+
- lib/cbr_currency/configuration.rb
|
|
90
|
+
- lib/cbr_currency/currency.rb
|
|
91
|
+
- lib/cbr_currency/fetcher.rb
|
|
92
|
+
- lib/cbr_currency/version.rb
|
|
93
|
+
homepage: https://github.com/rambler-digital-solutions/cbr_currencies
|
|
94
|
+
licenses:
|
|
95
|
+
- MIT
|
|
96
|
+
metadata: {}
|
|
97
|
+
post_install_message:
|
|
98
|
+
rdoc_options: []
|
|
99
|
+
require_paths:
|
|
100
|
+
- lib
|
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
|
+
requirements:
|
|
103
|
+
- - ">="
|
|
104
|
+
- !ruby/object:Gem::Version
|
|
105
|
+
version: '0'
|
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - ">="
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0'
|
|
111
|
+
requirements: []
|
|
112
|
+
rubyforge_project:
|
|
113
|
+
rubygems_version: 2.4.5
|
|
114
|
+
signing_key:
|
|
115
|
+
specification_version: 4
|
|
116
|
+
summary: Fetches currency from CBR
|
|
117
|
+
test_files: []
|
|
118
|
+
has_rdoc:
|