Class: Jpmobile::Mobile::Docomo

Inherits:
AbstractMobile show all
Defined in:
lib/jpmobile/mobile/docomo.rb

Overview

DoCoMo携帯電話

Constant Summary collapse

USER_AGENT_REGEXP =

対応するUser-Agentの正規表現

/^DoCoMo/
MAIL_ADDRESS_REGEXP =

対応するメールアドレスの正規表現

/.+@docomo\.ne\.jp/
MAIL_CHARSET =

メールのデフォルトのcharset

'Shift_JIS'.freeze
MAIL_CONTENT_TRANSFER_ENCODING =

テキスト部分の content-transfer-encoding

'8bit'.freeze

Instance Attribute Summary

Attributes inherited from AbstractMobile

#decorated

Instance Method Summary collapse

Methods inherited from AbstractMobile

add_user_agent_regexp, #apply_filter?, #apply_params_filter?, carrier, check_carrier, #content_transfer_encoding, #decode_transfer_encoding, #decorated?, #display, #ident, #initialize, ip_address_class, #mail_charset, #mail_variants, #smart_phone?, #tablet?, #to_mail_subject, #to_mail_subject_encoded?, user_agent_regexp, #utf8_to_mail_encode, #valid_ip?, valid_ip?, #variants

Constructor Details

This class inherits a constructor from Jpmobile::Mobile::AbstractMobile

Instance Method Details

#areacodeObject

オープンiエリアがあればエリアコードを String で返す。無ければ nil を返す。



16
17
18
19
20
21
22
# File 'lib/jpmobile/mobile/docomo.rb', line 16

def areacode
  if params['ACTN'] == 'OK'
    params['AREACODE']
  else
    nil
  end
end

#decoratable?Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/jpmobile/mobile/docomo.rb', line 127

def decoratable?
  true
end

#default_charsetObject



101
102
103
# File 'lib/jpmobile/mobile/docomo.rb', line 101

def default_charset
  'Shift_JIS'
end

#guidObject

iモードIDを返す。



63
64
65
# File 'lib/jpmobile/mobile/docomo.rb', line 63

def guid
  @env['HTTP_X_DCMGUID']
end

#iccObject

FOMAカード製造番号があれば返す。無ければ nil を返す。



57
58
59
60
# File 'lib/jpmobile/mobile/docomo.rb', line 57

def icc
  @env['HTTP_USER_AGENT'] =~ /icc([0-9a-zA-Z]{20})\)/
  Regexp.last_match(1)
end

#ident_subscriberObject

iモードID, FOMAカード製造番号の順で調べ、あるものを返す。なければ nil を返す。



68
69
70
# File 'lib/jpmobile/mobile/docomo.rb', line 68

def ident_subscriber
  guid || icc
end

#imode_browser_versionObject

i-mode ブラウザのバージョンを返す。labs.unoh.net/2009/07/i_20.html



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/jpmobile/mobile/docomo.rb', line 137

