piplapis-ruby 5.0.4 → 5.0.5

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.
@@ -1,58 +1,58 @@
1
- module Pipl
2
-
3
- module Configurable
4
-
5
- SHOW_SOURCES_ALL = 'all'
6
- SHOW_SOURCES_MATCHING = 'matching'
7
- SHOW_SOURCES_NONE = 'false'
8
-
9
- attr_accessor :api_key, :minimum_probability, :minimum_match, :hide_sponsored, :live_feeds, :show_sources
10
- attr_accessor :match_requirements, :source_category_requirements, :infer_persons, :strict_validation, :user_agent
11
- attr_writer :api_endpoint
12
-
13
- class << self
14
-
15
- def keys
16
- @keys ||= [
17
- :api_key,
18
- :minimum_probability,
19
- :minimum_match,
20
- :hide_sponsored,
21
- :live_feeds,
22
- :show_sources,
23
- :match_requirements,
24
- :source_category_requirements,
25
- :infer_persons,
26
- :strict_validation,
27
- :api_endpoint,
28
- :user_agent
29
- ]
30
- end
31
-
32
- end
33
-
34
- def configure
35
- yield self
36
- end
37
-
38
- def reset!
39
- Pipl::Configurable.keys.each do |key|
40
- instance_variable_set(:"@#{key}", Pipl::Default.options[key])
41
- end
42
- self
43
- end
44
-
45
- alias setup reset!
46
-
47
- def api_endpoint
48
- File.join(@api_endpoint, '')
49
- end
50
-
51
- private
52
-
53
- def options
54
- Hash[Pipl::Configurable.keys.map { |key| [key, instance_variable_get(:"@#{key}")] }]
55
- end
56
-
57
- end
58
- end
1
+ module Pipl
2
+
3
+ module Configurable
4
+
5
+ SHOW_SOURCES_ALL = 'all'
6
+ SHOW_SOURCES_MATCHING = 'matching'
7
+ SHOW_SOURCES_NONE = 'false'
8
+
9
+ attr_accessor :api_key, :minimum_probability, :minimum_match, :hide_sponsored, :live_feeds, :show_sources
10
+ attr_accessor :match_requirements, :source_category_requirements, :infer_persons, :strict_validation, :user_agent
11
+ attr_writer :api_endpoint
12
+
13
+ class << self
14
+
15
+ def keys
16
+ @keys ||= [
17
+ :api_key,
18
+ :minimum_probability,
19
+ :minimum_match,
20
+ :hide_sponsored,
21
+ :live_feeds,
22
+ :show_sources,
23
+ :match_requirements,
24
+ :source_category_requirements,
25
+ :infer_persons,
26
+ :strict_validation,
27
+ :api_endpoint,
28
+ :user_agent
29
+ ]
30
+ end
31
+
32
+ end
33
+
34
+ def configure
35
+ yield self
36
+ end
37
+
38
+ def reset!
39
+ Pipl::Configurable.keys.each do |key|
40
+ instance_variable_set(:"@#{key}", Pipl::Default.options[key])
41
+ end
42
+ self
43
+ end
44
+
45
+ alias setup reset!
46
+
47
+ def api_endpoint
48
+ File.join(@api_endpoint, '')
49
+ end
50
+
51
+ private
52
+
53
+ def options
54
+ Hash[Pipl::Configurable.keys.map { |key| [key, instance_variable_get(:"@#{key}")] }]
55
+ end
56
+
57
+ end
58
+ end
@@ -1,76 +1,76 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- module Pipl
4
-
5
- DATE_FORMAT = '%Y-%m-%d'
6
-
7
- STATES = {
8
- US: {WA: 'Washington', VA: 'Virginia', DE: 'Delaware', DC: 'District Of Columbia', WI: 'Wisconsin',
9
- WV: 'West Virginia', HI: 'Hawaii', FL: 'Florida', YT: 'Yukon', WY: 'Wyoming', PR: 'Puerto Rico',
10
- NJ: 'New Jersey', NM: 'New Mexico', TX: 'Texas', LA: 'Louisiana', NC: 'North Carolina', ND: 'North Dakota',
11
- NE: 'Nebraska', FM: 'Federated States Of Micronesia', TN: 'Tennessee', NY: 'New York', PA: 'Pennsylvania',
12
- CT: 'Connecticut', RI: 'Rhode Island', NV: 'Nevada', NH: 'New Hampshire', GU: 'Guam', CO: 'Colorado',
13
- VI: 'Virgin Islands', AK: 'Alaska', AL: 'Alabama', AS: 'American Samoa', AR: 'Arkansas', VT: 'Vermont',
14
- IL: 'Illinois', GA: 'Georgia', IN: 'Indiana', IA: 'Iowa', MA: 'Massachusetts', AZ: 'Arizona',
15
- CA: 'California', ID: 'Idaho', PW: 'Pala', ME: 'Maine', MD: 'Maryland', OK: 'Oklahoma', OH: 'Ohio',
16
- UT: 'Utah', MO: 'Missouri', MN: 'Minnesota', MI: 'Michigan', MH: 'Marshall Islands', KS: 'Kansas',
17
- MT: 'Montana', MP: 'Northern Mariana Islands', MS: 'Mississippi', SC: 'South Carolina', KY: 'Kentucky',
18
- OR: 'Oregon', SD: 'South Dakota'},
19
- CA: {AB: 'Alberta', BC: 'British Columbia', MB: 'Manitoba', NB: 'New Brunswick', NT: 'Northwest Territories',
20
- NS: 'Nova Scotia', NU: 'Nunavut', ON: 'Ontario', PE: 'Prince Edward Island', QC: 'Quebec',
21
- SK: 'Saskatchewan', YU: 'Yukon', NL: 'Newfoundland and Labrador'},
22
- AU: {WA: 'State of Western Australia', SA: 'State of South Australia', NT: 'Northern Territory',
23
- VIC: 'State of Victoria', TAS: 'State of Tasmania', QLD: 'State of Queensland',
24
- NSW: 'State of New South Wales', ACT: 'Australian Capital Territory'},
25
- GB: {WLS: 'Wales', SCT: 'Scotland', NIR: 'Northern Ireland', ENG: 'England'}
26
- }
27
-
28
- COUNTRIES = {BD: 'Bangladesh', WF: 'Wallis And Futuna Islands', BF: 'Burkina Faso', PY: 'Paraguay',
29
- BA: 'Bosnia And Herzegovina', BB: 'Barbados', BE: 'Belgium', BM: 'Bermuda', BN: 'Brunei Darussalam',
30
- BO: 'Bolivia', BH: 'Bahrain', BI: 'Burundi', BJ: 'Benin', BT: 'Bhutan', JM: 'Jamaica',
31
- BV: 'Bouvet Island', BW: 'Botswana', WS: 'Samoa', BR: 'Brazil', BS: 'Bahamas', JE: 'Jersey',
32
- BY: 'Belarus', BZ: 'Belize', RU: 'Russian Federation', RW: 'Rwanda', LT: 'Lithuania', RE: 'Reunion',
33
- TM: 'Turkmenistan', TJ: 'Tajikistan', RO: 'Romania', LS: 'Lesotho', GW: 'Guinea-bissa', GU: 'Guam',
34
- GT: 'Guatemala', GS: 'South Georgia And South Sandwich Islands', GR: 'Greece', GQ: 'Equatorial Guinea',
35
- GP: 'Guadeloupe', JP: 'Japan', GY: 'Guyana', GG: 'Guernsey', GF: 'French Guiana', GE: 'Georgia',
36
- GD: 'Grenada', GB: 'Great Britain', GA: 'Gabon', GN: 'Guinea', GM: 'Gambia', GL: 'Greenland',
37
- GI: 'Gibraltar', GH: 'Ghana', OM: 'Oman', TN: 'Tunisia', JO: 'Jordan', HR: 'Croatia', HT: 'Haiti',
38
- SV: 'El Salvador', HK: 'Hong Kong', HN: 'Honduras', HM: 'Heard And Mcdonald Islands', AD: 'Andorra',
39
- PR: 'Puerto Rico', PS: 'Palestine', PW: 'Pala', PT: 'Portugal', SJ: 'Svalbard And Jan Mayen Islands',
40
- VG: 'Virgin Islands, British', AI: 'Anguilla', KP: 'North Korea', PF: 'French Polynesia',
41
- PG: 'Papua New Guinea', PE: 'Per', PK: 'Pakistan', PH: 'Philippines', PN: 'Pitcairn', PL: 'Poland',
42
- PM: 'Saint Pierre And Miquelon', ZM: 'Zambia', EH: 'Western Sahara', EE: 'Estonia', EG: 'Egypt',
43
- ZA: 'South Africa', EC: 'Ecuador', IT: 'Italy', AO: 'Angola', KZ: 'Kazakhstan', ET: 'Ethiopia',
44
- ZW: 'Zimbabwe', SA: 'Saudi Arabia', ES: 'Spain', ER: 'Eritrea', ME: 'Montenegro', MD: 'Moldova',
45
- MG: 'Madagascar', MA: 'Morocco', MC: 'Monaco', UZ: 'Uzbekistan', MM: 'Myanmar', ML: 'Mali', MO: 'Maca',
46
- MN: 'Mongolia', MH: 'Marshall Islands', US: 'United States', UM: 'United States Minor Outlying Islands',
47
- MT: 'Malta', MW: 'Malawi', MV: 'Maldives', MQ: 'Martinique', MP: 'Northern Mariana Islands',
48
- MS: 'Montserrat', NA: 'Namibia', IM: 'Isle Of Man', UG: 'Uganda', MY: 'Malaysia', MX: 'Mexico',
49
- IL: 'Israel', BG: 'Bulgaria', FR: 'France', AW: 'Aruba', AX: 'Åland', FI: 'Finland',
50
- FJ: 'Fiji', FK: 'Falkland Islands', FM: 'Micronesia', FO: 'Faroe Islands', NI: 'Nicaragua',
51
- NL: 'Netherlands', NO: 'Norway', SO: 'Somalia', NC: 'New Caledonia', NE: 'Niger', NF: 'Norfolk Island',
52
- NG: 'Nigeria', NZ: 'New Zealand', NP: 'Nepal', NR: 'Naur', NU: 'Niue', MR: 'Mauritania',
53
- CK: 'Cook Islands', CI: "Côte D'ivoire", CH: 'Switzerland', CO: 'Colombia', CN: 'China',
54
- CM: 'Cameroon', CL: 'Chile', CC: 'Cocos (keeling) Islands', CA: 'Canada', CG: 'Congo (brazzaville)',
55
- CF: 'Central African Republic', CD: 'Congo (kinshasa)', CZ: 'Czech Republic', CY: 'Cyprus',
56
- CX: 'Christmas Island', CS: 'Serbia', CR: 'Costa Rica', HU: 'Hungary', CV: 'Cape Verde', CU: 'Cuba',
57
- SZ: 'Swaziland', SY: 'Syria', KG: 'Kyrgyzstan', KE: 'Kenya', SR: 'Suriname', KI: 'Kiribati',
58
- KH: 'Cambodia', KN: 'Saint Kitts And Nevis', KM: 'Comoros', ST: 'Sao Tome And Principe', SK: 'Slovakia',
59
- KR: 'South Korea', SI: 'Slovenia', SH: 'Saint Helena', KW: 'Kuwait', SN: 'Senegal', SM: 'San Marino',
60
- SL: 'Sierra Leone', SC: 'Seychelles', SB: 'Solomon Islands', KY: 'Cayman Islands', SG: 'Singapore',
61
- SE: 'Sweden', SD: 'Sudan', DO: 'Dominican Republic', DM: 'Dominica', DJ: 'Djibouti', DK: 'Denmark',
62
- DE: 'Germany', YE: 'Yemen', AT: 'Austria', DZ: 'Algeria', MK: 'Macedonia', UY: 'Uruguay', YT: 'Mayotte',
63
- MU: 'Mauritius', TZ: 'Tanzania', LC: 'Saint Lucia', LA: 'Laos', TV: 'Tuval', TW: 'Taiwan',
64
- TT: 'Trinidad And Tobago', TR: 'Turkey', LK: 'Sri Lanka', LI: 'Liechtenstein', LV: 'Latvia',
65
- TO: 'Tonga', TL: 'Timor-leste', LU: 'Luxembourg', LR: 'Liberia', TK: 'Tokela', TH: 'Thailand',
66
- TF: 'French Southern Lands', TG: 'Togo', TD: 'Chad', TC: 'Turks And Caicos Islands', LY: 'Libya',
67
- VA: 'Vatican City', AC: 'Ascension Island', VC: 'Saint Vincent And The Grenadines',
68
- AE: 'United Arab Emirates', VE: 'Venezuela', AG: 'Antigua And Barbuda', AF: 'Afghanistan', IQ: 'Iraq',
69
- VI: 'Virgin Islands, U.s.', IS: 'Iceland', IR: 'Iran', AM: 'Armenia', AL: 'Albania', VN: 'Vietnam',
70
- AN: 'Netherlands Antilles', AQ: 'Antarctica', AS: 'American Samoa', AR: 'Argentina', AU: 'Australia',
71
- VU: 'Vanuat', IO: 'British Indian Ocean Territory', IN: 'India', LB: 'Lebanon', AZ: 'Azerbaijan',
72
- IE: 'Ireland', ID: 'Indonesia', PA: 'Panama', UA: 'Ukraine', QA: 'Qatar', MZ: 'Mozambique',
73
- BL: 'Saint Barthélemy', BQ: 'Caribbean Netherlands', MF: 'Saint Martin', SS: 'South Sudan',
74
- SX: 'Sint Maarten', XK: 'Kosovo', CW: 'Curaçao', RS: 'Serbia'}
75
-
76
- end
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module Pipl
4
+
5
+ DATE_FORMAT = '%Y-%m-%d'
6
+
7
+ STATES = {
8
+ US: {WA: 'Washington', VA: 'Virginia', DE: 'Delaware', DC: 'District Of Columbia', WI: 'Wisconsin',
9
+ WV: 'West Virginia', HI: 'Hawaii', FL: 'Florida', YT: 'Yukon', WY: 'Wyoming', PR: 'Puerto Rico',
10
+ NJ: 'New Jersey', NM: 'New Mexico', TX: 'Texas', LA: 'Louisiana', NC: 'North Carolina', ND: 'North Dakota',
11
+ NE: 'Nebraska', FM: 'Federated States Of Micronesia', TN: 'Tennessee', NY: 'New York', PA: 'Pennsylvania',
12
+ CT: 'Connecticut', RI: 'Rhode Island', NV: 'Nevada', NH: 'New Hampshire', GU: 'Guam', CO: 'Colorado',
13
+ VI: 'Virgin Islands', AK: 'Alaska', AL: 'Alabama', AS: 'American Samoa', AR: 'Arkansas', VT: 'Vermont',
14
+ IL: 'Illinois', GA: 'Georgia', IN: 'Indiana', IA: 'Iowa', MA: 'Massachusetts', AZ: 'Arizona',
15
+ CA: 'California', ID: 'Idaho', PW: 'Pala', ME: 'Maine', MD: 'Maryland', OK: 'Oklahoma', OH: 'Ohio',
16
+ UT: 'Utah', MO: 'Missouri', MN: 'Minnesota', MI: 'Michigan', MH: 'Marshall Islands', KS: 'Kansas',
17
+ MT: 'Montana', MP: 'Northern Mariana Islands', MS: 'Mississippi', SC: 'South Carolina', KY: 'Kentucky',
18
+ OR: 'Oregon', SD: 'South Dakota'},
19
+ CA: {AB: 'Alberta', BC: 'British Columbia', MB: 'Manitoba', NB: 'New Brunswick', NT: 'Northwest Territories',
20
+ NS: 'Nova Scotia', NU: 'Nunavut', ON: 'Ontario', PE: 'Prince Edward Island', QC: 'Quebec',
21
+ SK: 'Saskatchewan', YU: 'Yukon', NL: 'Newfoundland and Labrador'},
22
+ AU: {WA: 'State of Western Australia', SA: 'State of South Australia', NT: 'Northern Territory',
23
+ VIC: 'State of Victoria', TAS: 'State of Tasmania', QLD: 'State of Queensland',
24
+ NSW: 'State of New South Wales', ACT: 'Australian Capital Territory'},
25
+ GB: {WLS: 'Wales', SCT: 'Scotland', NIR: 'Northern Ireland', ENG: 'England'}
26
+ }
27
+
28
+ COUNTRIES = {BD: 'Bangladesh', WF: 'Wallis And Futuna Islands', BF: 'Burkina Faso', PY: 'Paraguay',
29
+ BA: 'Bosnia And Herzegovina', BB: 'Barbados', BE: 'Belgium', BM: 'Bermuda', BN: 'Brunei Darussalam',
30
+ BO: 'Bolivia', BH: 'Bahrain', BI: 'Burundi', BJ: 'Benin', BT: 'Bhutan', JM: 'Jamaica',
31
+ BV: 'Bouvet Island', BW: 'Botswana', WS: 'Samoa', BR: 'Brazil', BS: 'Bahamas', JE: 'Jersey',
32
+ BY: 'Belarus', BZ: 'Belize', RU: 'Russian Federation', RW: 'Rwanda', LT: 'Lithuania', RE: 'Reunion',
33
+ TM: 'Turkmenistan', TJ: 'Tajikistan', RO: 'Romania', LS: 'Lesotho', GW: 'Guinea-bissa', GU: 'Guam',
34
+ GT: 'Guatemala', GS: 'South Georgia And South Sandwich Islands', GR: 'Greece', GQ: 'Equatorial Guinea',
35
+ GP: 'Guadeloupe', JP: 'Japan', GY: 'Guyana', GG: 'Guernsey', GF: 'French Guiana', GE: 'Georgia',
36
+ GD: 'Grenada', GB: 'Great Britain', GA: 'Gabon', GN: 'Guinea', GM: 'Gambia', GL: 'Greenland',
37
+ GI: 'Gibraltar', GH: 'Ghana', OM: 'Oman', TN: 'Tunisia', JO: 'Jordan', HR: 'Croatia', HT: 'Haiti',
38
+ SV: 'El Salvador', HK: 'Hong Kong', HN: 'Honduras', HM: 'Heard And Mcdonald Islands', AD: 'Andorra',
39
+ PR: 'Puerto Rico', PS: 'Palestine', PW: 'Pala', PT: 'Portugal', SJ: 'Svalbard And Jan Mayen Islands',
40
+ VG: 'Virgin Islands, British', AI: 'Anguilla', KP: 'North Korea', PF: 'French Polynesia',
41
+ PG: 'Papua New Guinea', PE: 'Per', PK: 'Pakistan', PH: 'Philippines', PN: 'Pitcairn', PL: 'Poland',
42
+ PM: 'Saint Pierre And Miquelon', ZM: 'Zambia', EH: 'Western Sahara', EE: 'Estonia', EG: 'Egypt',
43
+ ZA: 'South Africa', EC: 'Ecuador', IT: 'Italy', AO: 'Angola', KZ: 'Kazakhstan', ET: 'Ethiopia',
44
+ ZW: 'Zimbabwe', SA: 'Saudi Arabia', ES: 'Spain', ER: 'Eritrea', ME: 'Montenegro', MD: 'Moldova',
45
+ MG: 'Madagascar', MA: 'Morocco', MC: 'Monaco', UZ: 'Uzbekistan', MM: 'Myanmar', ML: 'Mali', MO: 'Maca',
46
+ MN: 'Mongolia', MH: 'Marshall Islands', US: 'United States', UM: 'United States Minor Outlying Islands',
47
+ MT: 'Malta', MW: 'Malawi', MV: 'Maldives', MQ: 'Martinique', MP: 'Northern Mariana Islands',
48
+ MS: 'Montserrat', NA: 'Namibia', IM: 'Isle Of Man', UG: 'Uganda', MY: 'Malaysia', MX: 'Mexico',
49
+ IL: 'Israel', BG: 'Bulgaria', FR: 'France', AW: 'Aruba', AX: 'Åland', FI: 'Finland',
50
+ FJ: 'Fiji', FK: 'Falkland Islands', FM: 'Micronesia', FO: 'Faroe Islands', NI: 'Nicaragua',
51
+ NL: 'Netherlands', NO: 'Norway', SO: 'Somalia', NC: 'New Caledonia', NE: 'Niger', NF: 'Norfolk Island',
52
+ NG: 'Nigeria', NZ: 'New Zealand', NP: 'Nepal', NR: 'Naur', NU: 'Niue', MR: 'Mauritania',
53
+ CK: 'Cook Islands', CI: "Côte D'ivoire", CH: 'Switzerland', CO: 'Colombia', CN: 'China',
54
+ CM: 'Cameroon', CL: 'Chile', CC: 'Cocos (keeling) Islands', CA: 'Canada', CG: 'Congo (brazzaville)',
55
+ CF: 'Central African Republic', CD: 'Congo (kinshasa)', CZ: 'Czech Republic', CY: 'Cyprus',
56
+ CX: 'Christmas Island', CS: 'Serbia', CR: 'Costa Rica', HU: 'Hungary', CV: 'Cape Verde', CU: 'Cuba',
57
+ SZ: 'Swaziland', SY: 'Syria', KG: 'Kyrgyzstan', KE: 'Kenya', SR: 'Suriname', KI: 'Kiribati',
58
+ KH: 'Cambodia', KN: 'Saint Kitts And Nevis', KM: 'Comoros', ST: 'Sao Tome And Principe', SK: 'Slovakia',
59
+ KR: 'South Korea', SI: 'Slovenia', SH: 'Saint Helena', KW: 'Kuwait', SN: 'Senegal', SM: 'San Marino',
60
+ SL: 'Sierra Leone', SC: 'Seychelles', SB: 'Solomon Islands', KY: 'Cayman Islands', SG: 'Singapore',
61
+ SE: 'Sweden', SD: 'Sudan', DO: 'Dominican Republic', DM: 'Dominica', DJ: 'Djibouti', DK: 'Denmark',
62
+ DE: 'Germany', YE: 'Yemen', AT: 'Austria', DZ: 'Algeria', MK: 'Macedonia', UY: 'Uruguay', YT: 'Mayotte',
63
+ MU: 'Mauritius', TZ: 'Tanzania', LC: 'Saint Lucia', LA: 'Laos', TV: 'Tuval', TW: 'Taiwan',
64
+ TT: 'Trinidad And Tobago', TR: 'Turkey', LK: 'Sri Lanka', LI: 'Liechtenstein', LV: 'Latvia',
65
+ TO: 'Tonga', TL: 'Timor-leste', LU: 'Luxembourg', LR: 'Liberia', TK: 'Tokela', TH: 'Thailand',
66
+ TF: 'French Southern Lands', TG: 'Togo', TD: 'Chad', TC: 'Turks And Caicos Islands', LY: 'Libya',
67
+ VA: 'Vatican City', AC: 'Ascension Island', VC: 'Saint Vincent And The Grenadines',
68
+ AE: 'United Arab Emirates', VE: 'Venezuela', AG: 'Antigua And Barbuda', AF: 'Afghanistan', IQ: 'Iraq',
69
+ VI: 'Virgin Islands, U.s.', IS: 'Iceland', IR: 'Iran', AM: 'Armenia', AL: 'Albania', VN: 'Vietnam',
70
+ AN: 'Netherlands Antilles', AQ: 'Antarctica', AS: 'American Samoa', AR: 'Argentina', AU: 'Australia',
71
+ VU: 'Vanuat', IO: 'British Indian Ocean Territory', IN: 'India', LB: 'Lebanon', AZ: 'Azerbaijan',
72
+ IE: 'Ireland', ID: 'Indonesia', PA: 'Panama', UA: 'Ukraine', QA: 'Qatar', MZ: 'Mozambique',
73
+ BL: 'Saint Barthélemy', BQ: 'Caribbean Netherlands', MF: 'Saint Martin', SS: 'South Sudan',
74
+ SX: 'Sint Maarten', XK: 'Kosovo', CW: 'Curaçao', RS: 'Serbia'}
75
+
76
+ end
@@ -1,294 +1,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
- }
26
-
27
- attr_reader :names, :addresses, :phones, :emails, :jobs, :educations, :images, :usernames, :user_ids, :urls
28
- attr_reader :relationships, :tags, :ethnicities, :languages, :origin_countries, :dob, :gender
29
-
30
- def initialize(params={})
31
- @names = []
32
- @addresses = []
33
- @phones = []
34
- @emails = []
35
- @jobs = []
36
- @educations = []
37
- @images = []
38
- @usernames = []
39
- @user_ids = []
40
- @urls = []
41
- @ethnicities = []
42
- @languages = []
43
- @origin_countries = []
44
- @relationships = []
45
- @tags = []
46
- @dob = nil
47
- @gender = nil
48
-
49
- add_fields params[:fields] if params.key? :fields
50
- end
51
-
52
- def self.from_hash(h)
53
- raise AbstractMethodInvoked.new
54
- end
55
-
56
- def self.fields_from_hash(h)
57
- fields = self::CLASS_CONTAINER.map do |cls_name, container|
58
- cls = Pipl.const_get cls_name
59
- h[container.to_sym].map { |x| cls.from_hash(x) } if h.key? container.to_sym
60
- end
61
- .flatten.compact
62
- fields << DOB.from_hash(h[:dob]) if h.key? :dob
63
- fields << Gender.from_hash(h[:gender]) if h.key? :gender
64
- fields
65
- end
66
-
67
- def fields_to_hash
68
- h = {}
69
- h[:dob] = @dob.to_hash if @dob
70
- h[:gender] = @gender.to_hash if @gender
71
- self.class::CLASS_CONTAINER.values.each do |container|
72
- fields = instance_variable_get("@#{container}")
73
- h[container.to_sym] = fields.map { |field| field.to_hash }.compact unless fields.empty?
74
- end
75
- h.reject { |_, value| value.nil? or (value.kind_of?(Array) and value.empty?) }
76
- end
77
-
78
- def add_fields(fields)
79
- fields.each { |f| add_field f }
80
- end
81
-
82
- def add_field(field)
83
- cls_sym = field.class.name.split('::').last.to_sym
84
- container = self.class::CLASS_CONTAINER[cls_sym]
85
- if container
86
- instance_variable_get("@#{container}") << field
87
- elsif cls_sym == :DOB
88
- @dob = field
89
- elsif cls_sym == :Gender
90
- @gender = field
91
- else
92
- raise ArgumentError.new("Object of type #{field.class} is an invalid field")
93
- end
94
- end
95
-
96
- def all_fields
97
- fields = self.class::CLASS_CONTAINER.values.map { |container| instance_variable_get("@#{container}") }
98
- .flatten.compact
99
- fields << @dob if @dob
100
- fields << @gender if @gender
101
- fields
102
- end
103
-
104
- def job
105
- @jobs.first unless @jobs.empty?
106
- end
107
-
108
- def address
109
- @addresses.first unless @addresses.empty?
110
- end
111
-
112
- def education
113
- @educations.first unless @educations.empty?
114
- end
115
-
116
- def language
117
- @languages.first unless @languages.empty?
118
- end
119
-
120
- def ethnicity
121
- @ethnicities.first unless @ethnicities.empty?
122
- end
123
-
124
- def origin_country
125
- @origin_countries.first unless @origin_countries.empty?
126
- end
127
-
128
- def phone
129
- @phones.first unless @phones.empty?
130
- end
131
-
132
- def email
133
- @emails.first unless @emails.empty?
134
- end
135
-
136
- def name
137
- @names.first unless @names.empty?
138
- end
139
-
140
- def image
141
- @images.first unless @images.empty?
142
- end
143
-
144
- def url
145
- @urls.first unless @urls.empty?
146
- end
147
-
148
- def username
149
- @usernames.first unless @usernames.empty?
150
- end
151
-
152
- def user_id
153
- @user_ids.first unless @user_ids.empty?
154
- end
155
-
156
- def relationship
157
- @relationships.first unless @relationships.empty?
158
- end
159
-
160
- end
161
-
162
-
163
- class Relationship < FieldsContainer
164
-
165
- CLASS_CONTAINER = FieldsContainer::CLASS_CONTAINER.clone
166
- CLASS_CONTAINER.delete :Relationship
167
-
168
- # @!attribute valid_since
169
- # @see Field
170
- # @!attribute inferred
171
- # @see Field
172
- # @!attribute type
173
- # @return [String] Type of association of this relationship to a person.
174
- # Possible values are:
175
- # friend
176
- # family
177
- # work
178
- # other
179
- # @!attribute subtype
180
- # @return [String] Subtype of association of this relationship to a person. Free text.
181
-
182
- attr_accessor :valid_since, :inferred, :type, :subtype
183
-
184
- def initialize(params={})
185
- super params
186
- @valid_since = params[:valid_since]
187
- @inferred = params[:inferred]
188
- @type = params[:type]
189
- @subtype = params[:subtype]
190
- end
191
-
192
- def self.from_hash(h)
193
- params = Pipl::Field.base_params_from_hash h
194
- params[:subtype] = h[:@subtype]
195
- params[:fields] = self.fields_from_hash(h)
196
- self.new(params)
197
- end
198
-
199
- def to_hash
200
- fields_to_hash
201
- end
202
-
203
- def to_s
204
- @names.first.to_s unless @names.empty?
205
- end
206
-
207
- end
208
-
209
-
210
- class Source < FieldsContainer
211
-
212
- attr_reader :match, :name, :category, :origin_url, :sponsored, :domain, :source_id, :person_id, :premium, :valid_since
213
-
214
- def initialize(params={})
215
- super params
216
- @name = params[:name]
217
- @category = params[:category]
218
- @origin_url = params[:origin_url]
219
- @domain = params[:domain]
220
- @source_id = params[:source_id]
221
- @person_id = params[:person_id]
222
- @sponsored = params[:sponsored]
223
- @premium = params[:premium]
224
- @match = params[:match]
225
- @valid_since = params[:valid_since]
226
- end
227
-
228
- def self.from_hash(h)
229
- params = {
230
- name: h[:@name],
231
- category: h[:@category],
232
- origin_url: h[:@origin_url],
233
- domain: h[:@domain],
234
- source_id: h[:@id],
235
- person_id: h[:@person_id],
236
- match: h[:@match],
237
- sponsored: h[:@sponsored],
238
- premium: h[:@premium],
239
- }
240
- params[:valid_since] = Pipl::Utils.str_to_date(h[:@valid_since]) if h.key? :@valid_since
241
- params[:fields] = self.fields_from_hash(h)
242
- self.new(params)
243
- end
244
-
245
- end
246
-
247
- class Person < FieldsContainer
248
-
249
- attr_reader :id, :match, :search_pointer, :inferred
250
-
251
- def initialize(params={})
252
- super params
253
- @id = params[:id]
254
- @match = params[:match]
255
- @search_pointer = params[:search_pointer]
256
- @inferred = params[:inferred] || false
257
- end
258
-
259
- def self.from_hash(h)
260
- params = {
261
- id: h[:@id],
262
- match: h[:@match],
263
- search_pointer: h[:@search_pointer],
264
- inferred: h[:@inferred],
265
- }
266
- params[:fields] = fields_from_hash(h)
267
- self.new(params)
268
- end
269
-
270
- def to_hash
271
- h = {}
272
- h[:search_pointer] = @search_pointer if @search_pointer and not @search_pointer.empty?
273
- h.update(fields_to_hash)
274
- h
275
- end
276
-
277
- def is_searchable?
278
- not @search_pointer.nil? or
279
- @names.any? { |f| f.is_searchable? } or
280
- @emails.any? { |f| f.is_searchable? } or
281
- @phones.any? { |f| f.is_searchable? } or
282
- @usernames.any? { |f| f.is_searchable? } or
283
- @user_ids.any? { |f| f.is_searchable? } or
284
- @urls.any? { |f| f.is_searchable? } or
285
- @addresses.any? { |f| f.is_sole_searchable? }
286
- end
287
-
288
- def unsearchable_fields
289
- all_fields.reject { |f| f.is_searchable? }
290
- end
291
-
292
- end
293
-
294
- end
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
+ attr_reader :names, :addresses, :phones, :emails, :jobs, :educations, :images, :usernames, :user_ids, :urls
28
+ attr_reader :relationships, :tags, :ethnicities, :languages, :origin_countries, :dob, :gender
29
+
30
+ def initialize(params={})
31
+ @names = []
32
+ @addresses = []
33
+ @phones = []
34
+ @emails = []
35
+ @jobs = []
36
+ @educations = []
37
+ @images = []
38
+ @usernames = []
39
+ @user_ids = []
40
+ @urls = []
41
+ @ethnicities = []
42
+ @languages = []
43
+ @origin_countries = []
44
+ @relationships = []
45
+ @tags = []
46
+ @dob = nil
47
+ @gender = nil
48
+
49
+ add_fields params[:fields] if params.key? :fields
50
+ end
51
+
52
+ def self.from_hash(h)
53
+ raise AbstractMethodInvoked.new
54
+ end
55
+
56
+ def self.fields_from_hash(h)
57
+ fields = self::CLASS_CONTAINER.map do |cls_name, container|
58
+ cls = Pipl.const_get cls_name
59
+ h[container.to_sym].map { |x| cls.from_hash(x) } if h.key? container.to_sym
60
+ end
61
+ .flatten.compact
62
+ fields << DOB.from_hash(h[:dob]) if h.key? :dob
63
+ fields << Gender.from_hash(h[:gender]) if h.key? :gender
64
+ fields
65
+ end
66
+
67
+ def fields_to_hash
68
+ h = {}
69
+ h[:dob] = @dob.to_hash if @dob
70
+ h[:gender] = @gender.to_hash if @gender
71
+ self.class::CLASS_CONTAINER.values.each do |container|
72
+ fields = instance_variable_get("@#{container}")
73
+ h[container.to_sym] = fields.map { |field| field.to_hash }.compact unless fields.empty?
74
+ end
75
+ h.reject { |_, value| value.nil? or (value.kind_of?(Array) and value.empty?) }
76
+ end
77
+
78
+ def add_fields(fields)
79
+ fields.each { |f| add_field f }
80
+ end
81
+
82
+ def add_field(field)
83
+ cls_sym = field.class.name.split('::').last.to_sym
84
+ container = self.class::CLASS_CONTAINER[cls_sym]
85
+ if container
86
+ instance_variable_get("@#{container}") << field
87
+ elsif cls_sym == :DOB
88
+ @dob = field
89
+ elsif cls_sym == :Gender
90
+ @gender = field
91
+ else
92
+ raise ArgumentError.new("Object of type #{field.class} is an invalid field")
93
+ end
94
+ end
95
+
96
+ def all_fields
97
+ fields = self.class::CLASS_CONTAINER.values.map { |container| instance_variable_get("@#{container}") }
98
+ .flatten.compact
99
+ fields << @dob if @dob
100
+ fields << @gender if @gender
101
+ fields
102
+ end
103
+
104
+ def job
105
+ @jobs.first unless @jobs.empty?
106
+ end
107
+
108
+ def address
109
+ @addresses.first unless @addresses.empty?
110
+ end
111
+
112
+ def education
113
+ @educations.first unless @educations.empty?
114
+ end
115
+
116
+ def language
117
+ @languages.first unless @languages.empty?
118
+ end
119
+
120
+ def ethnicity
121
+ @ethnicities.first unless @ethnicities.empty?
122
+ end
123
+
124
+ def origin_country
125
+ @origin_countries.first unless @origin_countries.empty?
126
+ end
127
+
128
+ def phone
129
+ @phones.first unless @phones.empty?
130
+ end
131
+
132
+ def email
133
+ @emails.first unless @emails.empty?
134
+ end
135
+
136
+ def name
137
+ @names.first unless @names.empty?
138
+ end
139
+
140
+ def image
141
+ @images.first unless @images.empty?
142
+ end
143
+
144
+ def url
145
+ @urls.first unless @urls.empty?
146
+ end
147
+
148
+ def username
149
+ @usernames.first unless @usernames.empty?
150
+ end
151
+
152
+ def user_id
153
+ @user_ids.first unless @user_ids.empty?
154
+ end
155
+
156
+ def relationship
157
+ @relationships.first unless @relationships.empty?
158
+ end
159
+
160
+ end
161
+
162
+
163
+ class Relationship < FieldsContainer
164
+
165
+ CLASS_CONTAINER = FieldsContainer::CLASS_CONTAINER.clone
166
+ CLASS_CONTAINER.delete :Relationship
167
+
168
+ # @!attribute valid_since
169
+ # @see Field
170
+ # @!attribute inferred
171
+ # @see Field
172
+ # @!attribute type
173
+ # @return [String] Type of association of this relationship to a person.
174
+ # Possible values are:
175
+ # friend
176
+ # family
177
+ # work
178
+ # other
179
+ # @!attribute subtype
180
+ # @return [String] Subtype of association of this relationship to a person. Free text.
181
+
182
+ attr_accessor :valid_since, :inferred, :type, :subtype
183
+
184
+ def initialize(params={})
185
+ super params
186
+ @valid_since = params[:valid_since]
187
+ @inferred = params[:inferred]
188
+ @type = params[:type]
189
+ @subtype = params[:subtype]
190
+ end
191
+
192
+ def self.from_hash(h)
193
+ params = Pipl::Field.base_params_from_hash h
194
+ params[:subtype] = h[:@subtype]
195
+ params[:fields] = self.fields_from_hash(h)
196
+ self.new(params)
197
+ end
198
+
199
+ def to_hash
200
+ fields_to_hash
201
+ end
202
+
203
+ def to_s
204
+ @names.first.to_s unless @names.empty?
205
+ end
206
+
207
+ end
208
+
209
+
210
+ class Source < FieldsContainer
211
+
212
+ attr_reader :match, :name, :category, :origin_url, :sponsored, :domain, :source_id, :person_id, :premium, :valid_since
213
+
214
+ def initialize(params={})
215
+ super params
216
+ @name = params[:name]
217
+ @category = params[:category]
218
+ @origin_url = params[:origin_url]
219
+ @domain = params[:domain]
220
+ @source_id = params[:source_id]
221
+ @person_id = params[:person_id]
222
+ @sponsored = params[:sponsored]
223
+ @premium = params[:premium]
224
+ @match = params[:match]
225
+ @valid_since = params[:valid_since]
226
+ end
227
+
228
+ def self.from_hash(h)
229
+ params = {
230
+ name: h[:@name],
231
+ category: h[:@category],
232
+ origin_url: h[:@origin_url],
233
+ domain: h[:@domain],
234
+ source_id: h[:@id],
235
+ person_id: h[:@person_id],
236
+ match: h[:@match],
237
+ sponsored: h[:@sponsored],
238
+ premium: h[:@premium],
239
+ }
240
+ params[:valid_since] = Pipl::Utils.str_to_date(h[:@valid_since]) if h.key? :@valid_since
241
+ params[:fields] = self.fields_from_hash(h)
242
+ self.new(params)
243
+ end
244
+
245
+ end
246
+
247
+ class Person < FieldsContainer
248
+
249
+ attr_reader :id, :match, :search_pointer, :inferred
250
+
251
+ def initialize(params={})
252
+ super params
253
+ @id = params[:id]
254
+ @match = params[:match]
255
+ @search_pointer = params[:search_pointer]
256
+ @inferred = params[:inferred] || false
257
+ end
258
+
259
+ def self.from_hash(h)
260
+ params = {
261
+ id: h[:@id],
262
+ match: h[:@match],
263
+ search_pointer: h[:@search_pointer],
264
+ inferred: h[:@inferred],
265
+ }
266
+ params[:fields] = fields_from_hash(h)
267
+ self.new(params)
268
+ end
269
+
270
+ def to_hash
271
+ h = {}
272
+ h[:search_pointer] = @search_pointer if @search_pointer and not @search_pointer.empty?
273
+ h.update(fields_to_hash)
274
+ h
275
+ end
276
+
277
+ def is_searchable?
278
+ not @search_pointer.nil? or
279
+ @names.any? { |f| f.is_searchable? } or
280
+ @emails.any? { |f| f.is_searchable? } or
281
+ @phones.any? { |f| f.is_searchable? } or
282
+ @usernames.any? { |f| f.is_searchable? } or
283
+ @user_ids.any? { |f| f.is_searchable? } or
284
+ @urls.any? { |f| f.is_searchable? } or
285
+ @addresses.any? { |f| f.is_sole_searchable? }
286
+ end
287
+
288
+ def unsearchable_fields
289
+ all_fields.reject { |f| f.is_searchable? }
290
+ end
291
+
292
+ end
293
+
294
+ end