internetbs 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/Gemfile +5 -0
  4. data/LICENSE +19 -0
  5. data/README.md +758 -0
  6. data/internetbs.gemspec +18 -0
  7. data/lib/internetbs.rb +64 -0
  8. data/lib/internetbs/account_balance.rb +8 -0
  9. data/lib/internetbs/account_balances.rb +40 -0
  10. data/lib/internetbs/account_domain.rb +11 -0
  11. data/lib/internetbs/account_domains.rb +100 -0
  12. data/lib/internetbs/account_price.rb +19 -0
  13. data/lib/internetbs/account_prices.rb +70 -0
  14. data/lib/internetbs/account_transaction.rb +9 -0
  15. data/lib/internetbs/account_transactions.rb +54 -0
  16. data/lib/internetbs/additional_attributes.rb +41 -0
  17. data/lib/internetbs/base.rb +33 -0
  18. data/lib/internetbs/client.rb +49 -0
  19. data/lib/internetbs/configuration.rb +61 -0
  20. data/lib/internetbs/country_codes.rb +288 -0
  21. data/lib/internetbs/domain_availability.rb +37 -0
  22. data/lib/internetbs/domain_contact.rb +109 -0
  23. data/lib/internetbs/domain_host.rb +46 -0
  24. data/lib/internetbs/domain_hosts.rb +101 -0
  25. data/lib/internetbs/domain_information.rb +128 -0
  26. data/lib/internetbs/domain_push.rb +33 -0
  27. data/lib/internetbs/domain_record.rb +31 -0
  28. data/lib/internetbs/domain_records.rb +172 -0
  29. data/lib/internetbs/domain_total.rb +8 -0
  30. data/lib/internetbs/dot_asia_attributes.rb +56 -0
  31. data/lib/internetbs/dot_de_attributes.rb +64 -0
  32. data/lib/internetbs/dot_eu_attributes.rb +20 -0
  33. data/lib/internetbs/dot_fr_attributes.rb +138 -0
  34. data/lib/internetbs/dot_it_attributes.rb +182 -0
  35. data/lib/internetbs/dot_nl_attributes.rb +47 -0
  36. data/lib/internetbs/dot_uk_attributes.rb +60 -0
  37. data/lib/internetbs/dot_us_attributes.rb +54 -0
  38. data/lib/internetbs/error.rb +38 -0
  39. data/lib/internetbs/language_codes.rb +27 -0
  40. data/lib/internetbs/order_domain.rb +78 -0
  41. data/lib/internetbs/private_whois.rb +81 -0
  42. data/lib/internetbs/registrar_lock.rb +73 -0
  43. data/lib/internetbs/registry_status.rb +39 -0
  44. data/lib/internetbs/renew_domain.rb +43 -0
  45. data/lib/internetbs/update_domain.rb +71 -0
  46. data/lib/internetbs/version.rb +10 -0
  47. metadata +104 -0
