class Jpmobile::Mobile::Docomo

DoCoMo携帯電話

Constants

MAIL_ADDRESS_REGEXP

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

MAIL_CHARSET

メールのデフォルトのcharset

MAIL_CONTENT_TRANSFER_ENCODING

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

USER_AGENT_REGEXP

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

Public Instance Methods

areacode() click to toggle source

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

# File lib/jpmobile/mobile/docomo.rb, line 16
def areacode
  if params["ACTN"] == "OK"
    return params["AREACODE"]
  else
    return nil
  end
end
decoratable?() click to toggle source
# File lib/jpmobile/mobile/docomo.rb, line 118
def decoratable?
  true
end
default_charset() click to toggle source
# File lib/jpmobile/mobile/docomo.rb, line 96
def default_charset
  "Shift_JIS"
end
guid() click to toggle source

iモードIDを返す。

# File lib/jpmobile/mobile/docomo.rb, line 60
def guid
  @env['HTTP_X_DCMGUID']
end
icc() click to toggle source

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

# File lib/jpmobile/mobile/docomo.rb, line 54
def icc
  @env['HTTP_USER_AGENT'] =~ /icc([0-9a-zA-Z]{20})\)/
  return $1
end
ident_device()
Alias for: serial_number
ident_subscriber() click to toggle source

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

# File lib/jpmobile/mobile/docomo.rb, line 65
def ident_subscriber
  guid || icc
end
imode_browser_version() click to toggle source

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

# File lib/jpmobile/mobile/docomo.rb, line 127
def imode_browser_version
  ver = '1.0'
  case @request.env['HTTP_USER_AGENT']
  when %r{^DoCoMo/1.0/}
    # 必ずv1.0
  when %r{^DoCoMo/2.0 }
    @request.env['HTTP_USER_AGENT'] =~ / (\w+)\(c(\d+);/
    model = $1
    cache_size = $2.to_i

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

  ver
end
model_name() click to toggle source

モデル名を返す。

# File lib/jpmobile/mobile/docomo.rb, line 147
def model_name
  if @env["HTTP_USER_AGENT"] =~ /^DoCoMo\/2.0 (.+)\(/
    return $1
  elsif @env["HTTP_USER_AGENT"] =~ /^DoCoMo\/1.0\/(.+?)\//
    return $1
  end
  return nil
end
position() click to toggle source

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

# 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" if geo.downcase != "wgs84"
  pos = Jpmobile::Position.new
  raise "Unsuppoted" unless lat =~ /^([+-]\d+)\.(\d+)\.(\d+\.\d+)/
  pos.lat = Jpmobile::Position.dms2deg($1,$2,$3)
  raise "Unsuppoted" unless lon =~ /^([+-]\d+)\.(\d+)\.(\d+\.\d+)/
  pos.lon = Jpmobile::Position.dms2deg($1,$2,$3)
  return @__position = pos
end
serial_number() click to toggle source

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

# File lib/jpmobile/mobile/docomo.rb, line 41
def serial_number
  case @env["HTTP_USER_AGENT"]
  when /ser([0-9a-zA-Z]{11})$/ # mova
    return $1
  when /ser([0-9a-zA-Z]{15});/ # FOMA
    return $1
  else
    return nil
  end
end
Also aliased as: ident_device
to_external(str, content_type, charset) click to toggle source
# File lib/jpmobile/mobile/docomo.rb, line 83
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) click to toggle source

文字コード変換

# File lib/jpmobile/mobile/docomo.rb, line 75
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) click to toggle source

メール送信用

# File lib/jpmobile/mobile/docomo.rb, line 101
def to_mail_body(str)
  to_external(str, nil, nil).first
end
to_mail_body_encoded?(str) click to toggle source
# File lib/jpmobile/mobile/docomo.rb, line 115
def to_mail_body_encoded?(str)
  Jpmobile::Util.shift_jis?(str)
end
to_mail_encoding(str) click to toggle source
# File lib/jpmobile/mobile/docomo.rb, line 104
def to_mail_encoding(str)
  to_external(str, nil, nil).first
end
to_mail_internal(str, charset) click to toggle source
# File lib/jpmobile/mobile/docomo.rb, line 107
def to_mail_internal(str, charset)
  if Jpmobile::Util.shift_jis?(str) or Jpmobile::Util.ascii_8bit?(str) or charset == mail_charset
    # 絵文字を数値参照に変換
    str = Jpmobile::Emoticon.external_to_unicodecr_docomo(Jpmobile::Util.sjis(str))
  end

  str
end