sinesp_client_v2 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 54a2d43387fb7756262a39cb36f414694cf4c418
4
- data.tar.gz: f06b052d42d5d8503c4529bbf43e323ad28f112b
3
+ metadata.gz: 4c5da3daf20ebd71831f571e09d6cdd76f8dbc9e
4
+ data.tar.gz: 7ca7ba7095eace566748ebfbc6921f4272075f6e
5
5
  SHA512:
6
- metadata.gz: 0b2d3e0d36bc13dbd14f9e2181b0cfdb72c4275e43bbdabb60b7b11e3adec7620aea1152d6ef5f661d0ef5da3fcc9b18ae69e3809f0c46be8aae9d6e0c4a8424
7
- data.tar.gz: ad324cf7863d7f4268e9e9133013f8c2484174d09d9cc86a7ffb9c4c18fdf29e788697180d9f3b7de20ec2dccc4259034515fbda96d376cf01ddd7283b3eccf9
6
+ metadata.gz: f11518db817fe73a41a60338912bb1b7129a51671abd7dc995ac4c1e743946fb0336277b9d6c1e6df89df006adda88036b7d432157f7e314e5e5362c2b681ddb
7
+ data.tar.gz: fcc392e315ae54e7cad6cfbe50836646f3b98c8ca11811e021e4168ca254e72fd48fe9b5c8fbf7ef70ceefe9d339b91663cd51e1fd8662ad9056536b2f5320e3
@@ -0,0 +1,14 @@
1
+ /.idea
2
+ /.bundle/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+ *.gem
14
+ *.gemspec
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.4
5
+ before_install: gem install bundler -v 1.16.0
@@ -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 aschiavon91@gmail.com. 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/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sinesp_client.gemspec
4
+
5
+ gem 'httparty', '~> 0.15.6'
6
+
7
+ gemspec
@@ -0,0 +1,40 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sinesp_client_v2 (0.1.6)
5
+ httparty (~> 0.15.6)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.3)
11
+ httparty (0.15.6)
12
+ multi_xml (>= 0.5.2)
13
+ multi_xml (0.6.0)
14
+ rake (10.5.0)
15
+ rspec (3.7.0)
16
+ rspec-core (~> 3.7.0)
17
+ rspec-expectations (~> 3.7.0)
18
+ rspec-mocks (~> 3.7.0)
19
+ rspec-core (3.7.0)
20
+ rspec-support (~> 3.7.0)
21
+ rspec-expectations (3.7.0)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.7.0)
24
+ rspec-mocks (3.7.0)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.7.0)
27
+ rspec-support (3.7.0)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ bundler (~> 1.16)
34
+ httparty (~> 0.15.6)
35
+ rake (~> 10.0)
36
+ rspec (~> 3.0)
37
+ sinesp_client_v2!
38
+
39
+ BUNDLED WITH
40
+ 1.16.1
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Antonio Schiavon
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,62 @@
1
+
2
+ # Ruby Sinesp Client V2
3
+ [![Gem Version](https://badge.fury.io/rb/sinesp_client_v2.svg)](https://badge.fury.io/rb/sinesp_client_v2)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/65507b0d81085748bdc6/maintainability)](https://codeclimate.com/github/aschiavon91/sinesp_client/maintainability)
5
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/65507b0d81085748bdc6/test_coverage)](https://codeclimate.com/github/aschiavon91/sinesp_client/test_coverage)
6
+
7
+ This gem provides a client for searching vehicle data based on the license plate from Sinesp database. This data is publicly available at https://www.sinesp.gov.br/sinesp-cidadao. The gem just makes it easier to fetch results, through the same endpoint used by the mobile app.
8
+
9
+ For a python version, please check this: https://github.com/victor-torres/sinesp-client
10
+
11
+ Inspirated by [Original gem](https://github.com/fabianoarruda/sinesp_client)
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'sinesp_client_v2'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install sinesp_client_v2
28
+
29
+ ## Usage
30
+
31
+ ```ruby
32
+ require "sinesp_client_v2"
33
+ SinespClientV2.search('ABC1234')
34
+ ```
35
+ OR
36
+ ```ruby
37
+ proxy = { host: 'XXX.XXX.XXX.XXX', port: 'XXXX', user: 'anonymous', password: 'veryhardpassword' }
38
+ SinespClientV2.search('ABC1234', proxy)
39
+
40
+ ```
41
+
42
+ Returns a hash with basic vehicle data.
43
+
44
+ ## Limitations
45
+
46
+ Sinesp seems to block connections originated from outside of Brazil.
47
+
48
+ ## Development
49
+
50
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
51
+
52
+ To install this gem onto your local machine, run `bundle exec rake install`.
53
+
54
+ ## Contributing
55
+
56
+ Bug reports and pull requests are welcome on GitHub at https://github.com/aschiavon91/sinesp_client.
57
+
58
+
59
+ ## License
60
+
61
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
62
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sinesp_client_v2"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,103 @@
1
+ require_relative 'sinesp_client_v2/version'
2
+ require 'openssl'
3
+ require 'httparty'
4
+
5
+ module SinespClientV2
6
+ include HTTParty
7
+
8
+ BASE_URL = '189.9.194.154'.freeze
9
+ ANDROID_VERSION = '8.1.0'.freeze
10
+ KEYBASE = 'Mw6HqdLgQsX41xAGZgsF'.freeze
11
+ SECRET_KEY = "##{ANDROID_VERSION}##{KEYBASE}".freeze
12
+
13
+
14
+ def self.search(plate, proxy = {})
15
+ unless proxy.empty?
16
+ configure_proxy(proxy[:host], proxy[:port], proxy[:user], proxy[:password])
17
+ end
18
+
19
+ @plate = plate.gsub(/\W+/, '')
20
+
21
+ response = post(
22
+ "https://#{BASE_URL}/sinesp-cidadao/mobile/consultar-placa/v3",
23
+ body: body,
24
+ headers: header,
25
+ timeout: 10,
26
+ cookies: captcha_cookie,
27
+ verify: false
28
+ )
29
+
30
+ response["Envelope"]["Body"]["getStatusResponse"]["return"].to_h
31
+ end
32
+
33
+ private
34
+
35
+ def self.captcha_cookie
36
+ response = get("https://sinespcidadao.sinesp.gov.br/sinesp-cidadao/captchaMobile.png", verify: false)
37
+ cookies = response.headers['set-cookie']
38
+ {
39
+ JSESSIONID: parse_cookie_to_jsessionid(cookies)
40
+ }
41
+ end
42
+
43
+ def self.parse_cookie_to_jsessionid(cookie)
44
+ cookie.split(';').map{
45
+ |value| value if value.include?('JSESSION')
46
+ }.compact.first
47
+ end
48
+
49
+ def self.lat
50
+ rand(-90.000000000...90.000000000)
51
+ end
52
+
53
+ def self.long
54
+ rand(-180.000000000...180.000000000)
55
+ end
56
+
57
+ def self.generate_token
58
+ digest = OpenSSL::Digest.new('sha1')
59
+ OpenSSL::HMAC.hexdigest(digest, @plate + SECRET_KEY, @plate)
60
+ end
61
+
62
+ def self.header
63
+ {
64
+ "Timeout" => "30000",
65
+ "Content-length" => body.length.to_s,
66
+ "User-Agent" => "SinespCidadao / 3.0.2.1 CFNetwork / 758.2.8 Darwin / 15.0.0",
67
+ "Accept" => "text/plain, */*; q=0.01",
68
+ "Cache-Control" => "no-cache",
69
+ "Content-Length" => "661",
70
+ "Content-Type" => "application/x-www-form-urlencoded; charset=UTF-8",
71
+ "Host" => "#{BASE_URL}",
72
+ "Connection" => "close"
73
+ }
74
+ end
75
+
76
+ def self.body
77
+ "<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
78
+ <v:Envelope xmlns:v='http://schemas.xmlsoap.org/soap/envelope/'>
79
+ <v:Header>
80
+ <b>Samsung GT-I9192</b>
81
+ <c>ANDROID</c>
82
+ <d>#{ANDROID_VERSION}</d>
83
+ <i>#{lat}</i>
84
+ <e>4.3.2</e>
85
+ <f>192.168.0.200</f>
86
+ <g>#{generate_token}</g>
87
+ <k></k>
88
+ <h>#{long}</h>
89
+ <l>#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}</l>
90
+ <m>8797e74f0d6eb7b1ff3dc114d4aa12d3</m>
91
+ </v:Header>
92
+ <v:Body>
93
+ <n0:getStatus xmlns:n0='http://soap.ws.placa.service.sinesp.serpro.gov.br/'>
94
+ <a>#{@plate}</a>
95
+ </n0:getStatus>
96
+ </v:Body>
97
+ </v:Envelope>"
98
+ end
99
+
100
+ def self.configure_proxy(host, port, user, password)
101
+ http_proxy(host, port,user, password)
102
+ end
103
+ end
@@ -0,0 +1,3 @@
1
+ module SinespClientV2
2
+ VERSION = "0.1.7"
3
+ end
@@ -1,38 +1,27 @@
1
-
2
- lib = File.expand_path("../lib", __FILE__)
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "sinesp_client_v2/version"
4
+ require 'sinesp_client_v2/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "sinesp_client_v2"
7
+ spec.name = 'sinesp_client_v2'
8
8
  spec.version = SinespClientV2::VERSION
9
- spec.authors = ["Antonio Schiavon"]
10
- spec.email = ["aschiavon91@gmail.com"]
11
-
12
- spec.summary = "Another version of sinesp client gem"
13
- spec.description = "Usage: include sinesp_client_v2 and call SinespClient.search(plate: 'ABC1234')"
14
- spec.homepage = "https://github.com/aschiavon91/sinesp_client"
15
- spec.license = "MIT"
16
-
17
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
- # to allow pushing to a single host or delete this section to allow pushing to any host.
19
- # if spec.respond_to?(:metadata)
20
- # spec.metadata["allowed_push_host"] = "https://rubygems.com"
21
- # else
22
- # raise "RubyGems 2.0 or newer is required to protect against " \
23
- # "public gem pushes."
24
- # end
25
-
26
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
- f.match(%r{^(test|spec|features)/})
28
- end.delete("#{__FILE__}")
29
-
30
- spec.bindir = "exe"
31
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
- spec.require_paths = ["lib"]
9
+ spec.authors = ['Antonio Schiavon']
10
+ spec.email = ['aschiavon91@gmail.com']
11
+ spec.summary = 'Another version of sinesp client gem'
12
+ spec.description = "Usage: include sinesp_client_v2 and call SinespClientV2.search(plate: 'ABC1234')"
13
+ spec.homepage = 'https://github.com/aschiavon91/sinesp_client'
14
+ spec.license = 'MIT'
33
15
 
34
16
  spec.add_development_dependency "bundler", "~> 1.16"
35
17
  spec.add_development_dependency "rake", "~> 10.0"
36
18
  spec.add_development_dependency "rspec", "~> 3.0"
37
19
  spec.add_dependency "httparty", "~> 0.15.6"
20
+
21
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
22
+ f.match(%r{^(test|spec|features)/})
23
+ end
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.required_ruby_version = '>= 2.0.0'
38
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinesp_client_v2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antonio Schiavon
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-03 00:00:00.000000000 Z
11
+ date: 2018-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,7 +66,7 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.15.6
69
- description: 'Usage: include sinesp_client_v2 and call SinespClient.search(plate:
69
+ description: 'Usage: include sinesp_client_v2 and call SinespClientV2.search(plate:
70
70
  ''ABC1234'')'
71
71
  email:
72
72
  - aschiavon91@gmail.com
@@ -74,6 +74,19 @@ executables: []
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - CODE_OF_CONDUCT.md
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - LICENSE
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - lib/sinesp_client_v2.rb
89
+ - lib/sinesp_client_v2/version.rb
77
90
  - sinesp_client_v2.gemspec
78
91
  homepage: https://github.com/aschiavon91/sinesp_client
79
92
  licenses:
@@ -87,7 +100,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
100
  requirements:
88
101
  - - ">="
89
102
  - !ruby/object:Gem::Version
90
- version: '0'
103
+ version: 2.0.0
91
104
  required_rubygems_version: !ruby/object:Gem::Requirement
92
105
  requirements:
93
106
  - - ">="
@@ -95,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
108
  version: '0'
96
109
  requirements: []
97
110
  rubyforge_project:
98
- rubygems_version: 2.6.11
111
+ rubygems_version: 2.6.14
99
112
  signing_key:
100
113
  specification_version: 4
101
114
  summary: Another version of sinesp client gem