def imode_browser_version
  case @request.env['HTTP_USER_AGENT']
  when %r{^DoCoMo/1.0/}
    ver = '1.0'
  when %r{^DoCoMo/2.0 }
    @request.env['HTTP_USER_AGENT'] =~ / (\w+)\(c(\d+);/
    model = Regexp.last_match(1)
    cache_size = Regexp.last_match(2).to_i

    ver = if cache_size >= 500
            (%w[P03B P05B L01B].member?(model) ? '2.0LE' : '2.0')
          else
            '1.0'
          end
  else
    # DoCoMo/3.0以降等は、とりあえず非v1.0扱い
    ver = '2.0'
  end

  ver
end

#model_nameObject

モデル名を返す。



160
161
162
163
164
165
166
167
168
# File 'lib/jpmobile/mobile/docomo.rb', line 160

def model_name
  case @env['HTTP_USER_AGENT']
  when %r{^DoCoMo/2.0 (.+)\(},
       %r{^DoCoMo/1.0/(.+?)/}
    Regexp.last_match(1)
  else
    nil
  end
end

#positionObject

位置情報があれば Position のインスタンスを返す。無ければ nil を返す。



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/jpmobile/mobile/docomo.rb', line 25

def position
  return @__position if defined? @__position

  lat = params['lat'] || params['LAT']
  lon = params['lon'] || params['LON']
  geo = params['geo'] || params['GEO']
  return @__position = nil if lat.nil? || lat == '' || lon.nil? || lon == ''
  raise 'Unsuppoted datum' unless geo.casecmp('wgs84')

  pos = Jpmobile::Position.new
  raise 'Unsuppoted' unless lat =~ /^([+-]\d+)\.(\d+)\.(\d+\.\d+)/

  pos.lat = Jpmobile::Position.dms2deg(Regexp.last_match(1), Regexp.last_match(2), Regexp.last_match(3))
  raise 'Unsuppoted' unless lon =~ /^([+-]\d+)\.(\d+)\.(\d+\.\d+)/

  pos.lon = Jpmobile::Position.dms2deg(Regexp.last_match(1), Regexp.last_match(2), Regexp.last_match(3))
  @__position = pos
end

Returns:

  • (Boolean)


131
132
133
# File 'lib/jpmobile/mobile/docomo.rb', line 131

def require_related_part?
  true
end

#serial_numberObject Also known as: ident_device

端末製造番号があれば返す。無ければ nil を返す。



45
46
47
48
49
50
51
52
53
# File 'lib/jpmobile/mobile/docomo.rb', line 45

def serial_number
  case @env['HTTP_USER_AGENT']
  when /ser([0-9a-zA-Z]{11})$/, # mova
       /ser([0-9a-zA-Z]{15});/ # FOMA
    Regexp.last_match(1)
  else
    nil
  end
end

#supports_cookie?Boolean

cookieに対応しているか?

Returns:

  • (Boolean)


73
74
75
# File 'lib/jpmobile/mobile/docomo.rb', line 73

def supports_cookie?
  imode_browser_version != '1.0'
end

#to_external(str, content_type, charset) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/jpmobile/mobile/docomo.rb', line 87

def to_external(str, content_type, charset)
  # UTF-8を数値参照に
  str = Jpmobile::Emoticon.utf8_to_unicodecr(str)
  # 文字コードを Shift_JIS に変換
  if [nil, 'text/html', 'application/xhtml+xml'].include?(content_type)
    str = Jpmobile::Util.utf8_to_sjis(str)
    charset = default_charset unless str.empty?
  end
  # 数値参照を絵文字コードに変換
  str = Jpmobile::Emoticon.unicodecr_to_external(str, Jpmobile::Emoticon::CONVERSION_TABLE_TO_DOCOMO, true)

  [str, charset]
end

#to_internal(str) ⇒ Object

文字コード変換



78
79
80
81
82
83
84
85
# File 'lib/jpmobile/mobile/docomo.rb', line 78

def to_internal(str)
  # 絵文字を数値参照に変換
  str = Jpmobile::Emoticon.external_to_unicodecr_docomo(Jpmobile::Util.sjis(str))
  # 文字コードを UTF-8 に変換
  str = Jpmobile::Util.sjis_to_utf8(str)
  # 数値参照を UTF-8 に変換
  Jpmobile::Emoticon.unicodecr_to_utf8(str)
end

#to_mail_body(str) ⇒ Object

メール送信用



106
107
108
# File 'lib/jpmobile/mobile/docomo.rb', line 106

def to_mail_body(str)
  to_external(str, nil, nil).first
end

#to_mail_body_encoded?(str) ⇒ Boolean

Returns:

  • (Boolean)


123
124
125
# File 'lib/jpmobile/mobile/docomo.rb', line 123

def to_mail_body_encoded?(str)
  Jpmobile::Util.shift_jis?(str)
end

#to_mail_encoding(str) ⇒ Object



110
111
112
# File 'lib/jpmobile/mobile/docomo.rb', line 110

def to_mail_encoding(str)
  to_external(str, nil, nil).first
end

#to_mail_internal(str, charset) ⇒ Object



114
115
116
117
118
119
120
121
# File 'lib/jpmobile/mobile/docomo.rb', line 114

def to_mail_internal(str, charset)
  if Jpmobile::Util.shift_jis?(str) || Jpmobile::Util.ascii_8bit?(str) || (charset == mail_charset)
    # 絵文字を数値参照に変換
    str = Jpmobile::Emoticon.external_to_unicodecr_docomo(Jpmobile::Util.sjis(str))
  end

  str
end