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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a1c4b383d91f4ad21fc044cdb93170c13cd097cf04f47d0eb973ad49cbb20030
4
- data.tar.gz: a265fce14d08e714a372ba1f049f4fa5cb3c4b871c8cc83228c90a39f6b2de38
3
+ metadata.gz: 3f0e01abc9ca4e65e1f22527f880650253b861badbd36e6b7f4c387e44a0fc04
4
+ data.tar.gz: c9b29f47fca3b6dec463b896b665ab65907f22ad45645941ab06a1e806d265fc
5
5
  SHA512:
6
- metadata.gz: bcefbc683faa59247e875254834a524fc100797610e38c4d02052226953eb670376467cb02bf18dcc2015ff2275dcab9bc76bac435f2dc58fb71e04005c3c0fc
7
- data.tar.gz: b9c7ef36a12e8072f01de2c024f31e0d98c5ebe80387c7ef13535fc7a2e3ecc7fb6a45af7b52b583fe390cea86e836e371710df474eebcf04e53134343c29089
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 oro Nicaragüense) versus USD (United States dollar) money exchange rates consuming the official Central Bank of Nicaragüa (BCN) SOAP Service
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.3'
70
+ gem 'bcn_ni', '>= 0.1.4'
71
71
 
72
72
  # Using gem install
73
73
  gem install bcn_ni
@@ -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
- request = BcnNi::Request.new(args)
7
+ engine = BcnNi::Request.new(args)
8
+
9
+ result = engine.exchange_month(year, month)
10
+ @@exceptions = engine.exceptions
6
11
 
7
- return request.exchange_month(year, month)
12
+ return result
8
13
  end
9
14
 
10
15
  def self.exchange_day(year, month, day, args = {})
11
- request = BcnNi::Request.new(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
12
23
 
13
- return request.exchange_day(year, month, day)
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 Exception.new('Request mode not implemented')
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
- case request_mode
38
- when :scrapping
39
- return scra__exchange_month(year, month)
40
- when :soap
41
- return soap__exchange_month(year, month)
42
- else
43
- raise Exception.new('Request mode not implemented')
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
- case request_mode
49
- when :scrapping
50
- return scra__exchange_day(year, month, day)
51
- when :soap
52
- return soap__exchange_day(year, month, day)
53
- else
54
- raise Exception.new('Request mode not implemented')
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
- # Fetch and parse HTML document
74
- doc = Nokogiri::HTML(open(full_url, { ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE }))
111
+ # Parse the HTML document
112
+ doc = Nokogiri::HTML(response)
75
113
 
76
114
  result = []
77
115
  # Iterate table
@@ -1,3 +1,3 @@
1
1
  module BcnNi
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
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.3
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-13 00:00:00.000000000 Z
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.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
28
  name: nokogiri
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
31
  - - "~>"
38
32
  - !ruby/object:Gem::Version
39
- version: '1.10'
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.10'
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 tool pretends to be helpful for developers who can request exchange
76
- rates in a easier way
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 gem provides NIO (Córdoba oro Nicaragüense) versus USD (United States
116
- dollar) money exchange rates consuming the official Central Bank of Nicaragüa (BCN)
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: []