Class: Pulp::ApiClient
- Inherits:
-
Object
- Object
- Pulp::ApiClient
- Defined in:
- lib/puppet_x/pulp/api_client.rb
Instance Method Summary collapse
- #delete(path) ⇒ Object
- #finish ⇒ Object
- #get(path, params = {}) ⇒ Object
-
#initialize(domain, port, options = {}) ⇒ ApiClient
constructor
A new instance of ApiClient.
- #post(path, params = {}) ⇒ Object
- #put(path, params = {}) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(domain, port, options = {}) ⇒ ApiClient
Returns a new instance of ApiClient.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/puppet_x/pulp/api_client.rb', line 9 def initialize(domain, port, = {}) @http = Net::HTTP.new(domain, port) @http.use_ssl = .fetch(:use_ssl) { true } @http.verify_mode = .fetch(:verify_mode) { OpenSSL::SSL::VERIFY_PEER } @http.open_timeout = .fetch(:open_timeout) { 10 } @http.read_timeout = .fetch(:read_timeout) { 120 } @http.ca_file = .fetch(:ca_file) { nil } @http.cert = .fetch(:cert) { nil} @http.key = .fetch(:key) { nil} end |
Instance Method Details
#delete(path) ⇒ Object
50 51 52 53 |
# File 'lib/puppet_x/pulp/api_client.rb', line 50 def delete(path) request = Net::HTTP::Delete.new(path) parse fetch(request) end |
#finish ⇒ Object
30 31 32 |
# File 'lib/puppet_x/pulp/api_client.rb', line 30 def finish @http.finish if @http.started? end |
#get(path, params = {}) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/puppet_x/pulp/api_client.rb', line 34 def get(path, params = {}) uri = URI.parse(path) uri.query = URI.encode_www_form(params) unless params.empty? request = Net::HTTP::Get.new(uri.to_s) parse fetch(request) end |
#post(path, params = {}) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/puppet_x/pulp/api_client.rb', line 41 def post(path, params = {}) request = Net::HTTP::Post.new(path) request.content_type = 'application/json' auth = params.delete(:basic_auth) request.basic_auth(auth[:username], auth[:password]) if auth request.body = JSON.generate(params) unless params.empty? parse fetch(request) end |
#put(path, params = {}) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/puppet_x/pulp/api_client.rb', line 55 def put(path, params = {}) request = Net::HTTP::Put.new(path) request.content_type = 'application/json' request.body = JSON.generate(params) unless params.empty? parse fetch(request) end |
#start ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/puppet_x/pulp/api_client.rb', line 20 def start if block_given? @http.start unless @http.started? yield(self) @http.finish if @http.started? else @http.start unless @http.started? end end |