16
Photo By John Shardlow http://www.flickr.com/photos/john_scone/493915787/ ACSをベースに1人でスマフ ォとWebアプリ開発に取り 組んでいた話 14219日水曜日

2014 02-19-titanium meetupvol16

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: 2014 02-19-titanium meetupvol16

Photo By John Shardlowhttp://www.flickr.com/photos/john_scone/493915787/

ACSをベースに1人でスマフォとWebアプリ開発に取り

組んでいた話

14年2月19日水曜日

Page 2: 2014 02-19-titanium meetupvol16

簡単に自己紹介

こういうブログを書いてます

アプリ2本リリース

14年2月19日水曜日

Page 3: 2014 02-19-titanium meetupvol16

最近の活動社内向けに営業支援業務アプリ作ってました

Titanium Mobile+ACS Node.js+express+Jade+acs-node

アプリで利用する企業やユーザ情報を管理するバックエンドツール

平日早朝+週末で

14年2月19日水曜日

Page 4: 2014 02-19-titanium meetupvol16

ACSとは?• Titaniumの開発元のAppceleratorが提供するMBaaS(エムバース)

• MBaaSについて詳しくは技術評論社さんの記事をhttp://gihyo.jp/dev/serial/01/mbaas/0002

• Parseの方が知名度高いかなぁ・・• スマフォアプリのバックエンドの機能で必要になりそうな機能が揃ってる

• 当然Titanium Mobileから扱いやすい• Appceleratorが提供するNode.js用のnpmモジュールのインターフェースがTitaniumのそれとほぼ同じなのでTitaniumの延長線上で気軽にWebアプリも作れる

14年2月19日水曜日

Page 5: 2014 02-19-titanium meetupvol16

ACSの管理画面はこんな感じ

14年2月19日水曜日

Page 6: 2014 02-19-titanium meetupvol16

• TitaniumStudioでプロジェクト設定を行った後tiapp.xmlを開いてEnable Cloud Serviceesの項目のEnableボタンをポチッとする

• Production Keyと Development Keyの2つが表示されればOKです

ACS利用する方法

tiapp.xml

14年2月19日水曜日

Page 7: 2014 02-19-titanium meetupvol16

©Garry Inghttp://www.flickr.com/photos/garrtron/4469056722/

ACSのサンプルコードをちょっと紹介

14年2月19日水曜日

Page 8: 2014 02-19-titanium meetupvol16

ある地点の周辺のお店検索# ACS利用するためのおまじないACS = require('ti.cloud')# 東京駅周辺の緯度と経度latitude = 35.681382longitude = 139.766084# Webの管理画面からお店情報などを登録しておくと# 以下クエリで東京駅周辺の情報が20件検索できるACS.Places.query page: 1 per_page: 20 where: lnglat: $nearSphere:[longitude,latitude] $maxDistance: 0.01, (e) -> if e.success for place in e.places Ti.API.info place.name

14年2月19日水曜日

Page 9: 2014 02-19-titanium meetupvol16

登録済のユーザのメールアドレスを表示する

# ACS利用するためのおまじないACS = require('ti.cloud')ACS.Users.query page: 1 per_page: 1 where: username:”h5y1m141”, (e) -> if e.success for user in e.users Ti.API.info user.email

14年2月19日水曜日

Page 10: 2014 02-19-titanium meetupvol16

登録済のユーザ宛にメールする# ACS利用するためのおまじないACS = require('ti.cloud')ACS.Users.query page: 1 per_page: 20, (e) -> if e.success for user in e.users # Webの管理画面からSAMPLEという名前のテンプレートを作成 # テンプレート内にmessageBodyという変数を設定 ACS.Emails.send( template:'SAMPLE' recipients:user.email messageBody:”test mail to #{user.name}” ,(result) -> Ti.API.info "sendmail result: #{result}" )

14年2月19日水曜日

Page 11: 2014 02-19-titanium meetupvol16

直感的にコード書けるAPIが提供されています

©jeffrey james pacres http://www.flickr.com/photos/jjpacres/3293117576/

14年2月19日水曜日

Page 12: 2014 02-19-titanium meetupvol16

良さそうに見えるけどやっぱりそれなりに落とし穴もあります

たまに出る謎のエラー

標準機能ではオブジェクト単位での一括登録や削除機能がない

14年2月19日水曜日

Page 13: 2014 02-19-titanium meetupvol16

後者についてはNode.jsをちょっと勉強してacs-nodeというnpmモジュール使えば解決できる

log4js = require("log4js")log4js.configure appenders: [  type: "file" category: "request" filename: "logs/request.log" pattern: "-yyyy-MM-dd" ]loggerRequest = log4js.getLogger("request")loggerRequest.info "this is request log" # 自作モジュール類の読み込みpath = require("path")modulePath = path.resolve(__dirname, "lib/geocoder.js")Geocoder = require(modulePath).Geocodergeocoder = new Geocoder() serverModulePath = path.resolve(__dirname, "lib/server.js")Server = require(serverModulePath).Serverserver = new Server() wait = (item, callback) -> setTimeout((-> geocodingAPI = "http://www.geocoding.jp/api/" address = encodeURIComponent(item.address) url = "#{geocodingAPI}?v=1.1&q=#{address}"  geocoder.start(url,(err,statusCode,body) -> if not err callback(body,item.clientName) )  ), 5000) clientList =[{"clientName":"xx","address":"xxx"}]

act = ()-> # パラメータが無くなっていれば終了 return if clientList.length is 0 param = clientList[0] geocodingAPI = "http://www.geocoding.jp/api/" address = encodeURIComponent(param.address) clientName = param.clientName address = param.address url = "#{geocodingAPI}?v=1.1&q=#{address}" geocoder.start(url,(err,statusCode,body) -> if not err and body.lat isnt null and body.lng isnt null clientData = name:clientName address:address latitude:body.lat longitude:body.lng loggerRequest.info("client: #{clientName}") server.confirmClientInfo(clientData,(response) -> if response is true loggerRequest.info("#{clientName} already exist!!") else server.registClientInfo(clientData,(response) -> if response is false loggerRequest.info("FAIL: #{clientName} data is #{clientData}") else loggerRequest.info("success data is #{clientData}"") ) ) else loggerRequest.info("error clientName is #{clientName}") ) clientList.shift() setTimeout (-> act() ), 6500act()

14年2月19日水曜日

Page 14: 2014 02-19-titanium meetupvol16

使ってる方いましたらお互い積極的にアウトプットしていきましょう!

Photo By Rusty Sheriffhttp://www.flickr.com/photos/rustysheriff/4908212366/

14年2月19日水曜日

Page 15: 2014 02-19-titanium meetupvol16

• とても初歩的な内容ですがGitHubに資料あるので興味ある方こちらご覧ください

• https://github.com/h5y1m141/streetAcademy/blob/master/4thStep.md

• 上記資料使った少人数制のTitaniumMobile開発のワークショップをたまにやってます

• 詳しくはStreetAcademy(http://street-academy.com/myclass/443)

おまけ:Titanium+ACS連携サンプルアプリ

14年2月19日水曜日

Page 16: 2014 02-19-titanium meetupvol16

LT Finish

14年2月19日水曜日