Method: Curl::PostField.content

Defined in:
ext/curb_postfield.c

.Curl::PostField.content(name, content) ⇒ #<Curl::PostField...> .Curl::PostField.content(name, content, content_type = nil) ⇒ #<Curl::PostField...> .Curl::PostField.content(name, content_type = nil) {|field| ... } ⇒ #<Curl::PostField...>

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:



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'ext/curb_postfield.c', line 210

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;
    } else {
      // default content type      
      rbcpf->content_type = Qnil;
    }
  } else {
    // no block, so make sure content was provided    
    if (rbcpf->content == Qnil) {
      rb_raise(rb_eArgError, "Incorrect number of arguments (expected 2 or 3)");
    }    
  }
      
  /* assoc objects */
  rbcpf->local_file = Qnil;
  rbcpf->remote_file = Qnil;
  rbcpf->buffer_str = Qnil;
  
  return Data_Wrap_Struct(cCurlPostField, curl_postfield_mark, curl_postfield_free, rbcpf);
}