Class: Typhoeus::Form

Inherits:
Object
  • Object
show all
Defined in:
lib/typhoeus/form.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Form

Returns a new instance of Form.



8
9
10
11
12
13
14
15
# File 'lib/typhoeus/form.rb', line 8

def initialize(params = {})
  # ideally we should escape params here with Typhoeus::Utils.escape_params. I don't do it in this commit because I don't know the implications yet.
  @params = params 
  @first = ::FFI::MemoryPointer.new(:pointer)
  @last = ::FFI::MemoryPointer.new(:pointer)

  ObjectSpace.define_finalizer(self, self.class.finalizer(self))
end

Instance Attribute Details

#firstObject (readonly)

Returns the value of attribute first.



6
7
8
# File 'lib/typhoeus/form.rb', line 6

def first
  @first
end

#paramsObject

Returns the value of attribute params.



5
6
7
# File 'lib/typhoeus/form.rb', line 5

def params
  @params
end

#traversalObject (readonly)

Returns the value of attribute traversal.



6
7
8
# File 'lib/typhoeus/form.rb', line 6

def traversal
  @traversal
end

Class Method Details

.finalizer(form) ⇒ Object



17
18
19
# File 'lib/typhoeus/form.rb', line 17

def self.finalizer(form)
  proc { Curl.formfree(form.first) }
end

Instance Method Details

#multipart?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/typhoeus/form.rb', line 54

def multipart?
  !traversal[:files].empty?
end

#process!Object



46
47
48
49
50
51
52
# File 'lib/typhoeus/form.rb', line 46

def process!
  # add params
  traversal[:params].each { |p| formadd_param(p[0], p[1]) }

  # add files
  traversal[:files].each { |file_args| formadd_file(*file_args) }
end

#to_sObject



58
59
60
# File 'lib/typhoeus/form.rb', line 58

def to_s
  Typhoeus::Utils.traversal_to_param_string(traversal, false)
end