targetdata 0.2.1 → 0.4.0

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
  SHA256:
3
- metadata.gz: 3b329756fa1e0daf4889f08cc5292b57f358537d2674c8e0179f91ecdb0d8b7e
4
- data.tar.gz: f0703077fa07f33028c2bacb7e7cb4c718e02d96ada596686ec2fd114d8bf4ff
3
+ metadata.gz: 38655018ad04b6f1f7629dcee0489e8561ac0615408bfcedfbfd1df4ecf0700f
4
+ data.tar.gz: 0b2283d590af8cba37742cee2fa45860f4351b24d484747955d071ad59fd0a06
5
5
  SHA512:
6
- metadata.gz: 36657fabf70b21af3a6e646e4dbaff17fbf9abca0402441f55ea0a3c127a9f76e72bcd999f4b1eae3290779a6eb831f1d08a3cb0514154f05740763fd003fd2f
7
- data.tar.gz: d1bca2349b336ead78032b9024d7e620ad4277e7902b882dd71f0cc0c7cc83a71f068d3cf5a76a0deed6385768a3305d9d1c41a21f43ffacb0694b178a76136f
6
+ metadata.gz: 54c5b8c25cfb20ef8f7ba1088251481ebc814fe45319fd670668b05bdce0292568207c51760a76fe11841ecc2caea029cf14300a97e217457e2813ae9731b80b
7
+ data.tar.gz: 517541f5efc02d33bc1251a9caf9cb3289256a92682c8461fcec012926f174756312d6f897777c8b6f06901c9f7a784f769d43e06ba15c6c39f15ea2acc5485c
@@ -2,9 +2,7 @@ module Targetdata
2
2
  module Api
3
3
  module Auth
4
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"]
5
+ ENV.fetch('TARGET_DATA_ACCESS_TOKEN') || generate_access_token
8
6
  end
9
7
 
10
8
  private
@@ -25,6 +23,12 @@ module Targetdata
25
23
  'Accept': 'application/json'
26
24
  }
27
25
  end
26
+
27
+ def generate_access_token
28
+ response = HTTP.headers(auth_headers).post(Targetdata::BASE_URL + '/token', form: auth_body)
29
+ parsed = JSON.parse(response.body.to_s)
30
+ parsed["access_token"]
31
+ end
28
32
  end
29
33
  end
30
- end
34
+ end
@@ -16,14 +16,24 @@ module Targetdata
16
16
  private
17
17
  def hash_person string_body
18
18
  parsed = JSON.parse(string_body)
19
-
20
19
  raise Targetdata::Errors::PersonNotFound unless person_found?(parsed)
21
- parsed["result"].first["pessoa"]["cadastral"]
20
+ parse_person_hash parsed
22
21
  end
23
22
 
24
23
  def person_found? hash
25
24
  !hash["result"].empty?
26
25
  end
26
+
27
+ def parse_person_hash hash
28
+ pessoa = hash["result"].first["pessoa"]
29
+ pessoa["cadastral"]["email"] = nil
30
+
31
+ if hash["report"]["email"] >= 1
32
+ pessoa["cadastral"]["email"] = pessoa["contato"]["email"].first["email"]
33
+ end
34
+
35
+ pessoa["cadastral"]
36
+ end
27
37
  end
28
38
  end
29
39
  end
@@ -2,6 +2,7 @@ module Targetdata
2
2
  module Entities
3
3
  class Person
4
4
  attr_accessor :cpf,
5
+ :email,
5
6
  :first_name,
6
7
  :middle_name,
7
8
  :last_name,
@@ -23,6 +24,7 @@ module Targetdata
23
24
 
24
25
  def initialize params = {}
25
26
  @cpf = params['CPF']
27
+ @email = params['email']
26
28
  @first_name = params['nomePrimeiro']
27
29
  @middle_name = params['nomeMeio']
28
30
  @last_name = params['nomeUltimo']
@@ -43,6 +45,10 @@ module Targetdata
43
45
  @schooling = params['escolaridade']
44
46
  end
45
47
 
48
+ def full_name
49
+ "#{@first_name} #{@middle_name} #{@last_name}".strip
50
+ end
51
+
46
52
  def to_json
47
53
  {
48
54
  cpf: @cpf,
@@ -1,3 +1,3 @@
1
1
  module Targetdata
2
- VERSION = "0.2.1"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/targetdata.rb CHANGED
@@ -10,7 +10,7 @@ require_relative "targetdata/api/requester"
10
10
  require_relative "targetdata/api/pf"
11
11
 
12
12
  module Targetdata
13
- BASE_URL = 'https://targetdatasmart.com/api'
13
+ BASE_URL = 'https://api.targetdata-smart.com/api'
14
14
 
15
15
  class << self
16
16
  attr_writer :configuration
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: targetdata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kim Pastro
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-01 00:00:00.000000000 Z
11
+ date: 2022-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -65,7 +65,7 @@ metadata:
65
65
  homepage_uri: https://github.com/kimpastro/targetdata
66
66
  source_code_uri: https://github.com/kimpastro/targetdata
67
67
  changelog_uri: https://github.com/kimpastro/targetdata/CHANGELOG.md
68
- post_install_message:
68
+ post_install_message:
69
69
  rdoc_options: []
70
70
  require_paths:
71
71
  - lib
@@ -80,8 +80,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
80
  - !ruby/object:Gem::Version
81
81
  version: '0'
82
82
  requirements: []
83
- rubygems_version: 3.1.2
84
- signing_key:
83
+ rubygems_version: 3.2.22
84
+ signing_key:
85
85
  specification_version: 4
86
86
  summary: Targetdata Smart API integration
87
87
  test_files: []