jpmobile 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. data/README.rdoc +227 -0
  2. data/Rakefile +6 -13
  3. data/lib/jpmobile/docomo_guid.rb +42 -0
  4. data/lib/jpmobile/filter.rb +1 -1
  5. data/lib/jpmobile/helpers.rb +2 -1
  6. data/lib/jpmobile/hook_action_controller.rb +12 -0
  7. data/lib/jpmobile/hook_action_view.rb +82 -72
  8. data/lib/jpmobile/{hook_abstract_request.rb → hook_request.rb} +1 -1
  9. data/lib/jpmobile/mobile/au.rb +9 -3
  10. data/lib/jpmobile/mobile/z_display_info_docomo.rb +10 -2
  11. data/lib/jpmobile/mobile/z_ip_addresses_au.rb +1 -26
  12. data/lib/jpmobile/mobile/z_ip_addresses_willcom.rb +2 -4
  13. data/lib/jpmobile/rack/auth.rb +55 -0
  14. data/lib/jpmobile/rack/combined_logger.rb +54 -0
  15. data/lib/jpmobile/rack/request.rb +7 -0
  16. data/lib/jpmobile/rack/trans_sid.rb +14 -0
  17. data/lib/jpmobile/trans_sid.rb +70 -62
  18. data/lib/jpmobile/version.rb +1 -1
  19. data/test/{au_test.rb → legacy/au_test.rb} +0 -0
  20. data/test/{autoload_test.rb → legacy/autoload_test.rb} +0 -0
  21. data/test/{docomo_test.rb → legacy/docomo_test.rb} +0 -0
  22. data/test/{emoticon_functional_test.rb → legacy/emoticon_functional_test.rb} +1 -1
  23. data/test/{emoticon_test.rb → legacy/emoticon_test.rb} +0 -0
  24. data/test/{filter_test.rb → legacy/filter_test.rb} +0 -0
  25. data/test/{helper.rb → legacy/helper.rb} +4 -5
  26. data/test/{helpers_test.rb → legacy/helpers_test.rb} +1 -1
  27. data/test/{softbank_test.rb → legacy/softbank_test.rb} +0 -0
  28. data/test/{willcom_test.rb → legacy/willcom_test.rb} +0 -0
  29. data/test/rails/overrides/app/controllers/application.rb +5 -0
  30. data/test/rails/overrides/app/controllers/docomo_guid_controller.rb +13 -0
  31. data/test/rails/overrides/app/controllers/filter_controller.rb +26 -0
  32. data/test/rails/overrides/app/controllers/mobile_spec_controller.rb +5 -0
  33. data/test/rails/overrides/app/controllers/template_path_controller.rb +6 -0
  34. data/test/rails/overrides/app/controllers/trans_sid_controller.rb +28 -0
  35. data/test/rails/overrides/app/views/filter/index.html.erb +0 -0
  36. data/test/rails/overrides/app/views/hankaku_filter/index.html.erb +0 -0
  37. data/test/rails/overrides/app/views/template_path/_partial.html.erb +1 -0
  38. data/test/rails/overrides/app/views/template_path/_partial_mobile.html.erb +1 -0
  39. data/test/rails/overrides/app/views/template_path/_partial_mobile_docomo.html.erb +1 -0
  40. data/test/rails/overrides/app/views/template_path/index.html.erb +1 -0
  41. data/test/rails/overrides/app/views/template_path/index_mobile.html.erb +1 -0
  42. data/test/rails/overrides/app/views/template_path/index_mobile_docomo.html.erb +1 -0
  43. data/test/rails/overrides/app/views/template_path/partial.html.erb +2 -0
  44. data/test/rails/overrides/lib/tasks/rspec.rake +165 -0
  45. data/test/rails/overrides/spec/controllers/docomo_guid_spec.rb +77 -0
  46. data/test/rails/overrides/spec/controllers/docomo_spec.rb +28 -0
  47. data/test/rails/overrides/spec/controllers/emobile_spec.rb +35 -0
  48. data/test/rails/overrides/spec/controllers/filter_spec.rb +157 -0
  49. data/test/rails/overrides/spec/controllers/pc_spec.rb +11 -0
  50. data/test/rails/overrides/spec/controllers/softbank_emulator_spec.rb +40 -0
  51. data/test/rails/overrides/spec/controllers/template_path_spec.rb +115 -0
  52. data/test/rails/overrides/spec/controllers/trans_sid_spec.rb +98 -0
  53. data/test/rails/overrides/spec/helpers/helpers_spec.rb +13 -0
  54. data/test/rails/overrides/spec/rcov.opts +2 -0
  55. data/test/rails/overrides/spec/rspec.rake +165 -0
  56. data/test/rails/overrides/spec/spec.opts +4 -0
  57. data/test/rails/overrides/spec/spec_helper.rb +47 -0
  58. data/test/rails/rails_root/README +256 -0
  59. data/test/rails/rails_root/Rakefile +10 -0
  60. data/test/rails/rails_root/app/controllers/application.rb +5 -0
  61. data/test/rails/rails_root/app/controllers/docomo_guid_controller.rb +13 -0
  62. data/test/rails/rails_root/app/controllers/filter_controller.rb +26 -0
  63. data/test/rails/rails_root/app/controllers/mobile_spec_controller.rb +5 -0
  64. data/test/rails/rails_root/app/controllers/template_path_controller.rb +6 -0
  65. data/test/rails/rails_root/app/controllers/trans_sid_controller.rb +26 -0
  66. data/test/rails/rails_root/app/helpers/application_helper.rb +3 -0
  67. data/test/rails/rails_root/app/views/template_path/index.html.erb +1 -0
  68. data/test/rails/rails_root/app/views/template_path/index_mobile.html.erb +1 -0
  69. data/test/rails/rails_root/app/views/template_path/index_mobile_docomo.html.erb +1 -0
  70. data/test/rails/rails_root/config/boot.rb +109 -0
  71. data/test/rails/rails_root/config/database.yml +22 -0
  72. data/test/rails/rails_root/config/environment.rb +75 -0
  73. data/test/rails/rails_root/config/environments/development.rb +17 -0
  74. data/test/rails/rails_root/config/environments/production.rb +24 -0
  75. data/test/rails/rails_root/config/environments/test.rb +22 -0
  76. data/test/rails/rails_root/config/initializers/inflections.rb +10 -0
  77. data/test/rails/rails_root/config/initializers/mime_types.rb +5 -0
  78. data/test/rails/rails_root/config/initializers/new_rails_defaults.rb +17 -0
  79. data/test/rails/rails_root/config/locales/en.yml +5 -0
  80. data/test/rails/rails_root/config/routes.rb +43 -0
  81. data/test/rails/rails_root/db/development.sqlite3 +0 -0
  82. data/test/rails/rails_root/db/schema.rb +14 -0
  83. data/test/rails/rails_root/db/test.sqlite3 +0 -0
  84. data/test/rails/rails_root/doc/README_FOR_APP +5 -0
  85. data/test/rails/rails_root/lib/tasks/rspec.rake +165 -0
  86. data/test/rails/rails_root/log/development.log +38 -0
  87. data/test/rails/rails_root/log/production.log +0 -0
  88. data/test/rails/rails_root/log/server.log +0 -0
  89. data/test/rails/rails_root/log/test.log +401 -0
  90. data/test/rails/rails_root/public/404.html +30 -0
  91. data/test/rails/rails_root/public/422.html +30 -0
  92. data/test/rails/rails_root/public/500.html +33 -0
  93. data/test/rails/rails_root/public/dispatch.cgi +10 -0
  94. data/test/rails/rails_root/public/dispatch.fcgi +24 -0
  95. data/test/rails/rails_root/public/dispatch.rb +10 -0
  96. data/test/rails/rails_root/public/favicon.ico +0 -0
  97. data/test/rails/rails_root/public/images/rails.png +0 -0
  98. data/test/rails/rails_root/public/index.html +274 -0
  99. data/test/rails/rails_root/public/javascripts/application.js +2 -0
  100. data/test/rails/rails_root/public/javascripts/controls.js +963 -0
  101. data/test/rails/rails_root/public/javascripts/dragdrop.js +973 -0
  102. data/test/rails/rails_root/public/javascripts/effects.js +1128 -0
  103. data/test/rails/rails_root/public/javascripts/prototype.js +4320 -0
  104. data/test/rails/rails_root/public/robots.txt +5 -0
  105. data/test/rails/rails_root/script/about +4 -0
  106. data/test/rails/rails_root/script/console +3 -0
  107. data/test/rails/rails_root/script/dbconsole +3 -0
  108. data/test/rails/rails_root/script/destroy +3 -0
  109. data/test/rails/rails_root/script/generate +3 -0
  110. data/test/rails/rails_root/script/performance/benchmarker +3 -0
  111. data/test/rails/rails_root/script/performance/profiler +3 -0
  112. data/test/rails/rails_root/script/performance/request +3 -0
  113. data/test/rails/rails_root/script/plugin +3 -0
  114. data/test/rails/rails_root/script/process/inspector +3 -0
  115. data/test/rails/rails_root/script/process/reaper +3 -0
  116. data/test/rails/rails_root/script/process/spawner +3 -0
  117. data/test/rails/rails_root/script/runner +3 -0
  118. data/test/rails/rails_root/script/server +3 -0
  119. data/test/rails/rails_root/spec/controllers/docomo_guid_spec.rb +77 -0
  120. data/test/rails/rails_root/spec/controllers/docomo_spec.rb +28 -0
  121. data/test/rails/rails_root/spec/controllers/emobile_spec.rb +35 -0
  122. data/test/rails/rails_root/spec/controllers/filter_spec.rb +157 -0
  123. data/test/rails/rails_root/spec/controllers/pc_spec.rb +11 -0
  124. data/test/rails/rails_root/spec/controllers/softbank_emulator_spec.rb +40 -0
  125. data/test/rails/rails_root/spec/controllers/template_path_spec.rb +85 -0
  126. data/test/rails/rails_root/spec/controllers/trans_sid_spec.rb +96 -0
  127. data/test/rails/rails_root/spec/helpers/helpers_spec.rb +13 -0
  128. data/test/rails/rails_root/spec/rcov.opts +2 -0
  129. data/test/rails/rails_root/spec/rspec.rake +165 -0
  130. data/test/rails/rails_root/spec/spec.opts +4 -0
  131. data/test/rails/rails_root/spec/spec_helper.rb +47 -0
  132. data/test/rails/rails_root/test/performance/browsing_test.rb +9 -0
  133. data/test/rails/rails_root/test/test_helper.rb +38 -0
  134. data/test/rails/rails_root/vendor/plugins/jpmobile/CHANGELOG +7 -0
  135. data/test/rails/rails_root/vendor/plugins/jpmobile/MIT-LICENSE +7 -0
  136. data/{README → test/rails/rails_root/vendor/plugins/jpmobile/README.rdoc} +15 -17
  137. data/test/rails/rails_root/vendor/plugins/jpmobile/Rakefile +116 -0
  138. data/test/rails/rails_root/vendor/plugins/jpmobile/init.rb +3 -0
  139. data/test/rails/rails_root/vendor/plugins/jpmobile/install.rb +1 -0
  140. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile.rb +42 -0
  141. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/datum_conv.rb +72 -0
  142. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/docomo_guid.rb +42 -0
  143. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/email.rb +19 -0
  144. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon.rb +123 -0
  145. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/au.rb +1287 -0
  146. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/conversion_table.rb +3908 -0
  147. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/docomo.rb +255 -0
  148. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/softbank.rb +477 -0
  149. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/z_combine.rb +20 -0
  150. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/filter.rb +173 -0
  151. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/helpers.rb +185 -0
  152. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/hook_action_controller.rb +11 -0
  153. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/hook_action_view.rb +142 -0
  154. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/hook_request.rb +13 -0
  155. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/abstract_mobile.rb +73 -0
  156. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/au.rb +97 -0
  157. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/display.rb +33 -0
  158. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/docomo.rb +97 -0
  159. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/emobile.rb +17 -0
  160. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/softbank.rb +110 -0
  161. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/willcom.rb +39 -0
  162. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_display_info_docomo.rb +688 -0
  163. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_au.rb +22 -0
  164. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_docomo.rb +12 -0
  165. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_emobile.rb +10 -0
  166. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_softbank.rb +17 -0
  167. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_willcom.rb +117 -0
  168. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/position.rb +67 -0
  169. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/request_with_mobile.rb +44 -0
  170. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/trans_sid.rb +105 -0
  171. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/util.rb +21 -0
  172. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/version.rb +9 -0
  173. data/test/rails/rails_root/vendor/plugins/jpmobile/spec/spec.opts +6 -0
  174. data/test/rails/rails_root/vendor/plugins/jpmobile/spec/spec_helper.rb +36 -0
  175. data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/detect_by_email_spec.rb +31 -0
  176. data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/detect_by_ua_spec.rb +42 -0
  177. data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/is_carrier_spec.rb +93 -0
  178. data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/spec_helper.rb +5 -0
  179. data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/util_spec.rb +28 -0
  180. data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/valid_ip_spec.rb +60 -0
  181. data/test/rails/rails_root/vendor/plugins/jpmobile/tasks/jpmobile_tasks.rake +59 -0
  182. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/emoji/genregexp.rb +47 -0
  183. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/generate_au_emoticon_table.rb +34 -0
  184. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/generate_docomo_emoticon_table.rb +34 -0
  185. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/generate_emoticon_conversion_table.rb +107 -0
  186. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/generate_softbank_emoticon_table.rb +32 -0
  187. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/list_gps_unsupported_au.rb +23 -0
  188. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/update_display_info_docomo.rb +45 -0
  189. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/update_ip_addresses_au.rb +29 -0
  190. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/update_ip_addresses_willcom.rb +17 -0
  191. data/tools/update_ip_addresses_au.rb +15 -5
  192. metadata +188 -22
