bcn_ni 0.1.1 → 0.1.6

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: e687cc892ddd27815cedafcc53c8ac76a6ae090c
4
- data.tar.gz: 050b889fdc9738670cb61676f44736304c331687
2
+ SHA256:
3
+ metadata.gz: a678080d77772ee8a800974da131c7e329f74162dd0054fa55e3e741fd5688ae
4
+ data.tar.gz: 7ebf4ff1bc693aec7c34e4fc10a6b80b69d4b3aea659fa968684ce8af2056759
5
5
  SHA512:
6
- metadata.gz: d6112bb3e847d9d7bd0e99f77ab140820d2b5ae3da3ba019ee9403bea8366fb0e877306bb2948de8de373609b0b5e5e1abce282bb7306ef43d7cdb183facce2c
7
- data.tar.gz: 87671fb475ac304b24df347dd391218a4a5f6cbc3ad0a51f8f0c6abcfc33a180df38741ff59c448be78c21eeb04f799877525a9af5db3d13bf86c15aa7ed2c6a
6
+ metadata.gz: 4ff4b144e27a5fae7b3c3d99e67b58060c7b6cac5ae052269eea7f1f189da59a55b5f6d5122dca4f89bdd182484791f628f432b2ab334db9072780617e0e5668
7
+ data.tar.gz: 6c61cafb9d37780f08cc29e5f97cb9c64cc110236665776a1f249a6401ef8140b1798d9064cf6307d65f96864f2b195e478e23a9e15a118255a9c5fe7d9cda24
@@ -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,72 +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
- # Returns the exchange rate for September 15th, 2017
7
- rate = BcnNi.exchange_day(2017,9,15)
8
- #
9
- # => 30.3537
10
-
11
- # Returns 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
- # From git repository
54
- gem 'bcn_ni', git: 'https://github.com/mldoscar/bcn_ni', branch: 'master'
55
-
56
- # From ruby gems
57
- gem 'bcn_ni'
58
-
59
- # Using gem install
60
- gem install bcn_ni
61
- ```
62
-
63
- And then execute:
64
- ```bash
65
- $ bundle
66
- ```
67
-
68
- ## Contributing
69
- Contribution directions go here.
70
-
71
- ## License
72
- 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,107 +1,4 @@
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
+ module BcnNi
2
+ require 'bcn_ni/version'
3
+ require 'bcn_ni/core'
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('%m'),
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.1'
2
+ VERSION = '0.1.6'
3
3
  end
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bcn_ni
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.6
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-10-04 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
14
  name: activesupport
@@ -16,79 +16,79 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '5.1'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 5.1.3
19
+ version: '5.2'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '5.1'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 5.1.3
26
+ version: '5.2'
33
27
  - !ruby/object:Gem::Dependency
34
- name: rails
28
+ name: nokogiri
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
31
  - - "~>"
38
32
  - !ruby/object:Gem::Version
39
- version: '5.1'
40
- - - ">="
33
+ version: '1.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
41
39
  - !ruby/object:Gem::Version
42
- version: 5.1.3
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.3'
43
48
  type: :development
44
49
  prerelease: false
45
50
  version_requirements: !ruby/object:Gem::Requirement
46
51
  requirements:
47
52
  - - "~>"
48
53
  - !ruby/object:Gem::Version
49
- version: '5.1'
50
- - - ">="
51
- - !ruby/object:Gem::Version
52
- version: 5.1.3
54
+ version: '12.3'
53
55
  - !ruby/object:Gem::Dependency
54
- name: sqlite3
56
+ name: rspec
55
57
  requirement: !ruby/object:Gem::Requirement
56
58
  requirements:
57
59
  - - "~>"
58
60
  - !ruby/object:Gem::Version
59
- version: '1.3'
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: 1.3.12
61
+ version: '3.8'
63
62
  type: :development
64
63
  prerelease: false
65
64
  version_requirements: !ruby/object:Gem::Requirement
66
65
  requirements:
67
66
  - - "~>"
68
67
  - !ruby/object:Gem::Version
69
- version: '1.3'
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- version: 1.3.12
73
- description: A pretty basic gem for consulting Nicaraguan money exchange reates using
74
- 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
75
72
  email:
76
73
  - mld.oscar@yahoo.com
77
74
  executables: []
78
75
  extensions: []
79
76
  extra_rdoc_files: []
80
77
  files:
78
+ - CODE_OF_CONDUCT.md
81
79
  - MIT-LICENSE
82
80
  - README.md
83
81
  - Rakefile
84
82
  - lib/bcn_ni.rb
83
+ - lib/bcn_ni/core.rb
84
+ - lib/bcn_ni/helpers/request.rb
85
85
  - lib/bcn_ni/version.rb
86
86
  - lib/tasks/bcn_ni_tasks.rake
87
87
  homepage: https://github.com/mldoscar/bcn_ni
88
88
  licenses:
89
89
  - MIT
90
90
  metadata: {}
91
- post_install_message:
91
+ post_install_message:
92
92
  rdoc_options: []
93
93
  require_paths:
94
94
  - lib
@@ -103,10 +103,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
105
  requirements: []
106
- rubyforge_project:
107
- rubygems_version: 2.6.8
108
- signing_key:
106
+ rubygems_version: 3.0.6
107
+ signing_key:
109
108
  specification_version: 4
110
- summary: A pretty basic gem for consulting Nicaraguan money exchange reates using
111
- 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
112
111
  test_files: []