bcn_ni 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/bcn_ni/core.rb +16 -4
- data/lib/bcn_ni/helpers/request.rb +64 -26
- data/lib/bcn_ni/version.rb +1 -1
- metadata +11 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f0e01abc9ca4e65e1f22527f880650253b861badbd36e6b7f4c387e44a0fc04
|
4
|
+
data.tar.gz: c9b29f47fca3b6dec463b896b665ab65907f22ad45645941ab06a1e806d265fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 677ca5cc3b6f864b40e4573ad0fe0c978ec3929b6262eb1212f9ec9455ddfe107b268db429af33cdbf97a70b20a325a56922335736130600e760201f20b46157
|
7
|
+
data.tar.gz: ed2a566e0fc5477a53fbd9c24abbc0f22ac7adee37c397857a10dd2beeceaffb675aae64c0910ffc37acc66154026ebe2ee76ba5082416c83f6d75fef7ace016
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# BcnNi
|
2
|
-
This gem provides NIO (Córdoba
|
2
|
+
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
|
3
3
|
|
4
4
|
## Basic usage
|
5
5
|
```ruby
|
@@ -67,7 +67,7 @@ Add this line to your application's Gemfile:
|
|
67
67
|
gem 'bcn_ni', git: 'https://github.com/mldoscar/bcn_ni', branch: 'master'
|
68
68
|
|
69
69
|
# From ruby gems
|
70
|
-
gem 'bcn_ni', '>= 0.1.
|
70
|
+
gem 'bcn_ni', '>= 0.1.4'
|
71
71
|
|
72
72
|
# Using gem install
|
73
73
|
gem install bcn_ni
|
data/lib/bcn_ni/core.rb
CHANGED
@@ -1,15 +1,27 @@
|
|
1
1
|
module BcnNi
|
2
2
|
require File.expand_path(File.dirname(__FILE__)) + '/helpers/request'
|
3
3
|
|
4
|
+
@@exceptions = []
|
5
|
+
|
4
6
|
def self.exchange_month(year, month, args = {})
|
5
|
-
|
7
|
+
engine = BcnNi::Request.new(args)
|
8
|
+
|
9
|
+
result = engine.exchange_month(year, month)
|
10
|
+
@@exceptions = engine.exceptions
|
6
11
|
|
7
|
-
return
|
12
|
+
return result
|
8
13
|
end
|
9
14
|
|
10
15
|
def self.exchange_day(year, month, day, args = {})
|
11
|
-
|
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
|
12
23
|
|
13
|
-
|
24
|
+
def self.exceptions
|
25
|
+
return @@exceptions
|
14
26
|
end
|
15
27
|
end
|
@@ -8,11 +8,25 @@ require 'json'
|
|
8
8
|
|
9
9
|
module BcnNi
|
10
10
|
class Request
|
11
|
-
@request_url =
|
11
|
+
@request_url = nil
|
12
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
|
13
26
|
|
14
27
|
def initialize(args = {})
|
15
28
|
@request_mode = (args[:request_mode] || :scrapping).to_sym
|
29
|
+
@exceptions = []
|
16
30
|
|
17
31
|
case @request_mode
|
18
32
|
when :scrapping
|
@@ -21,37 +35,43 @@ module BcnNi
|
|
21
35
|
# See 'https://servicios.bcn.gob.ni/Tc_Servicio/ServicioTC.asmx' for more info about how to build a RAW SOAP request
|
22
36
|
@request_url = "https://servicios.bcn.gob.ni/Tc_Servicio/ServicioTC.asmx?WSDL"
|
23
37
|
else
|
24
|
-
raise
|
38
|
+
raise NotImplementedError, 'Request mode not implemented'
|
25
39
|
end
|
26
40
|
end
|
27
41
|
|
28
|
-
def request_url
|
29
|
-
return @request_url
|
30
|
-
end
|
31
|
-
|
32
|
-
def request_mode
|
33
|
-
return @request_mode
|
34
|
-
end
|
35
|
-
|
36
42
|
def exchange_month(year, month)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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 []
|
44
57
|
end
|
45
58
|
end
|
46
59
|
|
47
60
|
def exchange_day(year, month, day)
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
55
75
|
end
|
56
76
|
end
|
57
77
|
|
@@ -69,9 +89,27 @@ module BcnNi
|
|
69
89
|
|
70
90
|
# Generate the full url
|
71
91
|
full_url = request_url + '?' + args.to_param
|
92
|
+
|
93
|
+
# This loop prevents a random EOFError (main cause is not known yet)
|
94
|
+
retries = 0
|
95
|
+
response = nil
|
96
|
+
while true
|
97
|
+
# Raise an error if too many retries
|
98
|
+
raise StopIteration if retries >= 5
|
99
|
+
|
100
|
+
begin
|
101
|
+
response = open(full_url, { ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE })
|
102
|
+
# Exit loop if response has been assigned
|
103
|
+
break
|
104
|
+
rescue EOFError => e
|
105
|
+
# Sum retry and sleep the thread for a while
|
106
|
+
retries += 1
|
107
|
+
sleep(2.seconds)
|
108
|
+
end
|
109
|
+
end
|
72
110
|
|
73
|
-
#
|
74
|
-
doc = Nokogiri::HTML(
|
111
|
+
# Parse the HTML document
|
112
|
+
doc = Nokogiri::HTML(response)
|
75
113
|
|
76
114
|
result = []
|
77
115
|
# Iterate table
|
data/lib/bcn_ni/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oscar Rodriguez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,34 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '5.
|
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.
|
30
|
-
- - ">="
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 5.1.3
|
26
|
+
version: '5.2'
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: nokogiri
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
36
30
|
requirements:
|
37
31
|
- - "~>"
|
38
32
|
- !ruby/object:Gem::Version
|
39
|
-
version: '1.
|
33
|
+
version: '1.6'
|
40
34
|
type: :runtime
|
41
35
|
prerelease: false
|
42
36
|
version_requirements: !ruby/object:Gem::Requirement
|
43
37
|
requirements:
|
44
38
|
- - "~>"
|
45
39
|
- !ruby/object:Gem::Version
|
46
|
-
version: '1.
|
40
|
+
version: '1.6'
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
42
|
name: rake
|
49
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,8 +66,9 @@ dependencies:
|
|
72
66
|
- - "~>"
|
73
67
|
- !ruby/object:Gem::Version
|
74
68
|
version: '3.8'
|
75
|
-
description: This
|
76
|
-
rates
|
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
|
77
72
|
email:
|
78
73
|
- mld.oscar@yahoo.com
|
79
74
|
executables: []
|
@@ -112,7 +107,6 @@ rubyforge_project:
|
|
112
107
|
rubygems_version: 2.7.7
|
113
108
|
signing_key:
|
114
109
|
specification_version: 4
|
115
|
-
summary: This
|
116
|
-
|
117
|
-
SOAP Service
|
110
|
+
summary: This tool pretends to be helpful for developers who can request exchange
|
111
|
+
rates from Nicaragua in a easier way
|
118
112
|
test_files: []
|