¥È¥Ã¥×   ¿·µ¬ °ìÍ÷ ñ¸ì¸¡º÷ ºÇ½ª¹¹¿·   ¥Ø¥ë¥×   ºÇ½ª¹¹¿·¤ÎRSS

Titanium Mobile/¥µ¥ó¥×¥ë/Web¥µ¡¼¥Ó¥¹¤ÈÏ¢·È¤·¤¿¥¢¥×¥êºîÀ®¹ÖºÂ ¤Î¥Ð¥Ã¥¯¥¢¥Ã¥×º¹Ê¬(No.2)


  • Äɲ䵤줿¹Ô¤Ï¤³¤Î¿§¤Ç¤¹¡£
  • ºï½ü¤µ¤ì¤¿¹Ô¤Ï¤³¤Î¿§¤Ç¤¹¡£
*(1) QiitaViewer¤È¤¤¤¦¥×¥í¥¸¥§¥¯¥È¤òºîÀ®
[[¥¹¥Þ¡¼¥È¥Õ¥©¥ó¥¢¥×¥ê³«È¯´Ä¶­¡ÖTitanium¡×¤òÃΤë¹ÖºÂ - Web¥µ¡¼¥Ó¥¹¤ÈÏ¢·È¤·¤¿¥¢¥×¥êºîÀ®>https://www.c-place.ne.jp/0000engine/pec_engine.cgi?mode=show&call_dir=../2024PrgSeminorDetail&engine_dir=../0000engine&search_mode=1&search_domain=CGI_SERIAL&search_word=20130716113930]]¤Ë¹Ô¤Ã¤Æ¤­¤Þ¤·¤¿¡£
HTTP¤ò»ÈÍѤ·¤¿¥½¡¼¥¹¤¬¿§¡¹»²¹Í¤Ë¤Ê¤ê¤Þ¤·¤¿¡£°Ê²¼¤Ï¤½¤Î¥µ¥ó¥×¥ë¥½¡¼¥¹¤Ê¤É¤Ç¤¹¡£~
~
Ìܼ¡
#contents

*(2) app.js¤ò¿§¡¹»î¤¹¡£
**


*(1) ¥Ö¥é¥¦¥¶¤Ç»î¤·¤ËQiita¤ÎAPI¤Ë¥¢¥¯¥»¥¹
-[[https://qiita.com/api/v1/items]]
-[[https://qiita.com/api/v1/users/h5y1m141@github]]



*(2) ¥×¥í¥¸¥§¥¯¥È¤òºîÀ®
+[File] - [New] - [Mobile Project] - [Classic] - [Default Project]
+Project name: QiitaViewer
+App Id: jp.papuu.QiitaViewer
+iPhone, Android¤Î¤ß¤Ë¥Á¥§¥Ã¥¯



*(3) app.js¤ò¿§¡¹Á´½ñ¤­´¹¤¨¤·¤Æ»î¤¹
**(a) httpClient¤òÍѤ¤¤¿´ðËÜŪ¤Ê¥×¥í¥°¥é¥à
#pre{{
var xhr, qiitaURL, method;

qiitaURL = 'http://qiita.com/api/v1/items';
method = 'GET';
xhr = Ti.Network.createHTTPClient();
xhr.open(method, qiitaURL);
xhr.onload = function() {
	var body;
	if (this.status === 200) {
		body = JSON.parse(this.responseText);
		Ti.API.info(body);
	} else {
		Ti.API.info('error: status code is ' + this.status);
	}
}
xhr.onerror = function(e) {
	var error;
	error = JSON.parse(this.responseText);
	Ti.API.info(error.error);
}
xhr.timeout = 5000;
xhr.send();
}}



**(b) ¥¢¥×¥êÃæ¤Îsample.json¤òTableView¤Çɽ¼¨
¤Þ¤º¤ÏÄÌ¿®Ìµ¤·¤Ç¡¢¥¢¥×¥êÆâ¤ËÇÛÃÖ¤·¤¿json¥Õ¥¡¥¤¥ë¤ÎÆâÍƤòTableView¤Çɽ¼¨¤·¤Æ¤ß¤Þ¤¹¡£~
json¥Õ¥¡¥¤¥ë¤Ï¼¡¤òResources¥Õ¥©¥ë¥Àľ²¼¤ËÇÛÃÖ¤·¤Þ¤¹¡£~
https://raw.github.com/h5y1m141/20130817-tistudy/master/sample.json

#pre{{
var sample, file, body, mainTable, win, i, len, row, rows, textLabel;

sample = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, 'sample.json');
file = sample.read().toString();
body = JSON.parse(file);

win = Ti.UI.createWindow({
	title: 'QiitaViewer'
});

mainTable = Ti.UI.createTableView({
	width: 'auto',
	height: 'auto',
	backgroundColor: '#fff',
	left: 0,
	top: 0
});
rows = [];
for (i = 0, len = body.length; i < len; i++) {
	row = Ti.UI.createTableViewRow({
		width: 'auto',
		height: 40,
		borderWidth :0,
		className: 'entry',
		color: '#222'
	});
	textLabel = Ti.UI.createLabel({
		width: 'auto',
		height: 30,
		top: 5,
		left: 5,
		color: '#222',
		cont: {
			fontSize: 16,
			fontWeight: 'bold'
		},
		text: body[i].title
	});
	row.add(textLabel);
	rows.push(row);
}
mainTable.setData(rows);

win.add(mainTable);
win.open();
}}



**(c) QiitaÅê¹Æ¾ðÊó¤Î¥Æ¥­¥¹¥È¤òTableView¤Çɽ¼¨
#pre{{
var xhr, qiitaURL, method, mainTable, win;

win = Ti.UI.createWindow({
	title: 'QiitaViewer'
});

mainTable = Ti.UI.createTableView({
	width: 'auto',
	height: 'auto',
	backgroundColor: '#fff',
	left: 0,
	top: 0
});

qiitaURL = 'http://qiita.com/api/v1/items';
method = 'GET';

xhr = Ti.Network.createHTTPClient();
xhr.open(method, qiitaURL);
xhr.onload = function() {
	var body, i, len, row, rows, textLabel, iconImage, imagePath;
	if (this.status === 200) {
		body = JSON.parse(this.responseText);
		rows = [];
		for (i = 0, len = body.length; i < len; i++) {
			Ti.API.info(body[i].title);
			row = Ti.UI.createTableViewRow({
				width: 'auto',
				height: 40,
				borderWindth: 0,
				className: 'entry',
				color: '#222'
			});
			textLabel = Ti.UI.createLabel({
				width: 'auto',
				height: 30,
				top: 5,
				left: 5,
				color: '#222',
				font: {
					fontSize: 16,
					fontWeight: 'bold'
				},
				text: body[i].title
			});
			row.add(textLabel);
			rows.push(row);
		}
		mainTable.setData(rows);
		win.add(mainTable);
		win.open();
	} else {
		Ti.API.info('error: status code is ' + this.status);
	}
};

xhr.onerror = function(e) {
	var error;
	error = JSON.parse(this.responseText);
	Ti.API.info(error.error);
}
xhr.timeout = 5000;
xhr.send();
}}



