Class: ReeHttp::HttpExec

Inherits:
Object
  • Object
show all
Includes:
Ree::FnDSL
Defined in:
lib/ree_lib/packages/ree_http/package/ree_http/functions/http_exec.rb

Constant Summary collapse

DEFAULTS =
{
  headers: {},
  timeout: DEFAULT_TIMEOUT,
  write_timeout: DEFAULT_WRITE_TIMEOUT,
  force_ssl: DEFAULT_FORCE_SSL,
}.freeze
OPTS_CONTRACT =
{
  headers?: HashOf[Or[String, Symbol], Or[String, Integer]],
  body?: Or[String, Hash, File],
  form_data?: HashOf[Or[Symbol, String], Or[Integer, Float, Bool, String, Array, File]],
  write_timeout?: Integer,
  timeout?: Integer,
  redirects_count?: Integer,
  strict_redirect_mode?: Bool,
  query_params?: HashOf[Or[String, Symbol], Any],
  force_ssl?: Bool,
  ca_certs?: ArrayOf[File],
  basic_auth?: {
    username: String,
    password: String
  },
  bearer_token?: String,
  proxy?: {
    address: String,
    port?: Integer,
    username?: String,
    password?: String
  }
}

Instance Method Summary collapse

Instance Method Details

#call(method, url, **opts, &block) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/ree_lib/packages/ree_http/package/ree_http/functions/http_exec.rb', line 79

def call(method, url, **opts, &block)
  opts = DEFAULTS.merge(opts)

  request = build_request(
    method, url,
    **slice(opts, [
        :headers, :body, :form_data, :query_params,
        :force_ssl, :ca_certs, :basic_auth, :bearer_token
    ])
  )

  request_opts = slice(
    opts, [
      :timeout, :force_ssl, :ca_certs, :proxy, :write_timeout,
      :redirects_count, :strict_redirect_mode
    ]
  )

  execute_request(request, **request_opts, &block)
end