p 妙 t0 - みる会図書館


検索対象: Building the Realtime User Experience
314件見つかりました。

1. Building the Realtime User Experience

$attributes = $l->attributes(); if(($attributes[ ・ rel ・ ] ・ alternate') & & ・ text/html ・ ) ) ($attributes[ 'type' ] $href = $attributes[ ・ href' ] ; $entry_id $db->insert array('entries ・ array(' url' = > $href, itl ざ = > $e->title, ・ atom entry id' 'date created' = 〉 $e->published, ・ date updated ・ = > $e->updated, As the protocol specifies, the publish part of the protocol has no special flags. The hub just POSTs the updated feed to the callback URL. To parse it out, we use PHP's 。、 superglobal" variable called $HTTP RAW POST DATA. When working with a POST re- quest, this variable will contain the entire payload of that POST request. The payload we receive from the hub is an Atom XML feed of the new and updated entries. TO parse that XML we use SimpleXML again. For most 0f the XML entities, we can simply grab them from the SimpleXML object. However, the link back to the original post is a bit more tricky. ln the Atom format, there can be multiple links for each entry. loop the link entities t0 find the alternate location in text/html format. TO save the data, we're reusing our entries table in the syndication test database. If you haven't already created thattable, go ahead and d0 that now. We're using the same d わ . php file introduced in the first chapter. Now that we have everything we need in our index. php file, we can copy this file along with p 励 5 励わ励わ励 . p 妙 t0 a public-facing server t0 test it out. Once you have uploaded these files [ 0 a server, point your browser t0 the file with the query string ?request subscription=l. This will request a subscription from the hub, which will start pinging this script whenever you share new items. Figure 2-7 shOWS 日 g 尾 2-7. & ル s ロ舫ⅲ g the S わの℃ d れ夜な翻 Do 皿 ... we ould all subscnbed, shanng れ面 ng. ←寺 1 , ☆ http://yada.tedroden.com/ch02/index.php?request_subscriptionel ) h p : / / yada. d 「 0d0 れ . ( om / ( x the result Of a subscription request. PubSubHubbub ー 35

2. Building the Realtime User Experience

17 “ー D 0 酊 d TOday Paq を V に 5 : 3962 T 町Ⅵ引ー 2 4 AntWne Ⅵ 5 お : 377595 す M 田 290 住 An な を R 印 0 杙、 0 5 市 0 E Ⅵ 5 = 物 , CustomLiveMap 、 0 No に求 i02 日い rv 橋 0 ( E 01P ト : し 0 、引ⅲ % を pla び m : 、ⅵ 1d0 ) 、の 「 0 賀叩 h に [ ⅳ新 w 新、纛 0 ′ Details 、Ⅵ引 t 学 223573 Ⅵ、橋・「 DetaiIs Ⅵ、滝 N 議ⅵ 0 物む 0 拠い 0 を 0 。を 新、纛研 # 223573 い ) 新、飛 0 「 # 223572 ( 2 ) Visitor 物靆 35 アーい ) いれ gcl 市 ( 2 ) 、代 # 223563 ( 4 ) 、世 # 223540 ( 2 ) hackroid い ) 、叩 b い ) 新、 t # 223570 ( 2 ) 第議、い ) 新、飛 # 2 ー 6328 い ) 新、飛 0 ′物 223459 ( 9 ) ( 0 川い ) 、研物 223555 い 2 ) rcounts ( 3 ) 新、破物 223534 い 5 ) fusion ( 4 ) 新 0 羆 ・第 HO 式 : ー 20. り 3 」 3L2 ′ Country: 物報 00W れ , [ 田 u き 00 : ] み P 、ら 第・ 0 ′ 0 物、 0 日「 ox 3 , 円び 0 ロ川ⅲ dow 、 xp, 5 せに R で、 0 恤ⅱ 0 川いき ( 曜「物田 y ⅵ物ⅲ 0 / ナ・ Ref 汁に h 社 p : / / 曲ョい 0 に 3k0.0 ′ 0 / を b 00k / 物 00P をにを物 0 し 3 ( k ⅲ 0 N 靆扣れ Path い t 面 .1 Ⅵ引れ第物 223571 T 武 T 面肥 5P0 れヒ 22 5 で ( onds ヨ A にⅵ、飛 Time: 22 、 0 ( 0 " d 、・ To をⅥ、 5 : ーー T 硬 P 物 0 ⅵに w 当 : 2 ー A マに′ 00 ~ P 0 にⅵ物引、に 2 Ⅵ研 H 減 0 Ⅳ 尋比 3 物叩 . W00 物ト田 b ゼ「、 A 代査 - 5 up 伝「 0 物 00 新 ( 0 Ⅲ纛 W00 社 - W を b 、に Tracking 田 Analytics 新ⅵ 0 n Path ( 2 物山。 n 、 ) ( 汁 0 最ⅵ ew ⅲ 0 / れれ市 0 門物・ト p 物 0 、をドⅳ efO 鷲 3 , 円「 m : M 物ら、 ( ′ 00n Pesolution: ー 280 / 80 り HOSt: ー当 0 は 8 06 ノ 09 ー ( 国飛纛Ⅳ : A ′ 0 ←み , City: 日← no 、知、卩 Ⅵ虱 t 0 ls 。 1 、Ⅵ引 tO 「物 223572 0 吶 1 に′代 r : h をゆ : / / 物 0 ト・ m ke ⅲ 10 0 ・ 0 ー we し要 00b / W00 k00 0 ト物、 0 は Total 石れ肥 Sp に最 : 0 ( 0 い d 、 . ー物 00 新引 t Time: 0 、 0 ( 0 物 d 、 . To をも i : ーーー 0 を P ⅵ ew ーー A に′ 0 に P 0 ⅵ 0 物 5 / ⅵを it: ー V 飛 0 「、 tO Ⅳ W00 r 物・ハに Trackitig 議Ⅱ物ⅳい ( 、 Vis 纛 0 「 0 、 い′に n 日 y ⅵ 0 物ⅲ g れ田れし er5 第・ 0 物 50 れ FireiOx 3. 円靆 fo 心当 dows は 5 ( 当 ・第日 0 : 77. 6.2 曾ヨ 3'Country: リいはを 4 K 0 、一れ 0 むみ W 動 0 a - Website ョ ( k ⅲ 0 凱ー冨 y を ic 、 ・ woopra M ・。市 " 、 Area - い吶ー N 試津 h ( 3 “を汚 ) ま霧を email: i ⅱにト飛にり " il. ( om. 覺に b 、に、 : ⅱⅱに bo ドに工 0 Ⅲ ( 0 g Ⅲ℃ 9-3. MO ⅲⅱ〃 g 4 1 怩わⅵ ro ″ g わ the Woopra d い kt0 〃 4 〃〃 i0 〃 WOOP を 寰ヤを可 oy 05 Qui ( kS 物 : A ・「 ag をⅵ′ minute 0 、 01 ⅵ Website D 0 ヨ 31.2010 433 : 42 PM 5 イ ) NO 氈 i ( ions ・ヤ Fi 「 5 , Manage Vi 、 0 「 # 5 を 1 V itO 「 # 4 , Chat ー An 』 Y 「に 5 , R ・ PO 代 5 一 Calendar 0 50 誂 ( h 第 Live Dashboard 第 M 総れ 0 TOday 9 をⅵ 0W5 : 4 TodayVisits: ~ AlltimeVisits:4 Ⅵ 5 0 ′第 5 You: 0432 : 53 •hello Hope 謝い 5 well.. End ( 0 れ 0 な iO れ ウ” A chat request h35 been 5 に n ー ( oVi 引 to 「 # 5. 、、 ! 。 Ta 新 V 0 ′ 0 、 LOOkup History Send , ( リ omi Map ・ 日 g Ⅲ℃ 9-4. わⅱ行 a 〃 g a chat ↓ⅵ a ″ s 夜・ⅵ / 00 〃 ra 188 Chapter 9 : Measuring User Engagement: Analytics on the Realtime Web

3. Building the Realtime User Experience

! 5 ted ー 0 れ e obile Activate ド 0b00k Texts ( 5 p 1 of 3 ) P 厄 as に ( h005 に your country and mobile 5 にⅣにに 0 ⅵ de 「 below.* 〔 4 」」」こ」」」」こ : 」イ Choose a carrier 引ま yo リ「 mo を厄 ( を町 ov 電を「 AT&T Verizon Sprint Nextel B00 式 Virgin USA Helio Cellular South T-Mobile CeIIcom リ 0P0 广 them this 朝 N に ーれ 0 ー e COA iOn ( 0 e. 式 ( h 「 92 fO 「 this 5 を「朝 ( 色 5 盟 nd ~ 電 me 3 M を 55a905 Figure 8-7. Entering ツ 0 ″ r ル汁 el い s c のⅵげ 0 れ朝 c 訪 00 た e.dlAT&T 3G Ca Messages 8 : PM 1010100018 CanceI Edit Add to Contacts D00 19 , 2009 8 : 21 PM FRM:troden@neIson.Ioca I(TedRoden) SUBJ:Greetings MSG:SMS from the command line 0 日 g 尾 8-2. The emailed 川お g ビ 0 〃 a 〃わ 0 〃に おト d The 5M5 Landscape ー 155

4. Building the Realtime User Experience

/ / create a div and give it the line class var line = dOC. createElement('div ・ ) ; ・ line ・ ); line. setAttribute(' class ・ / / if data contains a profile image, add it t0 the line div if(' profile_image ・ in data) { var img = dOC. createElement(' img' ) ; img. setAttribute( ・ align' ・ right ' ) ; img. setAttribute('class ・ , ・ profile image' ) ; img. setAttribute(' src' , data. profile image); line. appendChi1d(img); / / create a P tag tO h01d the content = dOC. createE1ement(' p'); var p p. innerHTML / / if there is a username, show it if(' username' in data) ' く strong> ・十 data. username 十 " く /stronp: p. innerHTML + = / / if there is html content, show that if(' html ・ in data) { p. innerHTML + = data. html; / / add the p tO the line div line. appendChi1d(p) ; / / add the line onto the widget itself var targetDiv = dOC. getElementById(targetDivId); / / prepend it t0 the top 0f the widget targetDiv. insertBefore(1ine, targetDiv. firstChild); / / clean up the DOM var dom limit = 60 ; = targetDiv. getElementsByC1assName(' line'); var elements for(var i = elements. length 1 ; i > = dom limit; targetDiv. removeChi1d(e1ements[i]); This method will end up being used by all of the widgets that we're building, so it has t0 be generic enough t0 be used for a few different purposes. Rather than give this method tons Of optional parameters, this makes dO with only tWO. The first parameter is the id 0f the div in which to append the content. The second parameter is a JavaScript object containing any 0f the fields thatthis method may use: profile image The URL to a profile image or avatar to show with this line. 46 ー Chapter 3 : The Dynamic Homepage (Widgets in Pseudorealtime)

5. Building the Realtime User Experience

/ / clean up the DOM var limit = 100 ; var messages for(var x = messages. length-l; x > limit; $(messages[x]) ・ remove(); T. p 。 11 ( ) ; If we ran this COde now, it would give us some JavaScript errors, but we've got every- thing in place [ 0 actually show the tweets on the page. The first thing we d0 is check [ 0 see whether this is our first time through this function.\Ve determine this by checking for the existence Of a cursor variable; if there isn't one, it's our first time through and we remove the "Waiting for content... ' message. After that, we save the id Of the last tweet t0 our cursor field. This is the field that is sent back in the P011 method. Next, we IOOP through all Of the tweets we've Just received, check tO see whether we should display them, and actually add them to the page. We've already built the HTML string in 〃〃ビ r. , so all we need [ 0 d0 is add i い 0 the DOM. We use jQuery t0 create the DOM element, prepend it to our content DIV, and show it with the s1ideDown effect. We'II be appending quite a few tweets to the page every second, so the DOM is going t0 get quite large. TO counter this, we re going t0 keep only the last IOO tweets on the page. We use jQuery's CSS selector methods [ 0 grab all of the messages and remove all but the latest IOO of them. Once we've cleaned up the DOM a bit, we call the P011 method and start the process over agalll. You've probably noticed that we checked [ 0 see whether we should display the tweets using the should show tweet method, but we haven't defined it yet. SO let's create that method now. Add the following code t0 your 加襯げ file: T. should show tweet = function(tweet) { $('#all-count ・ ). text(parselnt($('#all-count ・ ) . text()) + 1); = false; var ShOW tweet for(x in T. types) { var type = T. types[x]; / / does the tweet have the specified type? if(tweet. stats[type] . length) { / / does the user want tO see it? if($("#" + type). attr('checked ・ )) show tweet = true; var count div = $ ( ・ # ・ + type + '-count'); count div. text(parselnt(count div. text()) + 1); return show tweet; 98 ー Chapter 5 : Taming the Firehose with Tornad0

6. Building the Realtime User Experience

Pick a unique keyword (your TextMark): mykeyword ト↑水 E 、第 OR. D A AI 8 圧 . YO 町 0 will send 対 rnessaoes わ 41411 駅 a 「 t 9 with 止 keyword 、 What should your TextMark do? 0 ( dinate p 厄伺 e , ch , ( ・ ) 色 ) Res 面いヨ levordwithtextfroma 肥 b 内 URL: ト p : ″ i t 引 - 代ー国 p 陸 @First 1 加 ( ct 針 58 肥 b A 代総 TO Right: す 0 Left: CIip Text? ( S 新 . t お 1 切朝 95 ~ 叩 ty, P ー「 1 お ofSe 内 ) (YOJ 編曲第協をを 0 印 fymump セ 15 に . ) CREATE NOW create your TextMark! Show Si Preview Clipped Text Preview Entire page 166 ー Chapter8: 5M5 URL should look identical with the exception that ⅱ uses your application-id. messaging ・ aPPSP0t ・ com/sms/incoming/via/textmark?uid=\p&body=\o&action=\a. Your App Engine application. ln my case, the URL for this callback is http : //instant- in the previous chapter. This is built using the application- id Of your current the response. TO configure that URL, you'll want tO use the same server that you used Marks will request a URL 0f our choosing and respond with the text that appears in page. ' ' This means that when a user sends a text message [ 0 a specific keyword, Text- ln the second step, instruct the service tO "Respond to a keyword with text from a web our application or another application. message tO that shortcode, TextMarks is able tO know whether tO send a message [ 0 code number. By asking your users to prepend a specific keyword when sending a sign up for a keyword, the actual end users are all sending messages tO the same short- with your intended application. Although any number of application developers can For step one 0f the form, feel free to select any keyword that is available or makes sense 日 g レ尾 & 4. R 夜ⅵれ g a たル 0 ↓ⅵ the Te M の・ s 夜ⅵ記

7. Building the Realtime User Experience

user start typing and stop? ls this person still online? These are the types 0f features that change a standard chat script into a living, breathing realtime application. Luckily, with the COde that's already written, these features are easy tO implement. Realtime Chat Ⅱ、十い h p : / / lo ( ho 8888 / Chatting with Paul You: 印 , paul Paul : H 創 0 ! e ()• C00 ( ホ Chatting with = 80 「 You: George! Cant believe you*re on ⅱ冊 ! い記ⅲ 0 新 p : ″ IO ( 引 0 化 888 & 「 . completed 8 0f9 items 影、にコ十 Oh p : ′ / lo ( 謝 h05 を 8888 / with J0hn J0hn: , paul Y にト日 0 ! Realtime Chat e [(q•Google Cha 盟 ng with 30 「 George: What*s with JOhn? You:I know, right? い記 ing 物 p : / ハ 0 ( a 旧 0 式 : 888 引を completed 8 0f9 ms Ⅱ十 = 6 ⅸ tp : / ハ 0 ( 謝 ho 8888 / C hatting w れ JOhn JOhn: George! Cant believe YOLfre on ⅱ ! Yep R 3 m Chat e C000 に Cha れ it w にれ PauI You: What's with John? Paul:I know, right? Loading t ゆ : / ハ 0 ( 3 物 05t : 8888 に ( 0E0 はを d 10 Of 11 ms 日 g Ⅲ℃ 6-4. A 川〃 chatsession ⅲ〃れ市ゆにわ ro ル s 夜・ルⅲ do ル s 122 ー Chapter 6 : Chat

8. Building the Realtime User Experience

After signing up for the service and registering a keyword, you'll still need t0 create an API key to use the API functions. This is a simple process initiated from the developer section on the TextMarks website ( 印 : 〃ルルル . x la s. co 川 / ツ 4 / 尾 g 庄 You'll be greeted with a form resembling Figure 8-6. After filling outthis form, you should receive an email message from the service almost immediately with your API key. Save this key in a safe place; it'll be used when we start writing the messaging functionality. Registration Form FiII に form t*low for each a 叩ⅱⅱ intend 協 integrate with けに TextMarls V2 API. Your Web Si : http://therealtimebook.com URL ⅸ y 似 web 、い , ℃ 01 半田 IY. E-mail: tedroden@gmail.com A 朝 1 朝 1 い m , for 登 p 「 0 ℃ 0 & 5 朝 app め化 lnte 社 Use: My u “ ge. ・・ D 合 sc 「の 0 t め物 you ⅲ t 田 tO 0 0 API, ex 0 にづ traffc, 飜 c. Ylread & ag 「 to Tex ひぬⅸ sT msof rvi ( 色 REGISTER 日 g Ⅲ℃ 8-6. A 叫″ⅲれ g の 1 ハ円た 0 〃 T こ M の・ The Python class Having built the SMSService interface class, we can start building the actual service classes by expanding on the class we have already defined. ln this case, we'll create a class called Textmark. TO handle sending messages from the TextMarks service, we only need t0 override two methods. lnside your s 川 s. file, add the following code: class Textmark(SMSService) : def init_(self) : # The authentication parameters supplied by textmarks self. auth user = yo リて -0 リ t わ - user ' self. auth pass = yo - 側 t わ - P055 ・ # ( a11 the constructor Of the parent class init_(self, SMSService. 141r # textmarks. (0mな short code ノ 0 - 々 ey Ⅳ 0 て d ・ , api key= ・ Y0礪-0廖-keノ 168 ー Ch 叩 ter 8 : SMS

9. Building the Realtime User Experience

h 紅 p : 〃 127 , 0.0 ユ : 8080 / 十を h p : / / 12 み 0 、 0.1 : 8080 / c metD - ( Q 第 COOQ に These demonstrations show the cometd java Ⅳ e 「 runmng againstthe dojox and Jquery javascript clients 0j0X : ・代 load - keep connection over pages ・ ! 山」・ NTP-like extension C 0 ・ private messages ・ cometd chat ・ with ack demo and Ack ・ Auction with 00 れ Clustering, T1mesync Jquery: ・ cometd chat- with XD demo ん g Ⅲ℃ 4-3. The CO 川 e 電 D 夜れ 0 page Putting Everything in 虧 PIace After looking around at the examples and glancing atthe directorystructure ofCometd, you've probably noticed a couple 0f things. There are a 10t 0f files in that package, and there iS no clear place tO put your COde. The entire package is geared toward showing off a couple of examples, not building real applications. So the first thing I recommend iS tO get S01 れ e Of those files out Of the way and put everything we need intO one self- contained directory. Amongst other things, this will allow us t0 build the distributable WAR file much easier. What we're really after is a cleaned-up version of the cometd-java directory. That's going t0 require a couple 0f very easy tasks. First 0f all, we need t0 tell the pro ド c い 0 use the Jetty plug-in. By default, this plug-in is included up the chain a little bit, but since we re getting rid Of the extra fOlders, we need tO dO it here. 62 ー Chapter4: River 0fContent

10. Building the Realtime User Experience

N ew messages? MyWeb ( 弱 myPostHandIerFu nction() Tornad0 Async Code Waiting … calIbackResponse Function() N0tify via callback New messages g レ尾 5-2. TO 川 4 hanging 尾甲イ es なⅵ 4 ca ″黻ルれ 0 〃 s BuiIding an AppIication SO before we can build any realtime features with Tornado, we need tO put together an app that responds t0 basic requests in using this framework. Create a file called runner ・ and add the following code. import logging import tornado. httpserver import tornado. i0100P import tornado. web from tornado. options import define, options import OS # Define options that can be changed as we run this via the command line define("port", defau1t=8888, he1p="Run server on a specific port", type=int) class MainHand1er(tornado. web. RequestHand1er) : def get(self) : logging. inf0("Request t0 MainHandler! " ) self. write("Great, now let's make this app speak in realtime. " ) 10Ca1 static path = OS. path. join(os. path. dirname( file ) , application = tornado. web. App1ication([ (r"/", MainHand1er), ] , static_path=local static path) "static") name ma1n http server = tornado. httpserver.HTTPServer(appIication) tornado. options. parse command line() http server. listen(options. port) tornado. i0100P. IOLOOP. instance(). start() Like all Python scripts, this script first imports the libraries it needs tO run and does a bit of housekeeping. ln this case we define the port on which this server should run. Using Tornad0's options library, we set it t0 port 8888 , but that can be changed at 82 ー Chapter 5 : Taming the Firehose with Tornad0