APIãã«ã¹ãã§ãã¯ã®ã¹ã¹ã¡: API Health
ããã¯Enterprise APIs Advent Calendar 2015ã®12/20ã®ã¨ã³ããªã§ããï¼ãã®ããã°ãããæ°å¹´å¹´æ«ã®ã¢ããã³ãã«ã¬ã³ãã¼ç¨ã®ã¨ã³ããªãããªãâ¦^^;ï¼
ä¸è¬åãã§ãããç¹å®ãã¼ããã¼åãã§ãããWeb APIã®éç¨ã«ã¯ãµã¼ãã¹ç£è¦ãéè¦ã§ããããã¦ããµã¼ããµã¤ãã«ãããå é¨çãªç£è¦ã大åã§ãããAPIå©ç¨è ã«æ£ãããµã¼ãã¹ãæä¾ã§ãã¦ãããã¨ã確èªããããã«ã¯ãã¯ã©ã¤ã¢ã³ãããå®éã«ãªã¯ã¨ã¹ããéãå½¢æ ã®ãã«ã¹ãã§ãã¯ã¯æ¬ ããã¾ããã
Apigeeã®API Healthã¯ããã®ã¯ã©ã¤ã¢ã³ãè¦ç¹ã®APIãã«ã¹ãã§ãã¯ãç°¡åã«å®ç¾ããç¬ç«ãããµã¼ãã¹ã§ãã2015å¹´12æç¾å¨ããã¼ã¿çã§æä¾ããã¦ãã誰ã§ãç¡æã§å©ç¨ã§ãã¾ããã¤ã³ã¿ã¼ãããããã¢ã¯ã»ã¹å¯è½ãªãã©ããªAPIã§ãç£è¦å¯¾è±¡ã«ãããã¨ãã§ãã¾ãããããããå®ç¾©ãããªã¯ã¨ã¹ããæå®ããé »åº¦ã§éä¿¡ãã¦ãã¨ã©ã¼ã®çºçãã¬ã¹ãã³ã¹ã¿ã¤ã ã®ç°å¸¸ãããã°ã¡ã¼ã«ãSlackãªã©ã§ã¢ã©ã¼ããéã£ã¦ããã¾ãããªã¯ã¨ã¹ãã¯ä¸çï¼å°ç¹ããéä¿¡ãããã¨ãå¯è½ã§ãæåçãã¬ã¹ãã³ã¹ã¿ã¤ã ãçºä¿¡å°ç¹ãã¨ã«ã°ã©ã表示ãããã¨ãªã©ãã§ãã¾ãã
使ãæ¹ã¯æ¬¡ã®éãï¼è©³ç´°ã¯公式ドキュメントãåç §ï¼ï¼
- (ããã¾ã æã£ã¦ããªããã°)Apigeeアカウントを用意する
- API Healthダッシュボードã«ãã°ã¤ã³
- å·¦ãµã¤ãã®"+"ãã¾ãã¯å³ä¸ã®"Add Prove"ãã¿ã³ã§ããã¼ããä½æ
- ããã¼ãåã¨ã¹ãããåãã¤ãããããã¼ãã¯1å以ä¸ã®ã¹ãããï¼APIå¼ã³åºãï¼ãããªããã«ã¹ãã§ãã¯ã®åä½ãåä¸ã®GETãªã¯ã¨ã¹ãã§ãããããèªè¨¼ãã¼ã¯ã³ãåå¾ãã¦ããã使ããããªä¸é£ã®å¼ã³åºãã·ã¼ã±ã³ã¹ã§ããã
- ã¹ãããã®ãªã¯ã¨ã¹ãURIã¨ã¡ã½ãããæå¾ ããã¬ã¹ãã³ã¹ã³ã¼ããè¨å®
- "Show Advanced"ã使ãã¨ãå¼ã³åºãåã«çãã¹ã¯ãªãããå®è¡ãããããªã¯ã¨ã¹ãã®ããããè¨å®ãããã§ãããã¾ããã¬ã¹ãã³ã¹ããããJSONããã£ã®ä¸é¨ãæ½åºãã¦å¤æ°ã«è¨å®ãããã¨ãå¯è½ï¼ã¢ãµã¼ã·ã§ã³ã«ä½¿ã£ãã次以éã®ã¹ãããã§åç §ã§ããï¼
- å¿ è¦ãªã"Add new step"ã§ã¹ãããã追å
- ããã¼ãã®åä½ãè¨å®
- ãã§ãã¯é »åº¦: 30ç§/1å/5å/15å/30å/1æéã®ãããã
- ã¢ã©ã¼ãæ¡ä»¶: ã¬ã¹ãã³ã¹ã³ã¼ããå¤æ°ã®ã¢ãµã¼ã·ã§ã³å¤±æåæ°ãã¬ã¹ãã³ã¹ã¿ã¤ã ãé¾å¤ãè¶ ããåæ°ãç°å¸¸ãªé 延
- éç¥å : ã¡ã¼ã«ãHipChatãSlack
- ãªã¯ã¨ã¹ãã®çºä¿¡å°ãè¨å®ï¼ä»¥ä¸ã®ï¼å°ç¹ãon/offï¼
- Oregon(ã¢ã¡ãªã«è¥¿æµ·å²¸)
- Washington DC(ã¢ã¡ãªã«æ±æµ·å²¸)
- Dublin(ã¢ã¤ã«ã©ã³ã)
- Sydney(ãªã¼ã¹ãã©ãªã¢)
æå¾ã«"I'm Done"ãæ¼ãã°å®æãã«ã¹ãã§ãã¯ãå§ã¾ããè¨å®ããæ¡ä»¶ã§ã¢ã©ã¼ããåããããããã·ã¥ãã¼ãã§ããã¾ã§ã®ãã«ã¹ãã§ãã¯ã®çµæãåç §ãããã¨ãã§ãã¾ãã
ç°¡åã«è¨å®ã§ãã便å©ãªç¡æãµã¼ãã¹ã§ãã®ã§ãç£è¦ãããAPIããããã¹ã¦ã®æ¹ã«ãªã¹ã¹ã¡ã§ãããã²ã試ãããï¼
Slackã®WebHookã¨NTTãã³ã¢ã®éè«å¯¾è©±APIã¨Apigeeã§éè«ããããã¤ãã #apijp
Web API Advent Calendar 2014ãæçµæ¥ã®ã¨ã³ããªã¯ãæè¿ä¸é¨ã§æµè¡ä¸ã®ãã¼ã ã³ãã¥ãã±ã¼ã·ã§ã³ãã¼ã«Slackã®ãã¿ã§ãã
ï¼å®æããããããSlackã§è©¦ãã¦ããã¨ããï¼
Slackãã¿ã¯id:i2keyããã®12/13ã®ç´ æµãªã¨ã³ããªï¼
ZapierでSlackを佐野ひなこちゃんで埋め尽くす #apijp - @i2key のBlog
ã§ãã§ã«ä½¿ããã¦ãã¾ãã¾ããããããã§ã¯Slackãæä¾ããå¥ã®ã¤ã³ãã°ã¬ã¼ã·ã§ã³æ¹æ³ã使ã£ã¦éè«ããããä½ã£ã¦ã¿ã¾ãã
Slackã«ã¯å¤é¨ããã°ã©ã ã¨ã®さまざまなインテグレーション方法ãç¨æããã¦ãã¾ãããã®ä¸ã®Outgoing WebHooksã®æ©è½ã¯ãSlackã«æ°ããã¡ãã»ã¼ã¸ãå ¥åããããã³ã«è¨å®ããå¤é¨URLãå¼ã³åºãã¦ãããã¨ãããã®ã§ããããã«ãå æ¥ã®API Meetup Tokyo #4ã§ドコモさんが紹介ãã¦ãã雑談対話APIãçµã¿åããã¾ãã
Slackã®WebHookå¼ã³åºãã¨éè«å¯¾è©±APIã®å¼ã³åºãå½¢å¼ã¯ç°ãªããããéã§ãã®èª¿æ´ãå¤æãè¡ãä½ããå¿ è¦ã«ãªãã¾ããé常ãªãä½ããã®ã¹ã¯ãªãããªã©ãæ¸ãã¨ããã§ãããããã§ã¯ããããªã(?)宣ä¼ãå ¼ãã¦Apigee Edgeã®API Proxyã®æ©è½ã使ã£ã¦ãã®æ¥ç¶ãå®ç¾ãã¦ã¿ã¾ããã
ããã¾ããªå¦çã®æµã
- æå®ãããæ¡ä»¶ã«åè´ããã¡ãã»ã¼ã¸ãå ¥åãããã¨ãè¨å®ãã¦ãããApigee Proxyã®URLã«Slackãã¡ãã»ã¼ã¸ããã¹ããªã©ãPOSTãã
- Apigeeããã©ã¼ã ãã¼ã¿ãåãåããã¡ãã»ã¼ã¸ããã¹ã(text)ãã¦ã¼ã¶å(user_name)ãªã©ãåãåºã
- ã¦ã¼ã¶åã"slackbot"ã®å ´åãçºè¨è ã¯ï¼èªåãå«ãï¼ããããªã®ã§ä½ããã200ã§ç©ºã®ã¬ã¹ãã³ã¹ãè¿ãã¦å¦çãçµããããããè¡ããªãã¨èªåã®çºè¨ã«å¯¾ãã¦ãWebHookå¼ã³åºããèµ·ããããç¡éã«ã¼ããçºçããï¼1åããããã¾ããï¼
- 以åã®ä¼è©±ã®ã³ã³ããã¹ãIDããã£ãã·ã¥ã«ããã°èªã¿åºã
- å¿ è¦ãªãã¼ã¿ãJSONå½¢å¼ã«ãã¦ãã³ã¢APIã«POSTãã
- ãã³ã¢APIãè¿ãJSONãã¼ã¿ãåãåãããããã®çºè¨(utt)ãã³ã³ããã¹ãID(context)ãåãåºã
- ã³ã³ããã¹ãIDã¯Slackã®channel_idããã¼ã¨ãã¦ãã£ãã·ã¥ã«ä¿åãã¦ãã
- ãããã®çºè¨ãWebHookã®è¿ä¿¡å½¢å¼ã®JSONã«ã¾ã¨ãç´ãã¦Slackã«è¿ã
Apigeeã§ã®å®è£
ãããã¯ã¯ã©ã¦ãåã®Apigeeç¡åçã§ãã¹ã¦å®ç¾ã§ãã¾ãã
ï¼ãããéçºä¸ã®Apigeeç»é¢ï¼
Apigeeã§ã®å®è£ ä¸ã®ãã¤ã³ãã¯ä»¥ä¸ã®éãï¼
- SlackããPOSTããããã©ã¼ã ãã¼ã¿ãããã³ã¢APIããè¿ãããJSONå ãã¼ã¿ããã®ãã©ã¡ã¿ã®åå¾ã«ã¯ExtractVariablesポリシーã使ã
- ãã³ã¢APIã¸ã®ãªã¯ã¨ã¹ãããSlackã¸ã®ã¬ã¹ãã³ã¹ã®ä½æã«ã¯AssignMessageポリシーã使ã
- contextã®ä¿åã»èªã¿åºãã«ã¯PopulateCacheポリシーã¨LookupCacheポリシーã使ã
- ãããçºè¨ã«ããç¡éã«ã¼ããé²ãããã«ã¯Conditional Flowã¨RaiseFaultポリシーã使ã
ï¼ãããªã·ã¼ãã¨ããã®ã¯Apigeeç¨èªã§ãããããç¨æãããå¦çé¨åã®ãã¨ï¼
ã¾ã¨ã
Slackã«éãããæè¿ã¯ãã¾ãã¾ãªãµã¼ãã¹ã§WebHookãæä¾ãããããã«ãªã£ã¦ãã¦ãã¾ããApigeeã®æã¤ã¤ã³ã¿ãã§ã¼ã¹å¤ææ©è½ã使ãã°ãèªåã§POSTãåãããµã¼ããã¹ã¯ãªãããç¨æãããã¨ãªãããã¾ãã¾ãªå¥ã®APIã«æ¥ç¶ãããã¨ãã§ãã¾ããï¼ããã§ã¯æ±ãã¾ããã§ãããè¤æ°APIã®ããã·ã¥ã¢ãããå¯è½ï¼
Apigeeã¯æ¬æ¥APIæä¾è ã«API管çã¬ã¤ã¤ãæä¾ãããã®ã§ãããã«æ¸ãããã¼ã«çãªç¨æ³ã¯æ¬è³ªçãªä½¿ãæ¹ã§ã¯ããã¾ããããããWebHookç¨ã®æ¥ç¶ãã¼ã«ã¨ãã¦ã¯ç¹ã«æç¨æ§ãé«ããããããªãã¨æãã¾ããã
ã¡ãªã¿ã«æ¸ãã¦ããéä¸ã§ãé常ã«ããä¼¼ãå
容ã®ããã°è¨äºãè¦ã¤ããã®ã§ãæ¬ã¨ã³ããªã®ã¿ã¤ãã«ã¯æ¬æã表ãã¦ãã¡ãã«ãããã¦ã¿ã¾ããã:-)
Safx: TypetalkのWebhookとNTTドコモの雑談対話APIとGoogle Apps Scriptで雑談ボットをつくる
Slackã§ã¯ãªãnulabããã®TypetalkãApigeeã§ã¯ãªãGoogle Apps Scriptã使ããã¦ãã¾ãããä»çµã¿çã«ã¯ã»ã¨ãã©åãã§ããä¸é¨åèã«ããã¦ããã ãã¾ãããæè¬ï¼
apibã§ã³ãã³ãã©ã¤ã³ããAPIãè² è·ãã¹ã #apijp
ããã¯Web API Advent Calendar 2014ã8æ¥ç®ã®ã¨ã³ããªã§ãããã¼ã«ã®å°ãã¿ç¬¬äºå¼¾ã§ãã
APIã®ãã¹ãã«ã¯ãç®çã«å¿ãã¦curlã³ãã³ããPostmanãããã¦JMeterãab(Apache Bench)ãªã©ãã¾ãã¾ãªãã¼ã«ã使ãã¾ããä»åã¯abã«ããä¼¼ãï¼ããã¦ããé²åããï¼ã·ã³ãã«ãªã³ãã³ãã©ã³ãã¼ã¹ã®è² è·ã»æ§è½ãã¹ããã¼ã«ã§ããapib(API Bench)ãç´¹ä»ãã¾ãã
ç¹å¾´
- keep-aliveãchunked encodingãå«ããHTTP 1.1ã®æ£ç¢ºãªãµãã¼ã
- è¤æ°ã®I/Oã¹ã¬ããã使ããã«ãã³ã¢ãæ´»ç¨
- 大ããªãªãã¸ã§ã¯ãã®POSTãPUTããµãã¼ã
- OAuth 1.0ã®ç½²åããµãã¼ã
- å®è¡çµæã¯ãã¡ã¤ã«åºåå¯è½ï¼èªååã®ããã®é£æºã容æï¼
ãªã©ã
ã¤ã³ã¹ãã¼ã«
MacãªãHomebrewã§ä¸çºã§ãï¼
brew install apib
ãã以å¤ã®ãã©ãããã©ã¼ã ã§ã¯GitHubããソースを取得してビルドããå¿ è¦ãããã¾ãã
å®è¡ä¾
åææ¥ç¶æ°10ã§30ç§éãé£ç¶ã§ç®ä¸æ¯ãªã¯ã¨ã¹ããéãï¼
$ apib -c 10 -d 30 <ã¿ã¼ã²ããURL> (5 / 30) 51.958 0% cpu (10 / 30) 54.582 0% cpu (15 / 30) 54.378 0% cpu (20 / 30) 54.787 0% cpu (25 / 30) 54.577 0% cpu (30 / 30) 54.387 0% cpu Duration: 30.012 seconds Attempted requests: 1624 Successful requests: 1624 Non-200 results: 0 Connections opened: 10 Socket errors: 0 Throughput: 54.111 requests/second Average latency: 184.049 milliseconds Minimum latency: 175.175 milliseconds Maximum latency: 384.165 milliseconds Latency std. dev: 15.330 milliseconds 50% latency: 181.145 milliseconds 90% latency: 190.309 milliseconds 98% latency: 192.284 milliseconds 99% latency: 192.580 milliseconds Client CPU average: 0% Client CPU max: 0% Client memory usage: 0% Total bytes sent: 0.13 megabytes Total bytes received: 0.17 megabytes Send bandwidth: 0.03 megabits / second Receive bandwidth: 0.05 megabits / second
apibã«ã¯ã¡ã½ããããããã®æå®ãèªè¨¼è¨å®ãªã©ä»ã«ãå¤ãã®ãªãã·ã§ã³ãããã¾ãã詳ããã¯ãapib -hã§ãã«ããè¦ãããこちらãåç §ãã¦ãã ããã
注æï¼
ããããã«å¤§éã®ãã©ãã£ãã¯ãçæãã¾ãã®ã§ãã¿ã¼ã²ããã¯ãããããæ éã«é¸ãã§ãã ããï¼é常ã¯èªåã§éçºã»ç®¡çãã¦ãããµã¼ãï¼ãããã¤ã«ä»äººã®ãµã¼ãã«è² è·ããããã¨æ»æã¨ã¿ãªããããã¨ãããã¾ãï¼
ããããã·ã¼ã±ã³ã¹å³ï¼WebSequenceDiagrams #apijp
ããã¯Web API Advent Calendar 2014ã7æ¥ç®ã®ã¨ã³ããªã§ããç¥ã£ã¦ããæ¹ãå¤ãã¨æãã¾ããããã¼ã«ã®å°ãã¿ã§ã
Web APIãæ±ã£ã¦ããã¨ãèªè¨¼ãããã·ã¥ã¢ããã®ããã¼ã®è¨è¿°ãªã©ãç°¡åãªã·ã¼ã±ã³ã¹å³ãæ¸ããããªãå ´åãããããã¾ãããããªã¨ãã«ãªã¹ã¹ã¡ãªã®ããã«ããã®Hanov Solutions社ãæä¾ãã便å©ãªWebãµã¼ãã¹WebSequenceDiagramsã
次ã®ãããªã·ã³ãã«ãªããã¹ããæ¸ãã ãã§ï¼
title GWã§ã®mashup ã¢ããª->GW: POST éµä¾¿çªå· GW->ãµã¼ãã¹A: GET /éµä¾¿çªå· ãµã¼ãã¹A->GW: ä½æ(JSON) GW->ãµã¼ãã¹B: POST ä½æ ãµã¼ãã¹B->GW: 緯度çµåº¦(XML) GW->ã¢ããª: 緯度çµåº¦(JSON)
次ã®ãããªã¤ã¡ã¼ã¸ãçæãã¦ããã¾ãï¼
åºæ¬çã«ç¡åã§ä½¿ãã¾ãããçæããå³ã¯ç´æ¥ãªã³ã¯ãã¦ä½¿ããã¨ãPNGã¤ã¡ã¼ã¸ã¨ãã¦exportãããã¨ãã§ãã¦é常ã«ä¾¿å©ã§ããã¹ã¿ã¤ã«ãããã¤ãç¨æããã¦ãã¾ããä¾ï¼
ã¡ããã¨APIãç¨æããã¦ããã®ã§ä»ã®ãã¼ã«ãè¨èªã¨çµã¿åãããã®ãç°¡åã有償のプレミアム版ã§ã¯å³ã®ç·¨éã«è¿½å¾ãããªã³ã¯ã®çæãããé«åº¦ãªè¨æ³ãPDF/SVGã§ã®exportãªã©ããµãã¼ãããã¾ãã
ã·ã³ãã«ã§ããé常ã«ä½¿ãåæã®è¯ããã¼ã«ã§ãããªãã®APIãã¼ã«ç®±ã«ãããã¦ããããåªããã®ã®ä¸ã¤ã§ãã
REST APIãè¨è¿°ããï¼Swaggerç´¹ä» #apijp
Web API Advent Calendar 2014ãåæ¥ã¯Swaggerãç´¹ä»ãã¾ãã
Swaggerã¯Reverbã«ãã£ã¦éçºããããRestfulãªAPIãè¨è¿°ããæ¨æºä»æ§ã§ããAPIãæ©æ¢°å¯èªãªå½¢ã§è¨è¿°ãããã¨ã¯ãããã¥ã¡ã³ãçæããã¼ã«éçºããã¾ãã¾ãªå½¢ã§ã®èªååã«é常ã«éè¦ã§ãã好ãå«ãã¯ã¨ããããSOAPã«ã¯WSDLã¨ããçµ±ä¸æ¨æºãããã¾ããããRESTã«ã¯æ¬è³ªçã«ãããã£ãæ¨æºããªããããé¡ä¼¼ãããã¾ãã¾ãªä»æ§ãéçºããã¦ãã¾ãããSwaggerã¯ãã®ä¸ã§ãæãææãªãã®ã®ä¸ã¤ã ã¨æãã¾ãã
1. ç¹å¾´
- è¨è¿°ã¯JSONã§ã·ã³ãã«ããããã å®ç¾©ã®ä¾ï¼
{ "swagger": "2.0", "info": { "version": "1.0.0", "title": "petstore" }, "paths": { "/users": { "get": { "responses": { "200": { "description": "Describe the 200 response in more detail" } } } } } }
Swaggerã®ãµã¤ãã«ã¯ãã©ã¦ã¶ä¸ã§è©¦ããSwagger Editorã¨ãããã®ãç¨æããã¦ãããå·¦å´ã«APIè¨è¿°ãæ¸ãã¨ãå³å´ã«çæãããããã¥ã¡ã³ãã®ãã¬ãã¥ã¼ãè¦ããã¨ãã§ãã¾ãï¼ä¸å³ï¼ããããå°ã試ãã¨Swaggerã®é°å²æ°ãããã¤ãããã¨æãã¾ããï¼APIã®è¨è¿°ã¯JSONã§ã¯ãªãYAMLãªã®ã§æ°ãã¤ãã¦ãã ããï¼
- ãªã¼ãã³ã§ãã³ãã¼ãå®è£ è¨èªãªã©ã«ä¾åããªããä»æ§ã¯GitHubで公開ããã¦ããApache 2.0ã©ã¤ã»ã³ã¹ã§å©ç¨ã§ãã¾ãã
- ã¨ã³ã·ã¹ãã ãå å®ãã³ãã¥ããã£ã«ããさまざまな言語に対応した多彩なツールやライブラリãä½ããã¦ãã¾ãã
- è³åã»ã¦ã¼ã¶ä¼æ¥ã®å¤ããSwagger 2.0ä»æ§ã¯ãªã³ã©ã¤ã³ãµã¼ãã¹ã®PayPalãGetty ImagesãAPIé¢é£ä¼æ¥ã®Apigeeã3scaleãå§ãã500è¿ãã®å¤§å°ä¼æ¥ã®è²¢ç®ã§ä½ããã¾ãããMicrosoftã米政府ã使ã£ã¦ãã¾ãã
2. ãã¼ã¸ã§ã³ã«ã¤ãã¦
2014/09/08ã«ææ°ã®Swagger 2.0がリリースããã¾ããã2.0ã¯ãããã¾ã§ã®1.x(ææ°ã¯1.2)ç³»ã¨ã¯äºææ§ããªãã®ã§æ³¨æãå¿ è¦ã§ãï¼ãã¤ã°ã¬ã¼ã·ã§ã³ã¬ã¤ãã¯こちらï¼ã2.0ãã¾ã åºãã°ãããªã®ã§ãwebä¸ã§è¦ã¤ããæ¥æ¬èªã®Swaggerè¨äºã¯ã»ã¨ãã©1.xç³»ã®ãã®ã§ãã注æãã¦ãã ããã
3. Swagger対å¿ã®ä¾¿å©ãã¼ã«
- Postman
- ã¿ããªå¤§å¥½ãAPIãã¹ãã¯ã©ã¤ã¢ã³ãã®å®çªãPostmanã«ãSwaggerã¤ã³ãã¼ãæ©è½ãããã¾ãï¼Swagger 1.2対å¿ï¼ã
- Mockable
- REST/SOAPãªã¢ãã¯ãµã¼ããç°¡åã«ç«ã¡ä¸ããããæå¾ ã®ãµã¼ãã¹ãMockableã§ãSwaggerã¤ã³ãã¼ãããµãã¼ãäºå®ã§ãï¼ç¾æç¹ã§ã¯æªå®è£ ï¼ã
- Apigee 127
- APIã¢ãã«å®ç¾©ããã¼ã¹ã«ãNode.jsã§ã®å®è£ ã¹ã±ã«ãã³ãçæãããããã£ãã·ã¥ãã¬ã¼ããªããããOAuthãªã©ã®API管çæ©è½ãç°¡åã«å®ç¾ã§ãããªã¼ãã³ã½ã¼ã¹ããã¸ã§ã¯ããApigee 127ã§ãSwagger 2.0ãåºç¤æè¡ã¨ãã¦æ¡ç¨ããã¦ãã¾ãã
ã¾ã¨ã
Swaggerã¯ç¾å¨ã¡ã¸ã£ã¼ãã¼ã¸ã§ã³ã®ç§»è¡æã«ããããããã¼ã«ããµãã¼ãã«è¥å¹²ã®æ··ä¹±ã¯ããã¾ããã2.0ã¸ã®ç§»è¡å®äºå¾ãã¨ã¦ã楽ãã¿ãªæè¡ã§ããWeb API好ããªãã°ä»ã®ãã¡ã«è©¦ãã¦ã¿ã価å¤ã¯ããã¾ããï¼
Raspberry Piã§Groovy! #gadvent2012
G* Advent Calendar 2012ãããããæçµæ¥ã¨ãªãã¾ãããæ¨æ¥ã¯ @shuji_w6e ããã®JavaのテストコードからはじめるGroovyã§ããã
ãã¦ãï¼æã«æ³¨æãã¦ãã話é¡ã®ä½ä¾¡æ ¼ã·ã³ã°ã«ãã¼ãã³ã³ãã¥ã¼ã¿ãRaspberry Piãã¤ãå æ¥ãããããæã家ã«ãå±ãã¾ãããã¿ã¤ãã³ã°ãããRaspberry Piä¸ã§åä½ããJDK 8ã®éçºè ãã¬ãã¥ã¼çï¼JavaFXãå«ãï¼ï¼ããªãªã¼ã¹ãããã®ã§ãããã¤ãã®ã£ãã¦ãããã«ãã®ä¸ã«Groovyããµãããã¦éãã§ã¿ã¾ãããã¨ãã話ã§ãã
1. Linux/JDKãè¼ãã
詳ããã¯ãã¡ããã覧ãã ããï¼è¨³ãã¦ããã¾ããï¼ï¼
Raspberry Pi で JavaFX - かんたん3ステップ
ããã§ã¯å®éã«ãã£ã¦ã¿ã¦ããã£ã注æäºé ãªã©ãããã¤ãããã¦ããã¾ãï¼
- é»æºã³ãã¯ã¿ã¯MicroUSBããã¸ã«ã¡ã§ãã使ããã¦ããMini-USBã¨ã¯å¥ç©ãªã®ã§æ³¨æ
- é»æºã¯5VãModel-Bã§ã¯700mA以ä¸å¿ è¦ãã¹ããå é»ç¨ã®é»æºã±ã¼ãã«ãè³¼å ¥ããããUSB 3.0ã§ããã°900mA以ä¸ã®çµ¦é»è½åãããã®ã§MacBook Proãªã©ããã§ã大ä¸å¤«ã¨ã®åãã
- SDã«ã¼ãã«ã¤ãã¦ã¯ã4GB/Class 4ãã大容éï¼é«éã®ãã®ã¯é¿ãããã¨ãã£ãããéã«JDKã®ããã¥ã¡ã³ãã®ããã«Class 10ã§å¤§å®¹éæ¨å¥¨ããªã©ã¨ãã¾ãã¾ãªæ å ±ãããæ··ä¹±ãã¦ãããç§ã¯ä½ã£ã¦ãã4GB/Class 6ã®ãã®ã使ã£ã¦ã¿ããç¹ã«åé¡ãªãã
- ã«ã¼ãã«ã¤ã¡ã¼ã¸ãæ¸ãè¾¼ãéãMac㧠RPi-sd Card Builder ã使ãå ´åã¯ã¤ã¡ã¼ã¸ãã¡ã¤ã«ã®ãã¹ã«ç©ºç½ãå ¥ã£ã¦ããªããã¨ã確èªãããç§ã¯"Raspberry Pi"ã¨ãããã©ã«ãã«å ¥ãã¦ãã¦ããã£ãã
- ãã±ã¼ã«ã¯ja_JPçã«è¨å®ããªãæ¹ããããã³ã³ã½ã¼ã«ãè¨å®ã¡ãã¥ã¼ãæ¥æ¬èªã«ãªãæååããã¦ãã¾ãããã
- sshã¯çµ¶å¯¾ã«enableã«ãã¦ãããã¨ï¼ï¼çç±ã¯å¾è¿°ï¼
2. JavaFXã§éã¶
JavaFXã®ãµã³ãã«ã¢ããªãJDKã®éçºè
ãã¬ãã¥ã¼ã¨åããã¼ã¸ãããã¦ã³ãã¼ãã§ãã¾ãï¼
http://jdk8.java.net/fxarmpreview/
以ä¸ã®ã¢ããªãå«ã¾ãã¦ãã¾ãï¼
- StopWatch
- BouncingBall
- Calculator
- BrickBreaker
- FXML-LoginDemo
- SwingInterop
- Ensemble
ã¾ã¨ãã«åãã®ã¯ä¸ã®ï¼ã¤ã ãã§ããããããä¸è¾ã«ãå®å®ãã¦ããã¨ã¯è¨ãã¾ããããã
ã¢ããªãåããã«ã¯æ¬¡ã®ããã«ãã¾ãï¼
java -Djavafx.platform=eglfb -cp /usr/local/java/jre/lib/jfxrt.jar:BrickBreaker.jar brickbreaker.Main
Dãªãã·ã§ã³ã§EGLFBã¢ã¼ããæå®ãã¾ããããã¯X Windowãªã©ãä»ããç´æ¥OpenGLä¸ã§åä½ããã¢ã¼ãã§ãç¾å¨å¯ä¸ã®é¸æè¢ã§ããJavaFXã¢ããªãç»é¢ãå æãã¦åä½ããã®ã§ãã³ã³ã½ã¼ã«ããç´æ¥èµ·åãã¦ãã¾ãã¾ããããã ããä¸è¨ã®ã¢ããªã«ã¯çµäºãã¿ã³ãªã©ããªãããã®ã¢ã¼ãã§ã¯çµäºããæ¹æ³ããªããªããããå¿ ãå¥ésshã§ãªã¢ã¼ããã°ã¤ã³ãã¦ãããpsã¨killã§çµäºã§ããããã«ãã¦ããã¾ãããã
jfxrt.jarã¯ï¼ã¾ã ï¼ããã©ã«ãã§ã¯ã¯ã©ã¹ãã¹ã«å ¥ã£ã¦ããªãã®ã§ãæ示çã«æå®ããå¿ è¦ãããã¾ãããã¨ã¯ãã¢ããªåºæã®jarãã¡ã¤ã«ã¨ãã¡ã¤ã³ã¯ã©ã¹ãæå®ãã¾ãã
ä¸è¨ã¯ããªãã¿BrickBreakerã¨Calculatorãåä½ãã¦ããç»é¢ã§ãï¼
3. Groovyã§éã¶ï¼
Java SEãåãã¨ãããã¨ã¯ããªãã¡Groovyãåããã¨ãããã¨ã§ãï¼æ®éã«ææ°çã®Groovy 2.0.6ãã¤ã³ã¹ãã¼ã«ãã¦è©¦ãã¦ã¿ã¾ããï¼
ããã£ï¼groovyshã¨groovyConsoleãåãã¦ããã®ãããããããã ããã§ããããï¼
ä»åã®G* Advent Calendarの12/2分ã§@tyama ãããä½ã£ããªãºã ããã¯ã¹ãåããã¦ã¿ã¾ããï¼
ï¼ã¡ãªã¿ã«Rasberry Piã«ã¯ã¹ãã¼ã«ã¯ããã¾ãããHDMIçµç±ã§ãã¬ãããé³ãã§ã¦ãã¾ãï¼
ããã¾ã§é 調ã«åä½ãã¦ããããã«è¦ããã¨æãã¾ãããå®ã¯å¤§åé¡ããé ããã¨ã«ããé ããããgroovyshãªãã¦ç«ã¡ä¸ããã¾ã§30ç§ããããããã¾ããgrovyConsoleã§ã¯ãã¼ã¿ã¤ãã«ã¤ãã¦ããã¾ãããå®ç¨ã¯ãããããã¢ã«ãå³ããã¬ãã«ã§ããJavaã®ããã©ã¼ãã³ã¹ã¯æªããªãã®ã§ãä½ãç¹æ®ãªåå ããããããªæ°ããã¾ãããä»åã¯èª¿æ»ãéã«åãã¾ããã§ãããããããªããã
ããã«ãã®å ãGroovyFXã¾ã§é²ãäºå®ã ã£ãã®ã§ãããJavaFXã®å®è£ ãä¸å®å ¨ï¼WebViewãMediaViewãªã©ãæªå®è£ ï¼ãªé¢ä¿ã§ãåæåæã«ã¨ã©ã¼ã«ãªã£ã¦GroovyFXãèµ·åã§ãã¾ããã§ãããæ®å¿µç¡å¿µï¼ãã®ã¸ããè¿ãå°æ¥æ½åã§ããã¨æãã¾ãã
ã¾ã¨ããããã¦One More Thing...
以ä¸ãåã®ããã¤ã¹ãRasberry Piã§ã®Groovyå®é¨ã¬ãã¼ã第ä¸å¼¾ã§ããã注æãã¦ããªããªãæã«å ¥ããªãããã¤ã¹ã§ãããæè¿ã¯å¢ç£ä½å¶ãæ´ã£ãã¨ã®åã§ãããæ¨æºã¡ã¢ãªã256MBâ512MBã«ã¢ãããã¦ãã¾ããä¸ååå°ã§è²·ããããã«ã¯ããªãéã¹ãããã¤ã¹ã§ãã®ã§ãã¾ã ã®æ¹ã¯ãã²æ³¨æãã¦ã¿ã¦ã¯ãããã§ããããã
ãã¦ãããã§2012å¹´ã®G* Advent Calendarãå®äºã§ããåå ãã¦ããã ããã¿ãªããããç²ããã¾ã§ããï¼ãããã¨ããããã¾ãããæå¾ã«ãプログラミングGroovyãã®å·çãã¼ã ããã®ã¯ãªã¹ãã¹ãã¬ã¼ã³ãã¨ãã¦ã
プログラミングGROOVY別冊:第8章 Groovy 2.0の新機能
ããå±ããã¾ãï¼ãã¥ã¼ãã£ã¹ãããã®mybetabookï¼Grails製ï¼ï¼ã使ã£ãããã³ã®ã³æ¬ã®ãã¼ãã£ã«å¥åã§ãï¼ç¡åï¼ãæ¬æ¸ãè²·ãããæ¹ãã¾ã ã®æ¹ã«ã楽ããã§ããã ããã°å¹¸ãã§ãã
ã§ã¯ã¿ãªãããGroovyãªè¯ããå¹´ããè¿ããã ããï¼
è¤éãªã¢ãã¡ã¼ã·ã§ã³ï¼SVGçã®GroovyFXçï¼
id:the48ãããåã®ã¨ã³ããªã®ãµã³ãã«ã¢ãã¡ã¼ã·ã§ã³ã®SVGçãæ¸ããã¦ãã¾ããï¼
複雑なアニメーション(SVG版) - 48's diary
JavaFXã«å«ã¾ãã¦ããå èµãã©ã¦ã¶ã¯SVGããµãã¼ããã¦ããã®ã§ãå®ã¯ãã®SVGçãJavaFX/GroovyFXã§ç°¡åã«åãããã¨ãã§ãã¾ãã
以ä¸ã¯GroovyFXã§æ¸ããä¾ã§ããSVGé¨åã¯id:the48ããã®ãã³ãããã¾ããã
JavaFXã®Webã³ã³ãã¼ãã³ãã«ã¤ãã¦ã¯ä¸è¨ãã©ããï¼