@@ -0,0 +1,33 @@
1
+ require 'virtus'
2
+
3
+ module InternetBS
4
+ class Base
5
+ include Virtus.model
6
+ include Virtus::Equalizer.new(name || inspect)
7
+
8
+ attribute :errors, Array[String]
9
+ attribute :status, String # SUCCESS or FAILURE or PENDING
10
+ attribute :transaction_id, String
11
+
12
+ def inspect
13
+ values = Hash[instance_variables.map{|name| [name, instance_variable_get(name)]}]
14
+ "<#{self.class.name} #{values}>"
15
+ end
16
+
17
+ private
18
+
19
+ def ensure_attribute_has_value(*attributes)
20
+ @errors.clear
21
+ attributes.each do |attr|
22
+ unless instance_variable_get(("@" + attr.to_s).intern)
23
+ @errors << "#{attr.to_s} is required"
24
+ end
25
+ end
26
+ end
27
+
28
+ def set_errors(response)
29
+ hash = JSON.parse(response.body)
30
+ @errors << hash["message"]
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,49 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+
4
+ module InternetBS
5
+ class Client
6
+ @headers = {
7
+ 'User-Agent' => InternetBS::VERSION::SUMMARY,
8
+ 'Accept' => 'application/json'
9
+ }
10
+
11
+ @params = {
12
+ :apikey => InternetBS.api_key,
13
+ :password => InternetBS.api_pwd,
14
+ :responseformat => 'json'
15
+ }
16
+
17
+ def self.get(endpoint, params = {})
18
+ begin
19
+ uri = URI.parse([InternetBS.api_uri, endpoint].join)
20
+ @params.merge!(params) if params.any?
21
+ uri.query = URI.encode_www_form(@params)
22
+ http = Net::HTTP.new(uri.host, uri.port)
23
+ http.use_ssl = true
24
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
25
+ request = Net::HTTP::Get.new(uri, @headers)
26
+ response = http.request(request)
27
+ rescue StandardError => error
28
+ puts "Request failed (#{error.message})"
29
+ end
30
+ end
31
+
32
+ def self.post(endpoint, params = {})
33
+ begin
34
+ uri = URI.parse([InternetBS.api_uri, endpoint].join)
35
+ uri.query = URI.encode_www_form(@params)
36
+ body = URI.encode_www_form(params)
37
+ http = Net::HTTP.new(uri.host, uri.port)
38
+ http.use_ssl = true
39
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
40
+ request = Net::HTTP::Post.new(uri, @headers)
41
+ request.add_field "Content-Type", "application/x-www-form-urlencoded"
42
+ request.body = body
43
+ response = http.request(request)
44
+ rescue StandardError => error
45
+ puts "Request failed (#{error.message})"
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,61 @@
1
+ module InternetBS
2
+ class Configuration
3
+ attr_writer :credentials
4
+
5
+ def api_key
6
+ InternetBS.credentials[InternetBS.environment][:api_key]
7
+ end
8
+
9
+ def api_key=(value)
10
+ InternetBS.credentials[InternetBS.environment][:api_key] = value
11
+ end
12
+
13
+ def api_pwd
14
+ InternetBS.credentials[InternetBS.environment][:api_pwd]
15
+ end
16
+
17
+ def api_pwd=(value)
18
+ InternetBS.credentials[InternetBS.environment][:api_pwd] = value
19
+ end
20
+
21
+ def api_uri
22
+ InternetBS.credentials[InternetBS.environment][:api_uri]
23
+ end
24
+
25
+ def api_uri=(value)
26
+ InternetBS.credentials[InternetBS.environment][:api_uri] = value
27
+ end
28
+
29
+ def credentials
30
+ @credentials ||= {
31
+ :production => {
32
+ :api_key => ENV['INTERNETBS_API_KEY'],
33
+ :api_pwd => ENV['INTERNETBS_API_PWD'],
34
+ :api_uri => "https://api.internet.bs"
35
+ },
36
+ :test => {
37
+ :api_key => "testapi",
38
+ :api_pwd => "testpass",
39
+ :api_uri => "https://testapi.internet.bs"
40
+ },
41
+ :development => {
42
+ :api_key => "testapi",
43
+ :api_pwd => "testpass",
44
+ :api_uri => "https://testapi.internet.bs"
45
+ }
46
+ }
47
+ end
48
+
49
+ def environment
50
+ @environment ||= :production
51
+ end
52
+
53
+ def environment=(value)
54
+ @environment = value.is_a?(String) ? value.to_sym : value
55
+ end
56
+
57
+ def environments
58
+ InternetBS.credentials.keys
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,288 @@
1
+ module InternetBS
2
+ # This list is derived from https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2.
3
+ # The hash keys are ISO_3166-1_alpha-2 codes and the values are the country display name.
4
+ # The top 20 countries by number of Internet users are grouped first, see
5
+ # https://en.wikipedia.org/wiki/List_of_countries_by_number_of_Internet_users.
6
+ COUNTRY_CODES = {
7
+ "BR" => "Brazil",
8
+ "CA" => "Canada",
9
+ "CN" => "China",
10
+ "EG" => "Egypt",
11
+ "FR" => "France",
12
+ "DE" => "Germany",
13
+ "IN" => "India",
14
+ "ID" => "Indonesia",
15
+ "IT" => "Italy",
16
+ "JP" => "Japan",
17
+ "MX" => "Mexico",
18
+ "NG" => "Nigeria",
19
+ "PH" => "Philippines",
20
+ "RU" => "Russian Federation",
21
+ "ES" => "Spain",
22
+ "KR" => "South Korea",
23
+ "TR" => "Turkey",
24
+ "GB" => "United Kingdom",
25
+ "US" => "United States",
26
+ "VN" => "Vietnam",
27
+ "AD" => "Andorra",
28
+ "AE" => "United Arab Emirates",
29
+ "AF" => "Afghanistan",
30
+ "AG" => "Antigua and Barbuda",
31
+ "AI" => "Anguilla",
32
+ "AL" => "Albania",
33
+ "AM" => "Armenia",
34
+ "AO" => "Angola",
35
+ "AQ" => "Antarctica",
36
+ "AR" => "Argentina",
37
+ "AS" => "American Samoa",
38
+ "AT" => "Austria",
39
+ "AU" => "Australia",
40
+ "AW" => "Aruba",
41
+ "AX" => "Åland Islands",
42
+ "AZ" => "Azerbaijan",
43
+ "BA" => "Bosnia and Herzegovina",
44
+ "BB" => "Barbados",
45
+ "BD" => "Bangladesh",
46
+ "BE" => "Belgium",
47
+ "BF" => "Burkina Faso",
48
+ "BG" => "Bulgaria",
49
+ "BH" => "Bahrain",
50
+ "BI" => "Burundi",
51
+ "BJ" => "Benin",
52
+ "BL" => "Saint Barthélemy",
53
+ "BM" => "Bermuda",
54
+ "BN" => "Brunei",
55
+ "BO" => "Bolivia",
56
+ "BQ" => "Bonaire, Sint Eustatius and Saba Caribbean Netherlands",
57
+ "BS" => "Bahamas",
58
+ "BT" => "Bhutan",
59
+ "BV" => "Bouvet Island",
60
+ "BW" => "Botswana",
61
+ "BY" => "Belarus",
62
+ "BZ" => "Belize",
63
+ "CC" => "Cocos (Keeling) Islands",
64
+ "CD" => "Congo, the Democratic Republic of",
65
+ "CF" => "Central African Republic",
66
+ "CG" => "Congo",
67
+ "CH" => "Switzerland",
68
+ "CI" => "Côte d'Ivoire",
69
+ "CK" => "Cook Islands",
70
+ "CL" => "Chile",
71
+ "CM" => "Cameroon",
72
+ "CO" => "Colombia",
73
+ "CR" => "Costa Rica",
74
+ "CU" => "Cuba",
75
+ "CV" => "Cabo Verde",
76
+ "CW" => "Curaçao",
77
+ "CX" => "Christmas Island",
78
+ "CY" => "Cyprus",
79
+ "CZ" => "Czech Republic",
80
+ "DJ" => "Djibouti",
81
+ "DK" => "Denmark",
82
+ "DM" => "Dominica",
83
+ "DO" => "Dominican Republic",
84
+ "DZ" => "Algeria",
85
+ "EC" => "Ecuador",
86
+ "EE" => "Estonia",
87
+ "EH" => "Western Sahara",
88
+ "ER" => "Eritrea",
89
+ "ET" => "Ethiopia",
90
+ "FI" => "Finland",
91
+ "FJ" => "Fiji",
92
+ "FK" => "Falkland Islands (Malvinas)",
93
+ "FM" => "Federated States of Micronesia",
94
+ "FO" => "Faroe Islands",
95
+ "GA" => "Gabon",
96
+ "GD" => "Grenada",
97
+ "GE" => "Georgia",
98
+ "GF" => "French Guiana",
99
+ "GG" => "Guernsey",
100
+ "GH" => "Ghana",
101
+ "GI" => "Gibraltar",
102
+ "GL" => "Greenland",
103
+ "GM" => "Gambia",
104
+ "GN" => "Guinea",
105
+ "GP" => "Guadeloupe",
106
+ "GQ" => "Equatorial Guinea",
107
+ "GR" => "Greece",
108
+ "GS" => "South Georgia and the South Sandwich Islands",
109
+ "GT" => "Guatemala",
110
+ "GU" => "Guam",
111
+ "GW" => "Guinea-Bissau",
112
+ "GY" => "Guyana",
113
+ "HK" => "Hong Kong",
114
+ "HM" => "Heard Island and McDonald Islands",
115
+ "HN" => "Honduras",
116
+ "HR" => "Croatia",
117
+ "HT" => "Haiti",
118
+ "HU" => "Hungary",
119
+ "IE" => "Ireland",
120
+ "IL" => "Israel",
121
+ "IM" => "Isle of Man",
122
+ "IO" => "British Indian Ocean Territory",
123
+ "IQ" => "Iraq",
124
+ "IR" => "Iran",
125
+ "IS" => "Iceland",
126
+ "JE" => "Jersey",
127
+ "JM" => "Jamaica",
128
+ "JO" => "Jordan",
129
+ "KE" => "Kenya",
130
+ "KG" => "Kyrgyzstan",
131
+ "KH" => "Cambodia",
132
+ "KI" => "Kiribati",
133
+ "KM" => "Comoros",
134
+ "KN" => "Saint Kitts and Nevis",
135
+ "KP" => "North Korea",
136
+ "KW" => "Kuwait",
137
+ "KY" => "Cayman Islands",
138
+ "KZ" => "Kazakhstan",
139
+ "LA" => "Laos",
140
+ "LB" => "Lebanon",
141
+ "LC" => "Saint Lucia",
142
+ "LI" => "Liechtenstein",
143
+ "LK" => "Sri Lanka",
144
+ "LR" => "Liberia",
145
+ "LS" => "Lesotho",
146
+ "LT" => "Lithuania",
147
+ "LU" => "Luxembourg",
148
+ "LV" => "Latvia",
149
+ "LY" => "Libya",
150
+ "MA" => "Morocco",
151
+ "MC" => "Monaco",
152
+ "MD" => "Moldova",
153
+ "ME" => "Montenegro",
154
+ "MF" => "Saint Martin (French part)",
155
+ "MG" => "Madagascar",
156
+ "MH" => "Marshall Islands",
157
+ "MK" => "Macedonia",
158
+ "ML" => "Mali",
159
+ "MM" => "Myanmar",
160
+ "MN" => "Mongolia",
161
+ "MO" => "Macao",
162
+ "MP" => "Northern Mariana Islands",
163
+ "MQ" => "Martinique",
164
+ "MR" => "Mauritania",
165
+ "MS" => "Montserrat",
166
+ "MT" => "Malta",
167
+ "MU" => "Mauritius",
168
+ "MV" => "Maldives",
169
+ "MW" => "Malawi",
170
+ "MY" => "Malaysia",
171
+ "MZ" => "Mozambique",
172
+ "NA" => "Namibia",
173
+ "NC" => "New Caledonia",
174
+ "NE" => "Niger",
175
+ "NF" => "Norfolk Island",
176
+ "NI" => "Nicaragua",
177
+ "NL" => "Netherlands",
178
+ "NO" => "Norway",
179
+ "NP" => "Nepal",
180
+ "NR" => "Nauru",
181
+ "NU" => "Niue",
182
+ "NZ" => "New Zealand",
183
+ "OM" => "Oman",
184
+ "PA" => "Panama",
185
+ "PE" => "Peru",
186
+ "PF" => "French Polynesia",
187
+ "PG" => "Papua New Guinea",
188
+ "PK" => "Pakistan",
189
+ "PL" => "Poland",
190
+ "PM" => "Saint Pierre and Miquelon",
191
+ "PN" => "Pitcairn",
192
+ "PR" => "Puerto Rico",
193
+ "PS" => "Palestine",
194
+ "PT" => "Portugal",
195
+ "PW" => "Palau",
196
+ "PY" => "Paraguay",
197
+ "QA" => "Qatar",
198
+ "RE" => "Réunion",
199
+ "RO" => "Romania",
200
+ "RS" => "Serbia",
201
+ "RW" => "Rwanda",
202
+ "SA" => "Saudi Arabia",
203
+ "SB" => "Solomon Islands",
204
+ "SC" => "Seychelles",
205
+ "SD" => "Sudan",
206
+ "SE" => "Sweden",
207
+ "SG" => "Singapore",
208
+ "SH" => "Saint Helena, Ascension and Tristan da Cunha",
209
+ "SI" => "Slovenia",
210
+ "SJ" => "Svalbard and Jan Mayen",
211
+ "SK" => "Slovakia",
212
+ "SL" => "Sierra Leone",
213
+ "SM" => "San Marino",
214
+ "SN" => "Senegal",
215
+ "SO" => "Somalia",
216
+ "SR" => "Suriname",
217
+ "SS" => "South Sudan",
218
+ "ST" => "Sao Tome and Principe",
219
+ "SV" => "El Salvador",
220
+ "SX" => "Sint Maarten (Dutch part)",
221
+ "SY" => "Syria",
222
+ "SZ" => "Swaziland",
223
+ "TC" => "Turks and Caicos Islands",
224
+ "TD" => "Chad",
225
+ "TF" => "French Southern Territories",
226
+ "TG" => "Togo",
227
+ "TH" => "Thailand",
228
+ "TJ" => "Tajikistan",
229
+ "TK" => "Tokelau",
230
+ "TL" => "Timor-Leste",
231
+ "TM" => "Turkmenistan",
232
+ "TN" => "Tunisia",
233
+ "TO" => "Tonga",
234
+ "TT" => "Trinidad and Tobago",
235
+ "TV" => "Tuvalu",
236
+ "TW" => "Taiwan",
237
+ "TZ" => "Tanzania",
238
+ "UA" => "Ukraine",
239
+ "UG" => "Uganda",
240
+ "UM" => "United States Minor Outlying Islands",
241
+ "UY" => "Uruguay",
242
+ "UZ" => "Uzbekistan",
243
+ "VA" => "Vatican City",
244
+ "VC" => "Saint Vincent and the Grenadines",
245
+ "VE" => "Venezuela",
246
+ "VG" => "Virgin Islands, British",
247
+ "VI" => "Virgin Islands, U.S.",
248
+ "VU" => "Vanuatu",
249
+ "WF" => "Wallis and Futuna",
250
+ "WS" => "Samoa",
251
+ "YE" => "Yemen",
252
+ "YT" => "Mayotte",
253
+ "ZA" => "South Africa",
254
+ "ZM" => "Zambia",
255
+ "ZW" => "Zimbabwe"
256
+ }
257
+
258
+ COUNTRY_CODES_EU = {
259
+ "AT" => "Austria",
260
+ "BE" => "Belgium",
261
+ "BG" => "Bulgaria",
262
+ "HR" => "Croatia",
263
+ "CY" => "Cyprus",
264
+ "CZ" => "Czech Republic",
265
+ "DK" => "Denmark",
266
+ "EE" => "Estonia",
267
+ "FI" => "Finland",
268
+ "FR" => "France",
269
+ "DE" => "Germany",
270
+ "GR" => "Greece",
271
+ "HU" => "Hungary",
272
+ "IE" => "Ireland",
273
+ "IT" => "Italy",
274
+ "LV" => "Latvia",
275
+ "LT" => "Lithuania",
276
+ "LU" => "Luxembourg",
277
+ "MT" => "Malta",
278
+ "NL" => "Netherlands",
279
+ "PL" => "Poland",
280
+ "PT" => "Portugal",
281
+ "RO" => "Romania",
282
+ "SK" => "Slovakia",
283
+ "SI" => "Slovenia",
284
+ "ES" => "Spain",
285
+ "SE" => "Sweden",
286
+ "GB" => "United Kingdom"
287
+ }
288
+ end
@@ -0,0 +1,37 @@
1
+ module InternetBS
2
+ class DomainAvailability < Base
3
+ attribute :domain, String
4
+ attribute :max_reg_period, String
5
+ attribute :min_reg_period, String
6
+ attribute :private_whois_allowed, Boolean
7
+ attribute :realtime_registration, Boolean
8
+ attribute :registrar_lock_allowed, Boolean
9
+
10
+ def fetch
11
+ ensure_attribute_has_value :domain
12
+ return false if @errors.any?
13
+
14
+ params = {'domain' => @domain}
15
+ response = Client.get('/domain/check', params)
16
+ code = response.code rescue ""
17
+
18
+ case code
19
+ when '200'
20
+ hash = JSON.parse(response.body)
21
+
22
+ @status = hash['status']
23
+ @transaction_id = hash['transactid']
24
+ @max_registration_period = hash['maxregperiod']
25
+ @min_registration_period = hash['minregperiod']
26
+ @private_whois_allowed = hash['privatewhoisallowed'] == 'YES' ? true : false
27
+ @realtime_registration = hash['realtimeregistration'] == 'YES' ? true : false
28
+ @registrar_lock_allowed = hash['registrarlockallowed'] == 'YES' ? true : false
29
+
30
+ return true
31
+ else
32
+ set_errors(response)
33
+ return false
34
+ end
35
+ end
36
+ end
37
+ end