bcn_ni 0.1.0 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 695f93a3b768ebd4d0ec2ef72bb1052ea237d0a4
4
- data.tar.gz: 1a73f6527857ce6ef04658ecca0128b49c23bfb1
2
+ SHA256:
3
+ metadata.gz: a1c66337b41a7c0920341442f6f5ee66ec69b4aeb6154c940bb9a58cd073dcea
4
+ data.tar.gz: fb5a527398cba7ca4f8bc8662f456701493a476876ff5956390ffd36f7e41dee
5
5
  SHA512:
6
- metadata.gz: 16fac7bd6c32b9ce452869876061df34bda9f4e2f3a8a06e70df24caf65efa1061fdbfeb5564d510de1920f50e083bbf12ba0b2064179f6c9ac1964b0cfd55bf
7
- data.tar.gz: 3b3cabdc88cd6924aff646039daa1492e08160f2aae1b6917c59f9c0c6e22b8585c14d7ad9cf2d8a49fa2758cb4086bab5d7df18d9d172a36db63b5f9fba1cfb
6
+ metadata.gz: 61512751cd5a396b6b236e06501681e269fc84f0e4e323276022c92a9d8890ad837b61cdd8027b82fe079de9c19415275e136c41349dfafc2173fb3a8ebfc03e
7
+ data.tar.gz: f8b98e011ddd4dc15f282d9c80cc5d6f60f99ae4ca6501ebee28c2cd534e0527a853c26c14ae3acc5bfefb8166af0062edc10ce7b0f64a4d449d244cad4cc032
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at TODO: Write your email address. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/MIT-LICENSE CHANGED
File without changes
data/README.md CHANGED
@@ -1,70 +1,97 @@
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).
1
+ # BcnNi
2
+
3
+ This gem provides NIO (Córdoba Oro Nicaragüense) against USD (United States Dollar) money exchange rates consuming the official Central Bank of Nicaragüa (BCN) SOAP Service or HTML page
4
+
5
+ ## Basic usage
6
+
7
+ ```ruby
8
+ # Returns the exchange rate for September 15th, 2017
9
+ day_rate = BcnNi.exchange_day(2017, 9, 15)
10
+ #
11
+ # => 30.3537
12
+
13
+ # Returns the exchange rate table for September, 2017
14
+ month_rate = BcnNi.exchange_month(2017, 9)
15
+ #
16
+ # => [
17
+ # {:date=>Fri, 01 Sep 2017, :value=>30.2969},
18
+ # {:date=>Sat, 02 Sep 2017, :value=>30.301},
19
+ # {:date=>Sun, 03 Sep 2017, :value=>30.305},
20
+ # {:date=>Mon, 04 Sep 2017, :value=>30.3091},
21
+ # {:date=>Tue, 05 Sep 2017, :value=>30.3131},
22
+ # {:date=>Wed, 06 Sep 2017, :value=>30.3172},
23
+ # {:date=>Thu, 07 Sep 2017, :value=>30.3212},
24
+ # {:date=>Fri, 08 Sep 2017, :value=>30.3253},
25
+ # {:date=>Sat, 09 Sep 2017, :value=>30.3293},
26
+ # {:date=>Sun, 10 Sep 2017, :value=>30.3334},
27
+ # {:date=>Mon, 11 Sep 2017, :value=>30.3374},
28
+ # {:date=>Tue, 12 Sep 2017, :value=>30.3415},
29
+ # {:date=>Wed, 13 Sep 2017, :value=>30.3455},
30
+ # {:date=>Thu, 14 Sep 2017, :value=>30.3496},
31
+ # {:date=>Fri, 15 Sep 2017, :value=>30.3537},
32
+ # {:date=>Sat, 16 Sep 2017, :value=>30.3577},
33
+ # {:date=>Sun, 17 Sep 2017, :value=>30.3618},
34
+ # {:date=>Mon, 18 Sep 2017, :value=>30.3658},
35
+ # {:date=>Tue, 19 Sep 2017, :value=>30.3699},
36
+ # {:date=>Wed, 20 Sep 2017, :value=>30.374},
37
+ # {:date=>Thu, 21 Sep 2017, :value=>30.378},
38
+ # {:date=>Fri, 22 Sep 2017, :value=>30.3821},
39
+ # {:date=>Sat, 23 Sep 2017, :value=>30.3861},
40
+ # {:date=>Sun, 24 Sep 2017, :value=>30.3902},
41
+ # {:date=>Mon, 25 Sep 2017, :value=>30.3943},
42
+ # {:date=>Tue, 26 Sep 2017, :value=>30.3983},
43
+ # {:date=>Wed, 27 Sep 2017, :value=>30.4024},
44
+ # {:date=>Thu, 28 Sep 2017, :value=>30.4065},
45
+ # {:date=>Fri, 29 Sep 2017, :value=>30.4105},
46
+ # {:date=>Sat, 30 Sep 2017, :value=>30.4146}
47
+ # ]
48
+
49
+ ```
50
+
51
+ ## Changing the request mode
52
+
53
+ For changing the request mode simply add `request_mode` argument at the end of the method args. **The default request mode is scrapping** (which incredibly resulted to be faster than SOAP and with 24/7 availability). You can change this like the example given below:
54
+
55
+ ```ruby
56
+ # Scrapping mode
57
+ day_rate = BcnNi.exchange_day(2017, 9, 15, request_mode: :scrapping)
58
+ month_rate = BcnNi.exchange_month(2017, 9, request_mode: :scrapping)
59
+ # SOAP request mode
60
+ day_rate = BcnNi.exchange_day(2017, 9, 15, request_mode: :soap)
61
+ month_rate = BcnNi.exchange_month(2017, 9, request_mode: :soap)
62
+ ```
63
+
64
+ ## Installation
65
+
66
+ Add this line to your application's Gemfile:
67
+
68
+ ```ruby
69
+ # From git repository
70
+ gem 'bcn_ni', git: 'https://github.com/mldoscar/bcn_ni', branch: 'master'
71
+
72
+ # From ruby gems
73
+ gem 'bcn_ni', '>= 0.1.5'
74
+
75
+ # Using gem install
76
+ gem install bcn_ni
77
+ ```
78
+
79
+ And then execute:
80
+
81
+ ```bash
82
+ $ bundle
83
+ ```
84
+
85
+ ## Changelog
86
+
87
+ ```
88
+ 2021.06.28 - Bugfix: Cambio en el URI para el request de scrapping, el BCN cambió de parámetros y ubicación de URL
89
+ ```
90
+
91
+ ## Contributing
92
+
93
+ You guys are free to send your pull requests for contributing. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
94
+
95
+ ## License
96
+
97
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -31,3 +31,8 @@ end
31
31
 
