pushradar 2.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.document +5 -0
- data/.gemtest +0 -0
- data/.gitignore +35 -10
- data/.idea/.gitignore +8 -0
- data/.idea/inspectionProfiles/Project_Default.xml +5 -5
- data/.idea/misc.xml +3 -3
- data/.idea/modules.xml +7 -7
- data/.idea/{PushRadarRuby.iml → pushradar-server-ruby.iml} +15 -12
- data/.idea/vcs.xml +5 -5
- data/CHANGELOG.md +4 -29
- data/Gemfile +1 -4
- data/LICENSE +2 -2
- data/README.md +89 -80
- data/Rakefile +2 -1
- data/VERSION +1 -1
- data/lib/pushradar.rb +10 -0
- data/lib/pushradar/client.rb +101 -0
- data/lib/pushradar/version.rb +3 -0
- data/pushradar.gemspec +26 -0
- metadata +47 -23
- data/.idea/.rakeTasks +0 -7
- data/.idea/workspace.xml +0 -669
- data/PushRadar.gemspec +0 -25
- data/bin/console +0 -6
- data/bin/setup +0 -6
- data/lib/PushRadar.rb +0 -384
- data/lib/PushRadar/APIClient.rb +0 -53
- data/lib/PushRadar/Targeting.rb +0 -173
- data/lib/PushRadar/Utils.rb +0 -558
- data/lib/PushRadar/version.rb +0 -3
data/lib/PushRadar/Targeting.rb
DELETED
@@ -1,173 +0,0 @@
|
|
1
|
-
require 'PushRadar/version'
|
2
|
-
require 'PushRadar/Utils'
|
3
|
-
require 'ipaddr'
|
4
|
-
|
5
|
-
module PushRadar
|
6
|
-
|
7
|
-
# Specifies the target audience of a PushRadar notification
|
8
|
-
class Targeting
|
9
|
-
|
10
|
-
# Creates a new notification targeting object
|
11
|
-
def initialize
|
12
|
-
|
13
|
-
# Initialize variables
|
14
|
-
@target_user_ids = []
|
15
|
-
@target_actions = []
|
16
|
-
@target_not_actions = []
|
17
|
-
@target_browsers = []
|
18
|
-
@target_continents = []
|
19
|
-
@target_countries = []
|
20
|
-
@target_ips = []
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
# Adds a browser to the list of target browsers
|
25
|
-
def target_browser(browser)
|
26
|
-
|
27
|
-
# Trim the browser and convert it to lowercase
|
28
|
-
browser.strip!
|
29
|
-
browser = browser.downcase
|
30
|
-
|
31
|
-
# Validate the browser for being one of the supported types
|
32
|
-
unless %w(chrome ie edge safari opera firefox).include? browser
|
33
|
-
raise "The browser must be one of the following: 'chrome', 'ie', 'edge', 'safari', 'opera', 'firefox'."
|
34
|
-
end
|
35
|
-
|
36
|
-
# Add the browser to the list of target browser
|
37
|
-
unless @target_browsers.include? browser
|
38
|
-
@target_browsers.push browser
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
# Adds a country to the list of target countries
|
44
|
-
def target_country(country_code)
|
45
|
-
|
46
|
-
# Trim the country code and convert it to uppercase
|
47
|
-
country_code.strip!
|
48
|
-
country_code = country_code.upcase
|
49
|
-
|
50
|
-
# Ensure that the country code is not empty
|
51
|
-
if country_code == ''
|
52
|
-
raise 'The country code provided cannot be empty.'
|
53
|
-
end
|
54
|
-
|
55
|
-
# Validate the country code
|
56
|
-
unless Utils.get_countries.keys.include? country_code.to_sym
|
57
|
-
raise 'The country code provided must be a valid two-letter (ISO 3166-1 alpha-2) code.'
|
58
|
-
end
|
59
|
-
|
60
|
-
# Add the country to the list
|
61
|
-
unless @target_countries.include? country_code
|
62
|
-
@target_countries.push country_code
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
# Targets a continent by its continent code
|
68
|
-
def target_continent(continent_code)
|
69
|
-
|
70
|
-
# Target the countries located in this continent
|
71
|
-
Utils.get_countries_from_continent(continent_code).each {|country|
|
72
|
-
target_country country
|
73
|
-
}
|
74
|
-
|
75
|
-
# Add the continent code to the list
|
76
|
-
unless @target_continents.include? continent_code
|
77
|
-
@target_continents.push continent_code
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
81
|
-
|
82
|
-
# Targets the notification to clients with the given IP address
|
83
|
-
def target_ip(ip_address)
|
84
|
-
|
85
|
-
# Trim the IP address
|
86
|
-
ip_address.strip!
|
87
|
-
|
88
|
-
# Make sure that the IP address is not empty
|
89
|
-
if ip_address == ''
|
90
|
-
raise 'The IP address provided cannot be empty.'
|
91
|
-
end
|
92
|
-
|
93
|
-
# Check for wildcard IPs
|
94
|
-
if ip_address.include? '*'
|
95
|
-
raise 'Wildcard IP address targeting is not supported.'
|
96
|
-
end
|
97
|
-
|
98
|
-
# Validate the IP address
|
99
|
-
unless Utils.is_valid_ip ip_address
|
100
|
-
raise 'The IP address provided must be a valid IPv4 or IPv6 address.'
|
101
|
-
end
|
102
|
-
|
103
|
-
# Add the IP address to the list
|
104
|
-
unless @target_ips.include? ip_address
|
105
|
-
@target_ips.push ip_address
|
106
|
-
end
|
107
|
-
|
108
|
-
end
|
109
|
-
|
110
|
-
# Targets the notification to clients who have taken the given action
|
111
|
-
def target_action(action)
|
112
|
-
|
113
|
-
# Trim the action identifier
|
114
|
-
action.strip!
|
115
|
-
|
116
|
-
# Make sure the action identifier is not empty
|
117
|
-
if action == ''
|
118
|
-
raise 'The action identifier cannot be empty'
|
119
|
-
end
|
120
|
-
|
121
|
-
# Make sure that the action is not in the target "not" actions list
|
122
|
-
if @target_not_actions.include? action
|
123
|
-
raise "Action '" + action + "' is already in the 'not' actions list."
|
124
|
-
end
|
125
|
-
|
126
|
-
# Add the action to the list
|
127
|
-
unless @target_actions.include? action
|
128
|
-
@target_actions.push action
|
129
|
-
end
|
130
|
-
|
131
|
-
end
|
132
|
-
|
133
|
-
# Targets the notification to clients who have not taken the given action
|
134
|
-
def target_not_action(action)
|
135
|
-
|
136
|
-
# Trim the action identifier
|
137
|
-
action.strip!
|
138
|
-
|
139
|
-
# Make sure the action identifier is not empty
|
140
|
-
if action == ''
|
141
|
-
raise 'The action identifier cannot be empty'
|
142
|
-
end
|
143
|
-
|
144
|
-
# Make sure that the action is not in the target actions list
|
145
|
-
if @target_actions.include? action
|
146
|
-
raise "Action '" + action + "' is already in the actions list."
|
147
|
-
end
|
148
|
-
|
149
|
-
# Add the action to the list
|
150
|
-
unless @target_not_actions.include? action
|
151
|
-
@target_not_actions.push action
|
152
|
-
end
|
153
|
-
|
154
|
-
end
|
155
|
-
|
156
|
-
# Targets the notification to a specific user (identifier by their user ID)
|
157
|
-
def target_user(user_id)
|
158
|
-
|
159
|
-
# Make sure that the user ID is not empty
|
160
|
-
if user_id == nil
|
161
|
-
raise 'The user ID cannot be nil.'
|
162
|
-
end
|
163
|
-
|
164
|
-
# Add the user ID to the list
|
165
|
-
unless @target_user_ids.include? user_id
|
166
|
-
@target_user_ids.push user_id
|
167
|
-
end
|
168
|
-
|
169
|
-
end
|
170
|
-
|
171
|
-
end
|
172
|
-
|
173
|
-
end
|
data/lib/PushRadar/Utils.rb
DELETED
@@ -1,558 +0,0 @@
|
|
1
|
-
require 'PushRadar/version'
|
2
|
-
require 'resolv'
|
3
|
-
|
4
|
-
module PushRadar
|
5
|
-
|
6
|
-
# Contains helpful methods that are used throughout the library
|
7
|
-
class Utils
|
8
|
-
|
9
|
-
# Searches the given dictionary for values matching the value provided, and returns the keys of those elements
|
10
|
-
def self.keys_where_value(dictionary, value)
|
11
|
-
|
12
|
-
# Select the keys
|
13
|
-
keys = []
|
14
|
-
dictionary.each {|x|
|
15
|
-
if x[1] == value
|
16
|
-
keys.push x[0].to_s
|
17
|
-
end
|
18
|
-
}
|
19
|
-
|
20
|
-
# Return the keys
|
21
|
-
keys
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
# Gets a hash that associates ISO 3166-1 alpha-2 country codes with country names
|
26
|
-
def self.get_countries
|
27
|
-
|
28
|
-
{AD: 'Andorra',
|
29
|
-
AE: 'United Arab Emirates',
|
30
|
-
AF: 'Afghanistan',
|
31
|
-
AG: 'Antigua and Barbuda',
|
32
|
-
AI: 'Anguilla',
|
33
|
-
AL: 'Albania',
|
34
|
-
AM: 'Armenia',
|
35
|
-
AO: 'Angola',
|
36
|
-
AQ: 'Antarctica',
|
37
|
-
AR: 'Argentina',
|
38
|
-
AS: 'American Samoa',
|
39
|
-
AT: 'Austria',
|
40
|
-
AU: 'Australia',
|
41
|
-
AW: 'Aruba',
|
42
|
-
AX: 'Åland Islands',
|
43
|
-
AZ: 'Azerbaijan',
|
44
|
-
BA: 'Bosnia and Herzegovina',
|
45
|
-
BB: 'Barbados',
|
46
|
-
BD: 'Bangladesh',
|
47
|
-
BE: 'Belgium',
|
48
|
-
BF: 'Burkina Faso',
|
49
|
-
BG: 'Bulgaria',
|
50
|
-
BH: 'Bahrain',
|
51
|
-
BI: 'Burundi',
|
52
|
-
BJ: 'Benin',
|
53
|
-
BL: 'Saint Barthélemy',
|
54
|
-
BM: 'Bermuda',
|
55
|
-
BN: 'Brunei Darussalam',
|
56
|
-
BO: 'Bolivia, Plurinational State of',
|
57
|
-
BQ: 'Bonaire, Sint Eustatius and Saba',
|
58
|
-
BR: 'Brazil',
|
59
|
-
BS: 'Bahamas',
|
60
|
-
BT: 'Bhutan',
|
61
|
-
BV: 'Bouvet Island',
|
62
|
-
BW: 'Botswana',
|
63
|
-
BY: 'Belarus',
|
64
|
-
BZ: 'Belize',
|
65
|
-
CA: 'Canada',
|
66
|
-
CC: 'Cocos (Keeling) Islands',
|
67
|
-
CD: 'Congo, the Democratic Republic of the',
|
68
|
-
CF: 'Central African Republic',
|
69
|
-
CG: 'Congo',
|
70
|
-
CH: 'Switzerland',
|
71
|
-
CI: 'Côte d\'Ivoire',
|
72
|
-
CK: 'Cook Islands',
|
73
|
-
CL: 'Chile',
|
74
|
-
CM: 'Cameroon',
|
75
|
-
CN: 'China',
|
76
|
-
CO: 'Colombia',
|
77
|
-
CR: 'Costa Rica',
|
78
|
-
CU: 'Cuba',
|
79
|
-
CV: 'Cabo Verde',
|
80
|
-
CW: 'Curaçao',
|
81
|
-
CX: 'Christmas Island',
|
82
|
-
CY: 'Cyprus',
|
83
|
-
CZ: 'Czechia',
|
84
|
-
DE: 'Germany',
|
85
|
-
DJ: 'Djibouti',
|
86
|
-
DK: 'Denmark',
|
87
|
-
DM: 'Dominica',
|
88
|
-
DO: 'Dominican Republic',
|
89
|
-
DZ: 'Algeria',
|
90
|
-
EC: 'Ecuador',
|
91
|
-
EE: 'Estonia',
|
92
|
-
EG: 'Egypt',
|
93
|
-
EH: 'Western Sahara',
|
94
|
-
ER: 'Eritrea',
|
95
|
-
ES: 'Spain',
|
96
|
-
ET: 'Ethiopia',
|
97
|
-
FI: 'Finland',
|
98
|
-
FJ: 'Fiji',
|
99
|
-
FK: 'Falkland Islands (Malvinas)',
|
100
|
-
FM: 'Micronesia, Federated States of',
|
101
|
-
FO: 'Faroe Islands',
|
102
|
-
FR: 'France',
|
103
|
-
GA: 'Gabon',
|
104
|
-
GB: 'United Kingdom of Great Britain and Northern Ireland',
|
105
|
-
GD: 'Grenada',
|
106
|
-
GE: 'Georgia',
|
107
|
-
GF: 'French Guiana',
|
108
|
-
GG: 'Guernsey',
|
109
|
-
GH: 'Ghana',
|
110
|
-
GI: 'Gibraltar',
|
111
|
-
GL: 'Greenland',
|
112
|
-
GM: 'Gambia',
|
113
|
-
GN: 'Guinea',
|
114
|
-
GP: 'Guadeloupe',
|
115
|
-
GQ: 'Equatorial Guinea',
|
116
|
-
GR: 'Greece',
|
117
|
-
GS: 'South Georgia and the South Sandwich Islands',
|
118
|
-
GT: 'Guatemala',
|
119
|
-
GU: 'Guam',
|
120
|
-
GW: 'Guinea-Bissau',
|
121
|
-
GY: 'Guyana',
|
122
|
-
HK: 'Hong Kong',
|
123
|
-
HM: 'Heard Island and McDonald Islands',
|
124
|
-
HN: 'Honduras',
|
125
|
-
HR: 'Croatia',
|
126
|
-
HT: 'Haiti',
|
127
|
-
HU: 'Hungary',
|
128
|
-
ID: 'Indonesia',
|
129
|
-
IE: 'Ireland',
|
130
|
-
IL: 'Israel',
|
131
|
-
IM: 'Isle of Man',
|
132
|
-
IN: 'India',
|
133
|
-
IO: 'British Indian Ocean Territory',
|
134
|
-
IQ: 'Iraq',
|
135
|
-
IR: 'Iran, Islamic Republic of',
|
136
|
-
IS: 'Iceland',
|
137
|
-
IT: 'Italy',
|
138
|
-
JE: 'Jersey',
|
139
|
-
JM: 'Jamaica',
|
140
|
-
JO: 'Jordan',
|
141
|
-
JP: 'Japan',
|
142
|
-
KE: 'Kenya',
|
143
|
-
KG: 'Kyrgyzstan',
|
144
|
-
KH: 'Cambodia',
|
145
|
-
KI: 'Kiribati',
|
146
|
-
KM: 'Comoros',
|
147
|
-
KN: 'Saint Kitts and Nevis',
|
148
|
-
KP: 'Korea, Democratic People\'s Republic of',
|
149
|
-
KR: 'Korea, Republic of',
|
150
|
-
KW: 'Kuwait',
|
151
|
-
KY: 'Cayman Islands',
|
152
|
-
KZ: 'Kazakhstan',
|
153
|
-
LA: 'Lao People\'s Democratic Republic',
|
154
|
-
LB: 'Lebanon',
|
155
|
-
LC: 'Saint Lucia',
|
156
|
-
LI: 'Liechtenstein',
|
157
|
-
LK: 'Sri Lanka',
|
158
|
-
LR: 'Liberia',
|
159
|
-
LS: 'Lesotho',
|
160
|
-
LT: 'Lithuania',
|
161
|
-
LU: 'Luxembourg',
|
162
|
-
LV: 'Latvia',
|
163
|
-
LY: 'Libya',
|
164
|
-
MA: 'Morocco',
|
165
|
-
MC: 'Monaco',
|
166
|
-
MD: 'Moldova, Republic of',
|
167
|
-
ME: 'Montenegro',
|
168
|
-
MF: 'Saint Martin (French part)',
|
169
|
-
MG: 'Madagascar',
|
170
|
-
MH: 'Marshall Islands',
|
171
|
-
MK: 'Macedonia, the former Yugoslav Republic of',
|
172
|
-
ML: 'Mali',
|
173
|
-
MM: 'Myanmar',
|
174
|
-
MN: 'Mongolia',
|
175
|
-
MO: 'Macao',
|
176
|
-
MP: 'Northern Mariana Islands',
|
177
|
-
MQ: 'Martinique',
|
178
|
-
MR: 'Mauritania',
|
179
|
-
MS: 'Montserrat',
|
180
|
-
MT: 'Malta',
|
181
|
-
MU: 'Mauritius',
|
182
|
-
MV: 'Maldives',
|
183
|
-
MW: 'Malawi',
|
184
|
-
MX: 'Mexico',
|
185
|
-
MY: 'Malaysia',
|
186
|
-
MZ: 'Mozambique',
|
187
|
-
NA: 'Namibia',
|
188
|
-
NC: 'New Caledonia',
|
189
|
-
NE: 'Niger',
|
190
|
-
NF: 'Norfolk Island',
|
191
|
-
NG: 'Nigeria',
|
192
|
-
NI: 'Nicaragua',
|
193
|
-
NL: 'Netherlands',
|
194
|
-
NO: 'Norway',
|
195
|
-
NP: 'Nepal',
|
196
|
-
NR: 'Nauru',
|
197
|
-
NU: 'Niue',
|
198
|
-
NZ: 'New Zealand',
|
199
|
-
OM: 'Oman',
|
200
|
-
PA: 'Panama',
|
201
|
-
PE: 'Peru',
|
202
|
-
PF: 'French Polynesia',
|
203
|
-
PG: 'Papua New Guinea',
|
204
|
-
PH: 'Philippines',
|
205
|
-
PK: 'Pakistan',
|
206
|
-
PL: 'Poland',
|
207
|
-
PM: 'Saint Pierre and Miquelon',
|
208
|
-
PN: 'Pitcairn',
|
209
|
-
PR: 'Puerto Rico',
|
210
|
-
PS: 'Palestine, State of',
|
211
|
-
PT: 'Portugal',
|
212
|
-
PW: 'Palau',
|
213
|
-
PY: 'Paraguay',
|
214
|
-
QA: 'Qatar',
|
215
|
-
RE: 'Réunion',
|
216
|
-
RO: 'Romania',
|
217
|
-
RS: 'Serbia',
|
218
|
-
RU: 'Russian Federation',
|
219
|
-
RW: 'Rwanda',
|
220
|
-
SA: 'Saudi Arabia',
|
221
|
-
SB: 'Solomon Islands',
|
222
|
-
SC: 'Seychelles',
|
223
|
-
SD: 'Sudan',
|
224
|
-
SE: 'Sweden',
|
225
|
-
SG: 'Singapore',
|
226
|
-
SH: 'Saint Helena, Ascension and Tristan da Cunha',
|
227
|
-
SI: 'Slovenia',
|
228
|
-
SJ: 'Svalbard and Jan Mayen',
|
229
|
-
SK: 'Slovakia',
|
230
|
-
SL: 'Sierra Leone',
|
231
|
-
SM: 'San Marino',
|
232
|
-
SN: 'Senegal',
|
233
|
-
SO: 'Somalia',
|
234
|
-
SR: 'Suriname',
|
235
|
-
SS: 'South Sudan',
|
236
|
-
ST: 'Sao Tome and Principe',
|
237
|
-
SV: 'El Salvador',
|
238
|
-
SX: 'Sint Maarten (Dutch part)',
|
239
|
-
SY: 'Syrian Arab Republic',
|
240
|
-
SZ: 'Swaziland',
|
241
|
-
TC: 'Turks and Caicos Islands',
|
242
|
-
TD: 'Chad',
|
243
|
-
TF: 'French Southern Territories',
|
244
|
-
TG: 'Togo',
|
245
|
-
TH: 'Thailand',
|
246
|
-
TJ: 'Tajikistan',
|
247
|
-
TK: 'Tokelau',
|
248
|
-
TL: 'Timor-Leste',
|
249
|
-
TM: 'Turkmenistan',
|
250
|
-
TN: 'Tunisia',
|
251
|
-
TO: 'Tonga',
|
252
|
-
TR: 'Turkey',
|
253
|
-
TT: 'Trinidad and Tobago',
|
254
|
-
TV: 'Tuvalu',
|
255
|
-
TW: 'Taiwan, Province of China',
|
256
|
-
TZ: 'Tanzania, United Republic of',
|
257
|
-
UA: 'Ukraine',
|
258
|
-
UG: 'Uganda',
|
259
|
-
UM: 'United States Minor Outlying Islands',
|
260
|
-
US: 'United States of America',
|
261
|
-
UY: 'Uruguay',
|
262
|
-
UZ: 'Uzbekistan',
|
263
|
-
VA: 'Holy See',
|
264
|
-
VC: 'Saint Vincent and the Grenadines',
|
265
|
-
VE: 'Venezuela, Bolivarian Republic of',
|
266
|
-
VG: 'Virgin Islands, British',
|
267
|
-
VI: 'Virgin Islands, U.S.',
|
268
|
-
VN: 'Viet Nam',
|
269
|
-
VU: 'Vanuatu',
|
270
|
-
WF: 'Wallis and Futuna',
|
271
|
-
WS: 'Samoa',
|
272
|
-
YE: 'Yemen',
|
273
|
-
YT: 'Mayotte',
|
274
|
-
ZA: 'South Africa',
|
275
|
-
ZM: 'Zambia',
|
276
|
-
ZW: 'Zimbabwe'}
|
277
|
-
|
278
|
-
end
|
279
|
-
|
280
|
-
# Gets a hash that associates ISO 3166-1 alpha-2 country codes with two-letter continent codes
|
281
|
-
def self.get_country_continent_hash
|
282
|
-
|
283
|
-
# Return the hash
|
284
|
-
{AD: 'EU',
|
285
|
-
AE: 'AS',
|
286
|
-
AF: 'AS',
|
287
|
-
AG: 'NA',
|
288
|
-
AI: 'NA',
|
289
|
-
AL: 'EU',
|
290
|
-
AM: 'AS',
|
291
|
-
AO: 'AF',
|
292
|
-
AQ: 'AN',
|
293
|
-
AR: 'SA',
|
294
|
-
AS: 'OC',
|
295
|
-
AT: 'EU',
|
296
|
-
AU: 'OC',
|
297
|
-
AW: 'NA',
|
298
|
-
AX: 'EU',
|
299
|
-
AZ: 'AS',
|
300
|
-
BA: 'EU',
|
301
|
-
BB: 'NA',
|
302
|
-
BD: 'AS',
|
303
|
-
BE: 'EU',
|
304
|
-
BF: 'AF',
|
305
|
-
BG: 'EU',
|
306
|
-
BH: 'AS',
|
307
|
-
BI: 'AF',
|
308
|
-
BJ: 'AF',
|
309
|
-
BL: 'NA',
|
310
|
-
BM: 'NA',
|
311
|
-
BN: 'AS',
|
312
|
-
BO: 'SA',
|
313
|
-
BR: 'SA',
|
314
|
-
BS: 'NA',
|
315
|
-
BT: 'AS',
|
316
|
-
BV: 'AN',
|
317
|
-
BW: 'AF',
|
318
|
-
BY: 'EU',
|
319
|
-
BZ: 'NA',
|
320
|
-
CA: 'NA',
|
321
|
-
CC: 'AS',
|
322
|
-
CD: 'AF',
|
323
|
-
CF: 'AF',
|
324
|
-
CG: 'AF',
|
325
|
-
CH: 'EU',
|
326
|
-
CI: 'AF',
|
327
|
-
CK: 'OC',
|
328
|
-
CL: 'SA',
|
329
|
-
CM: 'AF',
|
330
|
-
CN: 'AS',
|
331
|
-
CO: 'SA',
|
332
|
-
CR: 'NA',
|
333
|
-
CU: 'NA',
|
334
|
-
CV: 'AF',
|
335
|
-
CX: 'AS',
|
336
|
-
CY: 'AS',
|
337
|
-
CZ: 'EU',
|
338
|
-
DE: 'EU',
|
339
|
-
DJ: 'AF',
|
340
|
-
DK: 'EU',
|
341
|
-
DM: 'NA',
|
342
|
-
DO: 'NA',
|
343
|
-
DZ: 'AF',
|
344
|
-
EC: 'SA',
|
345
|
-
EE: 'EU',
|
346
|
-
EG: 'AF',
|
347
|
-
EH: 'AF',
|
348
|
-
ER: 'AF',
|
349
|
-
ES: 'EU',
|
350
|
-
ET: 'AF',
|
351
|
-
FI: 'EU',
|
352
|
-
FJ: 'OC',
|
353
|
-
FK: 'SA',
|
354
|
-
FM: 'OC',
|
355
|
-
FO: 'EU',
|
356
|
-
FR: 'EU',
|
357
|
-
GA: 'AF',
|
358
|
-
GB: 'EU',
|
359
|
-
GD: 'NA',
|
360
|
-
GE: 'AS',
|
361
|
-
GF: 'SA',
|
362
|
-
GG: 'EU',
|
363
|
-
GH: 'AF',
|
364
|
-
GI: 'EU',
|
365
|
-
GL: 'NA',
|
366
|
-
GM: 'AF',
|
367
|
-
GN: 'AF',
|
368
|
-
GP: 'NA',
|
369
|
-
GQ: 'AF',
|
370
|
-
GR: 'EU',
|
371
|
-
GS: 'AN',
|
372
|
-
GT: 'NA',
|
373
|
-
GU: 'OC',
|
374
|
-
GW: 'AF',
|
375
|
-
GY: 'SA',
|
376
|
-
HK: 'AS',
|
377
|
-
HM: 'AN',
|
378
|
-
HN: 'NA',
|
379
|
-
HR: 'EU',
|
380
|
-
HT: 'NA',
|
381
|
-
HU: 'EU',
|
382
|
-
ID: 'AS',
|
383
|
-
IE: 'EU',
|
384
|
-
IL: 'AS',
|
385
|
-
IM: 'EU',
|
386
|
-
IN: 'AS',
|
387
|
-
IO: 'AS',
|
388
|
-
IQ: 'AS',
|
389
|
-
IR: 'AS',
|
390
|
-
IS: 'EU',
|
391
|
-
IT: 'EU',
|
392
|
-
JE: 'EU',
|
393
|
-
JM: 'NA',
|
394
|
-
JO: 'AS',
|
395
|
-
JP: 'AS',
|
396
|
-
KE: 'AF',
|
397
|
-
KG: 'AS',
|
398
|
-
KH: 'AS',
|
399
|
-
KI: 'OC',
|
400
|
-
KM: 'AF',
|
401
|
-
KN: 'NA',
|
402
|
-
KP: 'AS',
|
403
|
-
KR: 'AS',
|
404
|
-
KW: 'AS',
|
405
|
-
KY: 'NA',
|
406
|
-
KZ: 'AS',
|
407
|
-
LA: 'AS',
|
408
|
-
LB: 'AS',
|
409
|
-
LC: 'NA',
|
410
|
-
LI: 'EU',
|
411
|
-
LK: 'AS',
|
412
|
-
LR: 'AF',
|
413
|
-
LS: 'AF',
|
414
|
-
LT: 'EU',
|
415
|
-
LU: 'EU',
|
416
|
-
LV: 'EU',
|
417
|
-
LY: 'AF',
|
418
|
-
MA: 'AF',
|
419
|
-
MC: 'EU',
|
420
|
-
MD: 'EU',
|
421
|
-
ME: 'EU',
|
422
|
-
MF: 'NA',
|
423
|
-
MG: 'AF',
|
424
|
-
MH: 'OC',
|
425
|
-
MK: 'EU',
|
426
|
-
ML: 'AF',
|
427
|
-
MM: 'AS',
|
428
|
-
MN: 'AS',
|
429
|
-
MO: 'AS',
|
430
|
-
MP: 'OC',
|
431
|
-
MQ: 'NA',
|
432
|
-
MR: 'AF',
|
433
|
-
MS: 'NA',
|
434
|
-
MT: 'EU',
|
435
|
-
MU: 'AF',
|
436
|
-
MV: 'AS',
|
437
|
-
MW: 'AF',
|
438
|
-
MX: 'NA',
|
439
|
-
MY: 'AS',
|
440
|
-
MZ: 'AF',
|
441
|
-
NA: 'AF',
|
442
|
-
NC: 'OC',
|
443
|
-
NE: 'AF',
|
444
|
-
NF: 'OC',
|
445
|
-
NG: 'AF',
|
446
|
-
NI: 'NA',
|
447
|
-
NL: 'EU',
|
448
|
-
NO: 'EU',
|
449
|
-
NP: 'AS',
|
450
|
-
NR: 'OC',
|
451
|
-
NU: 'OC',
|
452
|
-
NZ: 'OC',
|
453
|
-
OM: 'AS',
|
454
|
-
PA: 'NA',
|
455
|
-
PE: 'SA',
|
456
|
-
PF: 'OC',
|
457
|
-
PG: 'OC',
|
458
|
-
PH: 'AS',
|
459
|
-
PK: 'AS',
|
460
|
-
PL: 'EU',
|
461
|
-
PM: 'NA',
|
462
|
-
PN: 'OC',
|
463
|
-
PR: 'NA',
|
464
|
-
PS: 'AS',
|
465
|
-
PT: 'EU',
|
466
|
-
PW: 'OC',
|
467
|
-
PY: 'SA',
|
468
|
-
QA: 'AS',
|
469
|
-
RE: 'AF',
|
470
|
-
RO: 'EU',
|
471
|
-
RS: 'EU',
|
472
|
-
RU: 'EU',
|
473
|
-
RW: 'AF',
|
474
|
-
SA: 'AS',
|
475
|
-
SB: 'OC',
|
476
|
-
SC: 'AF',
|
477
|
-
SD: 'AF',
|
478
|
-
SE: 'EU',
|
479
|
-
SG: 'AS',
|
480
|
-
SH: 'AF',
|
481
|
-
SI: 'EU',
|
482
|
-
SJ: 'EU',
|
483
|
-
SK: 'EU',
|
484
|
-
SL: 'AF',
|
485
|
-
SM: 'EU',
|
486
|
-
SN: 'AF',
|
487
|
-
SO: 'AF',
|
488
|
-
SR: 'SA',
|
489
|
-
ST: 'AF',
|
490
|
-
SV: 'NA',
|
491
|
-
SY: 'AS',
|
492
|
-
SZ: 'AF',
|
493
|
-
TC: 'NA',
|
494
|
-
TD: 'AF',
|
495
|
-
TF: 'AN',
|
496
|
-
TG: 'AF',
|
497
|
-
TH: 'AS',
|
498
|
-
TJ: 'AS',
|
499
|
-
TK: 'OC',
|
500
|
-
TL: 'AS',
|
501
|
-
TM: 'AS',
|
502
|
-
TN: 'AF',
|
503
|
-
TO: 'OC',
|
504
|
-
TR: 'EU',
|
505
|
-
TT: 'NA',
|
506
|
-
TV: 'OC',
|
507
|
-
TW: 'AS',
|
508
|
-
TZ: 'AF',
|
509
|
-
UA: 'EU',
|
510
|
-
UG: 'AF',
|
511
|
-
UM: 'OC',
|
512
|
-
US: 'NA',
|
513
|
-
UY: 'SA',
|
514
|
-
UZ: 'AS',
|
515
|
-
VA: 'EU',
|
516
|
-
VC: 'NA',
|
517
|
-
VE: 'SA',
|
518
|
-
VG: 'NA',
|
519
|
-
VI: 'NA',
|
520
|
-
VN: 'AS',
|
521
|
-
VU: 'OC',
|
522
|
-
WF: 'OC',
|
523
|
-
WS: 'OC',
|
524
|
-
YE: 'AS',
|
525
|
-
YT: 'AF',
|
526
|
-
ZA: 'AF',
|
527
|
-
ZM: 'AF',
|
528
|
-
ZW: 'AF'}
|
529
|
-
|
530
|
-
end
|
531
|
-
|
532
|
-
# Gets a list of ISO 3166-1 alpha-2 country codes, corresponding to countries located within the given continent
|
533
|
-
def self.get_countries_from_continent(continent_code)
|
534
|
-
|
535
|
-
# Convert the continent code to uppercase
|
536
|
-
continent_code.strip!
|
537
|
-
continent_code = continent_code.upcase
|
538
|
-
|
539
|
-
# Get the country codes where the value equals the continent code
|
540
|
-
keys_where_value(get_country_continent_hash, continent_code)
|
541
|
-
|
542
|
-
end
|
543
|
-
|
544
|
-
# Checks whether the given IP address is valid
|
545
|
-
def self.is_valid_ip(addr)
|
546
|
-
case addr
|
547
|
-
when Resolv::IPv4::Regex
|
548
|
-
return true
|
549
|
-
when Resolv::IPv6::Regex
|
550
|
-
return true
|
551
|
-
else
|
552
|
-
return false
|
553
|
-
end
|
554
|
-
end
|
555
|
-
|
556
|
-
end
|
557
|
-
|
558
|
-
end
|