multiparty 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -12,6 +12,9 @@ You can add multiple values, corresponding to multiple <input> statements:
12
12
  @multiparty = Multiparty.new
13
13
  @multiparty[:name] = "David Verhasselt"
14
14
  @multiparty[:state] = "awesome"
15
+ # or in one statement:
16
+ @multiparty << {:name => "David Verhasselt", :state => "awesome"}
17
+
15
18
  @multiparty[:avatar] = {:filename => "avatar.jpg", :content => "...jpegdata..."}
16
19
 
17
20
  # Retrieve the header and body like this:
@@ -64,6 +67,12 @@ tempfile.rewind
64
67
  @multiparty[:message] => File.open(tempfile.path)
65
68
  ```
66
69
 
70
+ Multiparty has the ```to_s``` method aliased to ```body``` so you can use it as a ```String```:
71
+
72
+ ```
73
+ puts "Hello World! My multipart body: #{@multiparty}"
74
+ ```
75
+
67
76
  Installation
68
77
  ------------
69
78
 
@@ -1,4 +1,5 @@
1
1
  require "mime/types"
2
+ require "tempfile"
2
3
 
3
4
  class Multiparty
4
5
  attr_accessor :boundary
@@ -34,6 +35,7 @@ class Multiparty
34
35
 
35
36
  result << "--"
36
37
  end
38
+ alias_method :to_s, :body
37
39
 
38
40
  def parse_part(name, value)
39
41
  content_disposition = "form-data"
@@ -71,4 +73,11 @@ class Multiparty
71
73
  end
72
74
  alias_method :[]=, :add_part
73
75
 
76
+ def add_parts(parts)
77
+ parts.each do |index, value|
78
+ add_part(index, value)
79
+ end
80
+ end
81
+ alias_method :<<, :add_parts
82
+
74
83
  end
@@ -38,6 +38,22 @@ describe "multiparty" do
38
38
  @multiparty[:key] = {:filename => "hello.jpg", :content => ""}
39
39
  end
40
40
 
41
+ it "should have a decent #to_s method" do
42
+ @multiparty[:key] = :value
43
+ @multiparty.body.should == "#{@multiparty}"
44
+ end
45
+
46
+ it "should be able to add multiple parts at once" do
47
+ multiparty1 = Multiparty.new("my-boundary")
48
+ multiparty2 = Multiparty.new("my-boundary")
49
+
50
+ multiparty1 << {:key1 => :value1, :key2 => :value2}
51
+ multiparty2[:key1] = :value1
52
+ multiparty2[:key2] = :value2
53
+
54
+ multiparty1.body.should == multiparty2.body
55
+ end
56
+
41
57
  it "should return a correctly formed multipart response" do
42
58
  @multiparty.boundary = "AaB03x"
43
59
  @multiparty['submit-name'] = "Larry"
@@ -4,7 +4,6 @@ Bundler.setup(:default, :test)
4
4
  Bundler.require(:default, :test)
5
5
 
6
6
  require 'rspec'
7
- require 'tempfile'
8
7
 
9
8
  $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
10
9
  require "multiparty"
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - David Verhasselt
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-09-18 00:00:00 +02:00
17
+ date: 2011-09-19 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency