cbr 0.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 +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +57 -0
- data/Rakefile +2 -0
- data/cbr.gemspec +25 -0
- data/lib/cbr.rb +42 -0
- data/lib/cbr/base.rb +21 -0
- data/lib/cbr/catalog.rb +9 -0
- data/lib/cbr/catalog_item.rb +13 -0
- data/lib/cbr/daily/collection.rb +19 -0
- data/lib/cbr/daily/core.rb +9 -0
- data/lib/cbr/daily/item.rb +22 -0
- data/lib/cbr/dynamic/collection.rb +13 -0
- data/lib/cbr/dynamic/core.rb +9 -0
- data/lib/cbr/dynamic/item.rb +18 -0
- data/lib/cbr/version.rb +3 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ac4b56fdca236e0721b1aab94dc3a96488806289
|
4
|
+
data.tar.gz: b5cb99a2ab9280a8e6fe38decfb661f76df10595
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7540374e609160a43952c0d8116e9d9ace9dc657c24c45e315ada56c6b782a6eaf90c8e3546d5405ee27e2cfc652d59d849c69f3b408d99b687ef8e6dc83f93e
|
7
|
+
data.tar.gz: 41cb481b87f926ae11a1e935eebce50f73959bacbdf647027aded294d7d0c2dcd2272696618627ab5cb5341d9b3dd30dec81b688dc502050b63a42b213b6aecb
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Andrey Deryabin
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# CBR
|
2
|
+
|
3
|
+
Ruby wrapper for The Central Bank of the Russian Federation API
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'cbr'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install cbr
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Reference currency codes
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
CBR.catalog
|
27
|
+
```
|
28
|
+
|
29
|
+
Extract a quotation for a current day
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
CBR.daily
|
33
|
+
```
|
34
|
+
|
35
|
+
Extract a quatation for a specific day:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
CBR.daily(Date.parse('12/12/2014'))
|
39
|
+
```
|
40
|
+
|
41
|
+
Extract currency for a specific day:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
CBR.daily(Date.parse('12/12/2014'))['usd']
|
45
|
+
```
|
46
|
+
|
47
|
+
Dynamic of quotations of the US dollar:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
CBR.dynamic('usd', Date.parse('01/12/2014'), Date.parse('12/12/2014'))
|
51
|
+
```
|
52
|
+
|
53
|
+
|
54
|
+
===
|
55
|
+
<p align="center"><a href="https://evilmartians.com/?utm_source=cbr">
|
56
|
+
<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54">
|
57
|
+
</a></p>
|
data/Rakefile
ADDED
data/cbr.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'cbr/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "cbr"
|
7
|
+
spec.version = CBR::VERSION
|
8
|
+
spec.authors = ["Andrey Deryabin"]
|
9
|
+
spec.email = ["deriabin@gmail.com"]
|
10
|
+
spec.summary = %q{Ruby wrapper for The Central Bank of the Russian Federation API}
|
11
|
+
spec.description = %q{Ruby wrapper for The Central Bank of the Russian Federation API}
|
12
|
+
spec.homepage = "http://github.com/aderyabin/cbr"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
|
23
|
+
spec.add_dependency 'sax-machine', '~> 1.0'
|
24
|
+
spec.add_dependency 'curb', '~> 0.8'
|
25
|
+
end
|
data/lib/cbr.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require_relative "cbr/version"
|
2
|
+
require 'curl'
|
3
|
+
require_relative 'cbr/base'
|
4
|
+
require_relative 'cbr/daily/core'
|
5
|
+
require_relative 'cbr/dynamic/core'
|
6
|
+
require_relative 'cbr/catalog'
|
7
|
+
|
8
|
+
|
9
|
+
module CBR
|
10
|
+
class << self
|
11
|
+
def daily(date = nil)
|
12
|
+
date ||= Date.today
|
13
|
+
|
14
|
+
http = Curl.get("http://www.cbr.ru/scripts/XML_daily.asp?date_req=#{format_date(date)}")
|
15
|
+
xml_data = http.body_str
|
16
|
+
|
17
|
+
Daily::Core.parse(xml_data).val_curs
|
18
|
+
end
|
19
|
+
|
20
|
+
def catalog
|
21
|
+
http = Curl.get("http://www.cbr.ru/scripts/XML_val.asp")
|
22
|
+
xml_data = http.body_str
|
23
|
+
|
24
|
+
CBR::Catalog.parse(xml_data)
|
25
|
+
end
|
26
|
+
|
27
|
+
def dynamic(char_code, from_date, to_date)
|
28
|
+
currency_id = daily[char_code].id
|
29
|
+
|
30
|
+
http = Curl.get("www.cbr.ru/scripts/XML_dynamic.asp?date_req1=#{format_date(from_date)}&date_req2=#{format_date(to_date)}&VAL_NM_RQ=#{currency_id.strip}")
|
31
|
+
xml_data = http.body_str
|
32
|
+
|
33
|
+
Dynamic::Core.parse(xml_data).val_curs
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def format_date(date)
|
39
|
+
"#{date.strftime("%d/%m/%Y")}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/cbr/base.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'sax-machine'
|
2
|
+
|
3
|
+
module CBR
|
4
|
+
class Base
|
5
|
+
include SAXMachine
|
6
|
+
|
7
|
+
def to_hash
|
8
|
+
Hash[instance_variables.map do |name|
|
9
|
+
hasherized_value = instance_variable_get(name)
|
10
|
+
hasherized_value = hasherized_value.to_hash rescue hasherized_value
|
11
|
+
if hasherized_value.is_a?(Array)
|
12
|
+
hasherized_value = hasherized_value.map do |v|
|
13
|
+
v.to_hash rescue v
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
[name[1..-1], hasherized_value]
|
18
|
+
end]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/cbr/catalog.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
|
3
|
+
module CBR
|
4
|
+
class CatalogItem < Base
|
5
|
+
|
6
|
+
element :Name, as: :name
|
7
|
+
element :EngName, as: :eng_name
|
8
|
+
element :Nominal, as: :nominal, class: Integer
|
9
|
+
element :ParentCode, as: :parent_code
|
10
|
+
|
11
|
+
attribute :ID, as: :id
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative 'item'
|
2
|
+
|
3
|
+
module CBR
|
4
|
+
module Daily
|
5
|
+
class Collection < CBR::Base
|
6
|
+
|
7
|
+
def date
|
8
|
+
Date.parse(@date)
|
9
|
+
end
|
10
|
+
|
11
|
+
attribute :Date, as: :date
|
12
|
+
elements :Valute, as: :valutes, class: Item
|
13
|
+
|
14
|
+
def [](code)
|
15
|
+
valutes.select{|v| v.char_code == code.to_s.to_s.upcase }.first
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module CBR
|
2
|
+
module Daily
|
3
|
+
class Item < CBR::Base
|
4
|
+
def value
|
5
|
+
@value.sub(',', '.').to_f
|
6
|
+
end
|
7
|
+
|
8
|
+
def char_code
|
9
|
+
@char_code.to_s.strip
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
element :NumCode, as: :num_code
|
14
|
+
element :CharCode, as: :char_code
|
15
|
+
element :Nominal, as: :nominal, class: Integer
|
16
|
+
element :Value, as: :value
|
17
|
+
element :Name, as: :name
|
18
|
+
|
19
|
+
attribute :ID, as: :id
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module CBR
|
2
|
+
module Dynamic
|
3
|
+
class Item < CBR::Base
|
4
|
+
def date
|
5
|
+
Date.parse(@date)
|
6
|
+
end
|
7
|
+
|
8
|
+
def value
|
9
|
+
@value.sub(',', '.').to_f
|
10
|
+
end
|
11
|
+
|
12
|
+
element :Nominal, as: :nominal, class: Integer
|
13
|
+
element :Value, as: :value
|
14
|
+
|
15
|
+
attribute :Date, as: :date
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/cbr/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cbr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrey Deryabin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-15 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
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: sax-machine
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: curb
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.8'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.8'
|
69
|
+
description: Ruby wrapper for The Central Bank of the Russian Federation API
|
70
|
+
email:
|
71
|
+
- deriabin@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- cbr.gemspec
|
82
|
+
- lib/cbr.rb
|
83
|
+
- lib/cbr/base.rb
|
84
|
+
- lib/cbr/catalog.rb
|
85
|
+
- lib/cbr/catalog_item.rb
|
86
|
+
- lib/cbr/daily/collection.rb
|
87
|
+
- lib/cbr/daily/core.rb
|
88
|
+
- lib/cbr/daily/item.rb
|
89
|
+
- lib/cbr/dynamic/collection.rb
|
90
|
+
- lib/cbr/dynamic/core.rb
|
91
|
+
- lib/cbr/dynamic/item.rb
|
92
|
+
- lib/cbr/version.rb
|
93
|
+
homepage: http://github.com/aderyabin/cbr
|
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.4
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: Ruby wrapper for The Central Bank of the Russian Federation API
|
117
|
+
test_files: []
|
118
|
+
has_rdoc:
|