rack-multipart_related 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,3 +1,96 @@
1
1
  # Rack multipart/related middleware
2
2
 
3
- Rack::MultipartRelated it's a rack middleware to parse multipart/related requests and rebuild a simple/merged parameters hash.
3
+ Rack::MultipartRelated it's a **rack middleware** to parse **multipart/related** requests and rebuild a simple/merged parameters hash.
4
+
5
+ ## What does it do?
6
+
7
+ When a ruby webserver receives a multipart/related request:
8
+
9
+ POST /users HTTP/1.1
10
+ Content-Type: multipart/related; boundary="the_boundary"; type="application/json"; start="json"
11
+
12
+ --the_boundary
13
+ Content-Type: application/json; charset=UTF-8
14
+ Content-Disposition: inline; name="json"\r
15
+
16
+ {"user":{"name": "Jhon", "avatar": "cid:avatar_image" }}
17
+ --the_boundary
18
+ Content-Type: image/png
19
+ Content-Disposition: inline; name="avatar_image"; filename="avatar.png"
20
+
21
+ <the binary content of image comes here>
22
+ --the_boundary--
23
+
24
+
25
+
26
+ The parameters hash arrives like this:
27
+
28
+ {
29
+ "json" => {
30
+ :type => "application/json; charset=UTF-8",
31
+ :tempfile => <File:/var/folders/Iu/IuwHUNlZE8OaYMACfwiapE+++TI/-Tmp-/RackMultipart20101217-30578-l17vkd-0>, # The json content
32
+ :head => "Content-Type: application/json; charset=UTF-8\r\nContent-Disposition: inline; name=\"json\"\r\n",
33
+ :name => "json"
34
+ },
35
+ "avatar_image" => {
36
+ :type => "image/png",
37
+ :filename =>"image.png",
38
+ :tempfile => <File:/var/folders/Iu/IuwHUNlZE8OaYMACfwiapE+++TI/-Tmp-/RackMultipart20101217-30578-bt18q9-0>, # The binary content of image
39
+ :head => "Content-Type: image/gif\r\nContent-Disposition: inline; name=\"avatar_image\"; filename=\"image.png\"\r\n",
40
+ :name =>"avatar_image"
41
+ }
42
+ }
43
+
44
+ Pay attention that the second part of the 'request' (in our example, "avatar\_image") needs to be referenced in the first part (in the example, "json") as "cid:REFERENCE\_NAME\_OF\_THE\_SECOND\_PART"
45
+
46
+ Using this middleware, the hash above is parsed and rebuilt like the code below:
47
+
48
+ {
49
+ "user" => {
50
+ "name" => "Jhon",
51
+ "avatar" => <File:/var/folders/Iu/IuwHUNlZE8OaYMACfwiapE+++TI/-Tmp-/RackMultipart20101217-30578-bt18q9-0>, # The binary content of image
52
+ }
53
+ }
54
+
55
+ ## Usage
56
+
57
+ ### Rails apps
58
+
59
+ In your Gemfile:
60
+
61
+ gem 'rack-multipart_related'
62
+ In your environment.rb:
63
+
64
+ require 'rack/multipart_related'
65
+ config.middleware.use Rack::MultipartRelated
66
+
67
+ ### Non-Rails apps
68
+
69
+ Just 'use Rack::MultipartRelated' as any other middleware
70
+
71
+ ## Restrictions
72
+
73
+ At this moment, this middleware only supports JSON in the start part.
74
+
75
+ ## TODO
76
+
77
+ * Support other formats to start part, like XML.
78
+
79
+ ## Report bugs and suggestions
80
+
81
+ * [Issue Tracker](https://github.com/lucasfais/rack-multipart_related/issues)
82
+
83
+ ## Authors
84
+
85
+ * [Lucas Fais](https://github.com/lucasfais)
86
+ * [Marcelo Manzan](https://github.com/kawamanza)
87
+
88
+ ## Contributors
89
+
90
+ * [Eric Fer](https://github.com/ericfer)
91
+
92
+ ## References
93
+
94
+ * [RFC 2387](http://www.faqs.org/rfcs/rfc2387.html)
95
+ * [Rails on rack](http://guides.rubyonrails.org/rails_on_rack.html)
96
+
@@ -1,6 +1,6 @@
1
1
  module Rack
2
2
  class MultipartRelated
3
- path = File.expand_path('../../..', __FILE__)
3
+ path = ::File.expand_path('../../..', __FILE__)
4
4
  v = nil
5
5
  v = $1 if path =~ /\/rack-multipart_related-([\w\.\-]+)/
6
6
  if v.nil?
@@ -12,8 +12,8 @@ module Rack
12
12
  end
13
13
  end
14
14
  if v.nil?
15
- path = File.expand_path('../../../../.git', __FILE__)
16
- if File.exists?(path)
15
+ path = ::File.expand_path('../../../../.git', __FILE__)
16
+ if ::File.exists?(path)
17
17
  require "step-up"
18
18
  v = StepUp::Driver::Git.last_version
19
19
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-multipart_related
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Lucas Fais