Module: PuppetX::Gitlab::APIClient
- Defined in:
- lib/puppet_x/gitlab/runner.rb
Class Method Summary collapse
- .delete(url, options, proxy) ⇒ Object
- .post(url, options, proxy) ⇒ Object
- .request(url, http_method, options, proxy) ⇒ Object
- .validate(response) ⇒ Object
Class Method Details
.delete(url, options, proxy) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/puppet_x/gitlab/runner.rb', line 8 def self.delete(url, , proxy) response = request(url, Net::HTTP::Delete, , proxy) validate(response) {} end |
.post(url, options, proxy) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/puppet_x/gitlab/runner.rb', line 15 def self.post(url, , proxy) response = request(url, Net::HTTP::Post, , proxy) validate(response) JSON.parse(response.body) end |
.request(url, http_method, options, proxy) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/puppet_x/gitlab/runner.rb', line 22 def self.request(url, http_method, , proxy) uri = URI.parse(url) headers = { 'Accept' => 'application/json', 'Content-Type' => 'application/json' } if proxy proxy_uri = URI.parse(proxy) proxy_host = proxy_uri.host proxy_port = proxy_uri.port else proxy_host = nil proxy_port = nil end http = Net::HTTP.new(uri.host, uri.port, proxy_host, proxy_port) if uri.scheme == 'https' http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_PEER end request = http_method.new(uri.request_uri, headers) request.body = .to_json http.request(request) end |
.validate(response) ⇒ Object
47 48 49 |
# File 'lib/puppet_x/gitlab/runner.rb', line 47 def self.validate(response) raise Net::HTTPError.new(response., response) unless response.code.start_with?('2') end |