**(d) QiitaÅê¹Æ¾ðÊó¤Î¥¿¥¤¥È¥ë¡¦¥¢¥¤¥³¥ó¤òTableView¤Çɽ¼¨
#pre{{
var xhr, qiitaURL, method, mainTable, win;

win = Ti.UI.createWindow({
	title: 'QiitaViewer'
});

mainTable = Ti.UI.createTableView({
	width: 'auto',
	height: 'auto',
	backgroundColor: '#fff',
	left: 0,
	top: 0
});

qiitaURL = 'http://qiita.com/api/v1/items';
method = 'GET';

xhr = Ti.Network.createHTTPClient();
xhr.open(method, qiitaURL);
xhr.onload = function() {
	var body, i, len, row, rows, textLabel, iconImage, imagePath;
	if (this.status === 200) {
		body = JSON.parse(this.responseText);
		rows = [];
		for (i = 0, len = body.length; i < len; i++) {
			row = Ti.UI.createTableViewRow({
				width: 'auto',
				height: 60,
				borderWindth: 0,
				className: 'entry',
				color: '#222'
			});
			textLabel = Ti.UI.createLabel({
				width: 250,
				height: 30,
				top: 5,
				left: 60,
				color: '#222',
				font: {
					fontSize: 16,
					fontWeight: 'bold'
				},
				text: body[i].title
			});
			imagePath = body[i].user.profile_image_url;
			iconImage = Ti.UI.createImageView({
				width: 40,
				height: 40,
				top: 5,
				left: 5,
				defaultImage: 'logo.png',
				image: imagePath
			});
			row.add(textLabel);
			row.add(iconImage);
			rows.push(row);
		}
		mainTable.setData(rows);
		win.add(mainTable);
		win.open();
	} else {
		Ti.API.info('error: status code is ' + this.status);
	}
};

xhr.onerror = function(e) {
	var error;
	error = JSON.parse(this.responseText);
	Ti.API.info(error.error);
}
xhr.timeout = 5000;
xhr.send();
}}



*»²¹Í»ñÎÁ httpClient°Ê³°¤ÇHTML¤ò¥Ñ¡¼¥¹¤¹¤ëÊýË¡
-[[YQL¤òTitanium¤Ç»È¤¦¤È¿§¡¹Ä½¤ë | ZeBeVogueÊÌ´Û>http://d.hatena.ne.jp/zebevogue/20120421/1334990568]]
-[[Titanium mobile parse html | GitHub gist>https://gist.github.com/zeuxisoo/1016047]]