Class: Proxmox::Connector
- Inherits:
-
Object
- Object
- Proxmox::Connector
- Defined in:
- lib/proxmox/connector.rb
Instance Method Summary collapse
- #call(method, path, data: {}, need_auth: true, headers: {}) ⇒ Object
- #delete(path, need_auth: true, headers: {}) ⇒ Object
- #get(path, data: {}, need_auth: true, headers: {}) ⇒ Object
-
#initialize(application) ⇒ Connector
constructor
A new instance of Connector.
- #post(path, data: {}, need_auth: true, headers: {}) ⇒ Object
- #put(path, data: {}, need_auth: true, headers: {}) ⇒ Object
Constructor Details
#initialize(application) ⇒ Connector
Returns a new instance of Connector.
5 6 7 |
# File 'lib/proxmox/connector.rb', line 5 def initialize(application) @application = application end |
Instance Method Details
#call(method, path, data: {}, need_auth: true, headers: {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/proxmox/connector.rb', line 25 def call(method, path, data: {}, need_auth: true, headers: {}) raise InvalidHTTPMethod, "invalid http method #{method}" unless API_HTTP_METHODS.include?(method) url = compute_url(path) body = +'' unless data.empty? case method when :get params = URI.encode_www_form(data) url << "?#{params}" when :post body << URI.encode_www_form(data) when :put body << URI.encode_www_form(data) when :delete params = URI.encode_www_form(data) url << "?#{params}" end end if need_auth headers.merge!({ 'Cookie' => "PMGAuthCookie=#{@application.ticket}", 'CSRFPreventionToken' => @application.csrf }) end do_request(method, url, body:, headers:) end |
#delete(path, need_auth: true, headers: {}) ⇒ Object
21 22 23 |
# File 'lib/proxmox/connector.rb', line 21 def delete(path, need_auth: true, headers: {}) call(:delete, path, need_auth:, headers:) end |
#get(path, data: {}, need_auth: true, headers: {}) ⇒ Object
9 10 11 |
# File 'lib/proxmox/connector.rb', line 9 def get(path, data: {}, need_auth: true, headers: {}) call(:get, path, data:, need_auth:, headers:) end |
#post(path, data: {}, need_auth: true, headers: {}) ⇒ Object
17 18 19 |
# File 'lib/proxmox/connector.rb', line 17 def post(path, data: {}, need_auth: true, headers: {}) call(:post, path, data:, need_auth:, headers:) end |
#put(path, data: {}, need_auth: true, headers: {}) ⇒ Object
13 14 15 |
# File 'lib/proxmox/connector.rb', line 13 def put(path, data: {}, need_auth: true, headers: {}) call(:put, path, data:, need_auth:, headers:) end |