bcn_ni 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -7
- data/lib/bcn_ni.rb +107 -103
- data/lib/bcn_ni/version.rb +1 -1
- metadata +37 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e687cc892ddd27815cedafcc53c8ac76a6ae090c
|
4
|
+
data.tar.gz: 050b889fdc9738670cb61676f44736304c331687
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6112bb3e847d9d7bd0e99f77ab140820d2b5ae3da3ba019ee9403bea8366fb0e877306bb2948de8de373609b0b5e5e1abce282bb7306ef43d7cdb183facce2c
|
7
|
+
data.tar.gz: 87671fb475ac304b24df347dd391218a4a5f6cbc3ad0a51f8f0c6abcfc33a180df38741ff59c448be78c21eeb04f799877525a9af5db3d13bf86c15aa7ed2c6a
|
data/README.md
CHANGED
@@ -3,12 +3,12 @@ A pretty basic gem for consulting Nicaraguan money exchange reates using the BCN
|
|
3
3
|
|
4
4
|
## Usage
|
5
5
|
```ruby
|
6
|
-
#
|
6
|
+
# Returns the exchange rate for September 15th, 2017
|
7
7
|
rate = BcnNi.exchange_day(2017,9,15)
|
8
8
|
#
|
9
9
|
# => 30.3537
|
10
10
|
|
11
|
-
#
|
11
|
+
# Returns the exchange rate table for September, 2017
|
12
12
|
table = BcnNi.exchange_month(2017,9)
|
13
13
|
#
|
14
14
|
# => [
|
@@ -50,7 +50,14 @@ table = BcnNi.exchange_month(2017,9)
|
|
50
50
|
Add this line to your application's Gemfile:
|
51
51
|
|
52
52
|
```ruby
|
53
|
+
# From git repository
|
54
|
+
gem 'bcn_ni', git: 'https://github.com/mldoscar/bcn_ni', branch: 'master'
|
55
|
+
|
56
|
+
# From ruby gems
|
53
57
|
gem 'bcn_ni'
|
58
|
+
|
59
|
+
# Using gem install
|
60
|
+
gem install bcn_ni
|
54
61
|
```
|
55
62
|
|
56
63
|
And then execute:
|
@@ -58,11 +65,6 @@ And then execute:
|
|
58
65
|
$ bundle
|
59
66
|
```
|
60
67
|
|
61
|
-
Or install it yourself as:
|
62
|
-
```bash
|
63
|
-
$ gem install bcn_ni
|
64
|
-
```
|
65
|
-
|
66
68
|
## Contributing
|
67
69
|
Contribution directions go here.
|
68
70
|
|
data/lib/bcn_ni.rb
CHANGED
@@ -1,103 +1,107 @@
|
|
1
|
-
require 'uri'
|
2
|
-
require 'net/http'
|
3
|
-
require 'net/https'
|
4
|
-
require '
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
#
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
#
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
require 'net/https'
|
4
|
+
require 'active_support/core_ext/hash'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
module BcnNi
|
8
|
+
|
9
|
+
def self.exchange_day(year, month, day)
|
10
|
+
# Build body through a XML envelope
|
11
|
+
body = self.bcn_envelope(self.exchange_day_letter(year, month, day))
|
12
|
+
|
13
|
+
json_response = self.do_request(body)
|
14
|
+
|
15
|
+
# Get the result value
|
16
|
+
value_result = json_response['Envelope']['Body']['RecuperaTC_DiaResponse']['RecuperaTC_DiaResult']
|
17
|
+
|
18
|
+
# Parse the result value and finally return it
|
19
|
+
return value_result.to_f
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.exchange_month(year, month)
|
24
|
+
# Build body through a XML envelope
|
25
|
+
body = self.bcn_envelope(self.exchange_month_letter(year, month))
|
26
|
+
|
27
|
+
json_response = self.do_request(body)
|
28
|
+
|
29
|
+
# Get the result array
|
30
|
+
exchange_table = json_response['Envelope']['Body']['RecuperaTC_MesResponse']['RecuperaTC_MesResult']['Detalle_TC']['Tc']
|
31
|
+
|
32
|
+
unless exchange_table.nil?
|
33
|
+
# Parse the table to a custom and better JSON
|
34
|
+
# The format example will be: {date: as Date, value: as Float}
|
35
|
+
parsed_table = exchange_table.map{|x| {date: Date.parse(x['Fecha']), value: x['Valor'].to_f} }
|
36
|
+
|
37
|
+
# Sort the parsed table and finally return it
|
38
|
+
return parsed_table.sort_by {|x| x[:date]}
|
39
|
+
else
|
40
|
+
return []
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def self.do_request(body)
|
47
|
+
# see 'https://servicios.bcn.gob.ni/Tc_Servicio/ServicioTC.asmx'
|
48
|
+
# for more info about how to build a RAW SOAP request
|
49
|
+
|
50
|
+
# Parse the URI
|
51
|
+
uri = URI.parse('https://servicios.bcn.gob.ni/Tc_Servicio/ServicioTC.asmx?WSDL')
|
52
|
+
|
53
|
+
# Create protocol to the URI
|
54
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
55
|
+
|
56
|
+
https.use_ssl = true
|
57
|
+
|
58
|
+
# Create a new POST request as XML content type
|
59
|
+
req = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' => 'text/xml'})
|
60
|
+
|
61
|
+
# Set the request body as a RAW SOAP XML request
|
62
|
+
req.body = body
|
63
|
+
|
64
|
+
# Process the request
|
65
|
+
res = https.request(req)
|
66
|
+
|
67
|
+
# Get the XML response
|
68
|
+
xml_response = res.body
|
69
|
+
|
70
|
+
# Parse to a JSON hash
|
71
|
+
return Hash.from_xml(xml_response)
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.bcn_envelope(letter)
|
75
|
+
envelope = <<EOF
|
76
|
+
<?xml version="1.0" encoding="utf-8"?>
|
77
|
+
<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/">
|
78
|
+
<soap:Body>
|
79
|
+
#{letter}
|
80
|
+
</soap:Body>
|
81
|
+
</soap:Envelope>
|
82
|
+
EOF
|
83
|
+
return envelope
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.exchange_day_letter(year, month, day)
|
87
|
+
letter = <<EOF
|
88
|
+
<RecuperaTC_Dia xmlns="http://servicios.bcn.gob.ni/">
|
89
|
+
<Ano>#{year}</Ano>
|
90
|
+
<Mes>#{month}</Mes>
|
91
|
+
<Dia>#{day}</Dia>
|
92
|
+
</RecuperaTC_Dia>
|
93
|
+
EOF
|
94
|
+
return letter
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.exchange_month_letter(year, month)
|
98
|
+
letter = <<EOF
|
99
|
+
<RecuperaTC_Mes xmlns="http://servicios.bcn.gob.ni/">
|
100
|
+
<Ano>#{year}</Ano>
|
101
|
+
<Mes>#{month}</Mes>
|
102
|
+
</RecuperaTC_Mes>
|
103
|
+
EOF
|
104
|
+
return letter
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
data/lib/bcn_ni/version.rb
CHANGED
metadata
CHANGED
@@ -1,20 +1,23 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bcn_ni
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oscar Rodriguez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.1'
|
20
|
+
- - ">="
|
18
21
|
- !ruby/object:Gem::Version
|
19
22
|
version: 5.1.3
|
20
23
|
type: :runtime
|
@@ -22,22 +25,51 @@ dependencies:
|
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '5.1'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 5.1.3
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rails
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '5.1'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 5.1.3
|
43
|
+
type: :development
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '5.1'
|
50
|
+
- - ">="
|
25
51
|
- !ruby/object:Gem::Version
|
26
52
|
version: 5.1.3
|
27
53
|
- !ruby/object:Gem::Dependency
|
28
54
|
name: sqlite3
|
29
55
|
requirement: !ruby/object:Gem::Requirement
|
30
56
|
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '1.3'
|
31
60
|
- - ">="
|
32
61
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
62
|
+
version: 1.3.12
|
34
63
|
type: :development
|
35
64
|
prerelease: false
|
36
65
|
version_requirements: !ruby/object:Gem::Requirement
|
37
66
|
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.3'
|
38
70
|
- - ">="
|
39
71
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
72
|
+
version: 1.3.12
|
41
73
|
description: A pretty basic gem for consulting Nicaraguan money exchange reates using
|
42
74
|
the BCN SOAP Service
|
43
75
|
email:
|