jpmobile 0.0.8 → 0.1.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. data/.gitignore +0 -3
  2. data/{spec/spec.opts → .rspec} +1 -2
  3. data/README.rdoc +122 -128
  4. data/Rakefile +23 -101
  5. data/VERSION.yml +4 -3
  6. data/jpmobile.gemspec +130 -182
  7. data/lib/jpmobile.rb +37 -24
  8. data/lib/jpmobile/docomo_guid.rb +2 -1
  9. data/lib/jpmobile/email.rb +3 -4
  10. data/lib/jpmobile/emoticon.rb +2 -6
  11. data/lib/jpmobile/encoding.rb +29 -0
  12. data/lib/jpmobile/filter.rb +42 -134
  13. data/lib/jpmobile/helpers.rb +5 -18
  14. data/lib/jpmobile/hook_action_controller.rb +24 -16
  15. data/lib/jpmobile/hook_action_view.rb +28 -89
  16. data/lib/jpmobile/mobile/abstract_mobile.rb +21 -4
  17. data/lib/jpmobile/mobile/android.rb +10 -0
  18. data/lib/jpmobile/mobile/au.rb +28 -3
  19. data/lib/jpmobile/mobile/ddipocket.rb +12 -0
  20. data/lib/jpmobile/mobile/display.rb +29 -26
  21. data/lib/jpmobile/mobile/docomo.rb +38 -12
  22. data/lib/jpmobile/mobile/iphone.rb +26 -0
  23. data/lib/jpmobile/mobile/smart_phone.rb +21 -0
  24. data/lib/jpmobile/mobile/softbank.rb +16 -41
  25. data/lib/jpmobile/mobile/vodafone.rb +17 -0
  26. data/lib/jpmobile/mobile/willcom.rb +1 -10
  27. data/lib/jpmobile/mobile/windows_phone.rb +10 -0
  28. data/lib/jpmobile/position.rb +4 -3
  29. data/lib/jpmobile/rack.rb +43 -0
  30. data/lib/jpmobile/rack/filter.rb +51 -0
  31. data/lib/jpmobile/rack/mobile_carrier.rb +33 -0
  32. data/lib/jpmobile/rack/params_filter.rb +47 -0
  33. data/lib/jpmobile/rails.rb +22 -0
  34. data/lib/jpmobile/request_with_mobile.rb +8 -12
  35. data/lib/jpmobile/trans_sid.rb +44 -26
  36. data/lib/jpmobile/util.rb +68 -0
  37. data/{tasks → lib/tasks}/jpmobile_tasks.rake +32 -13
  38. data/spec/rack/jpmobile/android_spec.rb +20 -0
  39. data/spec/rack/jpmobile/au_spec.rb +206 -0
  40. data/spec/rack/jpmobile/docomo_spec.rb +237 -0
  41. data/spec/rack/jpmobile/emoticon_spec.rb +215 -0
  42. data/spec/rack/jpmobile/filter_spec.rb +181 -0
  43. data/spec/rack/jpmobile/iphone_spec.rb +32 -0
  44. data/spec/rack/jpmobile/mobile_by_ua_spec.rb +39 -0
  45. data/spec/rack/jpmobile/params_filter_spec.rb +193 -0
  46. data/spec/rack/jpmobile/softbank_spec.rb +123 -0
  47. data/spec/rack/jpmobile/willcom_spec.rb +67 -0
  48. data/spec/rack/jpmobile/windows_phone.rb +20 -0
  49. data/spec/rack_helper.rb +86 -0
  50. data/spec/spec_helper.rb +3 -2
  51. data/spec/unit/detect_by_email_spec.rb +21 -27
  52. data/spec/unit/is_carrier_spec.rb +56 -84
  53. data/spec/unit/spec_helper.rb +1 -2
  54. data/spec/unit/util_spec.rb +2 -2
  55. data/spec/unit/valid_ip_spec.rb +43 -52
  56. data/test/legacy/autoload_test.rb +1 -3
  57. data/test/legacy/emoticon_test.rb +5 -6
  58. data/test/legacy/helper.rb +0 -71
  59. data/test/rails/overrides/.rspec +5 -0
  60. data/test/rails/overrides/Gemfile +32 -0
  61. data/test/rails/overrides/app/controllers/docomo_guid_always_controller.rb +3 -0
  62. data/test/rails/overrides/app/controllers/docomo_guid_base_controller.rb +5 -0
  63. data/test/rails/overrides/app/controllers/docomo_guid_docomo_controller.rb +3 -0
  64. data/test/rails/overrides/app/controllers/filter_controller.rb +0 -34
  65. data/test/rails/overrides/app/controllers/filter_controller_base.rb +19 -0
  66. data/test/rails/overrides/app/controllers/hankaku_filter_controller.rb +3 -0
  67. data/test/rails/overrides/app/controllers/links_controller.rb +28 -0
  68. data/test/rails/overrides/app/controllers/mobile_spec_controller.rb +1 -1
  69. data/test/rails/overrides/app/controllers/template_path_controller.rb +3 -0
  70. data/test/rails/overrides/app/controllers/trans_sid_always_and_session_off_controller.rb +4 -0
  71. data/test/rails/overrides/app/controllers/trans_sid_always_controller.rb +3 -0
  72. data/test/rails/overrides/app/controllers/trans_sid_base_controller.rb +18 -0
  73. data/test/rails/overrides/app/controllers/trans_sid_mobile_controller.rb +3 -0
  74. data/test/rails/overrides/app/controllers/trans_sid_none_controller.rb +3 -0
  75. data/test/rails/overrides/app/views/links/au_gps.html.erb +1 -0
  76. data/test/rails/overrides/app/views/links/au_location.html.erb +1 -0
  77. data/test/rails/overrides/app/views/links/docomo_foma_gps.html.erb +1 -0
  78. data/test/rails/overrides/app/views/links/docomo_openiarea.html.erb +1 -0
  79. data/test/rails/overrides/app/views/links/docomo_utn.html.erb +1 -0
  80. data/test/rails/overrides/app/views/links/link.html.erb +1 -0
  81. data/test/rails/overrides/app/views/links/show_all.html.erb +1 -0
  82. data/test/rails/overrides/app/views/links/softbank_location.html.erb +1 -0
  83. data/test/rails/overrides/app/views/links/willcom_location.html.erb +1 -0
  84. data/test/rails/overrides/app/views/template_path/_partial_smart_phone.html.erb +1 -0
  85. data/test/rails/overrides/app/views/template_path/_partial_smart_phone_iphone.html.erb +1 -0
  86. data/test/rails/overrides/app/views/template_path/index_smart_phone.html.erb +1 -0
  87. data/test/rails/overrides/app/views/template_path/index_smart_phone_iphone.html.erb +1 -0
  88. data/test/rails/overrides/app/views/template_path/show_mobile.html.erb +1 -0
  89. data/test/rails/overrides/app/views/template_path/show_mobile_docomo.html.erb +1 -0
  90. data/test/rails/overrides/autotest/discover.rb +2 -0
  91. data/test/rails/overrides/config/initializers/jpmobile_generator.rb +1 -0
  92. data/test/rails/overrides/config/routes.rb +58 -0
  93. data/test/rails/overrides/db/migrate/001_add_sessions_table.rb +16 -0
  94. data/test/rails/overrides/spec/helpers/helpers_spec.rb +2 -2
  95. data/test/rails/overrides/spec/{controllers → requests}/docomo_guid_spec.rb +37 -14
  96. data/test/rails/overrides/spec/{controllers → requests}/docomo_spec.rb +11 -8
  97. data/test/rails/overrides/spec/{controllers → requests}/emobile_spec.rb +24 -8
  98. data/test/rails/overrides/spec/requests/filter_spec.rb +171 -0
  99. data/test/rails/overrides/spec/requests/helpers_spec.rb +187 -0
  100. data/test/rails/overrides/spec/requests/pc_spec.rb +22 -0
  101. data/test/rails/overrides/spec/requests/softbank_emulator_spec.rb +21 -0
  102. data/test/rails/overrides/spec/requests/template_path_spec.rb +234 -0
  103. data/test/rails/overrides/spec/requests/trans_sid_spec.rb +142 -0
  104. data/test/rails/overrides/spec/spec_helper.rb +17 -48
  105. data/test/sinatra/guestbook.rb +40 -0
  106. data/test/sinatra/test/filter_test.rb +39 -0
  107. metadata +185 -312
  108. data/lib/jpmobile/hook_request.rb +0 -5
  109. data/lib/jpmobile/rack/auth.rb +0 -55
  110. data/lib/jpmobile/rack/combined_logger.rb +0 -54
  111. data/lib/jpmobile/rack/request.rb +0 -7
  112. data/lib/jpmobile/rack/trans_sid.rb +0 -14
  113. data/lib/jpmobile/version.rb +0 -9
  114. data/spec/unit/detect_by_ua_spec.rb +0 -40
  115. data/test/legacy/au_test.rb +0 -173
  116. data/test/legacy/docomo_test.rb +0 -187
  117. data/test/legacy/emoticon_functional_test.rb +0 -195
  118. data/test/legacy/filter_test.rb +0 -34
  119. data/test/legacy/helpers_test.rb +0 -217
  120. data/test/legacy/softbank_test.rb +0 -183
  121. data/test/legacy/willcom_test.rb +0 -56
  122. data/test/rails/2.3.2/spec/controllers/trans_sid_spec.rb +0 -99
  123. data/test/rails/overrides/app/controllers/docomo_guid_controller.rb +0 -13
  124. data/test/rails/overrides/app/controllers/trans_sid_controller.rb +0 -28
  125. data/test/rails/overrides/lib/tasks/rspec.rake +0 -165
  126. data/test/rails/overrides/spec/controllers/filter_spec.rb +0 -159
  127. data/test/rails/overrides/spec/controllers/pc_spec.rb +0 -13
  128. data/test/rails/overrides/spec/controllers/softbank_emulator_spec.rb +0 -42
  129. data/test/rails/overrides/spec/controllers/template_path_spec.rb +0 -117
  130. data/test/rails/overrides/spec/controllers/trans_sid_spec.rb +0 -117
  131. data/test/rails/overrides/spec/rspec.rake +0 -165
  132. data/test/rails/overrides/spec/spec.opts +0 -4
@@ -1,9 +1,11 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require 'ipaddr'
2
3
 
3
4
  module Jpmobile::Mobile
4
5
  # 携帯電話の抽象クラス。
5
6
  class AbstractMobile
6
- def initialize(request)
7
+ def initialize(env, request)
8
+ @env = env
7
9
  @request = request
8
10
  end
9
11
 
@@ -37,7 +39,7 @@ module Jpmobile::Mobile
37
39
  end
38
40
 
39
41
  def valid_ip?
40
- @__valid_ip ||= self.class.valid_ip? @request.remote_addr
42
+ @__valid_ip ||= self.class.valid_ip? @request.ip
41
43
  end
42
44
 
43
45
  # 画面情報を +Display+ クラスのインスタンスで返す。
@@ -50,10 +52,25 @@ module Jpmobile::Mobile
50
52
  return false
51
53
  end
52
54
 
55
+ # smartphone かどうか
56
+ def smart_phone?
57
+ false
58
+ end
59
+
60
+ # エンコーディング変換用
61
+ def to_internal(str)
62
+ str
63
+ end
64
+ def to_external(str, content_type, charset)
65
+ [str, charset]
66
+ end
67
+ def default_charset
68
+ "UTF-8"
69
+ end
53
70
  # リクエストがこのクラスに属するか調べる
54
71
  # メソッド名に関して非常に不安
55
- def self.check_request(request)
56
- self::USER_AGENT_REGEXP && request.user_agent =~ self::USER_AGENT_REGEXP
72
+ def self.check_carrier(env)
73
+ self::USER_AGENT_REGEXP && env['HTTP_USER_AGENT'] =~ self::USER_AGENT_REGEXP
57
74
  end
58
75
 
59
76
  #XXX: lib/jpmobile.rbのautoloadで先に各キャリアの定数を定義しているから動くのです
@@ -0,0 +1,10 @@
1
+ # -*- coding: utf-8 -*-
2
+ # =Android
3
+
4
+ module Jpmobile::Mobile
5
+ # ==Android
6
+ class Android < SmartPhone
7
+ # 対応するUser-Agentの正規表現
8
+ USER_AGENT_REGEXP = /Android/
9
+ end
10
+ end
@@ -1,8 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # =au携帯電話
3
3
 
4
- require 'ipaddr'
5
-
6
4
  module Jpmobile::Mobile
7
5
  # ==au携帯電話
8
6
  # CDMA 1X, CDMA 1X WINを含む。
@@ -68,7 +66,7 @@ module Jpmobile::Mobile
68
66
  a = r.split(/,/)
69
67
  cols = 2 ** a[0].to_i
70
68
  end
71
- @__display = Jpmobile::Display.new(p_w, p_h, nil, nil, col_p, cols)
69
+ @__display = Jpmobile::Mobile::Display.new(p_w, p_h, nil, nil, col_p, cols)
72
70
  end
73
71
 
74
72
  # デバイスIDを返す
@@ -99,5 +97,32 @@ module Jpmobile::Mobile
99
97
  true
100
98
  end
101
99
  end
100
+
101
+ # 文字コード変換
102
+ def to_internal(str)
103
+ # 絵文字を数値参照に変換
104
+ str = Jpmobile::Emoticon.external_to_unicodecr_au(Jpmobile::Util.sjis(str))
105
+ # 文字コードを UTF-8 に変換
106
+ str = Jpmobile::Util.sjis_to_utf8(str)
107
+ # 数値参照を UTF-8 に変換
108
+ Jpmobile::Emoticon::unicodecr_to_utf8(str)
109
+ # 半角->全角変換
110
+ end
111
+ def to_external(str, content_type, charset)
112
+ # UTF-8を数値参照に
113
+ str = Jpmobile::Emoticon.utf8_to_unicodecr(str)
114
+ # 文字コードを Shift_JIS に変換
115
+ if [nil, "text/html", "application/xhtml+xml"].include?(content_type)
116
+ str = Jpmobile::Util.utf8_to_sjis(str)
117
+ charset = default_charset unless str.empty?
118
+ end
119
+ # 数値参照を絵文字コードに変換
120
+ str = Jpmobile::Emoticon.unicodecr_to_external(str, Jpmobile::Emoticon::CONVERSION_TABLE_TO_AU, true)
121
+
122
+ [str, charset]
123
+ end
124
+ def default_charset
125
+ "Shift_JIS"
126
+ end
102
127
  end
103
128
  end
@@ -0,0 +1,12 @@
1
+ # -*- coding: utf-8 -*-
2
+ # =DDI-POCKET
3
+ module Jpmobile::Mobile
4
+ # ==DDI-POCKET
5
+ # スーパクラスはWillcom。
6
+ class Ddipocket < Willcom
7
+ # 対応するUser-Agentの正規表現
8
+ USER_AGENT_REGEXP = /^Mozilla\/3.0\(DDIPOCKET/
9
+
10
+ MAIL_ADDRESS_REGEXP = nil # DdipocketはEmail判定だとWillcomと判定させたい
11
+ end
12
+ end
@@ -1,33 +1,36 @@
1
+ # -*- coding: utf-8 -*-
1
2
  # = 端末のディスプレイに関する情報
2
3
  # request.mobile.display
3
4
  # で取得できる。
4
5
  module Jpmobile
5
- # ディスプレイ情報
6
- class Display
7
- def initialize(physical_width=nil, physical_height=nil, browser_width=nil, browser_height=nil, color_p=nil, colors=nil) # :nodoc:
8
- @physical_width = physical_width
9
- @physical_height = physical_height
10
- @browser_width = browser_width
11
- @browser_height = browser_height
12
- @colors = colors
13
- @color_p = color_p
6
+ module Mobile
7
+ # ディスプレイ情報
8
+ class Display
9
+ def initialize(physical_width=nil, physical_height=nil, browser_width=nil, browser_height=nil, color_p=nil, colors=nil) # :nodoc:
10
+ @physical_width = physical_width
11
+ @physical_height = physical_height
12
+ @browser_width = browser_width
13
+ @browser_height = browser_height
14
+ @colors = colors
15
+ @color_p = color_p
16
+ end
17
+
18
+ # 画面がカラーならば +true+、白黒ならば +false+ を返す。不明の場合は +nil+。
19
+ def color?; @color_p; end
20
+ # 画面の色数を返す。不明の場合は +nil+。
21
+ def colors; @colors; end
22
+ # ディスプレイの画面幅を返す。不明の場合は +nil+。
23
+ def physical_width; @physical_width; end
24
+ # ディスプレイの画面高さを返す。不明の場合は +nil+。
25
+ def physical_height; @physical_height; end
26
+ # ブラウザの画面幅を返す。不明の場合は +nil+。
27
+ def browser_width; @browser_width; end
28
+ # ブラウザの画面高さを返す。不明の場合は +nil+。
29
+ def browser_height; @browser_height; end
30
+ # 画面の幅を返す。ブラウザ画面の幅がわかる場合はそれを優先する。不明の場合は +nil+。
31
+ def width; browser_width || physical_width; end
32
+ # 画面の高さを返す。ブラウザ画面の高さがわかる場合はそれを優先する。不明の場合は +nil+。
33
+ def height; browser_height || physical_height; end
14
34
  end
15
-
16
- # 画面がカラーならば +true+、白黒ならば +false+ を返す。不明の場合は +nil+。
17
- def color?; @color_p; end
18
- # 画面の色数を返す。不明の場合は +nil+。
19
- def colors; @colors; end
20
- # ディスプレイの画面幅を返す。不明の場合は +nil+。
21
- def physical_width; @physical_width; end
22
- # ディスプレイの画面高さを返す。不明の場合は +nil+。
23
- def physical_height; @physical_height; end
24
- # ブラウザの画面幅を返す。不明の場合は +nil+。
25
- def browser_width; @browser_width; end
26
- # ブラウザの画面高さを返す。不明の場合は +nil+。
27
- def browser_height; @browser_height; end
28
- # 画面の幅を返す。ブラウザ画面の幅がわかる場合はそれを優先する。不明の場合は +nil+。
29
- def width; browser_width || physical_width; end
30
- # 画面の高さを返す。ブラウザ画面の高さがわかる場合はそれを優先する。不明の場合は +nil+。
31
- def height; browser_height || physical_height; end
32
35
  end
33
36
  end
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  # =DoCoMo携帯電話
2
3
 
3
4
  module Jpmobile::Mobile
@@ -38,7 +39,7 @@ module Jpmobile::Mobile
38
39
 
39
40
  # 端末製造番号があれば返す。無ければ +nil+ を返す。
40
41
  def serial_number
41
- case @request.env["HTTP_USER_AGENT"]
42
+ case @env["HTTP_USER_AGENT"]
42
43
  when /ser([0-9a-zA-Z]{11})$/ # mova
43
44
  return $1
44
45
  when /ser([0-9a-zA-Z]{15});/ # FOMA
@@ -51,13 +52,13 @@ module Jpmobile::Mobile
51
52
 
52
53
  # FOMAカード製造番号があれば返す。無ければ +nil+ を返す。
53
54
  def icc
54
- @request.env['HTTP_USER_AGENT'] =~ /icc([0-9a-zA-Z]{20})\)/
55
+ @env['HTTP_USER_AGENT'] =~ /icc([0-9a-zA-Z]{20})\)/
55
56
  return $1
