Class: FluidCLI::HttpRequest
- Inherits:
-
Object
- Object
- FluidCLI::HttpRequest
- Defined in:
- lib/fluid_cli/http_request.rb
Class Method Summary collapse
- .delete(uri, body, headers) ⇒ Object
- .get(uri, body, headers) ⇒ Object
- .multipart_post(uri, body, headers) ⇒ Object
- .multipart_put(uri, body, headers) ⇒ Object
- .post(uri, body, headers) ⇒ Object
- .put(uri, body, headers) ⇒ Object
- .request(uri, body, headers, req) ⇒ Object
Class Method Details
.delete(uri, body, headers) ⇒ Object
23 24 25 26 |
# File 'lib/fluid_cli/http_request.rb', line 23 def delete(uri, body, headers) req = ::Net::HTTP::Delete.new(uri.request_uri) request(uri, body, headers, req) end |
.get(uri, body, headers) ⇒ Object
18 19 20 21 |
# File 'lib/fluid_cli/http_request.rb', line 18 def get(uri, body, headers) req = ::Net::HTTP::Get.new(uri.request_uri) request(uri, body, headers, req) end |
.multipart_post(uri, body, headers) ⇒ Object
33 34 35 36 37 |
# File 'lib/fluid_cli/http_request.rb', line 33 def multipart_post(uri, body, headers) req = Net::HTTP::Post::Multipart.new(uri.request_uri, body) request(uri, nil, headers, req) end |
.multipart_put(uri, body, headers) ⇒ Object
28 29 30 31 |
# File 'lib/fluid_cli/http_request.rb', line 28 def multipart_put(uri, body, headers) req = Net::HTTP::Put::Multipart.new(uri.request_uri, body) request(uri, nil, headers, req) end |
.post(uri, body, headers) ⇒ Object
8 9 10 11 |
# File 'lib/fluid_cli/http_request.rb', line 8 def post(uri, body, headers) req = ::Net::HTTP::Post.new(uri.request_uri) request(uri, body, headers, req) end |
.put(uri, body, headers) ⇒ Object
13 14 15 16 |
# File 'lib/fluid_cli/http_request.rb', line 13 def put(uri, body, headers) req = ::Net::HTTP::Put.new(uri.request_uri) request(uri, body, headers, req) end |
.request(uri, body, headers, req) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/fluid_cli/http_request.rb', line 39 def request(uri, body, headers, req) cert_store = OpenSSL::X509::Store.new cert_store.set_default_paths http = ::Net::HTTP.new(uri.host, uri.port) http.use_ssl = uri.scheme == "https" http.cert_store = cert_store http.verify_mode = OpenSSL::SSL::VERIFY_NONE if ENV["SSL_VERIFY_NONE"] unless req.is_a?(Net::HTTP::Post::Multipart) req.body = body unless body.nil? req["Content-Type"] = "application/json" headers.each { |header, value| req[header] = value } else headers.each { |header, value| req.add_field(header, value) } end http.request(req) end |