Nozbe APIを使ったデモのソース
元記事はこちらです。
■Application.cfm
<cfprocessingdirective pageEncoding = "UTF-8"> <cfsetting enableCFoutputOnly="yes"> <cfapplication name="#hash( getCurrentTemplatePath() )#" sessionmanagement="yes" sessiontimeout=#CreateTimeSpan(1, 0, 0, 0)# > <!---=================================== 設定 ====================================---> <cfset request.blog_url = ""> <!--- 通常 <cfset request.proxyServer = ""> <cfset request.proxyPort = "80"> ---> <!--- 会社 <cfset request.proxyServer = "xx"> <cfset request.proxyPort = "xx"> ---> <cfset request.proxyServer = ""> <cfset request.proxyPort = "80"> <cfparam name="session.key" default=""> <!--- Nozbe key ---> <cfparam name="session.p_id" default=""> <!--- Nozbe project id ---> <cfparam name="session.style" default="color:black;"> <!--- action listの色 --->
■index.cfm
<cfprocessingdirective pageEncoding = "UTF-8"> <!---///////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////---> <cfparam name="url.p" default=""> <cfparam name="form.mail" default=""> <cfparam name="form.pass" default=""> <cfparam name="form.p_id" default=""> <cfparam name="form.data" default=""> <!--- 処理 ---> <cfswitch expression = "#url.p#"> <!--- hide ---> <cfcase value="hide"> <cfset session.style = "color:white;"> </cfcase> <!--- show ---> <cfcase value="show"> <cfset session.style = "color:black;"> </cfcase> <!--- login ---> <cfcase value="login"> <cfset cst_chkLogin()> </cfcase> <!--- logout ---> <cfcase value="logout"> <cfset session.key = ""> <cfset session.p_id = ""> </cfcase> <!--- listProject ---> <cfcase value="listProject"> <cfset session.p_id = ""> </cfcase> <!--- selectProject ---> <cfcase value="selectProject"> <cfset session.p_id = form.p_id> </cfcase> <!--- add ---> <cfcase value="add"> <cfset cst_createAction()> </cfcase> </cfswitch> <cfset content = ""> <cfif (session.key eq "")> <cfset content = cst_dspLogin()> <cfelse> <cfif (session.p_id eq "")> <cfset ary = cst_getProject()> <cfset content = cst_dspSelectProject(ary)> <cfelse> <cfif (url.p eq "next")> <cfset ary = cst_getNext()> <cfset content = cst_dspNext(ary)> <cfelse> <cfset ary = cst_getAction()> <cfset content = cst_dspContent(ary)> </cfif> </cfif> </cfif> <cfset cst_layout(content)> <!---================================================================= cst_dspNext ==================================================================---> <cffunction name="cst_dspNext" access="public" returnType="string" output="no"> <cfargument name="aryData" type="array" required="yes"> <cfset var local = structNew()> <cfset var ary = arguments.aryData> <cfset local.data = ""> <cfloop index="local.idx" array="#ary#"> <cfif local.idx.done eq "0"> <cfset local.data = local.data & local.idx.name & "#chr(13)##chr(10)#"> </cfif> </cfloop> <cfsavecontent variable = "local.tmp"> <cfoutput> <form name="frm_in"> <textarea name="data" cols="50" rows="10">#local.data#</textarea> </form> </cfoutput> </cfsavecontent> <cfreturn local.tmp> </cffunction> <!---================================================================= cst_dspContent ==================================================================---> <cffunction name="cst_dspContent" access="public" returnType="string" output="no"> <cfargument name="aryData" type="array" required="yes"> <cfset var local = structNew()> <cfset var ary = arguments.aryData> <cfsavecontent variable = "local.tmp"> <cfoutput> <form name="frm_in" action="index.cfm?p=add" method="post"> <input type="text" name="data" size="50" maxlength="50"> <input type="submit" value="add"> </form> <script language="JavaScript"> document.frm_in.data.focus(); </script> <table style="#session.style#"> <!--- <cfloop index="local.idx" array="#ary#"> <tr> <td>#local.idx.name#</td> </tr> </cfloop> ---> <!--- 最新順? ---> <cfloop index="local.idx" from="#arrayLen(ary)#" to="1" step="-1"> <tr> <td>#ary[local.idx].name#</td> </tr> </cfloop> </table> </cfoutput> </cfsavecontent> <cfreturn local.tmp> </cffunction> <!---================================================================= cst_dspSelectProject ==================================================================---> <cffunction name="cst_dspSelectProject" access="public" returnType="string" output="no"> <cfargument name="aryData" type="array" required="yes"> <cfset var local = structNew()> <cfset var ary = arguments.aryData> <cfsavecontent variable = "local.tmp"> <cfoutput> <form action="index.cfm?p=selectProject" method="post"> <table> <cfset local.chk_id = ""> <cfloop index="local.idx" array="#ary#"> <!--- 最初のデータをチェックしておく ---> <cfif (local.chk_id eq "")> <cfset local.chk_id = local.idx.id> </cfif> <tr> <td><input type="radio" name="p_id" value="#local.idx.id#" <cfif (local.chk_id eq local.idx.id)>checked</cfif>></td> <td>#local.idx.name#</td> </tr> </cfloop> </table> <input type="submit" value="send"> </form> </cfoutput> </cfsavecontent> <cfreturn local.tmp> </cffunction> <!---================================================================= cst_dspLogin ==================================================================---> <cffunction name="cst_dspLogin" access="public" returnType="string" output="no"> <cfset var local = structNew()> <cfset local.mailpass = form.mail & form.pass> <cfsavecontent variable = "local.tmp"> <cfoutput> <cfif local.mailpass neq ""> <br> <br> <strong>retry!</strong> </cfif> <form action="index.cfm?p=login" method="post"> <table> <tr> <td>e-mail</td> <td><input type="text" name="mail" value="#form.mail#"></td> </tr> <tr> <td>password</td> <td><input type="password" name="pass" value="#form.pass#"></td> </tr> </table> <input type="submit" value="login"> </form> </cfoutput> </cfsavecontent> <cfreturn local.tmp> </cffunction> <!---================================================================= cst_chkLogin ==================================================================---> <cffunction name="cst_chkLogin" access="public" returnType="void" output="no"> <cfset var local = structNew()> <cfset local.url = "http://www.nozbe.com/api/login/email-#form.mail#/password-#form.pass#"> <cfhttp url="#local.url#" proxyServer = "#request.proxyServer#" proxyPort = "#request.proxyPort#" method="get"> <cfset local.cfhttp = cfhttp.filecontent> <cfset local.data = DeserializeJSON(local.cfhttp)> <!--- keyにデータがない場合はnullが帰ってくる ---> <cfif (local.data.key eq "null")> <cfset local.data.key = ""> </cfif> <cfset session.key = local.data.key> </cffunction> <!---================================================================= cst_getProject ==================================================================---> <cffunction name="cst_getProject" access="public" returnType="array" output="no"> <cfset var local = structNew()> <cfset local.url = "http://www.nozbe.com/api/projects/key-#session.key#"> <cfhttp url="#local.url#" proxyServer = "#request.proxyServer#" proxyPort = "#request.proxyPort#" method="get"> <cfset local.cfhttp = cfhttp.filecontent> <cfset local.data = DeserializeJSON(local.cfhttp)> <cfreturn local.data> </cffunction> <!---================================================================= cst_getNext ==================================================================---> <cffunction name="cst_getNext" access="public" returnType="array" output="no"> <cfset var local = structNew()> <cfset local.url = "http://www.nozbe.com/api/actions/what-next/key-#session.key#"> <cfhttp url="#local.url#" proxyServer = "#request.proxyServer#" proxyPort = "#request.proxyPort#" method="get"> <cfset local.cfhttp = cfhttp.filecontent> <cfset local.data = DeserializeJSON(local.cfhttp)> <cfif not isArray(local.data)> <cfset local.data = arrayNew(1)> </cfif> <cfreturn local.data> </cffunction> <!---================================================================= cst_getAction ==================================================================---> <cffunction name="cst_getAction" access="public" returnType="array" output="no"> <cfset var local = structNew()> <cfset local.url = "http://www.nozbe.com/api/actions/what-project/id-#session.p_id#/key-#session.key#"> <cfhttp url="#local.url#" proxyServer = "#request.proxyServer#" proxyPort = "#request.proxyPort#" method="get"> <cfset local.cfhttp = cfhttp.filecontent> <cfset local.data = DeserializeJSON(local.cfhttp)> <cfif not isArray(local.data)> <cfset local.data = arrayNew(1)> </cfif> <cfreturn local.data> </cffunction> <!---================================================================= cst_createAction ==================================================================---> <cffunction name="cst_createAction" access="public" returnType="void" output="no"> <cfset var local = structNew()> <cfset local.url = "http://www.nozbe.com/api/newaction/name-#URLEncodedFormat(form.data)#/project_id-#session.p_id#/key-#session.key#"> <cfhttp url="#local.url#" proxyServer = "#request.proxyServer#" proxyPort = "#request.proxyPort#" method="get"> </cffunction> <!---================================================================= cst_layout ==================================================================---> <cffunction name="cst_layout" access="public" returnType="void" output="yes"> <cfargument name="content" type="string" required="yes"> <cfoutput> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="content-style-type" content="text/css; charset=utf-8" /> <title>demo</title> <meta name="keywords" content="Nozbe,api,demo" /> <meta name="description" content="Nozbe api demo (action add,list)" /> </head> <body> <cfif (session.key neq "")> <cfif (session.p_id neq "")> <a href="javascript:js_hide()">hide</a> <a href="javascript:js_show()">show</a> <a href="javascript:js_next()">next</a> <a href="javascript:js_listProject()">listProject</a> </cfif> <a href="javascript:js_logout()">logout</a> </cfif> <a href="#request.blog_url#">check!</a> #arguments.content# <script language="JavaScript"> <!-- function js_hide(){ location.href = "index.cfm?p=hide"; } function js_show(){ location.href = "index.cfm?p=show"; } function js_listProject(){ location.href = "index.cfm?p=listProject"; } function js_next(){ location.href = "index.cfm?p=next"; } function js_logout(){ location.href = "index.cfm?p=logout"; } //--> </script> </body> </html> </cfoutput> </cffunction>