bcn_ni 0.1.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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +70 -0
- data/Rakefile +33 -0
- data/lib/bcn_ni.rb +103 -0
- data/lib/bcn_ni/version.rb +3 -0
- data/lib/tasks/bcn_ni_tasks.rake +4 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 695f93a3b768ebd4d0ec2ef72bb1052ea237d0a4
|
4
|
+
data.tar.gz: 1a73f6527857ce6ef04658ecca0128b49c23bfb1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 16fac7bd6c32b9ce452869876061df34bda9f4e2f3a8a06e70df24caf65efa1061fdbfeb5564d510de1920f50e083bbf12ba0b2064179f6c9ac1964b0cfd55bf
|
7
|
+
data.tar.gz: 3b3cabdc88cd6924aff646039daa1492e08160f2aae1b6917c59f9c0c6e22b8585c14d7ad9cf2d8a49fa2758cb4086bab5d7df18d9d172a36db63b5f9fba1cfb
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017 Oscar Rodriguez
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# BcnNi
|
2
|
+
A pretty basic gem for consulting Nicaraguan money exchange reates using the BCN SOAP Service.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
```ruby
|
6
|
+
# Return the exchange rate for September 15th, 2017
|
7
|
+
rate = BcnNi.exchange_day(2017,9,15)
|
8
|
+
#
|
9
|
+
# => 30.3537
|
10
|
+
|
11
|
+
# Return the exchange rate table for September, 2017
|
12
|
+
table = BcnNi.exchange_month(2017,9)
|
13
|
+
#
|
14
|
+
# => [
|
15
|
+
# {:date=>Fri, 01 Sep 2017, :value=>30.2969},
|
16
|
+
# {:date=>Sat, 02 Sep 2017, :value=>30.301},
|
17
|
+
# {:date=>Sun, 03 Sep 2017, :value=>30.305},
|
18
|
+
# {:date=>Mon, 04 Sep 2017, :value=>30.3091},
|
19
|
+
# {:date=>Tue, 05 Sep 2017, :value=>30.3131},
|
20
|
+
# {:date=>Wed, 06 Sep 2017, :value=>30.3172},
|
21
|
+
# {:date=>Thu, 07 Sep 2017, :value=>30.3212},
|
22
|
+
# {:date=>Fri, 08 Sep 2017, :value=>30.3253},
|
23
|
+
# {:date=>Sat, 09 Sep 2017, :value=>30.3293},
|
24
|
+
# {:date=>Sun, 10 Sep 2017, :value=>30.3334},
|
25
|
+
# {:date=>Mon, 11 Sep 2017, :value=>30.3374},
|
26
|
+
# {:date=>Tue, 12 Sep 2017, :value=>30.3415},
|
27
|
+
# {:date=>Wed, 13 Sep 2017, :value=>30.3455},
|
28
|
+
# {:date=>Thu, 14 Sep 2017, :value=>30.3496},
|
29
|
+
# {:date=>Fri, 15 Sep 2017, :value=>30.3537},
|
30
|
+
# {:date=>Sat, 16 Sep 2017, :value=>30.3577},
|
31
|
+
# {:date=>Sun, 17 Sep 2017, :value=>30.3618},
|
32
|
+
# {:date=>Mon, 18 Sep 2017, :value=>30.3658},
|
33
|
+
# {:date=>Tue, 19 Sep 2017, :value=>30.3699},
|
34
|
+
# {:date=>Wed, 20 Sep 2017, :value=>30.374},
|
35
|
+
# {:date=>Thu, 21 Sep 2017, :value=>30.378},
|
36
|
+
# {:date=>Fri, 22 Sep 2017, :value=>30.3821},
|
37
|
+
# {:date=>Sat, 23 Sep 2017, :value=>30.3861},
|
38
|
+
# {:date=>Sun, 24 Sep 2017, :value=>30.3902},
|
39
|
+
# {:date=>Mon, 25 Sep 2017, :value=>30.3943},
|
40
|
+
# {:date=>Tue, 26 Sep 2017, :value=>30.3983},
|
41
|
+
# {:date=>Wed, 27 Sep 2017, :value=>30.4024},
|
42
|
+
# {:date=>Thu, 28 Sep 2017, :value=>30.4065},
|
43
|
+
# {:date=>Fri, 29 Sep 2017, :value=>30.4105},
|
44
|
+
# {:date=>Sat, 30 Sep 2017, :value=>30.4146}
|
45
|
+
# ]
|
46
|
+
|
47
|
+
```
|
48
|
+
|
49
|
+
## Installation
|
50
|
+
Add this line to your application's Gemfile:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
gem 'bcn_ni'
|
54
|
+
```
|
55
|
+
|
56
|
+
And then execute:
|
57
|
+
```bash
|
58
|
+
$ bundle
|
59
|
+
```
|
60
|
+
|
61
|
+
Or install it yourself as:
|
62
|
+
```bash
|
63
|
+
$ gem install bcn_ni
|
64
|
+
```
|
65
|
+
|
66
|
+
## Contributing
|
67
|
+
Contribution directions go here.
|
68
|
+
|
69
|
+
## License
|
70
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'BcnNi'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
require 'bundler/gem_tasks'
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'test'
|
28
|
+
t.pattern = 'test/**/*_test.rb'
|
29
|
+
t.verbose = false
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
task default: :test
|
data/lib/bcn_ni.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
require 'net/https'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module BcnNi
|
7
|
+
|
8
|
+
def self.exchange_day(year, month, day)
|
9
|
+
# (see 'https://servicios.bcn.gob.ni/Tc_Servicio/ServicioTC.asmx')
|
10
|
+
# for more info about how to build a SOAP RAW request)
|
11
|
+
|
12
|
+
# Parse the URI
|
13
|
+
uri = URI.parse('https://servicios.bcn.gob.ni/Tc_Servicio/ServicioTC.asmx?WSDL')
|
14
|
+
|
15
|
+
# Create protocol to the URI
|
16
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
17
|
+
https.use_ssl = true
|
18
|
+
|
19
|
+
# Create a new POST request as XML content type
|
20
|
+
req = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' => 'text/xml'})
|
21
|
+
|
22
|
+
# Set the request body as a RAW SOAP XML request
|
23
|
+
req.body = <<EOF
|
24
|
+
<?xml version="1.0" encoding="utf-8"?>
|
25
|
+
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
|
26
|
+
<soap:Body>
|
27
|
+
<RecuperaTC_Dia xmlns="http://servicios.bcn.gob.ni/">
|
28
|
+
<Ano>#{year}</Ano>
|
29
|
+
<Mes>#{month}</Mes>
|
30
|
+
<Dia>#{day}</Dia>
|
31
|
+
</RecuperaTC_Dia>
|
32
|
+
</soap:Body>
|
33
|
+
</soap:Envelope>
|
34
|
+
EOF
|
35
|
+
# Process the request
|
36
|
+
res = https.request(req)
|
37
|
+
|
38
|
+
# Get the XML response
|
39
|
+
xml_response = res.body
|
40
|
+
|
41
|
+
# Parse to a JSON hash
|
42
|
+
json_response = Hash.from_xml(xml_response)
|
43
|
+
|
44
|
+
# Get the result value
|
45
|
+
value_result = json_response['Envelope']['Body']['RecuperaTC_DiaResponse']['RecuperaTC_DiaResult']
|
46
|
+
|
47
|
+
# Parse the result value and finally return it
|
48
|
+
return value_result.to_f
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.exchange_month(year, month)
|
53
|
+
# (see 'https://servicios.bcn.gob.ni/Tc_Servicio/ServicioTC.asmx')
|
54
|
+
# for more info about how to build a SOAP RAW request)
|
55
|
+
|
56
|
+
# Parse the URI
|
57
|
+
uri = URI.parse('https://servicios.bcn.gob.ni/Tc_Servicio/ServicioTC.asmx?WSDL')
|
58
|
+
|
59
|
+
# Create protocol to the URI
|
60
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
61
|
+
https.use_ssl = true
|
62
|
+
|
63
|
+
# Create a new POST request as XML content type
|
64
|
+
req = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' => 'text/xml'})
|
65
|
+
|
66
|
+
# Set the request body as a RAW SOAP XML request
|
67
|
+
req.body = <<EOF
|
68
|
+
<?xml version="1.0" encoding="utf-8"?>
|
69
|
+
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
|
70
|
+
<soap:Body>
|
71
|
+
<RecuperaTC_Mes xmlns="http://servicios.bcn.gob.ni/">
|
72
|
+
<Ano>#{year}</Ano>
|
73
|
+
<Mes>#{month}</Mes>
|
74
|
+
</RecuperaTC_Mes>
|
75
|
+
</soap:Body>
|
76
|
+
</soap:Envelope>
|
77
|
+
EOF
|
78
|
+
# Process the request
|
79
|
+
res = https.request(req)
|
80
|
+
|
81
|
+
# Get the XML response
|
82
|
+
xml_response = res.body
|
83
|
+
|
84
|
+
# Parse to a JSON hash
|
85
|
+
json_response = Hash.from_xml(xml_response)
|
86
|
+
|
87
|
+
# Get the result array
|
88
|
+
exchange_table = json_response['Envelope']['Body']['RecuperaTC_MesResponse']['RecuperaTC_MesResult']['Detalle_TC']['Tc']
|
89
|
+
|
90
|
+
unless exchange_table.nil?
|
91
|
+
# Parse the table to a custom and better JSON
|
92
|
+
# The format example will be: {date: as Date, value: as Float}
|
93
|
+
parsed_table = exchange_table.map{|x| {date: Date.parse(x['Fecha']), value: x['Valor'].to_f} }
|
94
|
+
|
95
|
+
# Sort the parsed table and finally return it
|
96
|
+
return parsed_table.sort_by {|x| x[:date]}
|
97
|
+
else
|
98
|
+
return []
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bcn_ni
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Oscar Rodriguez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.1.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.1.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: A pretty basic gem for consulting Nicaraguan money exchange reates using
|
42
|
+
the BCN SOAP Service
|
43
|
+
email:
|
44
|
+
- mld.oscar@yahoo.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- MIT-LICENSE
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- lib/bcn_ni.rb
|
53
|
+
- lib/bcn_ni/version.rb
|
54
|
+
- lib/tasks/bcn_ni_tasks.rake
|
55
|
+
homepage: https://github.com/mldoscar/bcn_ni
|
56
|
+
licenses:
|
57
|
+
- MIT
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 2.6.8
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: A pretty basic gem for consulting Nicaraguan money exchange reates using
|
79
|
+
the BCN SOAP Service
|
80
|
+
test_files: []
|