opensrs-ruby 0.1.0 → 0.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 +4 -4
- data/lib/opensrs/domain.rb +58 -41
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ca301070c7f153b8a30427eb06c1c054eb2426e686b5bd5a8756e68aeebc3962
|
|
4
|
+
data.tar.gz: 2fde40733b76b76897cfd919abadcc71c7ebf07455d89c20a89d58fd2e341c82
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e1339e6aa4c6aa43ea153f127a175eceb8c9c494a66bbe0c7dd73f978c7c6b2f81ed8c24174b67822f87dc1c46fd013fe76ccf82e5e21ae322aaf8ec72a33e5e
|
|
7
|
+
data.tar.gz: 94b80af468d1024563399d4ddd7e1b8d186170bbcdbf8ccaa859d0f8ce3a89698ccb6157b002e2747c711ef292319a18782b5b0c41c298b2ed4ac262a7eaa15d
|
data/lib/opensrs/domain.rb
CHANGED
|
@@ -9,8 +9,8 @@ module OpenSRS
|
|
|
9
9
|
attr_reader :name, :expires_at, :created_at, :updated_at, :nameservers, :contacts
|
|
10
10
|
|
|
11
11
|
def initialize(name:, client: nil, expires_at: nil, created_at: nil,
|
|
12
|
-
updated_at: nil, auto_renew: false, locked:
|
|
13
|
-
whois_private:
|
|
12
|
+
updated_at: nil, auto_renew: false, locked: nil,
|
|
13
|
+
whois_private: nil, nameservers: [], contacts: {})
|
|
14
14
|
@name = name
|
|
15
15
|
@client = client || OpenSRS.default_client
|
|
16
16
|
@expires_at = expires_at
|
|
@@ -24,8 +24,26 @@ module OpenSRS
|
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
def auto_renew? = @auto_renew
|
|
27
|
-
|
|
28
|
-
def
|
|
27
|
+
|
|
28
|
+
def locked?
|
|
29
|
+
if @locked.nil?
|
|
30
|
+
result = @client.call(action: "GET", object: "DOMAIN",
|
|
31
|
+
attributes: { "type" => "status", "domain_name" => @name },
|
|
32
|
+
extra: { "domain" => @name })
|
|
33
|
+
@locked = result.dig("attributes", "lock_state").to_s == "1"
|
|
34
|
+
end
|
|
35
|
+
@locked
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def whois_private?
|
|
39
|
+
if @whois_private.nil?
|
|
40
|
+
result = @client.call(action: "GET", object: "DOMAIN",
|
|
41
|
+
attributes: { "type" => "whois_privacy_state" },
|
|
42
|
+
extra: { "domain" => @name })
|
|
43
|
+
@whois_private = result.dig("attributes", "state") == "enabled"
|
|
44
|
+
end
|
|
45
|
+
@whois_private
|
|
46
|
+
end
|
|
29
47
|
|
|
30
48
|
class << self
|
|
31
49
|
def available?(domain_name, client: OpenSRS.default_client)
|
|
@@ -108,19 +126,15 @@ module OpenSRS
|
|
|
108
126
|
end
|
|
109
127
|
|
|
110
128
|
def register!(domain_name, period: 1, contacts:, nameservers:, client: OpenSRS.default_client)
|
|
111
|
-
contact_set =
|
|
112
|
-
contacts.each do |role, data|
|
|
113
|
-
c = data.is_a?(Contact) ? data : Contact.new(**data)
|
|
114
|
-
contact_set[role.to_s] = c.to_api_hash
|
|
115
|
-
end
|
|
116
|
-
%w[admin billing].each { |r| contact_set[r] ||= contact_set["owner"] }
|
|
129
|
+
contact_set = build_contact_set(contacts)
|
|
117
130
|
|
|
118
131
|
ns_list = nameservers.each_with_index.map do |ns, i|
|
|
119
132
|
{ "name" => ns, "sortorder" => (i + 1).to_s }
|
|
120
133
|
end
|
|
121
134
|
|
|
122
135
|
reg_user = domain_name.gsub(/[^a-z0-9]/i, "")[0, 20]
|
|
123
|
-
|
|
136
|
+
reg_user = "user#{reg_user}" if reg_user.length < 3
|
|
137
|
+
reg_pass = "Rg!" + Digest::MD5.hexdigest(domain_name + Time.now.to_s)[0, 17]
|
|
124
138
|
|
|
125
139
|
client.call(action: "SW_REGISTER", object: "DOMAIN", attributes: {
|
|
126
140
|
"domain" => domain_name,
|
|
@@ -132,6 +146,7 @@ module OpenSRS
|
|
|
132
146
|
"custom_nameservers" => "1",
|
|
133
147
|
"custom_tech_contact" => "0",
|
|
134
148
|
"auto_renew" => "0",
|
|
149
|
+
"f_lock_domain" => "1",
|
|
135
150
|
"f_whois_privacy" => "1",
|
|
136
151
|
"contact_set" => contact_set,
|
|
137
152
|
"nameserver_list" => ns_list,
|
|
@@ -141,15 +156,11 @@ module OpenSRS
|
|
|
141
156
|
end
|
|
142
157
|
|
|
143
158
|
def transfer!(domain_name, auth_code:, contacts:, nameservers: [], client: OpenSRS.default_client)
|
|
144
|
-
contact_set =
|
|
145
|
-
contacts.each do |role, data|
|
|
146
|
-
c = data.is_a?(Contact) ? data : Contact.new(**data)
|
|
147
|
-
contact_set[role.to_s] = c.to_api_hash
|
|
148
|
-
end
|
|
149
|
-
%w[admin billing].each { |r| contact_set[r] ||= contact_set["owner"] }
|
|
159
|
+
contact_set = build_contact_set(contacts)
|
|
150
160
|
|
|
151
161
|
reg_user = domain_name.gsub(/[^a-z0-9]/i, "")[0, 20]
|
|
152
|
-
|
|
162
|
+
reg_user = "user#{reg_user}" if reg_user.length < 3
|
|
163
|
+
reg_pass = "Rg!" + Digest::MD5.hexdigest(domain_name + Time.now.to_s)[0, 17]
|
|
153
164
|
|
|
154
165
|
attrs = {
|
|
155
166
|
"domain" => domain_name,
|
|
@@ -177,6 +188,22 @@ module OpenSRS
|
|
|
177
188
|
|
|
178
189
|
private
|
|
179
190
|
|
|
191
|
+
def build_contact_set(contacts)
|
|
192
|
+
contact_set = {}
|
|
193
|
+
if contacts.is_a?(Contact)
|
|
194
|
+
contact_set["owner"] = contacts.to_api_hash
|
|
195
|
+
elsif contacts.is_a?(Hash) && contacts.values.first.is_a?(Contact)
|
|
196
|
+
contacts.each { |role, c| contact_set[role.to_s] = c.to_api_hash }
|
|
197
|
+
elsif contacts.is_a?(Hash)
|
|
198
|
+
contacts.each do |role, data|
|
|
199
|
+
c = data.is_a?(Hash) ? Contact.new(**data.transform_keys(&:to_sym).slice(*Contact.members)) : data
|
|
200
|
+
contact_set[role.to_s] = c.is_a?(Contact) ? c.to_api_hash : c
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
%w[admin billing tech].each { |r| contact_set[r] ||= contact_set["owner"] }
|
|
204
|
+
contact_set
|
|
205
|
+
end
|
|
206
|
+
|
|
180
207
|
def from_api(domain_name, attrs, client:)
|
|
181
208
|
nameservers = (attrs["nameserver_list"] || []).sort_by { |ns|
|
|
182
209
|
ns["sortorder"].to_i
|
|
@@ -194,8 +221,8 @@ module OpenSRS
|
|
|
194
221
|
created_at: parse_time(attrs["registry_createdate"]),
|
|
195
222
|
updated_at: parse_time(attrs["registry_updatedate"]),
|
|
196
223
|
auto_renew: attrs["auto_renew"].to_s == "1",
|
|
197
|
-
locked:
|
|
198
|
-
whois_private:
|
|
224
|
+
locked: nil,
|
|
225
|
+
whois_private: nil,
|
|
199
226
|
nameservers: nameservers,
|
|
200
227
|
contacts: contacts
|
|
201
228
|
)
|
|
@@ -221,39 +248,36 @@ module OpenSRS
|
|
|
221
248
|
end
|
|
222
249
|
|
|
223
250
|
def lock!
|
|
224
|
-
|
|
251
|
+
@client.call(action: "MODIFY", object: "DOMAIN",
|
|
252
|
+
attributes: { "domain" => @name, "data" => "status", "affect_domains" => "0", "lock_state" => "1" })
|
|
225
253
|
@locked = true
|
|
226
254
|
end
|
|
227
255
|
|
|
228
256
|
def unlock!
|
|
229
|
-
|
|
257
|
+
@client.call(action: "MODIFY", object: "DOMAIN",
|
|
258
|
+
attributes: { "domain" => @name, "data" => "status", "affect_domains" => "0", "lock_state" => "0" })
|
|
230
259
|
@locked = false
|
|
231
260
|
end
|
|
232
261
|
|
|
233
262
|
def set_nameservers(nameservers)
|
|
234
|
-
|
|
235
|
-
{ "name" => ns, "sortorder" => (i + 1).to_s }
|
|
236
|
-
}
|
|
237
|
-
@client.call(action: "MODIFY", object: "DOMAIN",
|
|
263
|
+
@client.call(action: "ADVANCED_UPDATE_NAMESERVERS", object: "DOMAIN",
|
|
238
264
|
attributes: {
|
|
239
|
-
"
|
|
240
|
-
"
|
|
241
|
-
"assign_ns" => nameservers
|
|
242
|
-
|
|
243
|
-
},
|
|
244
|
-
extra: { "domain" => @name })
|
|
265
|
+
"domain" => @name,
|
|
266
|
+
"op_type" => "assign",
|
|
267
|
+
"assign_ns" => nameservers
|
|
268
|
+
})
|
|
245
269
|
@nameservers = nameservers
|
|
246
270
|
end
|
|
247
271
|
|
|
248
272
|
def enable_whois_privacy!
|
|
249
|
-
@client.call(action: "
|
|
273
|
+
@client.call(action: "MODIFY", object: "DOMAIN",
|
|
250
274
|
attributes: { "affect_domains" => "0", "data" => "whois_privacy_state", "state" => "enable" },
|
|
251
275
|
extra: { "domain" => @name })
|
|
252
276
|
@whois_private = true
|
|
253
277
|
end
|
|
254
278
|
|
|
255
279
|
def disable_whois_privacy!
|
|
256
|
-
@client.call(action: "
|
|
280
|
+
@client.call(action: "MODIFY", object: "DOMAIN",
|
|
257
281
|
attributes: { "affect_domains" => "0", "data" => "whois_privacy_state", "state" => "disable" },
|
|
258
282
|
extra: { "domain" => @name })
|
|
259
283
|
@whois_private = false
|
|
@@ -267,12 +291,5 @@ module OpenSRS
|
|
|
267
291
|
@auto_renew = enabled
|
|
268
292
|
end
|
|
269
293
|
|
|
270
|
-
private
|
|
271
|
-
|
|
272
|
-
def modify_setting(key, value)
|
|
273
|
-
@client.call(action: "MODIFY", object: "DOMAIN",
|
|
274
|
-
attributes: { "affect_domains" => "0", "data" => "status", key => value },
|
|
275
|
-
extra: { "domain" => @name })
|
|
276
|
-
end
|
|
277
294
|
end
|
|
278
295
|
end
|