targetdata 0.2.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/targetdata/api/auth.rb +8 -4
- data/lib/targetdata/api/pf.rb +12 -2
- data/lib/targetdata/entities/person.rb +6 -0
- data/lib/targetdata/version.rb +1 -1
- data/lib/targetdata.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38655018ad04b6f1f7629dcee0489e8561ac0615408bfcedfbfd1df4ecf0700f
|
4
|
+
data.tar.gz: 0b2283d590af8cba37742cee2fa45860f4351b24d484747955d071ad59fd0a06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54c5b8c25cfb20ef8f7ba1088251481ebc814fe45319fd670668b05bdce0292568207c51760a76fe11841ecc2caea029cf14300a97e217457e2813ae9731b80b
|
7
|
+
data.tar.gz: 517541f5efc02d33bc1251a9caf9cb3289256a92682c8461fcec012926f174756312d6f897777c8b6f06901c9f7a784f769d43e06ba15c6c39f15ea2acc5485c
|
data/lib/targetdata/api/auth.rb
CHANGED
@@ -2,9 +2,7 @@ module Targetdata
|
|
2
2
|
module Api
|
3
3
|
module Auth
|
4
4
|
def token
|
5
|
-
|
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
|
data/lib/targetdata/api/pf.rb
CHANGED
@@ -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
|
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,
|
data/lib/targetdata/version.rb
CHANGED
data/lib/targetdata.rb
CHANGED
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.
|
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:
|
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.
|
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: []
|