32
32
 
33
33
  task default: :test
34
+
35
+ desc "Open an irb session preloaded with this library"
36
+ task :console do
37
+ sh "irb -r rubygems -I lib -r bcn_ni.rb"
38
+ end
data/lib/bcn_ni.rb CHANGED
@@ -1,103 +1,4 @@
1
- require 'uri'
2
- require 'net/http'
3
- require 'net/https'
4
- require 'json'
5
-
6
1
  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
-
2
+ require 'bcn_ni/version'
3
+ require 'bcn_ni/core'
103
4
  end
@@ -0,0 +1,27 @@
1
+ module BcnNi
2
+ require File.expand_path(File.dirname(__FILE__)) + '/helpers/request'
3
+
4
+ @@exceptions = []
5
+
6
+ def self.exchange_month(year, month, args = {})
7
+ engine = BcnNi::Request.new(args)
8
+
9
+ result = engine.exchange_month(year, month)
10
+ @@exceptions = engine.exceptions
11
+
12
+ return result
13
+ end
14
+
15
+ def self.exchange_day(year, month, day, args = {})
16
+ engine = BcnNi::Request.new(args)
17
+
18
+ result = engine.exchange_day(year, month, day)
19
+ @@exceptions = engine.exceptions
20
+
21
+ return result
22
+ end
23
+
24
+ def self.exceptions
25
+ return @@exceptions
26
+ end
27
+ end
@@ -0,0 +1,229 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'net/https'
4
+ require 'nokogiri'
5
+ require 'open-uri'
6
+ require 'active_support/core_ext/hash'
7
+ require 'json'
8
+
9
+ module BcnNi
10
+ class Request
11
+ @request_url = nil
12
+ @request_mode = nil
13
+ @exceptions = nil
14
+
15
+ def request_url
16
+ return @request_url
17
+ end
18
+
19
+ def request_mode
20
+ return @request_mode
21
+ end
22
+
23
+ def exceptions
24
+ return @exceptions
25
+ end
26
+
27
+ def initialize(args = {})
28
+ @request_mode = (args[:request_mode] || :scrapping).to_sym
29
+ @exceptions = []
30
+
31
+ case @request_mode
32
+ when :scrapping
33
+ @request_url = "https://www.bcn.gob.ni/IRR/tipo_cambio_mensual/mes.php"
34
+ when :soap
35
+ # See 'https://servicios.bcn.gob.ni/Tc_Servicio/ServicioTC.asmx' for more info about how to build a RAW SOAP request
36
+ @request_url = "https://servicios.bcn.gob.ni/Tc_Servicio/ServicioTC.asmx?WSDL"
37
+ else
38
+ raise NotImplementedError, 'Request mode not implemented'
39
+ end
40
+ end
41
+
42
+ def exchange_month(year, month)
43
+ begin
44
+ # Evaluate scrapping mode to call the correct method for processing the request
45
+ case request_mode
46
+ when :scrapping
47
+ return scra__exchange_month(year, month)
48
+ when :soap
49
+ return soap__exchange_month(year, month)
50
+ end
51
+ rescue Exception => e
52
+ # Save the exception into the exception list for future error messages or debugging
53
+ @exceptions.push e
54
+
55
+ # Return an empty value according to the called method
56
+ return []
57
+ end
58
+ end
59
+
60
+ def exchange_day(year, month, day)
61
+ begin
62
+ # Evaluate scrapping mode to call the correct method for processing the request
63
+ case request_mode
64
+ when :scrapping
65
+ return scra__exchange_day(year, month, day)
66
+ when :soap
67
+ return soap__exchange_day(year, month, day)
68
+ end
69
+ rescue Exception => e
70
+ # Save the exception into the exception list for future error messages or debugging
71
+ @exceptions.push e
72
+
73
+ # Return an empty value according to the called method
74
+ return nil
75
+ end
76
+ end
77
+
78
+ private
79
+ def scra__exchange_month(year, month)
80
+ # Parse the date
81
+ start_date = Date.new(year, month, 1)
82
+
83
+ # Create the arg hash
84
+ args = {
85
+ mes: start_date.strftime('%d'),
86
+ anio: start_date.strftime('%Y')
87
+ }
88
+
89
+ # Generate the full url
90
+ full_url = request_url + '?' + args.to_param
91
+
92
+ # This loop prevents a random EOFError (main cause is not known yet)
93
+ retries = 0
94
+ response = nil
95
+ while true
96
+ # Raise an error if too many retries
97
+ raise StopIteration if retries >= 5
98
+
99
+ begin
100
+ response = open(full_url, { ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE })
101
+ # Exit loop if response has been assigned
102
+ break
103
+ rescue EOFError => e
104
+ # Sum retry and sleep the thread for a while
105
+ retries += 1
106
+ sleep(2.seconds)
107
+ end
108
+ end
109
+
110
+ # Parse the HTML document
111
+ doc = Nokogiri::HTML(response)
112
+
113
+ result = []
114
+ # Iterate table
115
+ doc.css('table tr').each_with_index do |row, i|
116
+ next if i.zero?
117
+
118
+ # Parse the value
119
+ # (Date is not parsed because it's not given in a correct format, giving the month it in spanish)
120
+ # so, we must assume that dates are given in ascendent sort order
121
+ value = row.css('td')[1].content
122
+
123
+ # Push the result into the array
124
+ result.push({ date: start_date + (i - 1).day, value: value.strip.to_f })
125
+ end
126
+
127
+ return result
128
+ end
129
+
130
+ def scra__exchange_day(year, month, day)
131
+ # Parse the date
132
+ start_date = Date.new(year, month, day)
133
+
134
+ # Find the result into the month table
135
+ found_result = scra__exchange_month(year, month).find { |x| x[:date] == start_date }
136
+
137
+ # Return the result value
138
+ return (found_result || {})[:value]
139
+ end
140
+
141
+ def soap__exchange_day(year, month, day)
142
+ # Build body through a XML envelope
143
+ body = soap__envelope(soap__letter_exchange_day(year, month, day))
144
+ json_response = soap__request(body)
145
+
146
+ # Get the result value
147
+ value_result = json_response['Envelope']['Body']['RecuperaTC_DiaResponse']['RecuperaTC_DiaResult']
148
+ # Parse the result value and finally return it
149
+ return value_result.to_f
150
+ end
151
+
152
+ def soap__exchange_month(year, month)
153
+ # Build body through a XML envelope
154
+ body = soap__envelope(soap__letter_exchange_month(year, month))
155
+ json_response = soap__request(body)
156
+
157
+ # Get the result array
158
+ exchange_table = json_response['Envelope']['Body']['RecuperaTC_MesResponse']['RecuperaTC_MesResult']['Detalle_TC']['Tc']
159
+
160
+ if exchange_table.present?
161
+ # Parse the table to a custom and better JSON
162
+ # The format example will be: {date: as Date, value: as Float}
163
+ parsed_table = exchange_table.map{ |x| { date: Date.parse(x['Fecha']), value: x['Valor'].to_f } }
164
+ # Sort the parsed table and finally return it
165
+ return parsed_table.sort_by { |x| x[:date] }
166
+ else
167
+ return []
168
+ end
169
+ end
170
+
171
+ def soap__request(body)
172
+ # Parse the URI
173
+ uri = URI.parse(request_url)
174
+ # Create protocol to the URI
175
+ request_engine = Net::HTTP.new(uri.host, uri.port)
176
+ request_engine.use_ssl = true
177
+ request_engine.verify_mode = OpenSSL::SSL::VERIFY_NONE
178
+ request_engine.open_timeout = 15.seconds
179
+
180
+ # Create a new POST request as XML content type
181
+ req = Net::HTTP::Post.new(uri.path)
182
+ req['Content-Type'] = 'text/xml'
183
+
184
+ # Set the request body as a RAW SOAP XML request
185
+ req.body = body
186
+ # Process the request
187
+ res = request_engine.request(req)
188
+ # Get the XML response
189
+ xml_response = res.body
190
+
191
+ # Parse to a JSON hash
192
+ return Hash.from_xml(xml_response)
193
+ end
194
+
195
+ def soap__envelope(letter)
196
+ envelope = <<EOF
197
+ <?xml version="1.0" encoding="utf-8"?>
198
+ <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/">
199
+ <soap:Body>
200
+ #{letter}
201
+ </soap:Body>
202
+ </soap:Envelope>
203
+ EOF
204
+ return envelope
205
+ end
206
+
207
+ def soap__letter_exchange_day(year, month, day)
208
+ letter = <<EOF
209
+ <RecuperaTC_Dia xmlns="http://servicios.bcn.gob.ni/">
210
+ <Ano>#{year}</Ano>
211
+ <Mes>#{month}</Mes>
212
+ <Dia>#{day}</Dia>
213
+ </RecuperaTC_Dia>
214
+ EOF
215
+ return letter
216
+ end
217
+
218
+ def soap__letter_exchange_month(year, month)
219
+ letter = <<EOF
220
+ <RecuperaTC_Mes xmlns="http://servicios.bcn.gob.ni/">
221
+ <Ano>#{year}</Ano>
222
+ <Mes>#{month}</Mes>
223
+ </RecuperaTC_Mes>
224
+ EOF
225
+ return letter
226
+ end
227
+
228
+ end
229
+ end
@@ -1,3 +1,3 @@
1
1
  module BcnNi
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.5'
3
3
  end
File without changes
metadata CHANGED
@@ -1,62 +1,94 @@
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.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Rodriguez
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-18 00:00:00.000000000 Z
11
+ date: 2021-06-28 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
18
  - !ruby/object:Gem::Version
19
- version: 5.1.3
19
+ version: '5.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 5.1.3
26
+ version: '5.2'
27
27
  - !ruby/object:Gem::Dependency
28
- name: sqlite3
28
+ name: nokogiri
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '0'
47
+ version: '12.3'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - ">="
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
39
67
  - !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
68
+ version: '3.8'
69
+ description: This gem provides NIO (Córdoba Oro Nicaragüense) against USD (United
70
+ States Dollar) money exchange rates consuming the official Central Bank of Nicaragüa
71
+ (BCN) SOAP Service or HTML page
43
72
  email:
44
73
  - mld.oscar@yahoo.com
45
74
  executables: []
46
75
  extensions: []
47
76
  extra_rdoc_files: []
48
77
  files:
78
+ - CODE_OF_CONDUCT.md
49
79
  - MIT-LICENSE
50
80
  - README.md
51
81
  - Rakefile
52
82
  - lib/bcn_ni.rb
83
+ - lib/bcn_ni/core.rb
84
+ - lib/bcn_ni/helpers/request.rb
53
85
  - lib/bcn_ni/version.rb
54
86
  - lib/tasks/bcn_ni_tasks.rake
55
87
  homepage: https://github.com/mldoscar/bcn_ni
56
88
  licenses:
57
89
  - MIT
58
90
  metadata: {}
59
- post_install_message:
91
+ post_install_message:
60
92
  rdoc_options: []
61
93
  require_paths:
62
94
  - lib
@@ -71,10 +103,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
103
  - !ruby/object:Gem::Version
72
104
  version: '0'
73
105
  requirements: []
74
- rubyforge_project:
75
- rubygems_version: 2.6.8
76
- signing_key:
106
+ rubygems_version: 3.0.6
107
+ signing_key:
77
108
  specification_version: 4
78
- summary: A pretty basic gem for consulting Nicaraguan money exchange reates using
79
- the BCN SOAP Service
109
+ summary: This tool pretends to be helpful for developers who can request exchange
110
+ rates from Nicaragua in a easier way
80
111
  test_files: []