plesk-ruby 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1dc35be8ff5c85731b184a0ade7f2a3e6412e9b6
4
+ data.tar.gz: 27ebf446c26a0c7b13c0e31cb5ca9700ef745a8e
5
+ SHA512:
6
+ metadata.gz: ef9d7064f38f92402e2e9a1be34c04a1473b0623e46f6f216706550c86a017ecd45ee9cf2d071fae96cf04c6ed9d423b4bef44759c4e057da4e85ac7aa16047f
7
+ data.tar.gz: 0e49de6d8a6cdfa64f05c70c1dc15d7d8973a851970b14c0c31116c62cc39f777e32d57f42bed8bcce97dbe28cfa9e06e4a1e72d5a82436900de0a2f78401815
@@ -0,0 +1 @@
1
+ require 'plesk/client'
@@ -0,0 +1,50 @@
1
+ require 'net/https'
2
+ require 'nokogiri'
3
+ require 'plesk/param_builder'
4
+ require 'plesk/version'
5
+
6
+ module Plesk
7
+ class Client
8
+
9
+ class Error < StandardError; end
10
+ class RequestError < Error; end
11
+ class ActionError < Error; end
12
+
13
+ attr_reader :options
14
+
15
+ def initialize(host, username, password, options = {})
16
+ @host = host
17
+ @options = options
18
+ @username = username
19
+ @password = password
20
+ end
21
+
22
+ def request(controller, action, &block)
23
+ request = Net::HTTP::Post.new("/enterprise/control/agent.php")
24
+ params = ParamBuilder.build(&block)
25
+ request.body = "<packet><#{controller}><#{action}>#{params}</#{action}></#{controller}></packet>"
26
+ request.add_field 'User-Agent', "PleskRuby/#{Plesk::VERSION}"
27
+ request.add_field 'HTTP_AUTH_LOGIN', @username
28
+ request.add_field 'HTTP_AUTH_PASSWD', @password
29
+ request.add_field 'Content-Type', 'text/xml'
30
+ connection = Net::HTTP.new(@host, @options[:port] || 8443)
31
+ connection.use_ssl = true
32
+ connection.verify_mode = @options[:verify_ssl] == false ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
33
+ result = connection.request(request)
34
+ xml = Nokogiri::XML.parse(result.body)
35
+ if xml.xpath('/packet/system/status').first&.content == "error"
36
+ error_code = xml.xpath('/packet/system/errcode').first&.content
37
+ error_message = xml.xpath('/packet/system/errtext').first&.content
38
+ raise RequestError, "#{error_code || "-1"}: #{error_message}"
39
+ elsif xml.xpath("/packet/#{controller}/#{action}/result/status").first&.content == "error"
40
+ error_code = xml.xpath("/packet/#{controller}/#{action}/result/errcode").first&.content
41
+ error_message = xml.xpath("/packet/#{controller}/#{action}/result/errtext").first&.content
42
+ raise ActionError, "#{error_code || "-1"}: #{error_message}"
43
+ else
44
+ xml.xpath("//result")[0]
45
+ end
46
+ end
47
+
48
+ end
49
+ end
50
+
@@ -0,0 +1,37 @@
1
+ module Plesk
2
+ module ParamBuilder
3
+
4
+ class Block
5
+ attr_accessor :result
6
+ def initialize
7
+ @result = ""
8
+ end
9
+
10
+ def method_missing(key, value = nil, &block)
11
+ if block_given?
12
+ @result += "<#{key}>"
13
+ i = Block.new
14
+ result = i.instance_exec(&block)
15
+ @result += i.result
16
+ unless result.nil?
17
+ @result += result.to_s
18
+ end
19
+ @result += "</#{key}>"
20
+ elsif value
21
+ @result += "<#{key}>#{value}</#{key}>"
22
+ else
23
+ @result += "<#{key} />"
24
+ end
25
+
26
+ nil
27
+ end
28
+ end
29
+
30
+ def self.build(&block)
31
+ i = Block.new
32
+ i.instance_exec(&block)
33
+ i.result
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module Plesk
2
+ VERSION = '1.0.0'
3
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: plesk-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Adam Cooke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.7
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '1.8'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 1.6.7
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.8'
33
+ description: A client library which facilitates communication to and from the Plesk
34
+ API.
35
+ email:
36
+ - me@adamcooke.io
37
+ executables: []
38
+ extensions: []
39
+ extra_rdoc_files: []
40
+ files:
41
+ - lib/plesk.rb
42
+ - lib/plesk/client.rb
43
+ - lib/plesk/param_builder.rb
44
+ - lib/plesk/version.rb
45
+ homepage: https://adam.ac
46
+ licenses:
47
+ - MIT
48
+ metadata: {}
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 2.6.4
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: A client library for talking to the Plesk API.
69
+ test_files: []
70
+ has_rdoc: