rack_iphone 1.0.1

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. data/LICENSE.txt +20 -0
  2. data/README.md +21 -0
  3. data/lib/rack_iphone.rb +106 -0
  4. metadata +141 -0
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 meetme2meat
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,21 @@
1
+ **rack_iphone**
2
+ ===============
3
+
4
+
5
+ ### Description
6
+
7
+ rack_iphone enable auto login from iOS Home Screen shortcut
8
+
9
+ <p><code> sudo gem install rack_iphone </code></p>
10
+
11
+
12
+ inside your config.ru
13
+
14
+ <p><code> use Rack::Iphone </code> </p>
15
+
16
+
17
+
18
+ **Copyright**
19
+ ==================
20
+ Copyright (c) 2012 meetme2meat. See LICENSE.txt for
21
+ further details.
@@ -0,0 +1,106 @@
1
+ module Rack
2
+ class Iphone
3
+ CODE = %{
4
+ <script type="text/javascript">
5
+ (function(){
6
+ var RESEND_REQUEST = {{RESEND}};
7
+
8
+ function isFullScreen(){
9
+ return navigator.userAgent.match(/WebKit.*Mobile/) &&
10
+ !navigator.userAgent.match(/Safari/);
11
+ }
12
+
13
+ if(isFullScreen()){
14
+
15
+ if(!document.cookie.match(/{{REGEX}}/)){
16
+ var storedValues = localStorage.getItem('__cookie__');
17
+ if(storedValues){
18
+ var values = storedValues.split(';');
19
+ for(var i=0; i < values.length; i++)
20
+ document.cookie = values[i];
21
+ }
22
+ document.cookie = '_cookieset_=1';
23
+
24
+ if(RESEND_REQUEST){
25
+ window.location.reload();
26
+ }
27
+
28
+ }
29
+ }
30
+ })()
31
+ </script>
32
+ }
33
+ COOKIE = %{
34
+ <script type="text/javascript">
35
+ (function(){
36
+ var COOKIE = "{{COOKIE}}";
37
+ var lastCookie = null;
38
+ setInterval(function(){
39
+ if(lastCookie != ''+COOKIE){
40
+ lastCookie = ''+COOKIE;
41
+ localStorage.setItem('__cookie__', ''+COOKIE);
42
+ }
43
+ },1000);
44
+ })()
45
+ </script>
46
+ }
47
+
48
+ def initialize(app)
49
+ @app = app
50
+ end
51
+
52
+ def call(env)
53
+ if iphone_web_app?(env)
54
+ if new_session?(env)
55
+ [200,{'Content-Length' => code(true).length.to_s, 'Content-Type' => 'text/html'}, code(true)]
56
+ else
57
+ status, headers, body = @app.call(env)
58
+ # Put in patch code
59
+ ##
60
+ ##
61
+
62
+ request = Rack::Request.new(env)
63
+ response = Rack::Response.new([], status, headers)
64
+ cookie = String.new
65
+ request.cookies.each_pair do |key,value|
66
+ cookie += "#{key}=#{value};"
67
+ end
68
+ body.each do |part|
69
+ part.gsub!(/<\/head>/, "#{set_cookie(cookie)}</head>")
70
+ response.write(part)
71
+ end
72
+ response.finish
73
+ end
74
+ else
75
+ @app.call(env)
76
+ end
77
+ end
78
+
79
+ protected
80
+
81
+ def code(resend=false)
82
+ regex = "_session_id"
83
+ regex = Rails.configuration.session_options[:key] if Rails.configuration.session_store.name == "ActionDispatch::Session::CookieStore"
84
+ CODE.gsub('{{RESEND}}', resend.to_s).gsub('{{REGEX}}',regex.to_s)
85
+ end
86
+
87
+ def set_cookie(cookie)
88
+ COOKIE.gsub('{{COOKIE}}',cookie.to_s)
89
+ end
90
+
91
+ def new_session?(env)
92
+ request = Rack::Request.new(env)
93
+ if request.cookies['_cookieset_'].nil?
94
+ true
95
+ else
96
+ false
97
+ end
98
+ end
99
+
100
+ def iphone_web_app?(env)
101
+ if env['HTTP_USER_AGENT']
102
+ env['HTTP_USER_AGENT'] =~ /WebKit.*Mobile/ && !(env['HTTP_USER_AGENT'] =~ /Safari/)
103
+ end
104
+ end
105
+ end
106
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack_iphone
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 1
9
+ version: 1.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Viren Negi
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-04-10 00:00:00 +05:30
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ segments:
26
+ - 0
27
+ version: "0"
28
+ requirement: *id001
29
+ prerelease: false
30
+ type: :development
31
+ name: shoulda
32
+ - !ruby/object:Gem::Dependency
33
+ version_requirements: &id002 !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ segments:
38
+ - 3
39
+ - 12
40
+ version: "3.12"
41
+ requirement: *id002
42
+ prerelease: false
43
+ type: :development
44
+ name: rdoc
45
+ - !ruby/object:Gem::Dependency
46
+ version_requirements: &id003 !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ~>
49
+ - !ruby/object:Gem::Version
50
+ segments:
51
+ - 1
52
+ - 0
53
+ - 0
54
+ version: 1.0.0
55
+ requirement: *id003
56
+ prerelease: false
57
+ type: :development
58
+ name: bundler
59
+ - !ruby/object:Gem::Dependency
60
+ version_requirements: &id004 !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ~>
63
+ - !ruby/object:Gem::Version
64
+ segments:
65
+ - 1
66
+ - 8
67
+ - 3
68
+ version: 1.8.3
69
+ requirement: *id004
70
+ prerelease: false
71
+ type: :development
72
+ name: jeweler
73
+ - !ruby/object:Gem::Dependency
74
+ version_requirements: &id005 !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ requirement: *id005
82
+ prerelease: false
83
+ type: :development
84
+ name: rcov
85
+ - !ruby/object:Gem::Dependency
86
+ version_requirements: &id006 !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ requirement: *id006
94
+ prerelease: false
95
+ type: :runtime
96
+ name: rack
97
+ description: Rack Iphone is use for auto login for web app from iphone when activated from home screen shortcut. The Gem is Inspired by work of Jim Hoskins gem rack_iphone_web_app
98
+ email: meetme2meat@gmail.com
99
+ executables: []
100
+
101
+ extensions: []
102
+
103
+ extra_rdoc_files:
104
+ - LICENSE.txt
105
+ - README.md
106
+ files:
107
+ - lib/rack_iphone.rb
108
+ - LICENSE.txt
109
+ - README.md
110
+ has_rdoc: true
111
+ homepage: http://github.com/meetme2meat/rack_iphone
112
+ licenses:
113
+ - MIT
114
+ post_install_message:
115
+ rdoc_options: []
116
+
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ segments:
124
+ - 0
125
+ version: "0"
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ segments:
131
+ - 0
132
+ version: "0"
133
+ requirements: []
134
+
135
+ rubyforge_project:
136
+ rubygems_version: 1.3.6
137
+ signing_key:
138
+ specification_version: 3
139
+ summary: Rack Iphone is use for auto login from iphone home screen shortcut
140
+ test_files: []
141
+