56
57
  end
57
58
 
58
59
  # iモードIDを返す。
59
60
  def guid
60
- @request.env['HTTP_X_DCMGUID']
61
+ @env['HTTP_X_DCMGUID']
61
62
  end
62
63
 
63
64
  # iモードID, FOMAカード製造番号の順で調べ、あるものを返す。なければ +nil+ を返す。
@@ -67,11 +68,11 @@ module Jpmobile::Mobile
67
68
 
68
69
  # 画面情報を +Display+ クラスのインスタンスで返す。
69
70
  def display
70
- @__display ||= Jpmobile::Display.new(nil,nil,
71
- display_info[:browser_width],
72
- display_info[:browser_height],
73
- display_info[:color_p],
74
- display_info[:colors])
71
+ @__display ||= Jpmobile::Mobile::Display.new(nil,nil,
72
+ display_info[:browser_width],
73
+ display_info[:browser_height],
74
+ display_info[:color_p],
75
+ display_info[:colors])
75
76
  end
76
77
 
77
78
  # cookieに対応しているか?
@@ -79,6 +80,32 @@ module Jpmobile::Mobile
79
80
  imode_browser_version != '1.0'
80
81
  end
81
82
 
83
+ # 文字コード変換
84
+ def to_internal(str)
85
+ # 絵文字を数値参照に変換
86
+ str = Jpmobile::Emoticon.external_to_unicodecr_docomo(Jpmobile::Util.sjis(str))
87
+ # 文字コードを UTF-8 に変換
88
+ str = Jpmobile::Util.sjis_to_utf8(str)
89
+ # 数値参照を UTF-8 に変換
90
+ Jpmobile::Emoticon.unicodecr_to_utf8(str)
91
+ end
92
+ def to_external(str, content_type, charset)
93
+ # UTF-8を数値参照に
94
+ str = Jpmobile::Emoticon.utf8_to_unicodecr(str)
95
+ # 文字コードを Shift_JIS に変換
96
+ if [nil, "text/html", "application/xhtml+xml"].include?(content_type)
97
+ str = Jpmobile::Util.utf8_to_sjis(str)
98
+ charset = default_charset unless str.empty?
99
+ end
100
+ # 数値参照を絵文字コードに変換
101
+ str = Jpmobile::Emoticon.unicodecr_to_external(str, Jpmobile::Emoticon::CONVERSION_TABLE_TO_DOCOMO, true)
102
+
103
+ [str, charset]
104
+ end
105
+ def default_charset
106
+ "Shift_JIS"
107
+ end
108
+
82
109
  # i-mode ブラウザのバージョンを返す。
83
110
  # http://labs.unoh.net/2009/07/i_20.html
84
111
  def imode_browser_version
