Module: Panelbeater::Remote
- Included in:
- Whm::Commands
- Defined in:
- lib/panelbeater/remote.rb
Constant Summary collapse
- @@default_port =
2087
- @@default_user =
'root'
Instance Method Summary collapse
- #connect(server, port, command, username, api_key, options = {}) ⇒ Object
- #do_request(command, options = {}, mappings = nil) ⇒ Object
- #map_options_to_url(options = {}) ⇒ Object
- #set_server(options = {}) ⇒ Object
Instance Method Details
#connect(server, port, command, username, api_key, options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/panelbeater/remote.rb', line 14 def connect(server, port, command, username, api_key, ={}) http = Net::HTTP.new(server, port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE # Ignore invalid SSL certificates http.start do |http| req = Net::HTTP::Get.new "/json-api/#{command}#{()}" req.add_field 'Authorization', "WHM #{username}:#{api_key}" http.request(req) end end |
#do_request(command, options = {}, mappings = nil) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/panelbeater/remote.rb', line 25 def do_request(command, ={}, mappings=nil) = key_mappings(mappings, ) unless mappings.nil? = () response = connect self.base_url, self.port, command, self.user, self.api_key, Panelbeater::Response.new(command, response) end |
#map_options_to_url(options = {}) ⇒ Object
32 33 34 |
# File 'lib/panelbeater/remote.rb', line 32 def (={}) '?' + .map { |k,v| "%s=%s" % [URI.encode(k.to_s), URI.encode(v.to_s)] }.join('&') unless .nil? end |
#set_server(options = {}) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/panelbeater/remote.rb', line 7 def set_server(={}) self.base_url = [:url] self.user = [:user] ||= @@default_user self.api_key = [:api_key].gsub(/\n|\r/, '') self.port = [:port] ||= @@default_port end |