Class: Taps::Multipart

Inherits:
Object
  • Object
show all
Defined in:
lib/taps/multipart.rb

Defined Under Namespace

Classes: Container

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Multipart

Returns a new instance of Multipart.



32
33
34
# File 'lib/taps/multipart.rb', line 32

def initialize(opts={})
	@opts = opts
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



30
31
32
# File 'lib/taps/multipart.rb', line 30

def opts
  @opts
end

Class Method Details

.create {|c| ... } ⇒ Object

Yields:

  • (c)


52
53
54
55
56
# File 'lib/taps/multipart.rb', line 52

def self.create
	c = Taps::Multipart::Container.new
	yield c
	c.generate
end

.parse(response) ⇒ Object

response is a rest-client response



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/taps/multipart.rb', line 59

def self.parse(response)
	content = response.to_s
	env = {
		'CONTENT_TYPE' => response.headers[:content_type],
		'CONTENT_LENGTH' => content.size,
		'rack.input' => StringIO.new(content)
	}

	params = Rack::Utils::Multipart.parse_multipart(env)
	params.symbolize_keys!
	params
end

Instance Method Details

#content_typeObject



44
45
46
# File 'lib/taps/multipart.rb', line 44

def content_type
	opts[:content_type] || 'text/plain'
end

#nameObject



36
37
38
# File 'lib/taps/multipart.rb', line 36

def name
	opts[:name]
end

#original_filenameObject



48
49
50
# File 'lib/taps/multipart.rb', line 48

def original_filename
	opts[:original_filename]
end

#to_sObject



40
41
42
# File 'lib/taps/multipart.rb', line 40

def to_s
	opts[:payload]
end