Class: AsciidoctorExtensions::KrokiHttpClient
- Inherits:
-
Object
- Object
- AsciidoctorExtensions::KrokiHttpClient
- Defined in:
- lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb
Overview
Kroki HTTP client
Constant Summary collapse
- REFERER =
"asciidoctor/kroki.rb/#{Asciidoctor::AsciidoctorKroki::VERSION}"
Class Method Summary collapse
Class Method Details
.get(uri, opts, _) ⇒ Object
403 404 405 406 407 408 409 410 411 412 413 414 415 |
# File 'lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb', line 403 def get(uri, opts, _) uri = URI(uri) headers = opts.transform_keys { |key| "Kroki-Diagram-Options-#{key}" } .merge({ 'referer' => REFERER }) request = ::Net::HTTP::Get.new(uri, headers) ::Net::HTTP.start( uri.hostname, uri.port, use_ssl: (uri.scheme == 'https') ) do |http| http.request(request).body end end |
.post(uri, data, opts, _) ⇒ Object
417 418 419 420 421 422 423 424 425 426 427 428 429 |
# File 'lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb', line 417 def post(uri, data, opts, _) headers = opts.transform_keys { |key| "Kroki-Diagram-Options-#{key}" } .merge({ 'Content-Type' => 'text/plain', 'referer' => REFERER }) res = ::Net::HTTP.post( URI(uri), data, headers ) res.body end |