targetdata 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0a718c58dad3b172a252ffa56de2241b3fb1fde2c2f1e4198114808ea8657a46
4
+ data.tar.gz: 6f92c89434d9fe3fff763425c4beded7204787188d4e176f0d81b4e30929316c
5
+ SHA512:
6
+ metadata.gz: 7773ad5dd81e6de0f06129ab5b5033a8f38c23274ed95965dc3dd51b475d8df317f0d170cf0ee19c620975fb092578dd8d2336e6c2b99b4fe0a7d50cd479fa54
7
+ data.tar.gz: 33173334c935e7110c0042a8cb481eb2e4a881c003a5dfb48e1440432121ce262d6b2920e5a33a8e9780153a5bc7cf86ab066b5d2775f683d707a881fca5bc2b
@@ -0,0 +1,20 @@
1
+ Gemfile.lock
2
+ .DS_Store
3
+ .rbenv-gemsets
4
+ .ruby-version
5
+ .vscode/
6
+ .bundle
7
+ *gemfile.lock
8
+
9
+ /.bundle/
10
+ /.yardoc
11
+ /_yardoc/
12
+ /coverage/
13
+ /doc/
14
+ /pkg/
15
+ /spec/reports/
16
+ /tmp/
17
+
18
+ # rspec failure tracking
19
+ .rspec_status
20
+ .env.test
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.2
6
+ before_install: gem install bundler -v 2.1.4
@@ -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 kimpastro@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 [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem 'vcr', '~> 6.0'
9
+ gem 'webmock', '~> 3.8', '>= 3.8.3'
10
+ gem 'dotenv', '~> 2.7', '>= 2.7.6'
11
+ gem 'pry-byebug', '~> 3.9'
12
+ gem 'faker', '~> 2.13'
13
+ end
14
+
15
+ gem 'http', '~> 4.4', '>= 4.4.1'
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Kim Pastro
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,2 @@
1
+ console:
2
+ bin/console
@@ -0,0 +1,76 @@
1
+ # Targetdata
2
+ Integrates with Targetdata Smart API.
3
+
4
+ ## Resources
5
+ Get person by it CPF
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'targetdata'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install targetdata
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ Targetdata.configure do |config|
27
+ config.username = username
28
+ config.password = password
29
+ config.company_id = company_id
30
+ config.client_secret = client_secret
31
+ end
32
+
33
+ # Find by CPF
34
+ cpf = '88899988811'
35
+ person = Targetdata.person_by_cpf cpf
36
+
37
+ # Person's attributes
38
+ person.cpf
39
+ person.first_name
40
+ person.middle_name
41
+ person.last_name
42
+ person.gender
43
+ person.birth
44
+ person.status_receita_federal
45
+ person.rg_number
46
+ person.rg_orgao_emissor
47
+ person.rg_uf
48
+ person.voter_registration
49
+ person.death
50
+ person.nationality
51
+ person.minor
52
+ person.marital_status
53
+ person.mother_first_name
54
+ person.mother_middle_name
55
+ person.mother_last_name
56
+ person.schooling
57
+ ```
58
+
59
+ ## Development
60
+
61
+ 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.
62
+
63
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
64
+
65
+ ## Contributing
66
+
67
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/targetdata. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/targetdata/blob/master/CODE_OF_CONDUCT.md).
68
+
69
+
70
+ ## License
71
+
72
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
73
+
74
+ ## Code of Conduct
75
+
76
+ Everyone interacting in the Targetdata project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/targetdata/blob/master/CODE_OF_CONDUCT.md).
@@ -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 "targetdata"
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,30 @@
1
+ require "targetdata/version"
2
+ require "http"
3
+
4
+ require_relative "targetdata/configuration"
5
+ require_relative "targetdata/errors/unauthorized"
6
+ require_relative "targetdata/errors/person_not_found"
7
+ require_relative "targetdata/entities/person"
8
+ require_relative "targetdata/api/auth"
9
+ require_relative "targetdata/api/requester"
10
+ require_relative "targetdata/api/pf"
11
+
12
+ module Targetdata
13
+ BASE_URL = 'https://targetdatasmart.com/api'
14
+
15
+ class << self
16
+ attr_writer :configuration
17
+ end
18
+
19
+ def self.configuration
20
+ @configuration ||= Configuration.new
21
+ end
22
+
23
+ def self.configure
24
+ yield(configuration)
25
+ end
26
+
27
+ def self.person_by_cpf cpf
28
+ Targetdata::Api::Pf.new(cpf).person
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ module Targetdata
2
+ module Api
3
+ module Auth
4
+ def token
5
+ response = HTTP.headers(auth_headers).post(Targetdata::BASE_URL + '/token', form: auth_body)
6
+ parsed = JSON.parse(response.body.to_s)
7
+ parsed["access_token"]
8
+ end
9
+
10
+ private
11
+ def auth_body
12
+ {
13
+ grant_type: Targetdata.configuration.grant_type,
14
+ client_id: Targetdata.configuration.client_id,
15
+ client_secret: Targetdata.configuration.client_secret,
16
+ username: Targetdata.configuration.username,
17
+ password: Targetdata.configuration.password,
18
+ empresa: Targetdata.configuration.company_id
19
+ }
20
+ end
21
+
22
+ def auth_headers
23
+ {
24
+ 'Content-Type':'application/x-www-form-urlencoded',
25
+ 'Accept': 'application/json'
26
+ }
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,29 @@
1
+ module Targetdata
2
+ module Api
3
+ class Pf
4
+ include Auth
5
+ include Requester
6
+
7
+ def initialize cpf
8
+ @cpf = cpf
9
+ end
10
+
11
+ def person
12
+ response = get_person
13
+ Entities::Person.new hash_person(response.body.to_s)
14
+ end
15
+
16
+ private
17
+ def hash_person string_body
18
+ parsed = JSON.parse(string_body)
19
+
20
+ raise Targetdata::Errors::PersonNotFound unless person_found?(parsed)
21
+ parsed["result"].first["pessoa"]["cadastral"]
22
+ end
23
+
24
+ def person_found? hash
25
+ !hash["result"].empty?
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,21 @@
1
+ module Targetdata
2
+ module Api
3
+ module Requester
4
+ def get_person
5
+ response = HTTP.headers(cpf_headers).post(Targetdata::BASE_URL + '/PF/CPF', body: [@cpf].to_json)
6
+ raise Targetdata::Errors::Unauthorized if response.status.unauthorized?
7
+
8
+ response
9
+ end
10
+
11
+ private
12
+ def cpf_headers
13
+ {
14
+ 'Content-Type':'application/json',
15
+ 'Accept':'application/json',
16
+ 'Authorization': "Bearer #{token}"
17
+ }
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,10 @@
1
+ module Targetdata
2
+ class Configuration
3
+ attr_accessor :username, :password, :company_id, :client_secret, :grant_type, :client_id
4
+
5
+ def initialize
6
+ @grant_type = 'password'
7
+ @client_id = 2
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,71 @@
1
+ module Targetdata
2
+ module Entities
3
+ class Person
4
+ attr_accessor :cpf,
5
+ :first_name,
6
+ :middle_name,
7
+ :last_name,
8
+ :gender,
9
+ :birth,
10
+ :status_receita_federal,
11
+ :rg_number,
12
+ :rg_orgao_emissor,
13
+ :rg_uf,
14
+ :voter_registration,
15
+ :death,
16
+ :nationality,
17
+ :minor,
18
+ :marital_status,
19
+ :mother_first_name,
20
+ :mother_middle_name,
21
+ :mother_last_name,
22
+ :schooling
23
+
24
+ def initialize params = {}
25
+ @cpf = params['CPF']
26
+ @first_name = params['nomePrimeiro']
27
+ @middle_name = params['nomeMeio']
28
+ @last_name = params['nomeUltimo']
29
+ @gender = params['sexo']
30
+ @birth = params['dataNascimento']
31
+ @status_receita_federal = params['statusReceitaFederal']
32
+ @rg_number = params['rgNumero']
33
+ @rg_orgao_emissor = params['rgOrgaoEmissor']
34
+ @rg_uf = params['rgUf']
35
+ @voter_registration = params['tituloEleitoral']
36
+ @death = params['obito']
37
+ @nationality = params['nacionalidade']
38
+ @minor = params['menorDeIdade']
39
+ @marital_status = params['estadoCivil']
40
+ @mother_first_name = params['maeNomePrimeiro']
41
+ @mother_middle_name = params['maeNomeMeio']
42
+ @mother_last_name = params['maeNomeUltimo']
43
+ @schooling = params['escolaridade']
44
+ end
45
+
46
+ def to_json
47
+ {
48
+ cpf: @cpf,
49
+ first_name: @first_name,
50
+ middle_name: @middle_name,
51
+ last_name: @last_name,
52
+ gender: @gender,
53
+ birth: @birth,
54
+ status_receita_federal: @status_receita_federal,
55
+ rg_number: @rg_number,
56
+ rg_orgao_emissor: @rg_orgao_emissor,
57
+ rg_uf: @rg_uf,
58
+ voter_registration: @voter_registration,
59
+ death: @death,
60
+ nationality: @nationality,
61
+ minor: @minor,
62
+ marital_status: @marital_status,
63
+ mother_first_name: @mother_first_name,
64
+ mother_middle_name: @mother_middle_name,
65
+ mother_last_name: @mother_last_name,
66
+ schooling: @schooling
67
+ }.to_json
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,6 @@
1
+ module Targetdata
2
+ module Errors
3
+ class PersonNotFound < StandardError
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Targetdata
2
+ module Errors
3
+ class Unauthorized < StandardError
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module Targetdata
2
+ VERSION = "0.2.0"
3
+ end
@@ -0,0 +1,25 @@
1
+ require_relative 'lib/targetdata/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "targetdata"
5
+ spec.version = Targetdata::VERSION
6
+ spec.authors = ["Kim Pastro"]
7
+ spec.email = ["kimpastro@gmail.com"]
8
+
9
+ spec.summary = %q{Targetdata Smart API integration}
10
+ spec.description = %q{Integrates with Targetdata Smart API!}
11
+ spec.homepage = "https://github.com/kimpastro/targetdata"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://github.com/kimpastro/targetdata"
17
+ spec.metadata["changelog_uri"] = "https://github.com/kimpastro/targetdata/CHANGELOG.md"
18
+
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: targetdata
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Kim Pastro
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-09-01 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Integrates with Targetdata Smart API!
14
+ email:
15
+ - kimpastro@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".rspec"
22
+ - ".travis.yml"
23
+ - CODE_OF_CONDUCT.md
24
+ - Gemfile
25
+ - LICENSE.txt
26
+ - Makefile
27
+ - README.md
28
+ - Rakefile
29
+ - bin/console
30
+ - bin/setup
31
+ - lib/targetdata.rb
32
+ - lib/targetdata/api/auth.rb
33
+ - lib/targetdata/api/pf.rb
34
+ - lib/targetdata/api/requester.rb
35
+ - lib/targetdata/configuration.rb
36
+ - lib/targetdata/entities/person.rb
37
+ - lib/targetdata/errors/person_not_found.rb
38
+ - lib/targetdata/errors/unauthorized.rb
39
+ - lib/targetdata/version.rb
40
+ - targetdata.gemspec
41
+ homepage: https://github.com/kimpastro/targetdata
42
+ licenses:
43
+ - MIT
44
+ metadata:
45
+ homepage_uri: https://github.com/kimpastro/targetdata
46
+ source_code_uri: https://github.com/kimpastro/targetdata
47
+ changelog_uri: https://github.com/kimpastro/targetdata/CHANGELOG.md
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 2.3.0
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubygems_version: 3.1.2
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: Targetdata Smart API integration
67
+ test_files: []