sunrise-file-upload 0.1.3 → 0.1.4

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.
@@ -51,7 +51,10 @@ module Sunrise
51
51
  end
52
52
 
53
53
  def fetch
54
- self.write @request.raw_post
54
+ body = @request.raw_post
55
+ body = body.force_encoding('UTF-8') if body.respond_to?(:force_encoding)
56
+
57
+ self.write body
55
58
  self.rewind
56
59
  self
57
60
  end
@@ -22,6 +22,7 @@ module Sunrise
22
22
  def create(env)
23
23
  request = Request.new(env)
24
24
  params = request.params.symbolize_keys
25
+ headers = { 'Content-Type' => 'application/json' }
25
26
 
26
27
  asset = find_or_build_asset(params)
27
28
  asset.assetable_type = params[:assetable_type]
@@ -32,16 +33,14 @@ module Sunrise
32
33
  _run_callbacks(:before_create, env, asset)
33
34
 
34
35
  if asset.save
35
- body = asset.to_json
36
- status = 200
37
-
38
36
  _run_callbacks(:after_create, env, asset)
37
+
38
+ body = asset.to_json
39
+ [200, headers.merge('Content-Length' => body.size.to_s), [body]]
39
40
  else
40
41
  body = asset.errors.to_json
41
- status = 422
42
+ [422, headers.merge('Content-Length' => body.size.to_s), [body]]
42
43
  end
43
-
44
- [status, {'Content-Type' => 'text/html', 'Content-Length' => body.size.to_s}, body]
45
44
  end
46
45
 
47
46
  def find_or_build_asset(params)
@@ -15,7 +15,7 @@ module Sunrise
15
15
 
16
16
  def body
17
17
  if raw_post = @env['RAW_POST_DATA']
18
- raw_post.force_encoding(Encoding::BINARY) if raw_post.respond_to?(:force_encoding)
18
+ raw_post = raw_post.force_encoding(Encoding::BINARY) if raw_post.respond_to?(:force_encoding)
19
19
  StringIO.new(raw_post)
20
20
  else
21
21
  @env['rack.input']
@@ -1,5 +1,5 @@
1
1
  module Sunrise
2
2
  module FileUpload
3
- VERSION = "0.1.3".freeze
3
+ VERSION = "0.1.4".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sunrise-file-upload
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Igor Galeta
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-12-13 00:00:00 Z
19
+ date: 2012-04-11 00:00:00 Z
20
20
  dependencies: []
21
21
 
22
22
  description: Sunrise is a Aimbulance CMS