Class: Plesk::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/plesk.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, user, password) ⇒ Client

Returns a new instance of Client.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/plesk.rb', line 6

def initialize path, user, password
  @response = 0
  @uri = URI(path)
  http = Net::HTTP.new(@uri.host, @uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  @headers = {
    'HTTP_AUTH_LOGIN' => user,
    'HTTP_AUTH_PASSWD' => password,
    'Accept' => '*/*',
    'Content-Type' => 'text/xml',
  }
  @http = http
end

Instance Attribute Details

#httpObject

Returns the value of attribute http.



5
6
7
# File 'lib/plesk.rb', line 5

def http
  @http
end

#responseObject

Returns the value of attribute response.



5
6
7
# File 'lib/plesk.rb', line 5

def response
  @response
end

#uriObject

Returns the value of attribute uri.



5
6
7
# File 'lib/plesk.rb', line 5

def uri
  @uri
end

Instance Method Details

#get_domain_id_for(domain) ⇒ Object



25
26
27
28
29
30
# File 'lib/plesk.rb', line 25

def get_domain_id_for domain
  packet = PleskPacket.new
  packet.domain_info_for_domain domain
  answer = start_request packet.to_xml
  Nokogiri::XML(answer.body).at('id').text
end

#get_domain_infoObject



20
21
22
23
24
# File 'lib/plesk.rb', line 20

def get_domain_info
  packet = PleskPacket.new
  packet.domain_info
  start_request packet.to_xml
end

#get_mailgroup_info_for(mail) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/plesk.rb', line 31

def get_mailgroup_info_for mail
  name,domain = mail.split("@")
  domain_id = get_domain_id_for domain
  packet = PleskPacket.new
  packet.mailgroup_info name,domain_id
  answer = start_request packet.to_xml

  Nokogiri::XML(answer.body).search('address').map(&:text)
end

#set_mailgroup_for(mail, mails) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/plesk.rb', line 41

def set_mailgroup_for mail,mails
  name,domain = mail.split("@")
  domain_id = get_domain_id_for domain
  packet = PleskPacket.new
  packet.mailgroup_set name,domain_id,mails
  answer = start_request packet.to_xml
end

#start_request(body) ⇒ Object



49
50
51
52
# File 'lib/plesk.rb', line 49

def start_request(body)
  response = http.request_post(@uri.path,body,@headers)
  @response = response
end