萌える Rails の作り方 メイドさんはこうやって働いている! 古川大輔 http://mogya.com
自己紹介
古川大輔
大怪獣もぎゃ
「いいめも」作った人です。
兵庫県在住 33才 ヨメとインコ
フリーランス 一年生
お仕事 募集中!
メイドめーるについて
... の前に。
... それは 関西 Ruby 会議 の 懇親会でのこと。
「 50 分くらいしゃべってみませんか?」 「よろこんで!」
・・・
         ___ _        /    u  \       /  \    /\     /  し (>)  (<) \      |  ∪    ( __ 人 __ )   J |   _______ _         \   u    `⌒ ´    /  | |            |     ノ           \  | |            |   / ´                  | |            |   |     l              | |            |          ___ _        /    u  \       /  \    ─\    チラッ     /  し (>)  (●) \      |  ∪    ( __ 人 __ )   J |   _______ _      \   u    `⌒ ´    /  | |            |     ノ           \  | |            |   / ´                  | |            |   |     l              | |            | 試しに読んでみるお。
           ___ _        / :::::::::::::::: \       / ::::::─ 三三─\     / ::::::::  ( ○)三(○)\      |:::::::::::::::::::: ( __ 人 __ ) ::::    |   _______ _      \ :::::::::     |r┬-|     , /  .| |            |     ノ ::::::::::::    ` ー '´    \  | |            |   / :::::::::::::::::::::               | |            |   |:::::::::::::::::  l                | |            | 20 分しかないお・・・
ゆっくり進行に ご協力ください 途中の質問も大歓迎。
今日の予定 メイドめーるの紹介 メールのやりとり Google カレンダー Mextractr そのほか細かい話
メイドめーるについて
メイドさんが起こしてくれるサービス
メールで予定を登録
Gigazine
 
Award on rails 2008 協賛企業賞
実装の話
linux Ruby On Rails postfix Mail fetcher POP3 Mextractr lighttpd gcal api Apache
linux Ruby On Rails postfix Mail sender SMTP lighttpd gcal api Rake タスク
メールの 受信
postfix からアプリケーションに メールを渡す /etc/aliases hoge: "|(cd /var/hoge && ruby hoge_app)"
rails に渡す /etc/aliases hoge: "|(  export RAILS_ENV=\"production\"   && cd /var/maidmail   && ruby script/runner \"SchduleMailReceiver.receive(STDIN.read)\" )"
受け取る app\models\schdule_mail_receiver.rb class SchduleMailReceiver < ActionMailer::Base def receive(email) email.each_header{|name,value| :
問題 例外を吐くと .... This is the Postfix program at host snares.example.com. : The Postfix program >test@example.com< : Command died with status 1: &quot;/var/MailApp/mailserver/test.rb&quot;. Command output: /usr/lib/ruby/1.8/logger.rb:518:in `initialize': Permission denied - /var/MailApp/mailserver/../log/MailServer.log (Errno::EACCES) from /usr/lib/ruby/1.8/logger.rb:518:in `open'  from /usr/lib/ruby/1.8/logger.rb:518:in `open_logfile'  from ユーザー宛にエラーメール
app\models\schdule_mail_receiver.rb class SchduleMailReceiver < ActionMailer::Base def receive(email) begin email.each_header{|name,value| : rescue => ex bt = ex.backtrace logger.fatal &quot;\n !!!!!!!!!!!!!!!!!!!!!!\nexception caught:\n&quot; logger.fatal &quot;#{bt.shift}: #{ex.message} (#{ex.class})&quot; logger.fatal bt.map{|s| &quot;\tfrom #{s}&quot;}.join(&quot;\n&quot;) logger.fatal &quot;\n !!!!!!!!!!!!!!!!!!!!!!\n\n&quot; end 対策:例外は出さない。
def error_catch logger = ActiveRecord::Base.logger     begin yield     rescue => ex bt = ex.backtrace logger.fatal &quot;\n !!!!!!!!!!!!!!!!!!!!!!\nexception caught:\n&quot; logger.fatal &quot;#{bt.shift}: #{ex.message} (#{ex.class})&quot; logger.fatal bt.map{|s| &quot;\tfrom #{s}&quot;}.join(&quot;\n&quot;) logger.fatal &quot;\n !!!!!!!!!!!!!!!!!!!!!!\n\n&quot;     end end error_catch{ 普通の処理 }
問題 2 重い。
対策 一度 POP3 に入れてから処理 daemonize
require 'net/pop' task :mail_fetcher => [:environment] do @config = YAML.load(IO.read(&quot;#{RAILS_ROOT}/config/mail_fetcher.yml&quot;)) daemonize() loop do pop = Net::POP3.new(@config[RAILS_ENV]['server']) pop.start(@config[RAILS_ENV]['username'],  @config[RAILS_ENV]['password']) unless pop.mails.empty? pop.each_mail do |m| IncomingMailHandler.receive(m.pop) m.delete end end pop.finish sleep(SLEEP_TIME) end end
メールが少ないのだったら、  ruby script/runner  でいいかも ( ぼそ )
メールの処理 ここまで
Google カレンダー
GCalAPI
server = GoogleCalendar::Service.new(                GCAL_ACCOUNT, GCAL_PASSWORD) calendar = GoogleCalendar::Calendar.new(server, GCAL_FEED) event = calendar.create_event event.st = Time.parse(&quot;2008-12-04 22:46:39&quot;) event.en = Time.parse(&quot;2008-12-04 23:46:39&quot;) event.where = &quot; 場所 &quot; event.title = &quot; 予定 &quot; event.desc =&quot; 詳細 &quot; event.save! GCalAPI :予定の登録
conditions = {} conditions['start-min']=Time.parse(&quot;2008-12-04 22:46:39&quot;) conditions['start-max']=Time.parse(&quot;2008-12-05 22:46:39&quot;) conditions['sortorder']='d' conditions['timezone']='tokyo' events = calendar.events(conditions) events.each{|event| pp event } GCalAPI :予定の取得 event.st  :  2008-12-04 22:46:39 event.en  :  2008-12-04 23:46:39 event.where  :  &quot; 場所 &quot; event.title  :  &quot; 予定 &quot; event.desc  :  &quot; 詳細 &quot;
Google アカウント認証
よくあるインターフェイス 「 Google カレンダーのユーザー名とパスワードを入力してください」
予想される展開
Google アカウント認証 ClientLogin  普通のログイン  ユーザー名とパスワード  
Google アカウント認証 AuthSub   Web アプリケーションの  ための認証方法  
 
 
 
ユーザーを Google アクセス要求 URL に誘導 ユーザーが「許可」を押す アプリケーション アプリケーションに「一時トークン」が渡される 「一時トークン」を「永続トークン」と交換してもらう 「永続トークン」をつかって Google サービスにアクセス AuthSub のながれ
https://www.google.com/accounts/AuthSubRequest ?next=http://www.maidmail.jp/login/google_auth_responce &scope=http://www.google.com/calendar/feeds/ &secure=0&session=1&hd=default Google アクセス要求 URL 認証成功時に戻ってくる URL アクセスしたいサービスごとの URL
require 'gcalapi' require 'googlecalendar/auth_sub_util' @uri = GoogleCalendar::AuthSubUtil.build_request_url( 'http://www.example.com/responce',  'http://www.google.com/calendar/feeds/', false, #use_secure true #use_session )   GCalAPI で生成
 
成功時のレスポンス http://www.maidmail.jp/login/google_auth_responce ?Token=XXXX 一時トークン
トークンの交換 authsub_token = '' one_time_token = params[:token] session_token =     GoogleCalendar::      AuthSubUtil.        exchange_session_token(one_time_token)
トークンを使ってアクセス gserver = GoogleCalendar::ServiceAuthSub.new(user.calendarToken) calendar = GoogleCalendar::Calendar.new(gserver,     GoogleCalendar::Calendar::DEFAULT_CALENDAR_FEED) event = calendar.create_event event.st = Time.parse(&quot;2008-12-04 22:46:39&quot;) event.en = Time.parse(&quot;2008-12-04 23:46:39&quot;) event.where = &quot; 場所 &quot; event.title = &quot; 予定 &quot; event.desc =&quot; 詳細 &quot; event.save!
Google カレンダーの話 ここまで。
Mextractr について
Mextractr
http://api.emetadata.net/mextractr ?text=[[text]] &out=[[out]] &apikey=[[apikey]] 使い方 # POST でも動きます。 パラメータ 形式 意味 text UTF8 で URL エンコードした文字列 メタデータ抽出元の文字列 out 現状 &quot;atom&quot; だけ 出力データの形式:デフォルトは atom apikey 文字列 Mextractr の API キー(必須)
<?xml   version=&quot;1.0&quot;   encoding=&quot;utf-8&quot;?> :      <gd:extendedProperty   name='what'   value=&quot; 定時株主総会 &quot;/>      <gd:who   valueString=&quot;* メタデータ株式会社 &quot;/>      <gd:who   valueString=&quot; 野村直之 &quot;/>      <gd:when   startTime=&quot;2008-10-23&quot;   valueString=&quot;10 月 23 日 &quot;/>      <gd:where   valueString=&quot; 東京都墨田区本所 &quot;/>      <gd:where   valueString=&quot; 弊社本店 A 会議室 &quot;/>    </entry> </feed> レスポンス
$ sudo gem install mextractr_webapi Bulk updating Gem source index for: http://gems.rubyforge.org Successfully installed mextractr_webapi-0.0.1 1 gem installed gem : mextractr_webapi mextractr_result = MextractrWebApi.new(MEXTRACTR_API_KEY).parse(text) mextractr_result['when'][0]['startTime'] mextractr_result['where'][0]['valueString']
FAQ 解析精度? 時刻? 日々精進。 明日は晴れだ!
Mextractr の話 ここまで
( おまけ ) デザインについて
私がやりました。 今は反省している。
2ch でも絶賛! 【ネット】メイドさんが Google カレンダーの予定をメールで届けてくれる「メイドめーる」 6  :なまえないよぉ~ : 2008/11/11( 火 ) 13:09:10 ID:TJ3qrp7g このメールの内容担当してるヤツは 30 代独身の堅太りなおっさんなんだろ?  11  :なまえないよぉ~ : 2008/11/11( 火 ) 19:20:14 ID:kf6HEfeT 絵とかデザインがいまいちなのが痛い。
ふとってないもん!
↑ メイドさんの出所
「夢夢色 TOWN 」
個人・ 商用 どちらでも利用可。 利用なさる方が全責任を持つこと。 利用に際し、第三者や当局などから当サイトに問い合わせやクレームが一切来ないように配慮しなければなりません。 連絡不要 ライセンシー不要 著作権表示不要 リンク不要 使用の際の 使用報告不要 加工可 すばらしい利用条件
おまけ2 なんでメイド?
当初の予定: メールで Google カレンダーに 予定を書くアプリ
Google カレンダーって、 利用者少なくね?
集客力が必要!
秘書メール?
 
秘書よりメイドのほうが注目されるよね
萌え系 WEB アプリケーション 「メイドめーる」
ねらい通り!
「執事メールはないの?」 「ドジッ子が必要だろう」 「ツンデレツンデレ!」 主な反響
 
・・・だれか技術を見てくれ
萌え系アプリは、 いろいろたいへんです。 結論:
ご静聴 ありがとう ございました
メイドめーる  :  http://www.maidmail.jp/ Drecom Award on rails 2008 :  http://rails.drecom.jp/ 夢夢色 TOWN :  http://www.poipoi.com/yakko/index.html   Rails でのメール処理に関するサイト Stress-free Incoming E-Mail Processing with Rails  http://railspikes.com/2007/6/1/rails-email-processing   GCalAPI に関するサイト RubyForge: google calendar api: Project Info :  http://rubyforge.org/projects/gcalapi/ メールから Google Calendar に登録するサンプル  http://d.hatena.ne.jp/zorio/20060925/1159201438   Google カレンダー API に関するサイト Google Calendar API の基礎  : Under Construction, Baby :  http://www.rcdtokyo.com/ucb/contents/i000815.php  ↑ PHP ですけど、流れがとてもわかりやすくまとまっています。オススメ。 API Developer's Guide: The Protocol - Google Calendar APIs and Tools - Google Code :  http://code.google.com/intl/ja/apis/calendar/docs/2.0/developers_guide_protocol.html   Mextractr に関するサイト Mextractr  メタデータ抽出エンジン  :  http://api.emetadata.net/doc RubyForge: mextractr_webapi: Project Info :  http://rubyforge.org/projects/mextractr/   GoogleAuthSub に関するサイト [ruby]gcalapi を使って AuthSub ログイン  http://blog.mogya.com/2008/09/rubygcalapiauthsub.html [ruby]GoogleAuthSub を使う  http://blog.mogya.com/2008/09/googleauthsub.html AuthSub Authentication for Web Applications - Account Authentication API - Google Code :  http://code.google.com/apis/accounts/docs/AuthSub.html 興味を持っていただいた方のための URL :

メイドめーる