piplapis-ruby 5.0.5 → 5.2.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 +5 -5
- data/LICENSE +10 -10
- data/README.md +22 -25
- data/lib/pipl/client.rb +201 -177
- data/lib/pipl/configurable.rb +61 -58
- data/lib/pipl/consts.rb +76 -76
- data/lib/pipl/containers.rb +301 -294
- data/lib/pipl/default.rb +71 -66
- data/lib/pipl/errors.rb +62 -62
- data/lib/pipl/fields.rb +804 -732
- data/lib/pipl/response.rb +228 -220
- data/lib/pipl/utils.rb +68 -68
- data/lib/pipl/version.rb +3 -3
- data/lib/pipl.rb +35 -35
- data/pipl.gemspec +18 -18
- metadata +6 -7
data/lib/pipl/containers.rb
CHANGED
@@ -1,294 +1,301 @@
|
|
1
|
-
require_relative 'fields'
|
2
|
-
require_relative 'utils'
|
3
|
-
|
4
|
-
|
5
|
-
module Pipl
|
6
|
-
|
7
|
-
class FieldsContainer
|
8
|
-
|
9
|
-
CLASS_CONTAINER = {
|
10
|
-
Name: 'names',
|
11
|
-
Address: 'addresses',
|
12
|
-
Phone: 'phones',
|
13
|
-
Email: 'emails',
|
14
|
-
Job: 'jobs',
|
15
|
-
Education: 'educations',
|
16
|
-
Image: 'images',
|
17
|
-
Username: 'usernames',
|
18
|
-
UserID: 'user_ids',
|
19
|
-
Url: 'urls',
|
20
|
-
Ethnicity: 'ethnicities',
|
21
|
-
Language: 'languages',
|
22
|
-
OriginCountry: 'origin_countries',
|
23
|
-
Relationship: 'relationships',
|
24
|
-
Tag: 'tags',
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
attr_reader :
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
@
|
33
|
-
@
|
34
|
-
@
|
35
|
-
@
|
36
|
-
@
|
37
|
-
@
|
38
|
-
@
|
39
|
-
@
|
40
|
-
@
|
41
|
-
@
|
42
|
-
@
|
43
|
-
@
|
44
|
-
@
|
45
|
-
@
|
46
|
-
@
|
47
|
-
@
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
fields
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
h
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
elsif cls_sym == :
|
90
|
-
@
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
fields
|
100
|
-
|
101
|
-
fields
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
#
|
175
|
-
#
|
176
|
-
#
|
177
|
-
#
|
178
|
-
#
|
179
|
-
#
|
180
|
-
#
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
params[:
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
@
|
223
|
-
@
|
224
|
-
@
|
225
|
-
@
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
params
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
1
|
+
require_relative 'fields'
|
2
|
+
require_relative 'utils'
|
3
|
+
|
4
|
+
|
5
|
+
module Pipl
|
6
|
+
|
7
|
+
class FieldsContainer
|
8
|
+
|
9
|
+
CLASS_CONTAINER = {
|
10
|
+
Name: 'names',
|
11
|
+
Address: 'addresses',
|
12
|
+
Phone: 'phones',
|
13
|
+
Email: 'emails',
|
14
|
+
Job: 'jobs',
|
15
|
+
Education: 'educations',
|
16
|
+
Image: 'images',
|
17
|
+
Username: 'usernames',
|
18
|
+
UserID: 'user_ids',
|
19
|
+
Url: 'urls',
|
20
|
+
Ethnicity: 'ethnicities',
|
21
|
+
Language: 'languages',
|
22
|
+
OriginCountry: 'origin_countries',
|
23
|
+
Relationship: 'relationships',
|
24
|
+
Tag: 'tags',
|
25
|
+
Vehicle: 'vehicles',
|
26
|
+
}
|
27
|
+
|
28
|
+
attr_reader :names, :addresses, :phones, :emails, :jobs, :educations, :images, :usernames, :user_ids, :urls
|
29
|
+
attr_reader :relationships, :tags, :ethnicities, :languages, :origin_countries, :dob, :gender, :vehicles
|
30
|
+
|
31
|
+
def initialize(params={})
|
32
|
+
@names = []
|
33
|
+
@addresses = []
|
34
|
+
@phones = []
|
35
|
+
@emails = []
|
36
|
+
@jobs = []
|
37
|
+
@educations = []
|
38
|
+
@images = []
|
39
|
+
@usernames = []
|
40
|
+
@user_ids = []
|
41
|
+
@urls = []
|
42
|
+
@ethnicities = []
|
43
|
+
@languages = []
|
44
|
+
@origin_countries = []
|
45
|
+
@relationships = []
|
46
|
+
@tags = []
|
47
|
+
@dob = nil
|
48
|
+
@gender = nil
|
49
|
+
@vehicles = []
|
50
|
+
|
51
|
+
add_fields params[:fields] if params.key? :fields
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.from_hash(h)
|
55
|
+
raise AbstractMethodInvoked.new
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.fields_from_hash(h)
|
59
|
+
fields = self::CLASS_CONTAINER.map do |cls_name, container|
|
60
|
+
cls = Pipl.const_get cls_name
|
61
|
+
h[container.to_sym].map { |x| cls.from_hash(x) } if h.key? container.to_sym
|
62
|
+
end
|
63
|
+
.flatten.compact
|
64
|
+
fields << DOB.from_hash(h[:dob]) if h.key? :dob
|
65
|
+
fields << Gender.from_hash(h[:gender]) if h.key? :gender
|
66
|
+
fields
|
67
|
+
end
|
68
|
+
|
69
|
+
def fields_to_hash
|
70
|
+
h = {}
|
71
|
+
h[:dob] = @dob.to_hash if @dob
|
72
|
+
h[:gender] = @gender.to_hash if @gender
|
73
|
+
self.class::CLASS_CONTAINER.values.each do |container|
|
74
|
+
fields = instance_variable_get("@#{container}")
|
75
|
+
h[container.to_sym] = fields.map { |field| field.to_hash }.compact unless fields.empty?
|
76
|
+
end
|
77
|
+
h.reject { |_, value| value.nil? || (value.kind_of?(Array) && value.empty?) }
|
78
|
+
end
|
79
|
+
|
80
|
+
def add_fields(fields)
|
81
|
+
fields.each { |f| add_field f }
|
82
|
+
end
|
83
|
+
|
84
|
+
def add_field(field)
|
85
|
+
cls_sym = field.class.name.split('::').last.to_sym
|
86
|
+
container = self.class::CLASS_CONTAINER[cls_sym]
|
87
|
+
if container
|
88
|
+
instance_variable_get("@#{container}") << field
|
89
|
+
elsif cls_sym == :DOB
|
90
|
+
@dob = field
|
91
|
+
elsif cls_sym == :Gender
|
92
|
+
@gender = field
|
93
|
+
else
|
94
|
+
raise ArgumentError.new("Object of type #{field.class} is an invalid field")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def all_fields
|
99
|
+
fields = self.class::CLASS_CONTAINER.values.map { |container| instance_variable_get("@#{container}") }
|
100
|
+
.flatten.compact
|
101
|
+
fields << @dob if @dob
|
102
|
+
fields << @gender if @gender
|
103
|
+
fields
|
104
|
+
end
|
105
|
+
|
106
|
+
def job
|
107
|
+
@jobs.first unless @jobs.empty?
|
108
|
+
end
|
109
|
+
|
110
|
+
def address
|
111
|
+
@addresses.first unless @addresses.empty?
|
112
|
+
end
|
113
|
+
|
114
|
+
def education
|
115
|
+
@educations.first unless @educations.empty?
|
116
|
+
end
|
117
|
+
|
118
|
+
def language
|
119
|
+
@languages.first unless @languages.empty?
|
120
|
+
end
|
121
|
+
|
122
|
+
def ethnicity
|
123
|
+
@ethnicities.first unless @ethnicities.empty?
|
124
|
+
end
|
125
|
+
|
126
|
+
def origin_country
|
127
|
+
@origin_countries.first unless @origin_countries.empty?
|
128
|
+
end
|
129
|
+
|
130
|
+
def phone
|
131
|
+
@phones.first unless @phones.empty?
|
132
|
+
end
|
133
|
+
|
134
|
+
def email
|
135
|
+
@emails.first unless @emails.empty?
|
136
|
+
end
|
137
|
+
|
138
|
+
def name
|
139
|
+
@names.first unless @names.empty?
|
140
|
+
end
|
141
|
+
|
142
|
+
def image
|
143
|
+
@images.first unless @images.empty?
|
144
|
+
end
|
145
|
+
|
146
|
+
def url
|
147
|
+
@urls.first unless @urls.empty?
|
148
|
+
end
|
149
|
+
|
150
|
+
def username
|
151
|
+
@usernames.first unless @usernames.empty?
|
152
|
+
end
|
153
|
+
|
154
|
+
def user_id
|
155
|
+
@user_ids.first unless @user_ids.empty?
|
156
|
+
end
|
157
|
+
|
158
|
+
def relationship
|
159
|
+
@relationships.first unless @relationships.empty?
|
160
|
+
end
|
161
|
+
|
162
|
+
def vehicle
|
163
|
+
@vehicles.first unless @vehicles.empty?
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
|
168
|
+
|
169
|
+
class Relationship < FieldsContainer
|
170
|
+
|
171
|
+
CLASS_CONTAINER = FieldsContainer::CLASS_CONTAINER.clone
|
172
|
+
CLASS_CONTAINER.delete :Relationship
|
173
|
+
|
174
|
+
# @!attribute valid_since
|
175
|
+
# @see Field
|
176
|
+
# @!attribute inferred
|
177
|
+
# @see Field
|
178
|
+
# @!attribute type
|
179
|
+
# @return [String] Type of association of this relationship to a person.
|
180
|
+
# Possible values are:
|
181
|
+
# friend
|
182
|
+
# family
|
183
|
+
# work
|
184
|
+
# other
|
185
|
+
# @!attribute subtype
|
186
|
+
# @return [String] Subtype of association of this relationship to a person. Free text.
|
187
|
+
|
188
|
+
attr_accessor :valid_since, :inferred, :type, :subtype
|
189
|
+
|
190
|
+
def initialize(params={})
|
191
|
+
super params
|
192
|
+
@valid_since = params[:valid_since]
|
193
|
+
@inferred = params[:inferred]
|
194
|
+
@type = params[:type]
|
195
|
+
@subtype = params[:subtype]
|
196
|
+
end
|
197
|
+
|
198
|
+
def self.from_hash(h)
|
199
|
+
params = Pipl::Field.base_params_from_hash h
|
200
|
+
params[:subtype] = h[:@subtype]
|
201
|
+
params[:fields] = self.fields_from_hash(h)
|
202
|
+
self.new(params)
|
203
|
+
end
|
204
|
+
|
205
|
+
def to_hash
|
206
|
+
fields_to_hash
|
207
|
+
end
|
208
|
+
|
209
|
+
def to_s
|
210
|
+
@names.first.to_s unless @names.empty?
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
|
216
|
+
class Source < FieldsContainer
|
217
|
+
|
218
|
+
attr_reader :match, :name, :category, :origin_url, :sponsored, :domain, :source_id, :person_id, :premium, :valid_since
|
219
|
+
|
220
|
+
def initialize(params={})
|
221
|
+
super params
|
222
|
+
@name = params[:name]
|
223
|
+
@category = params[:category]
|
224
|
+
@origin_url = params[:origin_url]
|
225
|
+
@domain = params[:domain]
|
226
|
+
@source_id = params[:source_id]
|
227
|
+
@person_id = params[:person_id]
|
228
|
+
@sponsored = params[:sponsored]
|
229
|
+
@premium = params[:premium]
|
230
|
+
@match = params[:match]
|
231
|
+
@valid_since = params[:valid_since]
|
232
|
+
end
|
233
|
+
|
234
|
+
def self.from_hash(h)
|
235
|
+
params = {
|
236
|
+
name: h[:@name],
|
237
|
+
category: h[:@category],
|
238
|
+
origin_url: h[:@origin_url],
|
239
|
+
domain: h[:@domain],
|
240
|
+
source_id: h[:@id],
|
241
|
+
person_id: h[:@person_id],
|
242
|
+
match: h[:@match],
|
243
|
+
sponsored: h[:@sponsored],
|
244
|
+
premium: h[:@premium],
|
245
|
+
}
|
246
|
+
params[:valid_since] = Pipl::Utils.str_to_date(h[:@valid_since]) if h.key? :@valid_since
|
247
|
+
params[:fields] = self.fields_from_hash(h)
|
248
|
+
self.new(params)
|
249
|
+
end
|
250
|
+
|
251
|
+
end
|
252
|
+
|
253
|
+
class Person < FieldsContainer
|
254
|
+
|
255
|
+
attr_reader :id, :match, :search_pointer, :inferred
|
256
|
+
|
257
|
+
def initialize(params={})
|
258
|
+
super params
|
259
|
+
@id = params[:id]
|
260
|
+
@match = params[:match]
|
261
|
+
@search_pointer = params[:search_pointer]
|
262
|
+
@inferred = params[:inferred] || false
|
263
|
+
end
|
264
|
+
|
265
|
+
def self.from_hash(h)
|
266
|
+
params = {
|
267
|
+
id: h[:@id],
|
268
|
+
match: h[:@match],
|
269
|
+
search_pointer: h[:@search_pointer],
|
270
|
+
inferred: h[:@inferred],
|
271
|
+
}
|
272
|
+
params[:fields] = fields_from_hash(h)
|
273
|
+
self.new(params)
|
274
|
+
end
|
275
|
+
|
276
|
+
def to_hash
|
277
|
+
h = {}
|
278
|
+
h[:search_pointer] = @search_pointer if @search_pointer && ! @search_pointer.empty?
|
279
|
+
h.update(fields_to_hash)
|
280
|
+
h
|
281
|
+
end
|
282
|
+
|
283
|
+
def is_searchable?
|
284
|
+
!@search_pointer.nil? ||
|
285
|
+
@names.any? { |f| f.is_searchable? } ||
|
286
|
+
@emails.any? { |f| f.is_searchable? } ||
|
287
|
+
@phones.any? { |f| f.is_searchable? } ||
|
288
|
+
@usernames.any? { |f| f.is_searchable? } ||
|
289
|
+
@user_ids.any? { |f| f.is_searchable? } ||
|
290
|
+
@urls.any? { |f| f.is_searchable? } ||
|
291
|
+
@addresses.any? { |f| f.is_sole_searchable? } ||
|
292
|
+
@vehicles.any? { |f| f.is_searchable? }
|
293
|
+
end
|
294
|
+
|
295
|
+
def unsearchable_fields
|
296
|
+
all_fields.reject { |f| f.is_searchable? }
|
297
|
+
end
|
298
|
+
|
299
|
+
end
|
300
|
+
|
301
|
+
end
|