joker-dmapi 0.0.1 → 0.1.2
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.
- data/README.md +1 -1
- data/lib/joker-dmapi.rb +1 -1
- data/lib/joker-dmapi/client.rb +39 -24
- data/lib/joker-dmapi/contact.rb +38 -29
- data/lib/joker-dmapi/domain.rb +41 -35
- data/lib/joker-dmapi/host.rb +51 -0
- data/lib/joker-dmapi/result.rb +14 -8
- metadata +3 -2
data/README.md
CHANGED
data/lib/joker-dmapi.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require "joker-dmapi/client"
|
1
|
+
require "#{File.dirname(__FILE__)}/joker-dmapi/client"
|
data/lib/joker-dmapi/client.rb
CHANGED
@@ -1,27 +1,33 @@
|
|
1
1
|
require "net/http"
|
2
2
|
require "addressable/uri"
|
3
|
-
require "
|
4
|
-
require "
|
5
|
-
require "
|
3
|
+
require "#{File.dirname(__FILE__)}/result"
|
4
|
+
require "#{File.dirname(__FILE__)}/contact"
|
5
|
+
require "#{File.dirname(__FILE__)}/host"
|
6
|
+
require "#{File.dirname(__FILE__)}/domain"
|
6
7
|
|
7
8
|
module JokerDMAPI
|
8
|
-
VERSION = '0.
|
9
|
+
VERSION = '0.1.2'
|
9
10
|
|
10
11
|
class Client
|
11
|
-
|
12
|
+
DEFAULT_URI = 'https://dmapi.joker.com:443/request/'
|
12
13
|
|
13
14
|
include JokerDMAPI::Result
|
14
15
|
include JokerDMAPI::Contact
|
16
|
+
include JokerDMAPI::Host
|
15
17
|
include JokerDMAPI::Domain
|
16
18
|
|
17
|
-
def initialize(username, password)
|
18
|
-
@username, @password = username, password
|
19
|
+
def initialize(username, password, uri = DEFAULT_URI)
|
20
|
+
@username, @password, @uri = username, password, uri
|
19
21
|
end
|
20
22
|
|
21
|
-
def self.
|
22
|
-
connection = self.new(username, password)
|
23
|
-
|
24
|
-
|
23
|
+
def self.connection(username, password, uri = DEFAULT_URI, &block)
|
24
|
+
connection = self.new(username, password, uri)
|
25
|
+
if block_given?
|
26
|
+
yield connection
|
27
|
+
connection.logout
|
28
|
+
else
|
29
|
+
connection
|
30
|
+
end
|
25
31
|
end
|
26
32
|
|
27
33
|
def logout
|
@@ -32,14 +38,23 @@ module JokerDMAPI
|
|
32
38
|
end
|
33
39
|
|
34
40
|
def query(request, params = {})
|
35
|
-
|
36
|
-
response
|
37
|
-
check_status response
|
41
|
+
response = query_no_raise request, params
|
42
|
+
raise_response(response) unless response[:headers][:status_code] == '0'
|
38
43
|
response
|
39
44
|
end
|
40
45
|
|
46
|
+
def tlds
|
47
|
+
auth_sid unless @auth_sid
|
48
|
+
@tlds
|
49
|
+
end
|
50
|
+
|
41
51
|
private
|
42
52
|
|
53
|
+
def query_no_raise(request, params = {})
|
54
|
+
params['auth-sid'] = auth_sid
|
55
|
+
request(request, params.inject({}) { |r, (key, value)| r[key.to_s.gsub('_', '-')] = value; r })
|
56
|
+
end
|
57
|
+
|
43
58
|
def parse_line(line)
|
44
59
|
parts = line.split /\s*:\s*/, 2
|
45
60
|
if parts.length == 2
|
@@ -64,29 +79,29 @@ module JokerDMAPI
|
|
64
79
|
end
|
65
80
|
|
66
81
|
def request(request, params = {})
|
67
|
-
|
82
|
+
request = request.to_s.gsub('_', '-')
|
83
|
+
uri = Addressable::URI.parse(@uri + request)
|
68
84
|
uri.query_values = params
|
69
85
|
http = Net::HTTP.new(uri.host, uri.port)
|
70
86
|
http.use_ssl = true
|
71
|
-
|
72
|
-
puts ">> #{uri
|
87
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
88
|
+
puts ">> #{uri}" if ENV['JOKER_DMAPI_DEBUG']
|
73
89
|
parse_response http.request(Net::HTTP::Get.new(uri.request_uri)).body
|
74
90
|
end
|
75
91
|
|
76
|
-
def check_status(response)
|
77
|
-
if response[:headers][:status_code] != '0'
|
78
|
-
raise "#{response[:headers][:status_code]}: #{response[:headers][:error]}\n"
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
92
|
def auth_sid
|
83
93
|
if @auth_sid.nil?
|
84
94
|
response = request(:login, username: @username, password: @password)
|
85
|
-
|
95
|
+
raise "Authentication error" unless response[:headers].has_key? :auth_sid
|
86
96
|
@auth_sid = response[:headers][:auth_sid]
|
87
97
|
@tlds = response[:body].split "\n"
|
88
98
|
end
|
89
99
|
@auth_sid
|
90
100
|
end
|
101
|
+
|
102
|
+
def raise_response(response)
|
103
|
+
raise "\n\n" + response[:headers].inject([]) { |s, (key, value)| s << "#{key}: #{value}"}.join("\n") +
|
104
|
+
"\n\n" + response[:body] + "\n\n"
|
105
|
+
end
|
91
106
|
end
|
92
107
|
end
|
data/lib/joker-dmapi/contact.rb
CHANGED
@@ -4,7 +4,7 @@ module JokerDMAPI
|
|
4
4
|
CONTACT_ALLOWED = CONTACT_REQUIRED + [ :organization, :state, :fax ]
|
5
5
|
CONTACT_LENGTH_LIMIT = %w(biz cn eu)
|
6
6
|
|
7
|
-
# Returns the information about a contact
|
7
|
+
# Returns the information about a contact or <tt>nil</tt> if not exists
|
8
8
|
#
|
9
9
|
# Takes handler as string
|
10
10
|
#
|
@@ -23,27 +23,33 @@ module JokerDMAPI
|
|
23
23
|
# [<tt>:created_date</tt>] the date and time of contact created
|
24
24
|
# [<tt>:modified_date</tt>] the date and time of contact modified
|
25
25
|
def contact_info(handle)
|
26
|
-
response =
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
26
|
+
response = query_no_raise :query_whois, contact: handle
|
27
|
+
case response[:headers][:status_code]
|
28
|
+
when '2303' then nil
|
29
|
+
when '0' then
|
30
|
+
result = {}
|
31
|
+
response[:body].split("\n").each do |line|
|
32
|
+
line.slice! /^contact\./
|
33
|
+
line_parsed = parse_line(line)
|
34
|
+
next if line_parsed.is_a? String
|
35
|
+
key, value = line_parsed.first
|
36
|
+
case key
|
37
|
+
when :name then next if value == "- -"
|
38
|
+
when :address_1, :address_2, :address_3 then
|
39
|
+
result[:address] = [] unless result.has_key? :address
|
40
|
+
result[:address] << value
|
41
|
+
when :state then next if value == "--"
|
42
|
+
when :organization then next if value == "-" or value.empty?
|
43
|
+
when :created_date, :modified_date then
|
44
|
+
result[key] = DateTime.parse value
|
45
|
+
else
|
46
|
+
result.merge! line_parsed
|
47
|
+
end
|
48
|
+
end
|
49
|
+
result
|
50
|
+
else
|
51
|
+
raise_response response
|
45
52
|
end
|
46
|
-
result
|
47
53
|
end
|
48
54
|
|
49
55
|
# Create new contact
|
@@ -66,7 +72,7 @@ module JokerDMAPI
|
|
66
72
|
# [<tt>:proc_id</tt>] process ID (used at check result)
|
67
73
|
# [<tt>:tracking_id</tt>] tracking ID
|
68
74
|
def contact_create(fields)
|
69
|
-
query
|
75
|
+
query :contact_create, contact_prepare(fields)
|
70
76
|
end
|
71
77
|
|
72
78
|
# Check result of create contact
|
@@ -75,11 +81,15 @@ module JokerDMAPI
|
|
75
81
|
# Returned contact's handle name (and delete result) or <tt>nil</tt> if don't ready
|
76
82
|
def contact_create_result(proc_id)
|
77
83
|
result = parse_attributes(result_retrieve(proc_id)[:body].split("\n\n", 1)[0])
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
84
|
+
return nil unless result.has_key? :completion_status
|
85
|
+
case result[:completion_status]
|
86
|
+
when 'ack' then
|
87
|
+
result_delete proc_id
|
88
|
+
result[:object_name]
|
89
|
+
when 'nack' then
|
90
|
+
raise_response response
|
91
|
+
else
|
92
|
+
nil
|
83
93
|
end
|
84
94
|
end
|
85
95
|
|
@@ -117,8 +127,7 @@ module JokerDMAPI
|
|
117
127
|
|
118
128
|
def contact_prepare(fields)
|
119
129
|
raise ArgumentError, "Required fields not found" unless (CONTACT_REQUIRED - fields.keys).empty?
|
120
|
-
|
121
|
-
raise ArgumentError, "TLD must be one of accepted" unless @tlds.include? fields[:tld]
|
130
|
+
raise ArgumentError, "TLD must be one of accepted" unless self.tlds.include? fields[:tld]
|
122
131
|
if CONTACT_LENGTH_LIMIT.include? fields[:tld]
|
123
132
|
[ :name, :organization, :city, :state ].each do |field|
|
124
133
|
next unless fields.has_key? field
|
data/lib/joker-dmapi/domain.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module JokerDMAPI
|
2
2
|
module Domain
|
3
|
-
# Returns the information about a domain
|
3
|
+
# Returns the information about a domain or <tt>nil</tt> if not exists
|
4
4
|
#
|
5
5
|
# Takes FQDN as string
|
6
6
|
#
|
@@ -26,37 +26,43 @@ module JokerDMAPI
|
|
26
26
|
# [<tt>:modified_date</tt>] date and time of modification
|
27
27
|
# [<tt>:expires</tt>] date and time of expiration
|
28
28
|
def domain_info(domain)
|
29
|
-
response =
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
29
|
+
response = query_no_raise :query_whois, domain: domain
|
30
|
+
case response[:headers][:status_code]
|
31
|
+
when '2303' then nil
|
32
|
+
when '0' then
|
33
|
+
result = {}
|
34
|
+
response[:body].split("\n").each do |line|
|
35
|
+
line.slice! /^domain\./
|
36
|
+
line_parsed = parse_line(line)
|
37
|
+
next if line_parsed.is_a? String
|
38
|
+
key, value = line_parsed.first
|
39
|
+
case key
|
40
|
+
when :fqdn, :status then result.merge! line_parsed
|
41
|
+
when :name, :organization, :city, :postal_code, :country, :owner_c_email, :email, :phone, :fax then
|
42
|
+
result[:registrant] = {} unless result.has_key? :registrant
|
43
|
+
result[:registrant].merge! line_parsed
|
44
|
+
when :address_1, :address_2, :address_3 then
|
45
|
+
result[:registrant] = {} unless result.has_key? :registrant
|
46
|
+
result[:registrant][:address] = [] unless result[:registrant].has_key? :address
|
47
|
+
result[:registrant][:address] << value
|
48
|
+
when :reseller_line then
|
49
|
+
result[:reseller_lines] = [] unless result.has_key? :reseller_lines
|
50
|
+
result[:reseller_lines] << value
|
51
|
+
when :created_date, :modified_date, :expires then
|
52
|
+
result[key] = DateTime.parse value
|
53
|
+
when :admin_c, :tech_c, :billing_c then
|
54
|
+
result.merge! line_parsed
|
55
|
+
when :nservers_nserver_handle then
|
56
|
+
result[:nservers] = [] unless result.has_key? :nservers
|
57
|
+
result[:nservers] << value
|
58
|
+
else
|
59
|
+
next
|
60
|
+
end
|
61
|
+
end
|
62
|
+
result
|
63
|
+
else
|
64
|
+
raise_response response
|
58
65
|
end
|
59
|
-
result
|
60
66
|
end
|
61
67
|
|
62
68
|
# Register new domain
|
@@ -77,7 +83,7 @@ module JokerDMAPI
|
|
77
83
|
unless ([ :period, :registrant, :admin, :tech, :billing, :nservers ] - fields.keys).empty?
|
78
84
|
raise ArgumentError, "Required fields not found"
|
79
85
|
end
|
80
|
-
query
|
86
|
+
query :domain_register, {
|
81
87
|
domain: domain,
|
82
88
|
period: (fields[:period] * 12),
|
83
89
|
owner_c: fields[:registrant],
|
@@ -104,7 +110,7 @@ module JokerDMAPI
|
|
104
110
|
unless ([ :admin, :tech, :billing, :nservers ] - fields.keys).empty?
|
105
111
|
raise ArgumentError, "Required fields not found"
|
106
112
|
end
|
107
|
-
query
|
113
|
+
query :domain_modify, {
|
108
114
|
domain: domain,
|
109
115
|
admin_c: fields[:admin],
|
110
116
|
tech_c: fields[:tech],
|
@@ -118,7 +124,7 @@ module JokerDMAPI
|
|
118
124
|
# Takes <tt>domain</tt> and <tt>period</tt>
|
119
125
|
# WARNING!!! <tt>period</tt> in YEARS
|
120
126
|
def domain_renew(domain, period)
|
121
|
-
query
|
127
|
+
query :domain_renew, { domain: domain, period: (12 * period) }
|
122
128
|
end
|
123
129
|
|
124
130
|
# Update registrant's info
|
@@ -127,7 +133,7 @@ module JokerDMAPI
|
|
127
133
|
def domain_registrant_update(domain, fields)
|
128
134
|
fields = contact_prepare(fields)
|
129
135
|
fields[:domain] = domain
|
130
|
-
query
|
136
|
+
query :domain_owner_change, fields
|
131
137
|
end
|
132
138
|
end
|
133
139
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "resolv"
|
2
|
+
|
3
|
+
module JokerDMAPI
|
4
|
+
module Host
|
5
|
+
def host_info(host)
|
6
|
+
response = query_no_raise :query_whois, { host: host }
|
7
|
+
case response[:headers][:status_code]
|
8
|
+
when '2303' then nil
|
9
|
+
when '0' then
|
10
|
+
result = {}
|
11
|
+
response[:body].split("\n").each do |line|
|
12
|
+
line.slice! /^host\./
|
13
|
+
line_parsed = parse_line(line)
|
14
|
+
next if line_parsed.is_a? String
|
15
|
+
key, value = line_parsed.first
|
16
|
+
case key
|
17
|
+
when :fqdn then result[:host] = value
|
18
|
+
when :created_date, :modified_date then
|
19
|
+
result[key] = DateTime.parse value
|
20
|
+
else
|
21
|
+
result.merge! line_parsed
|
22
|
+
end
|
23
|
+
end
|
24
|
+
result
|
25
|
+
else
|
26
|
+
raise_response response
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def host_create(host, fields)
|
31
|
+
host_request :ns_create, host, fields
|
32
|
+
end
|
33
|
+
|
34
|
+
def host_update(host, fields)
|
35
|
+
host_request :ns_modify, host, fields
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def host_request(request, host, fields)
|
41
|
+
unless fields.has_key?(:ipv4)
|
42
|
+
raise ArgumentError, "Required fields not found"
|
43
|
+
end
|
44
|
+
p = { host: host }
|
45
|
+
p[:ip] = fields[:ipv4] unless fields[:ipv4].empty?
|
46
|
+
p[:ipv6] = fields[:ipv6] if fields.has_key? :ipv6
|
47
|
+
query request, p
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
data/lib/joker-dmapi/result.rb
CHANGED
@@ -5,21 +5,27 @@ module JokerDMAPI
|
|
5
5
|
# Get <tt>proc_id</tt>
|
6
6
|
# Returned <tt>true</tt> if done (result deleted)
|
7
7
|
def complete?(proc_id)
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
response = result_retrieve(proc_id)
|
9
|
+
result = parse_attributes(response[:body].split("\n\n", 1)[0])
|
10
|
+
return false unless result.has_key? :completion_status
|
11
|
+
case result[:completion_status]
|
12
|
+
when 'ack' then
|
13
|
+
result_delete proc_id
|
14
|
+
true
|
15
|
+
when 'nack' then
|
16
|
+
raise_response response
|
17
|
+
else
|
18
|
+
false
|
14
19
|
end
|
15
20
|
end
|
16
21
|
|
17
22
|
def result_retrieve(proc_id)
|
18
|
-
query
|
23
|
+
query :result_retrieve, { proc_id: proc_id }
|
19
24
|
end
|
20
25
|
|
21
26
|
def result_delete(proc_id)
|
22
|
-
query
|
27
|
+
query :result_delete, { proc_id: proc_id }
|
23
28
|
end
|
29
|
+
|
24
30
|
end
|
25
31
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: joker-dmapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: addressable
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- lib/joker-dmapi/client.rb
|
61
61
|
- lib/joker-dmapi/contact.rb
|
62
62
|
- lib/joker-dmapi/domain.rb
|
63
|
+
- lib/joker-dmapi/host.rb
|
63
64
|
- lib/joker-dmapi/result.rb
|
64
65
|
homepage: https://github.com/kolodovskyy/joker-dmapi
|
65
66
|
licenses: []
|