casual-api 3.0.5 → 3.0.6

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/casual.rb +9 -4
  3. data/lib/dsl.rb +8 -2
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 27624cbb80045ccfb0314a36d4219020df61eb69
4
- data.tar.gz: 8d3589a94eaa990792dd309cdc68589d391b9031
3
+ metadata.gz: 3049bc52a1d33d63c9aa5568779d01e0b38cab6c
4
+ data.tar.gz: 7e1c8f66974d79ac311ed4d5d42e75c7e77c0d12
5
5
  SHA512:
6
- metadata.gz: 073ebb071c6a17fa68ef6df11a358dd9b013e1eb8be506f2cf7907b3c3ff064128309ec7696722a66e3ae1089a88714466d18b7455096fce768e5d86428c7e77
7
- data.tar.gz: b401e0577583eb7ce467781a5046ab38efb89b5ef893a86b8e345be047a6968415067df2dadbbca835fd1c9fc3ced04f63004edbdfe29adda59506d95759cf03
6
+ metadata.gz: a1695dafa84bd878d25da410f438f621952bdb3c2a597e765655da27a4d78572aa125a11c69661d7a27a9e9b68ddec564c953a14707a29f2dcd2308e2be2dc41
7
+ data.tar.gz: d3b977773f0d016316ee3a0a7070e3312a274dfe773154bdd9201d391133a40b5c409a0f88f9dd1ce1f0e5dcfdcf0f4a0ed7f978528773b4d0feae6c0b38d608
data/lib/casual.rb CHANGED
@@ -14,6 +14,7 @@ module CasualAPI
14
14
  check_parameter
15
15
  obj = Action.fire @action, @params, @session
16
16
  {
17
+ redirect: obj.redirect,
17
18
  session: obj.session,
18
19
  status_code: obj.status_code,
19
20
  content_type: obj.content_type,
@@ -70,10 +71,14 @@ module CasualAPI
70
71
  result = cp.execute
71
72
  @req.session['casual.session'] = result[:session]
72
73
  res = Rack::Response.new(){|r|
73
- r.status = result[:status_code]
74
- r.write result[:body]
75
- r['Content-Type'] = map_content_type(result[:content_type])
76
- r['Access-Control-Allow-Origin'] = '*'
74
+ if result[:redirect]
75
+ r.redirect(result[:redirect])
76
+ else
77
+ r.status = result[:status_code]
78
+ r.write result[:body]
79
+ r['Content-Type'] = map_content_type(result[:content_type])
80
+ r['Access-Control-Allow-Origin'] = '*'
81
+ end
77
82
  }
78
83
  res.finish
79
84
  rescue CommandError => ex
data/lib/dsl.rb CHANGED
@@ -17,7 +17,7 @@ module CasualAPI
17
17
  @body << str.to_s << "\n"
18
18
  end
19
19
  def printf *p
20
- @body << (sprintf *p)
20
+ @body << sprintf(*p)
21
21
  end
22
22
  def command cmd
23
23
  write `#{cmd.to_s}`
@@ -39,6 +39,7 @@ module CasualAPI
39
39
 
40
40
  module Action
41
41
  def self.extended obj
42
+ obj.instance_variable_set(:@redirect, nil)
42
43
  obj.instance_variable_set(:@session, {})
43
44
  obj.instance_variable_set(:@content_type, nil)
44
45
  obj.instance_variable_set(:@status_code, 200)
@@ -57,9 +58,13 @@ module CasualAPI
57
58
  Action.tempfile self, file
58
59
  end
59
60
 
61
+ def redirect_to url
62
+ @redirect = url
63
+ end
64
+
60
65
  def session_clear
61
66
  session.clear
62
- session = nil
67
+ @session = nil
63
68
  end
64
69
 
65
70
  def session; @session; end
@@ -69,6 +74,7 @@ module CasualAPI
69
74
  def status_code; @status_code; end
70
75
  def content_type=(type); @content_type = type; end
71
76
  def status_code=(code); @status_code = code; end
77
+ def redirect; @redirect; end
72
78
 
73
79
 
74
80
  def self.fire(action, params, session)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: casual-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.5
4
+ version: 3.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takeshi Kojima