Class: Curl::PostField

Inherits:
Object
  • Object
show all
Defined in:
ext/curb_postfield.c

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) Curl::PostField.content(name, content) + (Object) Curl::PostField.content(name, content, content_type = nil) + (Object) Curl::PostField.content(name, content_type = nil) {|field| ... }

Create a new Curl::PostField, supplying the field name, content, and, optionally, Content-type (curl will attempt to determine this if not specified).

The block form allows a block to supply the content for this field, called during the perform. The block should return a ruby string with the field data.

Overloads:

  • + (Object) Curl::PostField.content(name, content_type = nil) {|field| ... }

    Yields:

    • (field)


# File 'ext/curb_postfield.c'

static VALUE ruby_curl_postfield_new_content(int argc, VALUE *argv, VALUE klass) {
  ruby_curl_postfield *rbcpf = ALLOC(ruby_curl_postfield);
 
  // wierdness - we actually require two args, unless a block is provided, but
  // we have to work that out below.
  rb_scan_args(argc, argv, "12&", &rbcpf->name, &rbcpf->content, &rbcpf->content_type, &rbcpf->content_proc);

  // special handling if theres a block, second arg is actually content_type
  if (rbcpf->content_proc != Qnil) {
if (rbcpf->content != Qnil) {
  // we were given a content-type
  rbcpf->content_type = rbcpf->content;
  rbcpf->content = Qnil;
}

+ (Object) Curl::PostField.file(name, local_file_name) + (Object) Curl::PostField.file(name, local_file_name, remote_file_name = local_file_name) + (Object) Curl::PostField.file(name, remote_file_name) {|field| ... }

Create a new Curl::PostField for a file upload field, supplying the local filename to read from, and optionally the remote filename (defaults to the local name).

The block form allows a block to supply the content for this field, called during the perform. The block should return a ruby string with the field data.

Overloads:

  • + (Object) Curl::PostField.file(name, remote_file_name) {|field| ... }

    Yields:

    • (field)


# File 'ext/curb_postfield.c'

static VALUE ruby_curl_postfield_new_file(int argc, VALUE *argv, VALUE klass) {
  // TODO needs to handle content-type too
  ruby_curl_postfield *rbcpf = ALLOC(ruby_curl_postfield);

  rb_scan_args(argc, argv, "21&", &rbcpf->name, &rbcpf->local_file, &rbcpf->remote_file, &rbcpf->content_proc);

  // special handling if theres a block, second arg is actually remote name.
  if (rbcpf->content_proc != Qnil) {
    if (rbcpf->local_file != Qnil) {
// we were given a local file
if (rbcpf->remote_file == Qnil) {
  // we weren't given a remote, so local is actually remote
  // (correct block call form)
  rbcpf->remote_file = rbcpf->local_file;
}

Instance Method Details

- (Object) content

Obtain the POST field content for this PostField.



# File 'ext/curb_postfield.c'

static VALUE ruby_curl_postfield_content_get(VALUE self) {
  CURB_OBJECT_GETTER(ruby_curl_postfield, content);
}

- (Object) content=

Set the POST field content for this PostField. Ignored when a content_proc is supplied via either Curl::PostField.file or set_content_proc.



# File 'ext/curb_postfield.c'

static VALUE ruby_curl_postfield_content_set(VALUE self, VALUE content) {
  CURB_OBJECT_SETTER(ruby_curl_postfield, content);
}

- (Object) content_type

Get the POST field Content-type for this PostField.



# File 'ext/curb_postfield.c'

static VALUE ruby_curl_postfield_content_type_get(VALUE self) {
  CURB_OBJECT_GETTER(ruby_curl_postfield, content_type);
}

- (Object) content_type=

Set the POST field Content-type for this PostField.



# File 'ext/curb_postfield.c'

static VALUE ruby_curl_postfield_content_type_set(VALUE self, VALUE content_type) {
  CURB_OBJECT_SETTER(ruby_curl_postfield, content_type);
}

- (Object) local_file

Get the POST field local filename for this PostField (when performing a file upload).



# File 'ext/curb_postfield.c'

static VALUE ruby_curl_postfield_local_file_get(VALUE self) {
  CURB_OBJECT_GETTER(ruby_curl_postfield, local_file);
}

- (Object) local_file=

Set the POST field local filename for this PostField (when performing a file upload). Ignored when a content_proc is supplied via either Curl::PostField.file or set_content_proc.



# File 'ext/curb_postfield.c'

static VALUE ruby_curl_postfield_local_file_set(VALUE self, VALUE local_file) {
  CURB_OBJECT_SETTER(ruby_curl_postfield, local_file);
}

- (Object) name

Obtain the POST field name for this PostField.



# File 'ext/curb_postfield.c'

static VALUE ruby_curl_postfield_name_get(VALUE self) {
  CURB_OBJECT_GETTER(ruby_curl_postfield, name);
}

- (Object) name=

Set the POST field name for this PostField.



# File 'ext/curb_postfield.c'

static VALUE ruby_curl_postfield_name_set(VALUE self, VALUE name) {
  CURB_OBJECT_SETTER(ruby_curl_postfield, name);
}

- (Object) local_file

Get the POST field remote filename for this PostField (when performing a file upload).



# File 'ext/curb_postfield.c'

static VALUE ruby_curl_postfield_remote_file_get(VALUE self) {
  CURB_OBJECT_GETTER(ruby_curl_postfield, remote_file);
}

- (Object) remote_file=

Set the POST field remote filename for this PostField (when performing a file upload). If no remote filename is provided, and no content_proc is supplied, the local filename is used. If no remote filename is specified when a content_proc is used, an exception will be raised during the perform.



# File 'ext/curb_postfield.c'

static VALUE ruby_curl_postfield_remote_file_set(VALUE self, VALUE remote_file) {
  CURB_OBJECT_SETTER(ruby_curl_postfield, remote_file);
}

- (Object) set_content_proc {|field| ... }

Set a content proc for this field. This proc will be called during the perform to supply the content for this field, overriding any setting of content or local_file.

Yields:

  • (field)


# File 'ext/curb_postfield.c'

static VALUE ruby_curl_postfield_content_proc_set(int argc, VALUE *argv, VALUE self) {
  CURB_HANDLER_PROC_SETTER(ruby_curl_postfield, content_proc);
}

- (Object) to_str - (Object) to_s

Obtain a String representation of this PostField in url-encoded format. This is used to construct the post data for non-multipart POSTs.

Only content fields may be converted to strings.



# File 'ext/curb_postfield.c'

static VALUE ruby_curl_postfield_to_str(VALUE self) {
  // FIXME This is using the deprecated curl_escape func
  ruby_curl_postfield *rbcpf;
  VALUE result = Qnil;
  VALUE name = Qnil;
  char *tmpchrs;
  
  Data_Get_Struct(self, ruby_curl_postfield, rbcpf);

    if (rbcpf->name != Qnil) {
name = rbcpf->name;
if (rb_type(name) == T_STRING) {
  name = rbcpf->name;
}