boa_vista 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/README.md +82 -1
- data/lib/boa_vista/client.rb +44 -0
- data/lib/boa_vista/configuration.rb +1 -1
- data/lib/boa_vista/errors.rb +7 -0
- data/lib/boa_vista/fixtures.rb +1 -0
- data/lib/boa_vista/line.rb +2 -4
- data/lib/boa_vista/request/default.rb +1 -1
- data/lib/boa_vista/response/layout/layout_138.rb +11 -13
- data/lib/boa_vista/response/layout/layout_221.rb +9 -11
- data/lib/boa_vista/response/layout/layout_249.rb +13 -15
- data/lib/boa_vista/response/layout/layout_282.rb +8 -10
- data/lib/boa_vista/response/layout/layout_283.rb +14 -16
- data/lib/boa_vista/response/layout/layout_285.rb +6 -8
- data/lib/boa_vista/response/layout/layout_353.rb +25 -27
- data/lib/boa_vista/response/layout/layout_354.rb +13 -15
- data/lib/boa_vista/response/layout/layout_901.rb +6 -8
- data/lib/boa_vista/response/layout/layout_999.rb +4 -6
- data/lib/boa_vista/response/layout.rb +9 -0
- data/lib/boa_vista/response/parser.rb +28 -0
- data/lib/boa_vista/response.rb +1 -1
- data/lib/boa_vista/version.rb +1 -1
- data/lib/boa_vista.rb +13 -1
- data/spec/fixtures/layout_999.txt +1 -1
- data/spec/fixtures/layout_invalid_353.txt +1 -0
- data/spec/fixtures/response_with_html.txt +1 -0
- data/spec/fixtures/unknown_layout.txt +1 -0
- data/spec/lib/boa_vista/client_spec.rb +45 -0
- data/spec/lib/boa_vista/configuration_spec.rb +2 -0
- data/spec/lib/boa_vista/fixtures.rb +12 -0
- data/spec/lib/boa_vista/line_spec.rb +3 -0
- data/spec/lib/boa_vista/response/layout/layout_999_spec.rb +1 -1
- data/spec/lib/boa_vista/response/layout_spec.rb +19 -0
- data/spec/lib/boa_vista/response/parser_spec.rb +16 -0
- data/spec/lib/boa_vista/version_spec.rb +1 -1
- data/spec/spec_helper.rb +6 -0
- metadata +62 -19
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZDZhNTFlNGFhMThkYzVjOThlM2NkZjY0ZTdmZDQ1ZjcyNDljYTNiZA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZjkyYmI3N2YwOTgxYWRmYjZmODk0YTFmYTQ5ZGM4YzY4OWQ5MTg0OA==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NzRkYzZiMWE2Y2IyNzAzOTQ3ODNiMjEzNDY2YTMwZTEyZGY4OTFlMDkwODZj
|
10
|
+
NzJjZWYyY2E1NWE3YWVmYzVlZTUxN2NiNGE5YTY1MDAzOTUyZjNmMWEwZmE3
|
11
|
+
OThhMDEyNjdjODQ4ZmFiOGViNDgwZDZlYzljZmYyY2IwN2U5MDI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YTIxYmExNGM3MzdhMGExMTZkN2M3ZDAwOTNiYmU0OGMyZjZlNTdlODYwNGY1
|
14
|
+
Njg3MWQ0ZWFiNGE3NDA0ODM4NDMzOTBiYTI2ZDMxMjJmZWU3NDBjZDhmNDIx
|
15
|
+
NzkxNjZlOTkzMDY0M2U0MjMwOWJlYTk1NjQxMDVmMmRhODRkOTM=
|
data/README.md
CHANGED
@@ -1 +1,82 @@
|
|
1
|
-
|
1
|
+
boa_vista
|
2
|
+
=========
|
3
|
+
[![wercker status](https://app.wercker.com/status/08f2a5316ce97f6f16acd51e3c1d3aee/s "wercker status")](https://app.wercker.com/project/bykey/08f2a5316ce97f6f16acd51e3c1d3aee)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/GabrielMalakias/boa_vista/badges/gpa.svg)](https://codeclimate.com/github/GabrielMalakias/boa_vista)
|
5
|
+
=======
|
6
|
+
|
7
|
+
Library to do requests and generate layouts for BoaVista SCPC.
|
8
|
+
|
9
|
+
Features
|
10
|
+
--------
|
11
|
+
* Generate Layout for requests
|
12
|
+
* Parse Layouts of responses
|
13
|
+
* Do requests in BoaVista
|
14
|
+
|
15
|
+
|
16
|
+
### Installation
|
17
|
+
Add this in your Gemfile
|
18
|
+
```ruby
|
19
|
+
gem 'boa_vista'
|
20
|
+
```
|
21
|
+
|
22
|
+
|
23
|
+
### Configuration
|
24
|
+
If you are using Rails add this code in config/initializers
|
25
|
+
```ruby
|
26
|
+
require 'boa_vista'
|
27
|
+
BoaVista.configure do |config|
|
28
|
+
config.code = '<YOUR_CODE>'
|
29
|
+
config.password = '<YOUR_PASSWORD>'
|
30
|
+
config.url = '<BOAVISTA_URL>'
|
31
|
+
config.timeout = '<MAX_SEC_TO_COMPLETE_REQUEST>'
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
### Usage
|
36
|
+
Considering a variable(attributes) equal to this:
|
37
|
+
```ruby
|
38
|
+
attributes = {
|
39
|
+
document_type: '1',
|
40
|
+
document_number: '00031030944410'
|
41
|
+
}.merge(BoaVista::Request::Default::CPF)
|
42
|
+
```
|
43
|
+
|
44
|
+
##### BoaVista::Client
|
45
|
+
To do a request in BoaVista do
|
46
|
+
```ruby
|
47
|
+
line = BoaVista::Client.new(attributes).call
|
48
|
+
```
|
49
|
+
Will return an instance of BoaVista::Line, you can use your methods to access attributes of specific layout
|
50
|
+
```ruby
|
51
|
+
line.transaction
|
52
|
+
=> ' CSR80'
|
53
|
+
```
|
54
|
+
For more information see lib/response/layouts folder
|
55
|
+
|
56
|
+
##### BoaVista::Response
|
57
|
+
Considering a variable below
|
58
|
+
```ruby
|
59
|
+
line = 'TTTTTTTTVVRRRRRRRRRRBBBBBBBBBBBBBBBBBBBBCCCCCCCCQQQQQQQQQVYCNNNNNNNTTTTZZZPPP'
|
60
|
+
```
|
61
|
+
To parse line you can use BoaVista::Response, a code to do this is
|
62
|
+
```ruby
|
63
|
+
parsed_line = BoaVista::Response.new(line).read
|
64
|
+
```
|
65
|
+
And will return an instance of line similar BoaVista::Client#call
|
66
|
+
|
67
|
+
##### BoaVista::Request
|
68
|
+
To create an request you need pass your values
|
69
|
+
```ruby
|
70
|
+
BoaVista::Request.new(attributes).create
|
71
|
+
```
|
72
|
+
|
73
|
+
and will return a similar line of this
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
"CSR60 01 CODE PASSWORDSINTON 012C100031030944410X"
|
77
|
+
```
|
78
|
+
|
79
|
+
#### Contributors
|
80
|
+
* [Gabriel Souza](https://github.com/gabrielmalakias)
|
81
|
+
* [Kleber Shimabuku](https://github.com/klebershimabuku)
|
82
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'timeout'
|
2
|
+
|
3
|
+
module BoaVista
|
4
|
+
|
5
|
+
class Client
|
6
|
+
def initialize(attributes, request = BoaVista::Request, response = BoaVista::Response)
|
7
|
+
@attributes = attributes
|
8
|
+
@request = request
|
9
|
+
@response = response
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
begin
|
14
|
+
response = nil
|
15
|
+
execute_with_timeout do
|
16
|
+
response = Net::HTTP.get_response(uri(create_request)).body
|
17
|
+
end
|
18
|
+
@response.new(parsed_response(response)).read
|
19
|
+
rescue Timeout::Error
|
20
|
+
fail Errors::Timeout.new('timed out')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def parsed_response(response)
|
27
|
+
BoaVista::Response::Parser.new(response).call
|
28
|
+
end
|
29
|
+
|
30
|
+
def execute_with_timeout
|
31
|
+
Timeout::timeout(BoaVista.configuration.timeout.to_i) do
|
32
|
+
yield if block_given?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def create_request
|
37
|
+
@request.new(@attributes).create
|
38
|
+
end
|
39
|
+
|
40
|
+
def uri(request)
|
41
|
+
URI("#{BoaVista.configuration.url}?consulta=#{CGI::escape(request)}")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "#{BoaVista.root}/spec/lib/boa_vista/fixtures"
|
data/lib/boa_vista/line.rb
CHANGED
@@ -45,10 +45,8 @@ module BoaVista
|
|
45
45
|
define_singleton_method(name) { @fields[name].value }
|
46
46
|
end
|
47
47
|
|
48
|
-
def
|
49
|
-
|
50
|
-
|
51
|
-
Object.const_get "BoaVista::Response::Layout::Layout#{layout}"
|
48
|
+
def valid_record?
|
49
|
+
record == 'S'.freeze
|
52
50
|
end
|
53
51
|
|
54
52
|
private
|
@@ -1,20 +1,18 @@
|
|
1
1
|
module BoaVista
|
2
2
|
class Response
|
3
|
-
module Layout
|
4
|
-
|
5
|
-
module_function
|
3
|
+
module Layout::Layout138
|
4
|
+
module_function
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
def initialize(fields)
|
7
|
+
@fields = fields
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
10
|
+
def attributes
|
11
|
+
BoaVista::Response::Layout.attributes.merge(record: { range: 77..77 },
|
12
|
+
document_number: { range: 78..91 },
|
13
|
+
company_name: { range: 92..206 },
|
14
|
+
city: { range: 207..246 },
|
15
|
+
uf: { range: 247..248 })
|
18
16
|
end
|
19
17
|
end
|
20
18
|
end
|
@@ -1,17 +1,15 @@
|
|
1
1
|
module BoaVista
|
2
2
|
class Response
|
3
|
-
module Layout
|
4
|
-
|
5
|
-
module_function
|
3
|
+
module Layout::Layout221
|
4
|
+
module_function
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
6
|
+
def attributes
|
7
|
+
BoaVista::Response::Layout.attributes.merge(record: { range: 77..77 },
|
8
|
+
name: { range: 78..127 },
|
9
|
+
document: { range: 128..138 },
|
10
|
+
birthday_date: { range: 139..146 },
|
11
|
+
mothers_name: { range: 149..198 },
|
12
|
+
voter_registration: { range: 199..211 })
|
15
13
|
end
|
16
14
|
end
|
17
15
|
end
|
@@ -1,21 +1,19 @@
|
|
1
1
|
module BoaVista
|
2
2
|
class Response
|
3
|
-
module Layout
|
4
|
-
|
5
|
-
module_function
|
3
|
+
module Layout::Layout249
|
4
|
+
module_function
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
6
|
+
def attributes
|
7
|
+
BoaVista::Response::Layout.attributes.merge(query_online: { range: 77..77 },
|
8
|
+
name: { range: 78..127 },
|
9
|
+
document: { range: 128..138 },
|
10
|
+
birthday_date: { range: 139..146 },
|
11
|
+
mothers_name: { range: 149..198 },
|
12
|
+
voter_registration: { range: 199..211 },
|
13
|
+
condition: { range: 212..212 },
|
14
|
+
query_date: { range: 213..220 },
|
15
|
+
query_time: { range: 221..226 },
|
16
|
+
protocol: { range: 227..246 })
|
19
17
|
end
|
20
18
|
end
|
21
19
|
end
|
@@ -1,16 +1,14 @@
|
|
1
1
|
module BoaVista
|
2
2
|
class Response
|
3
|
-
module Layout
|
4
|
-
|
5
|
-
module_function
|
3
|
+
module Layout::Layout282
|
4
|
+
module_function
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
6
|
+
def attributes
|
7
|
+
BoaVista::Response::Layout.attributes.merge(record: { range: 77..77 },
|
8
|
+
sequence_number: { range: 78..79 },
|
9
|
+
company_name: { range: 80..129 },
|
10
|
+
document_type: { range: 130..130 },
|
11
|
+
document_number: { range: 131..144 })
|
14
12
|
end
|
15
13
|
end
|
16
14
|
end
|
@@ -1,22 +1,20 @@
|
|
1
1
|
module BoaVista
|
2
2
|
class Response
|
3
|
-
module Layout
|
4
|
-
|
5
|
-
module_function
|
3
|
+
module Layout::Layout283
|
4
|
+
module_function
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
6
|
+
def attributes
|
7
|
+
BoaVista::Response::Layout.attributes.merge(record: { range: 77..77 },
|
8
|
+
sequence_number: { range: 78..82 },
|
9
|
+
company_name: { range: 83..132 },
|
10
|
+
document_type: { range: 133..133 },
|
11
|
+
document_number: { range: 134..147 },
|
12
|
+
entry_date: { range: 148..155 },
|
13
|
+
currency_type: { range: 156..156 },
|
14
|
+
value: { range: 157..171 },
|
15
|
+
function: { range: 172..191 },
|
16
|
+
signs: { range: 192..192 },
|
17
|
+
percentage: { range: 193..197 })
|
20
18
|
end
|
21
19
|
end
|
22
20
|
end
|
@@ -1,14 +1,12 @@
|
|
1
1
|
module BoaVista
|
2
2
|
class Response
|
3
|
-
module Layout
|
4
|
-
|
5
|
-
module_function
|
3
|
+
module Layout::Layout285
|
4
|
+
module_function
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
6
|
+
def attributes
|
7
|
+
BoaVista::Response::Layout.attributes.merge(record: { range: 77..77 },
|
8
|
+
hive_activity_code: { range: 78..85 },
|
9
|
+
hive_activity_description: { range: 86..140 })
|
12
10
|
end
|
13
11
|
end
|
14
12
|
end
|
@@ -1,33 +1,31 @@
|
|
1
1
|
module BoaVista
|
2
2
|
class Response
|
3
|
-
module Layout
|
4
|
-
|
5
|
-
module_function
|
3
|
+
module Layout::Layout353
|
4
|
+
module_function
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
6
|
+
def attributes
|
7
|
+
BoaVista::Response::Layout.attributes.merge(record: { range: 77..77 },
|
8
|
+
document_number: { range: 78..91 },
|
9
|
+
nire: { range: 92..102 },
|
10
|
+
company_name: { range: 103..217 },
|
11
|
+
condition: { range: 218..218 },
|
12
|
+
foundation_date: { range: 219..226 },
|
13
|
+
registration: { range: 227..240 },
|
14
|
+
registration_status: { range: 241..241 },
|
15
|
+
address: { range: 242..311 },
|
16
|
+
district: { range: 312..331 },
|
17
|
+
postal_code: { range: 332..339 },
|
18
|
+
city: { range: 340..379 },
|
19
|
+
uf: { range: 380..381 },
|
20
|
+
phone_1: { range: 382..401 },
|
21
|
+
phone_2: { range: 402..416 },
|
22
|
+
fax: { range: 417..431 },
|
23
|
+
ibge_code: { range: 432..439 },
|
24
|
+
legal_nature_code: { range: 440..447 },
|
25
|
+
legal_nature_description: { range: 448..502 },
|
26
|
+
segment: { range: 503..581 },
|
27
|
+
hive_activity_code: { range: 582..589 },
|
28
|
+
hive_activity_description: { range: 590..644 })
|
31
29
|
end
|
32
30
|
end
|
33
31
|
end
|
@@ -1,21 +1,19 @@
|
|
1
1
|
module BoaVista
|
2
2
|
class Response
|
3
|
-
module Layout
|
4
|
-
|
5
|
-
module_function
|
3
|
+
module Layout::Layout354
|
4
|
+
module_function
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
6
|
+
def attributes
|
7
|
+
BoaVista::Response::Layout.attributes.merge(record: { range: 77..77 },
|
8
|
+
document_number: { range: 78..91 },
|
9
|
+
currency_social_capital: { range: 92..95 },
|
10
|
+
value_social_capital: { range: 96..110 },
|
11
|
+
home_organ: { range: 111..118 },
|
12
|
+
register_date: { range: 119..126 },
|
13
|
+
currency_current_capital: { range: 127..130 },
|
14
|
+
value_current_capital: { range: 131..145 },
|
15
|
+
current_organ: { range: 146..153 },
|
16
|
+
change_date: { range: 154..161 })
|
19
17
|
end
|
20
18
|
end
|
21
19
|
end
|
@@ -1,14 +1,12 @@
|
|
1
1
|
module BoaVista
|
2
2
|
class Response
|
3
|
-
module Layout
|
4
|
-
|
5
|
-
module_function
|
3
|
+
module Layout::Layout901
|
4
|
+
module_function
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
6
|
+
def attributes
|
7
|
+
BoaVista::Response::Layout.attributes.merge(record: { range: 77..77 },
|
8
|
+
message_type: { range: 78..78 },
|
9
|
+
message: { range: 79..208 })
|
12
10
|
end
|
13
11
|
end
|
14
12
|
end
|
@@ -1,12 +1,10 @@
|
|
1
1
|
module BoaVista
|
2
2
|
class Response
|
3
|
-
module Layout
|
4
|
-
|
5
|
-
module_function
|
3
|
+
module Layout::Layout999
|
4
|
+
module_function
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
end
|
6
|
+
def attributes
|
7
|
+
BoaVista::Response::Layout.attributes.merge(record: { range: 77..171 })
|
10
8
|
end
|
11
9
|
end
|
12
10
|
end
|
@@ -21,6 +21,15 @@ module BoaVista
|
|
21
21
|
}
|
22
22
|
end
|
23
23
|
|
24
|
+
def detect(value)
|
25
|
+
begin
|
26
|
+
layout = value.slice(BoaVista::Response::Layout.range_of(:record_type))
|
27
|
+
eval "BoaVista::Response::Layout::Layout#{layout}"
|
28
|
+
rescue NameError
|
29
|
+
fail Errors::InvalidLayout.new("Layout of response invalid, layout_code: #{layout}")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
24
33
|
def range_of(attribute)
|
25
34
|
attributes[attribute][:range]
|
26
35
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module BoaVista
|
2
|
+
class Response
|
3
|
+
class Parser
|
4
|
+
INVALID_STRING = "\\n"
|
5
|
+
BLANK_SPACE = ''
|
6
|
+
|
7
|
+
def initialize(response, base_tag = '//pre')
|
8
|
+
@base_tag = '//pre'
|
9
|
+
@response = response
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
return @response if !@response.include?(INVALID_STRING)
|
14
|
+
sanitize(navigate_to_node)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def navigate_to_node
|
20
|
+
::Nokogiri::HTML(@response).xpath(@base_tag).text
|
21
|
+
end
|
22
|
+
|
23
|
+
def sanitize(response)
|
24
|
+
response.gsub(INVALID_STRING, BLANK_SPACE)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/boa_vista/response.rb
CHANGED
data/lib/boa_vista/version.rb
CHANGED
data/lib/boa_vista.rb
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'cgi'
|
3
|
+
require 'nokogiri'
|
4
|
+
|
1
5
|
require 'boa_vista/configuration'
|
6
|
+
require 'boa_vista/client'
|
2
7
|
|
3
8
|
require 'boa_vista/field'
|
4
9
|
require 'boa_vista/field/reader'
|
@@ -6,14 +11,17 @@ require 'boa_vista/field/writer'
|
|
6
11
|
|
7
12
|
require 'boa_vista/line'
|
8
13
|
|
14
|
+
require 'boa_vista/errors'
|
15
|
+
|
9
16
|
require 'boa_vista/request'
|
10
17
|
require 'boa_vista/request/layout'
|
11
18
|
require 'boa_vista/request/layout/cpf'
|
12
19
|
require 'boa_vista/request/layout/cnpj'
|
13
20
|
require 'boa_vista/request/factory'
|
14
21
|
|
15
|
-
require 'boa_vista/response/layout'
|
16
22
|
require 'boa_vista/response'
|
23
|
+
require 'boa_vista/response/layout'
|
24
|
+
require 'boa_vista/response/parser'
|
17
25
|
|
18
26
|
require 'boa_vista/response/layout/layout_138'
|
19
27
|
require 'boa_vista/response/layout/layout_282'
|
@@ -42,6 +50,10 @@ module BoaVista
|
|
42
50
|
def self.configure
|
43
51
|
yield(configuration)
|
44
52
|
end
|
53
|
+
|
54
|
+
def self.root
|
55
|
+
File.expand_path '../..', __FILE__
|
56
|
+
end
|
45
57
|
end
|
46
58
|
|
47
59
|
require 'boa_vista/request/default'
|
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
TTTTTTTTVVRRRRRRRRRRBBBBBBBBBBBBBBBBBBBBCCCCCCCCQQQQQQQQQVYCNNNNNNNTTTTZZZ999SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
|
@@ -0,0 +1 @@
|
|
1
|
+
TTTTTTTTVVRRRRRRRRRRBBBBBBBBBBBBBBBBBBBBCCCCCCCCQQQQQQQQQVYCNNNNNNNTTTTZZZ353NDDDDDDDDDDDDDDNNNNNNNNNNNCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCTFFFFFFFFRRRRRRRRRRRRRRSAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBPPPPPPPPCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCUUPPPPPPPPPPPPPPPPPPPPHHHHHHHHHHHHHHHFFFFFFFFFFFFFFFGGGGGGGGNNNNNNNNDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSRRRRRRRRDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
|
@@ -0,0 +1 @@
|
|
1
|
+
\n\n\t\n\t\t\n\t\t\n \n \n \t \n \n \n \t \n\t\n \n \n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n<PRE>\nCSR61 01 00000045 2900000000101098999* IDENTIFICADOR COM RESTRICAO DE ACESSO \n</PRE>\n\n
|
@@ -0,0 +1 @@
|
|
1
|
+
TTTTTTTTVVRRRRRRRRRRBBBBBBBBBBBBBBBBBBBBCCCCCCCCQQQQQQQQQVYCNNNNNNNTTTTZZZ888
|
@@ -0,0 +1,45 @@
|
|
1
|
+
RSpec.describe BoaVista::Client do
|
2
|
+
context 'when requests cpf' do
|
3
|
+
before do
|
4
|
+
stub_request(:get, url_stub).to_return(body: line)
|
5
|
+
end
|
6
|
+
|
7
|
+
let(:instance) { described_class.new(values) }
|
8
|
+
let(:line) { File.read('./spec/fixtures/layout_353.txt') }
|
9
|
+
let(:url_stub) { "http://localhost:3000/?consulta=CSR60%20%20%2001%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20CODE%20%20%20%20PASSWORDSINTON%20%20012C100031030944410X" }
|
10
|
+
let(:values) do
|
11
|
+
{
|
12
|
+
document_type: '1',
|
13
|
+
document_number: '00031030944410'
|
14
|
+
}.merge(BoaVista::Request::Default::CPF)
|
15
|
+
end
|
16
|
+
|
17
|
+
subject { instance.call }
|
18
|
+
|
19
|
+
its(:transaction) { is_expected.to eq('T' * 8) }
|
20
|
+
|
21
|
+
context 'when record is valid' do
|
22
|
+
its(:valid_record?) { is_expected.to be_truthy }
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when record is invalid' do
|
26
|
+
let(:line) { File.read('./spec/fixtures/layout_invalid_353.txt') }
|
27
|
+
|
28
|
+
its(:valid_record?) { is_expected.to be_falsey }
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when response has an html and has an invalid response' do
|
32
|
+
let(:line) { File.read('./spec/fixtures/response_with_html.txt') }
|
33
|
+
|
34
|
+
its(:record_type) { is_expected.to eq 999.to_s }
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'when timeout error' do
|
38
|
+
it 'raise BoaVista::Errors::Timeout' do
|
39
|
+
allow(Net::HTTP).to receive(:get_response).with(anything) { raise(Timeout::Error) }
|
40
|
+
expect { subject }.to raise_error(BoaVista::Errors::Timeout)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -2,5 +2,7 @@ RSpec.describe BoaVista::Configuration do
|
|
2
2
|
it 'configures with code and password' do
|
3
3
|
expect(BoaVista.configuration.code).to eq('CODE')
|
4
4
|
expect(BoaVista.configuration.password).to eq('PASSWORD')
|
5
|
+
expect(BoaVista.configuration.url).to eq('http://localhost:3000')
|
6
|
+
expect(BoaVista.configuration.timeout).to eq(10)
|
5
7
|
end
|
6
8
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module BoaVista
|
2
|
+
class Fixtures
|
3
|
+
def self.read(name)
|
4
|
+
begin
|
5
|
+
file_path = "#{BoaVista.root}/spec/fixtures/#{name}"
|
6
|
+
File.open(file_path).readlines
|
7
|
+
rescue Errno::ENOENT
|
8
|
+
fail Errors::FileNotExists.new("Specified fixture not exists: #{file_path}")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -1,2 +1,21 @@
|
|
1
1
|
RSpec.describe BoaVista::Response::Layout do
|
2
|
+
describe '.detect' do
|
3
|
+
subject { described_class.detect(response) }
|
4
|
+
|
5
|
+
context 'when layout is Layout999' do
|
6
|
+
let(:response) { File.read('./spec/fixtures/layout_999.txt') }
|
7
|
+
|
8
|
+
subject { described_class.detect(response) }
|
9
|
+
|
10
|
+
it { is_expected.to eq BoaVista::Response::Layout::Layout999 }
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'when layout is unknown' do
|
14
|
+
let(:response) { File.read('./spec/fixtures/unknown_layout.txt') }
|
15
|
+
|
16
|
+
it 'raise InvalidLayout error' do
|
17
|
+
expect{described_class.detect(response)}.to raise_error(BoaVista::Errors::InvalidLayout)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
2
21
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
RSpec.describe BoaVista::Response::Parser do
|
2
|
+
let(:response) { File.read('./spec/fixtures/response_with_html.txt') }
|
3
|
+
let(:instance) { described_class.new(response) }
|
4
|
+
|
5
|
+
context 'when response have html tags' do
|
6
|
+
subject { instance.call }
|
7
|
+
|
8
|
+
it { is_expected.to eq 'CSR61 01 00000045 2900000000101098999* IDENTIFICADOR COM RESTRICAO DE ACESSO ' }
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'when response haven\'t html tags' do
|
12
|
+
subject { instance.call }
|
13
|
+
|
14
|
+
it { is_expected.to eq 'CSR61 01 00000045 2900000000101098999* IDENTIFICADOR COM RESTRICAO DE ACESSO ' }
|
15
|
+
end
|
16
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,14 +3,20 @@ Bundler.setup
|
|
3
3
|
|
4
4
|
require 'rspec'
|
5
5
|
require 'rspec/its'
|
6
|
+
require 'webmock'
|
6
7
|
|
7
8
|
require 'boa_vista'
|
9
|
+
require 'codeclimate-test-reporter'
|
8
10
|
|
11
|
+
CodeClimate::TestReporter.start
|
9
12
|
RSpec.configure do |c|
|
10
13
|
c.disable_monkey_patching!
|
11
14
|
|
15
|
+
include WebMock::API
|
12
16
|
BoaVista.configure do |config|
|
13
17
|
config.code = 'CODE'
|
14
18
|
config.password = 'PASSWORD'
|
19
|
+
config.url = 'http://localhost:3000'
|
20
|
+
config.timeout = 10
|
15
21
|
end
|
16
22
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boa_vista
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Souza
|
@@ -9,62 +9,90 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-03-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: nokogiri
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ! '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ! '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: codeclimate-test-reporter
|
16
30
|
requirement: !ruby/object:Gem::Requirement
|
17
31
|
requirements:
|
18
|
-
- -
|
32
|
+
- - ! '>='
|
19
33
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
34
|
+
version: '0'
|
21
35
|
type: :development
|
22
36
|
prerelease: false
|
23
37
|
version_requirements: !ruby/object:Gem::Requirement
|
24
38
|
requirements:
|
25
|
-
- -
|
39
|
+
- - ! '>='
|
26
40
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
41
|
+
version: '0'
|
28
42
|
- !ruby/object:Gem::Dependency
|
29
|
-
name:
|
43
|
+
name: webmock
|
30
44
|
requirement: !ruby/object:Gem::Requirement
|
31
45
|
requirements:
|
32
|
-
- -
|
46
|
+
- - ! '>='
|
33
47
|
- !ruby/object:Gem::Version
|
34
48
|
version: '0'
|
35
49
|
type: :development
|
36
50
|
prerelease: false
|
37
51
|
version_requirements: !ruby/object:Gem::Requirement
|
38
52
|
requirements:
|
39
|
-
- -
|
53
|
+
- - ! '>='
|
40
54
|
- !ruby/object:Gem::Version
|
41
55
|
version: '0'
|
42
56
|
- !ruby/object:Gem::Dependency
|
43
|
-
name:
|
57
|
+
name: rspec
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rspec-its
|
44
72
|
requirement: !ruby/object:Gem::Requirement
|
45
73
|
requirements:
|
46
|
-
- -
|
74
|
+
- - ! '>='
|
47
75
|
- !ruby/object:Gem::Version
|
48
76
|
version: '0'
|
49
77
|
type: :development
|
50
78
|
prerelease: false
|
51
79
|
version_requirements: !ruby/object:Gem::Requirement
|
52
80
|
requirements:
|
53
|
-
- -
|
81
|
+
- - ! '>='
|
54
82
|
- !ruby/object:Gem::Version
|
55
83
|
version: '0'
|
56
84
|
- !ruby/object:Gem::Dependency
|
57
85
|
name: rake
|
58
86
|
requirement: !ruby/object:Gem::Requirement
|
59
87
|
requirements:
|
60
|
-
- -
|
88
|
+
- - ! '>='
|
61
89
|
- !ruby/object:Gem::Version
|
62
90
|
version: '0'
|
63
91
|
type: :development
|
64
92
|
prerelease: false
|
65
93
|
version_requirements: !ruby/object:Gem::Requirement
|
66
94
|
requirements:
|
67
|
-
- -
|
95
|
+
- - ! '>='
|
68
96
|
- !ruby/object:Gem::Version
|
69
97
|
version: '0'
|
70
98
|
description: Client for Boa Vista
|
@@ -77,10 +105,13 @@ extra_rdoc_files: []
|
|
77
105
|
files:
|
78
106
|
- README.md
|
79
107
|
- lib/boa_vista.rb
|
108
|
+
- lib/boa_vista/client.rb
|
80
109
|
- lib/boa_vista/configuration.rb
|
110
|
+
- lib/boa_vista/errors.rb
|
81
111
|
- lib/boa_vista/field.rb
|
82
112
|
- lib/boa_vista/field/reader.rb
|
83
113
|
- lib/boa_vista/field/writer.rb
|
114
|
+
- lib/boa_vista/fixtures.rb
|
84
115
|
- lib/boa_vista/line.rb
|
85
116
|
- lib/boa_vista/request.rb
|
86
117
|
- lib/boa_vista/request/default.rb
|
@@ -100,6 +131,7 @@ files:
|
|
100
131
|
- lib/boa_vista/response/layout/layout_354.rb
|
101
132
|
- lib/boa_vista/response/layout/layout_901.rb
|
102
133
|
- lib/boa_vista/response/layout/layout_999.rb
|
134
|
+
- lib/boa_vista/response/parser.rb
|
103
135
|
- lib/boa_vista/version.rb
|
104
136
|
- spec/fixtures/base.txt
|
105
137
|
- spec/fixtures/layout_138.txt
|
@@ -113,9 +145,14 @@ files:
|
|
113
145
|
- spec/fixtures/layout_901.txt
|
114
146
|
- spec/fixtures/layout_999.txt
|
115
147
|
- spec/fixtures/layout_cpf.txt
|
148
|
+
- spec/fixtures/layout_invalid_353.txt
|
149
|
+
- spec/fixtures/response_with_html.txt
|
150
|
+
- spec/fixtures/unknown_layout.txt
|
151
|
+
- spec/lib/boa_vista/client_spec.rb
|
116
152
|
- spec/lib/boa_vista/configuration_spec.rb
|
117
153
|
- spec/lib/boa_vista/field/writer_spec.rb
|
118
154
|
- spec/lib/boa_vista/field_spec.rb
|
155
|
+
- spec/lib/boa_vista/fixtures.rb
|
119
156
|
- spec/lib/boa_vista/line_spec.rb
|
120
157
|
- spec/lib/boa_vista/request/default_spec.rb
|
121
158
|
- spec/lib/boa_vista/request/factory_spec.rb
|
@@ -134,6 +171,7 @@ files:
|
|
134
171
|
- spec/lib/boa_vista/response/layout/layout_901_spec.rb
|
135
172
|
- spec/lib/boa_vista/response/layout/layout_999_spec.rb
|
136
173
|
- spec/lib/boa_vista/response/layout_spec.rb
|
174
|
+
- spec/lib/boa_vista/response/parser_spec.rb
|
137
175
|
- spec/lib/boa_vista/response_spec.rb
|
138
176
|
- spec/lib/boa_vista/version_spec.rb
|
139
177
|
- spec/spec_helper.rb
|
@@ -146,17 +184,17 @@ require_paths:
|
|
146
184
|
- lib
|
147
185
|
required_ruby_version: !ruby/object:Gem::Requirement
|
148
186
|
requirements:
|
149
|
-
- -
|
187
|
+
- - ! '>='
|
150
188
|
- !ruby/object:Gem::Version
|
151
189
|
version: '0'
|
152
190
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
191
|
requirements:
|
154
|
-
- -
|
192
|
+
- - ! '>='
|
155
193
|
- !ruby/object:Gem::Version
|
156
194
|
version: '0'
|
157
195
|
requirements: []
|
158
196
|
rubyforge_project:
|
159
|
-
rubygems_version: 2.4.
|
197
|
+
rubygems_version: 2.4.8
|
160
198
|
signing_key:
|
161
199
|
specification_version: 4
|
162
200
|
summary: Client for Boa Vista
|
@@ -173,9 +211,14 @@ test_files:
|
|
173
211
|
- spec/fixtures/layout_901.txt
|
174
212
|
- spec/fixtures/layout_999.txt
|
175
213
|
- spec/fixtures/layout_cpf.txt
|
214
|
+
- spec/fixtures/layout_invalid_353.txt
|
215
|
+
- spec/fixtures/response_with_html.txt
|
216
|
+
- spec/fixtures/unknown_layout.txt
|
217
|
+
- spec/lib/boa_vista/client_spec.rb
|
176
218
|
- spec/lib/boa_vista/configuration_spec.rb
|
177
219
|
- spec/lib/boa_vista/field/writer_spec.rb
|
178
220
|
- spec/lib/boa_vista/field_spec.rb
|
221
|
+
- spec/lib/boa_vista/fixtures.rb
|
179
222
|
- spec/lib/boa_vista/line_spec.rb
|
180
223
|
- spec/lib/boa_vista/request/default_spec.rb
|
181
224
|
- spec/lib/boa_vista/request/factory_spec.rb
|
@@ -194,7 +237,7 @@ test_files:
|
|
194
237
|
- spec/lib/boa_vista/response/layout/layout_901_spec.rb
|
195
238
|
- spec/lib/boa_vista/response/layout/layout_999_spec.rb
|
196
239
|
- spec/lib/boa_vista/response/layout_spec.rb
|
240
|
+
- spec/lib/boa_vista/response/parser_spec.rb
|
197
241
|
- spec/lib/boa_vista/response_spec.rb
|
198
242
|
- spec/lib/boa_vista/version_spec.rb
|
199
243
|
- spec/spec_helper.rb
|
200
|
-
has_rdoc:
|