opensrs-ruby 0.1.1 → 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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/opensrs/domain.rb +51 -29
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9db624959631865e046c75c2b1ce1ddf206660653b52c23d4ed1b3e16e2df99a
4
- data.tar.gz: 94305661d8151fc552a51a47c848ccf23dda4521d7b16537c5119852bb6a989e
3
+ metadata.gz: ca301070c7f153b8a30427eb06c1c054eb2426e686b5bd5a8756e68aeebc3962
4
+ data.tar.gz: 2fde40733b76b76897cfd919abadcc71c7ebf07455d89c20a89d58fd2e341c82
5
5
  SHA512:
6
- metadata.gz: c44c80fd62678fe427a04f62787a14211885db290b052e0e4b52dcf8bea55c323994188bb97c8da47aa5e7dbc98140d90a29ca60aeb76a19ec9137581fd3cf90
7
- data.tar.gz: 209b945d9cf72e39b1d3d7ed88b56cc8aa4585e78506c1edbccdc5de11e74caddedf95c84c0b301431b0574c13a119736ce45776cf8aa956e4269686b6cd948f
6
+ metadata.gz: e1339e6aa4c6aa43ea153f127a175eceb8c9c494a66bbe0c7dd73f978c7c6b2f81ed8c24174b67822f87dc1c46fd013fe76ccf82e5e21ae322aaf8ec72a33e5e
7
+ data.tar.gz: 94b80af468d1024563399d4ddd7e1b8d186170bbcdbf8ccaa859d0f8ce3a89698ccb6157b002e2747c711ef292319a18782b5b0c41c298b2ed4ac262a7eaa15d
@@ -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: false,
13
- whois_private: false, nameservers: [], contacts: {})
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
- def locked? = @locked
28
- def whois_private? = @whois_private
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
- reg_pass = Digest::MD5.hexdigest(domain_name + Time.now.to_s)[0, 20]
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
- reg_pass = Digest::MD5.hexdigest(domain_name + Time.now.to_s)[0, 20]
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: attrs["f_lock_domain"].to_s == "1",
198
- whois_private: attrs["whois_privacy_state"] == "enabled",
224
+ locked: nil,
225
+ whois_private: nil,
199
226
  nameservers: nameservers,
200
227
  contacts: contacts
201
228
  )
@@ -221,12 +248,14 @@ module OpenSRS
221
248
  end
222
249
 
223
250
  def lock!
224
- modify_setting("f_lock_domain", "1")
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
- modify_setting("f_lock_domain", "0")
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
 
@@ -262,12 +291,5 @@ module OpenSRS
262
291
  @auto_renew = enabled
263
292
  end
264
293
 
265
- private
266
-
267
- def modify_setting(key, value)
268
- @client.call(action: "MODIFY", object: "DOMAIN",
269
- attributes: { "affect_domains" => "0", "data" => "status", key => value },
270
- extra: { "domain" => @name })
271
- end
272
294
  end
273
295
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opensrs-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - usiegj00