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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -7
  3. data/lib/bcn_ni.rb +107 -103
  4. data/lib/bcn_ni/version.rb +1 -1
  5. metadata +37 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 695f93a3b768ebd4d0ec2ef72bb1052ea237d0a4
4
- data.tar.gz: 1a73f6527857ce6ef04658ecca0128b49c23bfb1
3
+ metadata.gz: e687cc892ddd27815cedafcc53c8ac76a6ae090c
4
+ data.tar.gz: 050b889fdc9738670cb61676f44736304c331687
5
5
  SHA512:
6
- metadata.gz: 16fac7bd6c32b9ce452869876061df34bda9f4e2f3a8a06e70df24caf65efa1061fdbfeb5564d510de1920f50e083bbf12ba0b2064179f6c9ac1964b0cfd55bf
7
- data.tar.gz: 3b3cabdc88cd6924aff646039daa1492e08160f2aae1b6917c59f9c0c6e22b8585c14d7ad9cf2d8a49fa2758cb4086bab5d7df18d9d172a36db63b5f9fba1cfb
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
- # Return the exchange rate for September 15th, 2017
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
- # Return the exchange rate table for September, 2017
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 '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
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
@@ -1,3 +1,3 @@
1
1
  module BcnNi
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
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.0
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-09-18 00:00:00.000000000 Z
11
+ date: 2017-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
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: '0'
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: '0'
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: