Method: Curl::Easy#initialize

Defined in:
ext/curb_easy.c

#Curl::Easy.new#<Curl::Easy... #Curl::Easy.new(url = nil) ⇒ #<Curl::Easy... #Curl::Easy.new(url = nil) {|self| ... } ⇒ #<Curl::Easy...

Initialize a new Curl::Easy instance, optionally supplying the URL. The block form allows further configuration to be supplied before the instance is returned.

Overloads:

  • #Curl::Easy.new#<Curl::Easy...

    Returns ].

  • #Curl::Easy.new(url = nil) ⇒ #<Curl::Easy...

    Returns ].

  • #Curl::Easy.new(url = nil) {|self| ... } ⇒ #<Curl::Easy...

    Returns ].

    Yields:

    • (self)


403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
# File 'ext/curb_easy.c', line 403

static VALUE ruby_curl_easy_initialize(int argc, VALUE *argv, VALUE self) {
  CURLcode ecode;
  VALUE url, blk;
  ruby_curl_easy *rbce;

  rb_scan_args(argc, argv, "01&", &url, &blk);

  Data_Get_Struct(self, ruby_curl_easy, rbce);

  /* handler */
  rbce->curl = curl_easy_init();
  if (!rbce->curl) {
    rb_raise(eCurlErrFailedInit, "Failed to initialize easy handle");
  }

  rbce->multi = Qnil;
  rbce->opts  = Qnil;

  ruby_curl_easy_zero(rbce);
  rbce->self = self;

  curl_easy_setopt(rbce->curl, CURLOPT_ERRORBUFFER, &rbce->err_buf);

  rb_easy_set("url", url);

  /* set the pointer to the curl handle */
  ecode = curl_easy_setopt(rbce->curl, CURLOPT_PRIVATE, (void*)rbce);
  if (ecode != CURLE_OK) {
    raise_curl_easy_error_exception(ecode);
  }

  if (blk != Qnil) {
    rb_funcall(blk, idCall, 1, self);
  }

  return self;
}