@@ -90,7 +117,7 @@ module Jpmobile::Mobile
90
117
  @request.env['HTTP_USER_AGENT'] =~ / (\w+)\(c(\d+);/
91
118
  model = $1
92
119
  cache_size = $2.to_i
93
-
120
+
94
121
  ver = cache_size >= 500 ? (%w(P03B P05B L01B).member?(model) ? '2.0LE' : '2.0') : '1.0'
95
122
  else
96
123
  # DoCoMo/3.0以降等は、とりあえず非v1.0扱い
@@ -100,13 +127,12 @@ module Jpmobile::Mobile
100
127
  ver
101
128
  end
102
129
 
103
-
104
130
  private
105
131
  # モデル名を返す。
106
132
  def model_name
107
- if @request.env["HTTP_USER_AGENT"] =~ /^DoCoMo\/2.0 (.+)\(/
133
+ if @env["HTTP_USER_AGENT"] =~ /^DoCoMo\/2.0 (.+)\(/
108
134
  return $1
109
- elsif @request.env["HTTP_USER_AGENT"] =~ /^DoCoMo\/1.0\/(.+?)\//
135
+ elsif @env["HTTP_USER_AGENT"] =~ /^DoCoMo\/1.0\/(.+?)\//
110
136
  return $1
111
137
  end
112
138
  return nil
@@ -0,0 +1,26 @@
1
+ # -*- coding: utf-8 -*-
2
+ # =iPhone
3
+
4
+ module Jpmobile::Mobile
5
+ # ==iPhone
6
+ class Iphone < SmartPhone
7
+ # 対応するUser-Agentの正規表現
8
+ USER_AGENT_REGEXP = /iPhone/
9
+
10
+ # 文字コード変換
11
+ def to_internal(str)
12
+ # 絵文字を数値参照に変換
13
+ str = Jpmobile::Emoticon.external_to_unicodecr_softbank(Jpmobile::Util.utf8(str))
14
+ # 数値参照を UTF-8 に変換
15
+ Jpmobile::Emoticon.unicodecr_to_utf8(str)
16
+ end
17
+ def to_external(str, content_type, charset)
18
+ # UTF-8を数値参照に
19
+ str = Jpmobile::Emoticon.utf8_to_unicodecr(str)
20
+ # 数値参照を絵文字コードに変換
21
+ str = Jpmobile::Emoticon.unicodecr_to_external(str, Jpmobile::Emoticon::CONVERSION_TABLE_TO_SOFTBANK, false)
22
+
23
+ [str, charset]
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ # -*- coding: utf-8 -*-
2
+ # =スマートフォンの親クラス
3
+
4
+ module Jpmobile::Mobile
5
+ class SmartPhone < AbstractMobile
6
+ # 無効化
7
+ def valid_ip?
8
+ false
9
+ end
10
+
11
+ # cookie は有効と見なす
12
+ def supports_cookie?
13
+ true
14
+ end
15
+
16
+ # smartphone なので true
17
+ def smart_phone?
18
+ true
19
+ end
20
+ end
21
+ end
@@ -1,11 +1,9 @@
1
+ # -*- coding: utf-8 -*-
1
2
  # =SoftBank携帯電話
2
- # J-PHONE, Vodafoneを含む
3
-
4
- require 'nkf'
5
-
3
+ # Vodafoneを含む
6
4
  module Jpmobile::Mobile
7
5
  # ==Softbank携帯電話
8
- # Vodafone, Jphoneのスーパクラス。
6
+ # Vodafoneのスーパクラス。
9
7
  class Softbank < AbstractMobile
10
8
  autoload :IP_ADDRESSES, 'jpmobile/mobile/z_ip_addresses_softbank'
11
9
 
@@ -60,51 +58,28 @@ module Jpmobile::Mobile
60
58
  cols = $1.to_i
61
59
  end
62
60
  end
63
- @__display = Jpmobile::Display.new(p_w, p_h, nil, nil, col_p, cols)
61
+ @__display = Jpmobile::Mobile::Display.new(p_w, p_h, nil, nil, col_p, cols)
64
62
  end
65
63
 
66
64
  # cookieに対応しているか?
67
65
  def supports_cookie?
68
66
  true
69
67
  end
70
- end
71
- # ==Vodafone 3G携帯電話(J-PHONE, SoftBank含まず)
72
- # スーパクラスはSoftbank。
73
- class Vodafone < Softbank
74
- # 対応するUser-Agentの正規表現
75
- USER_AGENT_REGEXP = /^(Vodafone|Vemulator)/
76
- # 対応するメールアドレスの正規表現
77
- MAIL_ADDRESS_REGEXP = /^.+@[dhtcrknsq]\.vodafone\.ne\.jp$/
78
68
 
79
- # cookieに対応しているか?
80
- def supports_cookie?
81
- true
69
+ # 文字コード変換
70
+ def to_internal(str)
71
+ # 絵文字を数値参照に変換
72
+ str = Jpmobile::Emoticon.external_to_unicodecr_softbank(Jpmobile::Util.utf8(str))
73
+ # 数値参照を UTF-8 に変換
74
+ Jpmobile::Emoticon::unicodecr_to_utf8(str)
82
75
  end
83
- end
84
- # ==SoftBank 2G携帯電話(J-PHONE/Vodafone 2G)
85
- # スーパクラスはVodafone。
86
- class Jphone < Vodafone
87
- # 対応するUser-Agentの正規表現
88
- USER_AGENT_REGEXP = /^(J-PHONE|J-EMULATOR)/
89
- # 対応するメールアドレスの正規表現
90
- MAIL_ADDRESS_REGEXP = /^.+@jp-[dhtcrknsq]\.ne\.jp$/
76
+ def to_external(str, content_type, charset)
77
+ # UTF-8を数値参照に
78
+ str = Jpmobile::Emoticon.utf8_to_unicodecr(str)
79
+ # 数値参照を絵文字コードに変換
80
+ str = Jpmobile::Emoticon.unicodecr_to_external(str, Jpmobile::Emoticon::CONVERSION_TABLE_TO_SOFTBANK, false)
91
81
 
92
- # 位置情報があれば Position のインスタンスを返す。無ければ +nil+ を返す。
93
- def position
94
- str = @request.env["HTTP_X_JPHONE_GEOCODE"]
95
- return nil if str.nil? || str == "0000000%1A0000000%1A%88%CA%92%75%8F%EE%95%F1%82%C8%82%B5"
96
- raise "unsuppoted format" unless str =~ /^(\d\d)(\d\d)(\d\d)%1A(\d\d\d)(\d\d)(\d\d)%1A(.+)$/
97
- pos = Jpmobile::Position.new
98
- pos.lat = Jpmobile::Position.dms2deg($1,$2,$3)
99
- pos.lon = Jpmobile::Position.dms2deg($4,$5,$6)
100
- pos.options = {"address"=>NKF.nkf("-m0 -Sw", CGI.unescape($7))}
101
- pos.tokyo2wgs84!
102
- return pos
103
- end
104
-
105
- # cookieに対応しているか?
106
- def supports_cookie?
107
- false
82
+ [str, charset]
108
83
  end
109
84
  end
110
85
  end
@@ -0,0 +1,17 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Vodafone
3
+ module Jpmobile::Mobile
4
+ # ==Vodafone 3G携帯電話(SoftBank含まず)
5
+ # スーパクラスはSoftbank。
6
+ class Vodafone < Softbank
7
+ # 対応するUser-Agentの正規表現
8
+ USER_AGENT_REGEXP = /^(Vodafone|Vemulator)/
9
+ # 対応するメールアドレスの正規表現
10
+ MAIL_ADDRESS_REGEXP = /^.+@[dhtcrknsq]\.vodafone\.ne\.jp$/
11
+
12
+ # cookieに対応しているか?
13
+ def supports_cookie?
14
+ true
15
+ end
16
+ end
17
+ end
@@ -1,6 +1,5 @@
1
+ # -*- coding: utf-8 -*-
1
2
  # =Willcom携帯電話
2
- # DDI-POCKETを含む。
3
-
4
3
  module Jpmobile::Mobile
5
4
  # ==Willcom携帯電話
6
5
  # Ddipocketのスーパクラス。
@@ -28,12 +27,4 @@ module Jpmobile::Mobile
28
27
  true
29
28
  end
30
29
  end
31
- # ==DDI-POCKET
32
- # スーパクラスはWillcom。
33
- class Ddipocket < Willcom
34
- # 対応するUser-Agentの正規表現
35
- USER_AGENT_REGEXP = /^Mozilla\/3.0\(DDIPOCKET/
36
-
37
- MAIL_ADDRESS_REGEXP = nil # DdipocketはEmail判定だとWillcomと判定させたい
38
- end
39
30
  end