@@ -0,0 +1,13 @@
1
+ require 'jpmobile/request_with_mobile'
2
+
3
+ if ::ActionPack::VERSION::MAJOR >=2 and ::ActionPack::VERSION::MINOR >= 3
4
+ ### Handle Rails 2.3 case
5
+ class ActionController::Request
6
+ include Jpmobile::RequestWithMobile
7
+ end
8
+ else
9
+ ### Handle Rails 2.2 or lower case
10
+ class ActionController::AbstractRequest
11
+ include Jpmobile::RequestWithMobile
12
+ end
13
+ end
@@ -0,0 +1,73 @@
1
+ require 'ipaddr'
2
+
3
+ module Jpmobile::Mobile
4
+ # 携帯電話の抽象クラス。
5
+ class AbstractMobile
6
+ def initialize(request)
7
+ @request = request
8
+ end
9
+
10
+ # 対応するuser-agentの正規表現
11
+ USER_AGENT_REGEXP = nil
12
+ # 対応するメールアドレスの正規表現
13
+ MAIL_ADDRESS_REGEXP = nil
14
+
15
+ # 緯度経度があれば Position のインスタンスを返す。
16
+ def position; return nil; end
17
+
18
+ # 契約者又は端末を識別する文字列があれば返す。
19
+ def ident; ident_subscriber || ident_device; end
20
+ # 契約者を識別する文字列があれば返す。
21
+ def ident_subscriber; nil; end
22
+ # 端末を識別する文字列があれば返す。
23
+ def ident_device; nil; end
24
+
25
+ # 当該キャリアのIPアドレス帯域からのアクセスであれば +true+ を返す。
26
+ # そうでなければ +false+ を返す。
27
+ # IP空間が定義されていない場合は +nil+ を返す。
28
+ def self.valid_ip? remote_addr
29
+ addrs = nil
30
+ begin
31
+ addrs = self::IP_ADDRESSES
32
+ rescue NameError => e
33
+ return nil
34
+ end
35
+ remote = IPAddr.new(remote_addr)
36
+ addrs.any? {|ip| ip.include? remote }
37
+ end
38
+
39
+ def valid_ip?
40
+ @__valid_ip ||= self.class.valid_ip? @request.remote_addr
41
+ end
42
+
43
+ # 画面情報を +Display+ クラスのインスタンスで返す。
44
+ def display
45
+ @__displlay ||= Jpmobile::Display.new
46
+ end
47
+
48
+ # クッキーをサポートしているか。
49
+ def supports_cookie?
50
+ return false
51
+ end
52
+
53
+ #XXX: lib/jpmobile.rbのautoloadで先に各キャリアの定数を定義しているから動くのです
54
+ Jpmobile::Mobile.carriers.each do |carrier|
55
+ carrier_class = Jpmobile::Mobile.const_get(carrier)
56
+ next if carrier_class == self
57
+
58
+ define_method "#{carrier.downcase}?" do
59
+ self.is_a?(carrier_class)
60
+ end
61
+ end
62
+
63
+ private
64
+ # リクエストのパラメータ。
65
+ def params
66
+ if @request.respond_to? :parameters
67
+ @request.parameters
68
+ else
69
+ @request.params
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,97 @@
1
+ # =au携帯電話
2
+
3
+ require 'ipaddr'
4
+
5
+ module Jpmobile::Mobile
6
+ # ==au携帯電話
7
+ # CDMA 1X, CDMA 1X WINを含む。
8
+ class Au < AbstractMobile
9
+ autoload :IP_ADDRESSES, 'jpmobile/mobile/z_ip_addresses_au'
10
+
11
+ # 対応するUser-Agentの正規表現
12
+ # User-Agent文字列中に "UP.Browser" を含むVodafoneの端末があるので注意が必要
13
+ USER_AGENT_REGEXP = /^(?:KDDI|UP.Browser\/.+?)-(.+?) /
14
+ # 対応するメールアドレスの正規表現
15
+ MAIL_ADDRESS_REGEXP = /^.+@ezweb\.ne\.jp$/
16
+ # 簡易位置情報取得に対応していないデバイスID
17
+ # http://www.au.kddi.com/ezfactory/tec/spec/eznavi.html
18
+ LOCATION_UNSUPPORTED_DEVICE_ID = ["PT21", "TS25", "KCTE", "TST9", "KCU1", "SYT5", "KCTD", "TST8", "TST7", "KCTC", "SYT4", "KCTB", "KCTA", "TST6", "KCT9", "TST5", "TST4", "KCT8", "SYT3", "KCT7", "MIT1", "MAT3", "KCT6", "TST3", "KCT5", "KCT4", "SYT2", "MAT1", "MAT2", "TST2", "KCT3", "KCT2", "KCT1", "TST1", "SYT1"]
19
+ # GPS取得に対応していないデバイスID
20
+ GPS_UNSUPPORTED_DEVICE_ID = ["PT21", "KC26", "SN28", "SN26", "KC23", "SA28", "TS25", "SA25", "SA24", "SN23", "ST14", "KC15", "SN22", "KC14", "ST13", "SN17", "SY15", "CA14", "HI14", "TS14", "KC13", "SN15", "SN16", "SY14", "ST12", "TS13", "CA13", "MA13", "HI13", "SN13", "SY13", "SN12", "SN14", "ST11", "DN11", "SY12", "KCTE", "TST9", "KCU1", "SYT5", "KCTD", "TST8", "TST7", "KCTC", "SYT4", "KCTB", "KCTA", "TST6", "KCT9", "TST5", "TST4", "KCT8", "SYT3", "KCT7", "MIT1", "MAT3", "KCT6", "TST3", "KCT5", "KCT4", "SYT2", "MAT1", "MAT2", "TST2", "KCT3", "KCT2", "KCT1", "TST1", "SYT1"]
21
+
22
+ # EZ番号(サブスクライバID)があれば返す。無ければ +nil+ を返す。
23
+ def subno
24
+ @request.env["HTTP_X_UP_SUBNO"]
25
+ end
26
+ alias :ident_subscriber :subno
27
+
28
+ # 位置情報があれば Position のインスタンスを返す。無ければ +nil+ を返す。
29
+ def position
30
+ return @__posotion if defined? @__posotion
31
+ return @__posotion = nil if ( params["lat"].nil? || params['lat'] == '' || params["lon"].nil? || params["lon"] == '' )
32
+ l = Jpmobile::Position.new
33
+ l.options = params.reject {|x,v| !["ver", "datum", "unit", "lat", "lon", "alt", "time", "smaj", "smin", "vert", "majaa", "fm"].include?(x) }
34
+ case params["unit"]
35
+ when "1"
36
+ l.lat = params["lat"].to_f
37
+ l.lon = params["lon"].to_f
38
+ when "0", "dms"
39
+ raise "Invalid dms form" unless params["lat"] =~ /^([+-]?\d+)\.(\d+)\.(\d+\.\d+)$/
40
+ l.lat = Jpmobile::Position.dms2deg($1,$2,$3)
41
+ raise "Invalid dms form" unless params["lon"] =~ /^([+-]?\d+)\.(\d+)\.(\d+\.\d+)$/
42
+ l.lon = Jpmobile::Position.dms2deg($1,$2,$3)
43
+ else
44
+ return @__posotion = nil
45
+ end
46
+ if params["datum"] == "1"
47
+ # ただし、params["datum"]=="tokyo"のとき(簡易位置情報)のときは、
48
+ # 実際にはWGS84系のデータが渡ってくる
49
+ # http://www.au.kddi.com/ezfactory/tec/spec/eznavi.html
50
+ l.tokyo2wgs84!
51
+ end
52
+ return @__posotion = l
53
+ end
54
+
55
+ # 画面情報を +Display+ クラスのインスタンスで返す。
56
+ def display
57
+ return @__display if @__display
58
+
59
+ p_w = p_h = col_p = cols = nil
60
+ if r = @request.env['HTTP_X_UP_DEVCAP_SCREENPIXELS']
61
+ p_w, p_h = r.split(/,/,2).map {|x| x.to_i}
62
+ end
63
+ if r = @request.env['HTTP_X_UP_DEVCAP_ISCOLOR']
64
+ col_p = (r == '1')
65
+ end
66
+ if r = @request.env['HTTP_X_UP_DEVCAP_SCREENDEPTH']
67
+ a = r.split(/,/)
68
+ cols = 2 ** a[0].to_i
69
+ end
70
+ @__display = Jpmobile::Display.new(p_w, p_h, nil, nil, col_p, cols)
71
+ end
72
+
73
+ # デバイスIDを返す
74
+ def device_id
75
+ if @request.env['HTTP_USER_AGENT'] =~ USER_AGENT_REGEXP
76
+ return $1
77
+ else
78
+ nil
79
+ end
80
+ end
81
+
82
+ # 簡易位置情報取得に対応している場合は +true+ を返す。
83
+ def supports_location?
84
+ ! LOCATION_UNSUPPORTED_DEVICE_ID.include?(device_id)
85
+ end
86
+
87
+ # GPS位置情報取得に対応している場合は +true+ を返す。
88
+ def supports_gps?
89
+ ! GPS_UNSUPPORTED_DEVICE_ID.include?(device_id)
90
+ end
91
+
92
+ # cookieに対応しているか?
93
+ def supports_cookie?
94
+ true
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,33 @@
1
+ # = 端末のディスプレイに関する情報
2
+ # request.mobile.display
3
+ # で取得できる。
4
+ 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
14
+ 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
+ end
33
+ end
@@ -0,0 +1,97 @@
1
+ # =DoCoMo携帯電話
2
+
3
+ module Jpmobile::Mobile
4
+ # ==DoCoMo携帯電話
5
+ class Docomo < AbstractMobile
6
+ autoload :IP_ADDRESSES, 'jpmobile/mobile/z_ip_addresses_docomo'
7
+ autoload :DISPLAY_INFO, 'jpmobile/mobile/z_display_info_docomo'
8
+
9
+ # 対応するUser-Agentの正規表現
10
+ USER_AGENT_REGEXP = /^DoCoMo/
11
+ # 対応するメールアドレスの正規表現
12
+ MAIL_ADDRESS_REGEXP = /^.+@docomo\.ne\.jp$/
13
+
14
+ # オープンiエリアがあればエリアコードを +String+ で返す。無ければ +nil+ を返す。
15
+ def areacode
16
+ if params["ACTN"] == "OK"
17
+ return params["AREACODE"]
18
+ else
19
+ return nil
20
+ end
21
+ end
22
+
23
+ # 位置情報があれば Position のインスタンスを返す。無ければ +nil+ を返す。
24
+ def position
25
+ return @__position if defined? @__position
26
+ lat = params["lat"] || params["LAT"]
27
+ lon = params["lon"] || params["LON"]
28
+ geo = params["geo"] || params["GEO"]
29
+ return @__position = nil if ( lat.nil? || lat == '' || lon.nil? || lon == '' )
30
+ raise "Unsuppoted datum" if geo.downcase != "wgs84"
31
+ pos = Jpmobile::Position.new
32
+ raise "Unsuppoted" unless lat =~ /^([+-]\d+)\.(\d+)\.(\d+\.\d+)/
33
+ pos.lat = Jpmobile::Position.dms2deg($1,$2,$3)
34
+ raise "Unsuppoted" unless lon =~ /^([+-]\d+)\.(\d+)\.(\d+\.\d+)/
35
+ pos.lon = Jpmobile::Position.dms2deg($1,$2,$3)
36
+ return @__position = pos
37
+ end
38
+
39
+ # 端末製造番号があれば返す。無ければ +nil+ を返す。
40
+ def serial_number
41
+ case @request.env["HTTP_USER_AGENT"]
42
+ when /ser([0-9a-zA-Z]{11})$/ # mova
43
+ return $1
44
+ when /ser([0-9a-zA-Z]{15});/ # FOMA
45
+ return $1
46
+ else
47
+ return nil
48
+ end
49
+ end
50
+ alias :ident_device :serial_number
51
+
52
+ # FOMAカード製造番号があれば返す。無ければ +nil+ を返す。
53
+ def icc
54
+ @request.env['HTTP_USER_AGENT'] =~ /icc([0-9a-zA-Z]{20})\)/
55
+ return $1
56
+ end
57
+
58
+ # iモードIDを返す。
59
+ def guid
60
+ @request.env['HTTP_X_DCMGUID']
61
+ end
62
+
63
+ # iモードID, FOMAカード製造番号の順で調べ、あるものを返す。なければ +nil+ を返す。
64
+ def ident_subscriber
65
+ guid || icc
66
+ end
67
+
68
+ # 画面情報を +Display+ クラスのインスタンスで返す。
69
+ 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])
75
+ end
76
+
77
+ # cookieに対応しているか?
78
+ def supports_cookie?
79
+ false
80
+ end
81
+ private
82
+ # モデル名を返す。
83
+ def model_name
84
+ if @request.env["HTTP_USER_AGENT"] =~ /^DoCoMo\/2.0 (.+)\(/
85
+ return $1
86
+ elsif @request.env["HTTP_USER_AGENT"] =~ /^DoCoMo\/1.0\/(.+?)\//
87
+ return $1
88
+ end
89
+ return nil
90
+ end
91
+
92
+ # 画面の情報を含むハッシュを返す。
93
+ def display_info
94
+ DISPLAY_INFO[model_name] || {}
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,17 @@
1
+ # =EMOBILE携帯電話
2
+
3
+ module Jpmobile::Mobile
4
+ # ==EMOBILE携帯電話
5
+ class Emobile < AbstractMobile
6
+ autoload :IP_ADDRESSES, 'jpmobile/mobile/z_ip_addresses_emobile'
7
+
8
+ USER_AGENT_REGEXP = %r{^emobile/|^Mozilla/5.0 \(H11T; like Gecko; OpenBrowser\) NetFront/3.4$|^Mozilla/4.0 \(compatible; MSIE 6.0; Windows CE; IEMobile 7.7\) S11HT$}
9
+ # 対応するメールアドレスの正規表現
10
+ MAIL_ADDRESS_REGEXP = /^.+@emnet\.ne\.jp$/
11
+ # EMnet対応端末から通知されるユニークなユーザIDを取得する。
12
+ def em_uid
13
+ @request.env['HTTP_X_EM_UID']
14
+ end
15
+ alias :ident_subscriber :em_uid
16
+ end
17
+ end
@@ -0,0 +1,110 @@
1
+ # =SoftBank携帯電話
2
+ # J-PHONE, Vodafoneを含む
3
+
4
+ require 'kconv'
5
+
6
+ module Jpmobile::Mobile
7
+ # ==Softbank携帯電話
8
+ # Vodafone, Jphoneのスーパクラス。
9
+ class Softbank < AbstractMobile
10
+ autoload :IP_ADDRESSES, 'jpmobile/mobile/z_ip_addresses_softbank'
11
+
12
+ # 対応するuser-agentの正規表現
13
+ USER_AGENT_REGEXP = /^(?:SoftBank|Semulator)/
14
+ # 対応するメールアドレスの正規表現 ディズニーモバイル対応
15
+ MAIL_ADDRESS_REGEXP = /^.+@(?:softbank\.ne\.jp|disney\.ne\.jp)$/
16
+
17
+ # 製造番号を返す。無ければ +nil+ を返す。
18
+ def serial_number
19
+ @request.env['HTTP_USER_AGENT'] =~ /SN(.+?) /
20
+ return $1
21
+ end
22
+ alias :ident_device :serial_number
23
+
24
+ # UIDを返す。
25
+ def x_jphone_uid
26
+ @request.env["HTTP_X_JPHONE_UID"]
27
+ end
28
+ alias :ident_subscriber :x_jphone_uid
29
+
30
+ # 位置情報があれば Position のインスタンスを返す。無ければ +nil+ を返す。
31
+ def position
32
+ return @__position if defined? @__position
33
+ if params["pos"] =~ /^([NS])(\d+)\.(\d+)\.(\d+\.\d+)([WE])(\d+)\.(\d+)\.(\d+\.\d+)$/
34
+ raise "Unsupported datum" if params["geo"] != "wgs84"
35
+ l = Jpmobile::Position.new
36
+ l.lat = ($1=="N" ? 1 : -1) * Jpmobile::Position.dms2deg($2,$3,$4)
37
+ l.lon = ($5=="E" ? 1 : -1) * Jpmobile::Position.dms2deg($6,$7,$8)
38
+ l.options = params.reject {|x,v| !["pos","geo","x-acr"].include?(x) }
39
+ return @__position = l
40
+ else
41
+ return @__position = nil
42
+ end
43
+ end
44
+
45
+ # 画面情報を +Display+ クラスのインスタンスで返す。
46
+ def display
47
+ return @__display if @__display
48
+ p_w = p_h = col_p = cols = nil
49
+ if r = @request.env['HTTP_X_JPHONE_DISPLAY']
50
+ p_w, p_h = r.split(/\*/,2).map {|x| x.to_i}
51
+ end
52
+ if r = @request.env['HTTP_X_JPHONE_COLOR']
53
+ case r
54
+ when /^C/
55
+ col_p = true
56
+ when /^G/
57
+ col_p = false
58
+ end
59
+ if r =~ /^.(\d+)$/
60
+ cols = $1.to_i
61
+ end
62
+ end
63
+ @__display = Jpmobile::Display.new(p_w, p_h, nil, nil, col_p, cols)
64
+ end
65
+
66
+ # cookieに対応しているか?
67
+ def supports_cookie?
68
+ true
69
+ 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
+
79
+ # cookieに対応しているか?
80
+ def supports_cookie?
81
+ true
82
+ 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$/
91
+
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"=>CGI.unescape($7).toutf8}
101
+ pos.tokyo2wgs84!
102
+ return pos
103
+ end
104
+
105
+ # cookieに対応しているか?
106
+ def supports_cookie?
107
+ false
108
+ end
109
+ end
110
+ end