galakei 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.md +8 -0
- data/lib/galakei/email.rb +15 -0
- data/lib/galakei/filter/base.rb +27 -0
- data/lib/galakei/filter/content_type.rb +18 -0
- data/lib/galakei/filter/haml.rb +15 -0
- data/lib/galakei/filter/session_id_parameter.rb +29 -0
- data/lib/galakei/filter/views.rb +10 -0
- data/lib/galakei/helper_methods.rb +13 -0
- data/lib/galakei/railtie.rb +15 -0
- data/lib/galakei/request.rb +36 -0
- data/lib/galakei/shoulda_macros.rb +19 -0
- data/lib/galakei.rb +14 -0
- metadata +111 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Portions copyright (c) 2010 Mobalean LLC
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# Galakei: Japanese feature phone support
|
2
|
+
|
3
|
+
[Japanese feature phones](http://www.mobalean.com/en/keitai_web_technology_guide) (a.k.a., keitai, galakei) have a number of restrictions over normal web browsers. This library adds support for them.
|
4
|
+
|
5
|
+
### Goals
|
6
|
+
|
7
|
+
* Provide support for 3G handsets from the major 3 carriers in Japan (docomo, au, SoftBank)
|
8
|
+
* Avoid modifying Rails internals as much as possible
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Galakei::Email
|
2
|
+
|
3
|
+
GALAKEI_EMAIL_ADDRESS_PATTERNS = [
|
4
|
+
/^.+@(.+\.)?pdx\.ne\.jp$/,
|
5
|
+
/^.+@ezweb\.ne\.jp$/,
|
6
|
+
/^.+@(?:softbank\.ne\.jp|disney\.ne\.jp)$/,
|
7
|
+
/^.+@[dhtcrknsq]\.vodafone\.ne\.jp$/,
|
8
|
+
/^.+@jp-[dhtcrknsq]\.ne\.jp$/,
|
9
|
+
/^.+@emnet\.ne\.jp$/,
|
10
|
+
/^.+@docomo\.ne\.jp$/ ]
|
11
|
+
|
12
|
+
def self.galakei_email_address?(email)
|
13
|
+
GALAKEI_EMAIL_ADDRESS_PATTERNS.any?{|p| p =~ email }
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Galakei
|
2
|
+
module Filter
|
3
|
+
class Base
|
4
|
+
attr_accessor :controller
|
5
|
+
|
6
|
+
def self.condition?(controller)
|
7
|
+
@instance ||= self.new
|
8
|
+
@instance.controller = controller
|
9
|
+
@instance.condition?
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.filter(controller, &block)
|
13
|
+
@instance ||= self.new
|
14
|
+
@instance.controller = controller
|
15
|
+
@instance.filter(&block)
|
16
|
+
end
|
17
|
+
|
18
|
+
def method_missing(m, *args)
|
19
|
+
if controller.respond_to?(m)
|
20
|
+
controller.send(m, *args)
|
21
|
+
else
|
22
|
+
super
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Takes care of ensuring the Content-Type is set to application/xhtml+xml
|
2
|
+
# for docomo devices as is required to use xhtml instead of text/html. If
|
3
|
+
# text/html is used, the content is rendered as the vastly inferior i-mode
|
4
|
+
# html (aka CHTML).
|
5
|
+
class Galakei::Filter::ContentType < Galakei::Filter::Base
|
6
|
+
def self.inject(klass)
|
7
|
+
this_class = self
|
8
|
+
klass.after_filter self, :if => lambda {|c| this_class.condition?(c) }
|
9
|
+
end
|
10
|
+
|
11
|
+
def condition?
|
12
|
+
request.docomo? && %r{text/html} =~ response.content_type
|
13
|
+
end
|
14
|
+
|
15
|
+
def filter
|
16
|
+
response.content_type = 'application/xhtml+xml'
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Set template format to xhtml. This method of setting the format is rails
|
2
|
+
# specific so leave a filter
|
3
|
+
class Galakei::Filter::Haml < Galakei::Filter::Base
|
4
|
+
def self.inject(klass)
|
5
|
+
klass.around_filter self, :if => :galakei?
|
6
|
+
end
|
7
|
+
|
8
|
+
def filter
|
9
|
+
old_format = ::Haml::Template.options[:format]
|
10
|
+
::Haml::Template.options[:format] = :xhtml
|
11
|
+
yield
|
12
|
+
ensure
|
13
|
+
::Haml::Template.options[:format] = old_format
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class Galakei::Filter::SessionIdParameter < Galakei::Filter::Base
|
2
|
+
def self.inject(klass)
|
3
|
+
klass.before_filter self
|
4
|
+
end
|
5
|
+
|
6
|
+
def filter
|
7
|
+
key = ::Rails.application.config.session_options[:key]
|
8
|
+
if device_needs_session_param_in_url?
|
9
|
+
session[:_dummy_param_to_force_session_init] = nil
|
10
|
+
logger.debug("adding session param '#{key}' to default_url_options")
|
11
|
+
default_url_options[key] = request.session_options[:id]
|
12
|
+
else
|
13
|
+
# workaround for issue in rails 3.0.3: default_url_options aren't cleared
|
14
|
+
default_url_options.delete(key)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def device_needs_session_param_in_url?
|
21
|
+
galakei? && !request.cookies? && session
|
22
|
+
end
|
23
|
+
|
24
|
+
def default_url_options
|
25
|
+
controller.send :default_url_options
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Galakei
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
config.galakei = ActiveSupport::OrderedOptions.new
|
4
|
+
config.galakei.session_id_parameter = false
|
5
|
+
initializer "galakei.extend.action_controller" do |app|
|
6
|
+
ActiveSupport.on_load :action_controller do
|
7
|
+
include Galakei::HelperMethods
|
8
|
+
filters = %w[Views ContentType]
|
9
|
+
filters << :Haml if defined?(Haml)
|
10
|
+
filters << :SessionIdParameter if app.config.galakei.session_id_parameter
|
11
|
+
filters.each {|f| Galakei::Filter.const_get(f).inject(self) }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "rack/request"
|
2
|
+
|
3
|
+
module Galakei
|
4
|
+
module Request
|
5
|
+
def docomo?
|
6
|
+
/DoCoMo/i =~ user_agent
|
7
|
+
end
|
8
|
+
|
9
|
+
def au?
|
10
|
+
# doesn't detect some 2G phones, but as they will be discontinued soon, doesn't really matter
|
11
|
+
/KDDI/ =~ user_agent
|
12
|
+
end
|
13
|
+
|
14
|
+
def softbank?
|
15
|
+
/^(SoftBank|Vodafone)/ =~ user_agent
|
16
|
+
end
|
17
|
+
|
18
|
+
def cookies?
|
19
|
+
!imode_browser_1_0?
|
20
|
+
end
|
21
|
+
|
22
|
+
def imode_browser_1_0?
|
23
|
+
if /docomo(.*\((.*;)?c(\d+)\;)?/i =~ user_agent
|
24
|
+
$3.to_i < 500
|
25
|
+
else
|
26
|
+
false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def galakei?
|
31
|
+
docomo? || au? || softbank?
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
Rack::Request.send :include, Galakei::Request
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class ActionController::TestCase
|
2
|
+
class << self
|
3
|
+
{:pc => "mozilla", :galakei => "DoCoMo/2.0 SH06A3(c500;TB;W24H14)"}.each do |method, user_agent|
|
4
|
+
class_eval(<<-EOD)
|
5
|
+
def with_#{method}(&block)
|
6
|
+
context("with #{method} browser") do
|
7
|
+
setup { @request.user_agent = '#{user_agent}' }
|
8
|
+
merge_block(&block)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
EOD
|
12
|
+
end
|
13
|
+
def with_pc_and_galakei(&block)
|
14
|
+
with_pc(&block)
|
15
|
+
with_galakei(&block)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
data/lib/galakei.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'galakei/railtie' if defined?(Rails)
|
2
|
+
require 'galakei/request'
|
3
|
+
|
4
|
+
module Galakei
|
5
|
+
autoload :Email, "galakei/email"
|
6
|
+
autoload :HelperMethods, "galakei/helper_methods"
|
7
|
+
module Filter
|
8
|
+
autoload :Base, "galakei/filter/base"
|
9
|
+
autoload :ContentType, "galakei/filter/content_type"
|
10
|
+
autoload :Haml, "galakei/filter/haml"
|
11
|
+
autoload :Views, "galakei/filter/views"
|
12
|
+
autoload :SessionIdParameter, "galakei/filter/session_id_parameter"
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: galakei
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Paul McMahon
|
14
|
+
- Michael Reinsch
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2011-01-07 00:00:00 +09:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: actionpack
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 1
|
31
|
+
segments:
|
32
|
+
- 3
|
33
|
+
- 0
|
34
|
+
- 3
|
35
|
+
version: 3.0.3
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id001
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: rack
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 29
|
47
|
+
segments:
|
48
|
+
- 1
|
49
|
+
- 2
|
50
|
+
- 1
|
51
|
+
version: 1.2.1
|
52
|
+
type: :runtime
|
53
|
+
version_requirements: *id002
|
54
|
+
description: Japanese feature phones (a.k.a., keitai, galakei) have a number of restrictions over normal web browsers. This library adds support for them
|
55
|
+
email: info@mobalean.com
|
56
|
+
executables: []
|
57
|
+
|
58
|
+
extensions: []
|
59
|
+
|
60
|
+
extra_rdoc_files: []
|
61
|
+
|
62
|
+
files:
|
63
|
+
- LICENSE
|
64
|
+
- README.md
|
65
|
+
- lib/galakei/email.rb
|
66
|
+
- lib/galakei/filter/base.rb
|
67
|
+
- lib/galakei/filter/content_type.rb
|
68
|
+
- lib/galakei/filter/haml.rb
|
69
|
+
- lib/galakei/filter/session_id_parameter.rb
|
70
|
+
- lib/galakei/filter/views.rb
|
71
|
+
- lib/galakei/helper_methods.rb
|
72
|
+
- lib/galakei/railtie.rb
|
73
|
+
- lib/galakei/request.rb
|
74
|
+
- lib/galakei/shoulda_macros.rb
|
75
|
+
- lib/galakei.rb
|
76
|
+
has_rdoc: true
|
77
|
+
homepage: http://www.mobalean.com
|
78
|
+
licenses: []
|
79
|
+
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
hash: 3
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
version: "0"
|
103
|
+
requirements: []
|
104
|
+
|
105
|
+
rubyforge_project: "[none]"
|
106
|
+
rubygems_version: 1.3.7
|
107
|
+
signing_key:
|
108
|
+
specification_version: 3
|
109
|
+
summary: Japanese feature phones support
|
110
|
+
test_files: []
|
111
|
+
|