145
1時間で作る マッシュアップ 株式会社ワイズノット 増井 雄一郎

How to build 1 hour mashup site

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: How to build 1 hour mashup site

1時間で作るマッシュアップ

株式会社ワイズノット 増井 雄一郎

Page 2: How to build 1 hour mashup site
Page 3: How to build 1 hour mashup site

↓Macbook pro

Page 4: How to build 1 hour mashup site

↓Macbook proNot 防水

Page 5: How to build 1 hour mashup site

1時間以上かけてたらゆだっちゃう

Page 6: How to build 1 hour mashup site

Rails使ったことある人

Page 7: How to build 1 hour mashup site

自分でMashup

したことある人

Page 8: How to build 1 hour mashup site

サイトなんかも公開しちゃってる人

Page 9: How to build 1 hour mashup site

Mashupマッシュアップ

Page 10: How to build 1 hour mashup site

音楽用語

Page 11: How to build 1 hour mashup site

Remixとの違い

Page 12: How to build 1 hour mashup site

曲をいじったりくっつけるのが

Remix

Page 13: How to build 1 hour mashup site

歌詞はこっちメロディーはあっちで

Mashup

Page 14: How to build 1 hour mashup site

繋げるだけじゃなく変えるだけじゃなく

Page 15: How to build 1 hour mashup site

いろんなサイトをごちゃまぜにしちゃえ

Page 16: How to build 1 hour mashup site

携帯と地図のMashup

Page 18: How to build 1 hour mashup site

実は私なんかより有名なMashupな人が北海道にいる

Page 19: How to build 1 hour mashup site

元道庁の黒田さん

Page 20: How to build 1 hour mashup site

Sun × RECRUIT Mash Up Award 最優秀賞出張JAWS

Page 21: How to build 1 hour mashup site
Page 22: How to build 1 hour mashup site

今日は来られないらしい

Page 23: How to build 1 hour mashup site

残念!

Page 24: How to build 1 hour mashup site

Mashupとは

Page 25: How to build 1 hour mashup site

アプリケーションの再構築

Page 26: How to build 1 hour mashup site

昔は無理矢理やっていた

Page 27: How to build 1 hour mashup site

HTML解析して・・・

Page 28: How to build 1 hour mashup site

自分で使う分には良いけど公開できない

Page 29: How to build 1 hour mashup site

いまでもAPI公開してないサイトのデータを使うときにやる

Page 30: How to build 1 hour mashup site

データが命!勝手に使わせるなんてもってのほか!

Page 31: How to build 1 hour mashup site

でもWeb2.0時代はサイト側がある程度自由にデータや

システムを使わせてくれる

Page 32: How to build 1 hour mashup site

なんで?

Page 33: How to build 1 hour mashup site

ビジネスモデルの変化

Page 34: How to build 1 hour mashup site

データを囲い込んでも換金する方法がない

Page 35: How to build 1 hour mashup site

でもトラフィックは広告で金になる

Page 36: How to build 1 hour mashup site

サイトに誘導するためデータを使おう

Page 37: How to build 1 hour mashup site

その使わせてくれる口がWebAPI

Page 38: How to build 1 hour mashup site

色々なWebAPIが提供されてきている

Page 39: How to build 1 hour mashup site

大別すると3種類

Page 40: How to build 1 hour mashup site

データ系

Page 41: How to build 1 hour mashup site

RSSAmazon Web Serviceホットペッパー

Google検索じゃらんnet

Page 42: How to build 1 hour mashup site

データを公開

Page 43: How to build 1 hour mashup site

ここの部分が多い

Page 44: How to build 1 hour mashup site

既存にデータを持っているところは容易に展開できる為

Page 45: How to build 1 hour mashup site

処理系

Page 46: How to build 1 hour mashup site

スクリーンショット形態素解析

テキスト→MP3変換

Page 47: How to build 1 hour mashup site

データを投げると何らかの処理をしてくれる

Page 48: How to build 1 hour mashup site

表示系

Page 49: How to build 1 hour mashup site

Google MapsNIFTY Timeline

べつやくメソッドAPI

Page 50: How to build 1 hour mashup site

色々なデータを表示する基盤

Page 51: How to build 1 hour mashup site

ほとんどのAPIはMVCのMやVに相当

Page 52: How to build 1 hour mashup site

Controllerをどうやって作る?

Page 53: How to build 1 hour mashup site

既存の手法と同じ

Page 54: How to build 1 hour mashup site

PHP, Perl, Ruby, Java....

Page 55: How to build 1 hour mashup site

ちゃんと作ると非同期処理が多く

PHPは不利

Page 56: How to build 1 hour mashup site

そこで我らがRuby on Rails

Page 57: How to build 1 hour mashup site

救世主

Page 58: How to build 1 hour mashup site

さすがはWeb2.0系フレークワーク

Page 59: How to build 1 hour mashup site

WebAPIを楽にするActiveResource

Page 60: How to build 1 hour mashup site

Rails2.0から標準添付

Page 61: How to build 1 hour mashup site

でもRails2.0がいつ出るかは謎

Page 62: How to build 1 hour mashup site

しかしActiveResourceは

Page 63: How to build 1 hour mashup site

Rails 対 Rails にしか使えない

Page 64: How to build 1 hour mashup site

別の方法を考えよう

Page 65: How to build 1 hour mashup site

さてMashupで何を作る?

Page 66: How to build 1 hour mashup site

今日のお題は「北海道温泉マップ」

Page 67: How to build 1 hour mashup site

YMOZE-Yさんのリクエスト

Page 68: How to build 1 hour mashup site

じゃらんが温泉情報をWebAPIで公開

Page 69: How to build 1 hour mashup site

これをマッピング

Page 70: How to build 1 hour mashup site

どっから初めるかな

Page 71: How to build 1 hour mashup site

まずは温泉情報を持ってこよう

Page 72: How to build 1 hour mashup site

APIのページを読む

Page 74: How to build 1 hour mashup site

API使うには登録がいる

Page 75: How to build 1 hour mashup site

APIキーをもらったらURLを叩くだけ

Page 77: How to build 1 hour mashup site

XMLで帰ってくる

Page 78: How to build 1 hour mashup site
Page 79: How to build 1 hour mashup site

これをプログラムでごにょごにょ・・・

Page 80: How to build 1 hour mashup site

Railsを使えば一発!

Page 81: How to build 1 hour mashup site

とは行かない・・・

Page 82: How to build 1 hour mashup site

require 'net/http'require 'cgi'require 'rexml/document'

class Onsen attr_accessor :address, :name, :id

KEY = 'phe11375af71ba' URL = 'http://jws.jalan.net/APICommon/OnsenSearch/V1/?' def self.find(params) results = [] get(params).elements.each('Results/Onsen') do |el| results << Onsen.new(el.elements["OnsenID"].text, el.elements["OnsenName"].text, el.elements["OnsenAddress"].text) end results end

def self.url(params) params[:key] = KEY URI.parse(URL+((params.map { |key,value| "#{key}=#{CGI::escape(value.to_s)}"}).join('&'))) end

def self.get(params) REXML::Document.new(Net::HTTP.get(url(params))) end def initialize(id, name, address) @id, @name, @address = id, name, address endend

Page 83: How to build 1 hour mashup site

これでAPIを使える

Page 84: How to build 1 hour mashup site

ちょっと読めないよね

Page 85: How to build 1 hour mashup site

詳細はWebで!

Page 86: How to build 1 hour mashup site

ニセコの温泉リストを取り出す

Page 87: How to build 1 hour mashup site

irb> puts Onsen.find(:count => 10, :s_area => '010802').map{|o| o.name}.join(',')=>いわない温泉,雷電温泉,朝日温泉,ニセコワイス高原温泉 (ニセコ),ワイス温泉 (ニセコ),ひらふ温泉 (ニセコ),ニセコアンヌプリ温泉 (ニセコ),ニセコ昆布温泉 (ニセコ),ニセコ薬師温泉...

Page 88: How to build 1 hour mashup site

こっちはマシ

Page 89: How to build 1 hour mashup site

このリストをGoogle Mapに入れる

Page 90: How to build 1 hour mashup site

こっちはRubyのライブラリがある

Page 91: How to build 1 hour mashup site

YM4R/GM

Page 92: How to build 1 hour mashup site

GoogleMaps APIをRailsで使うライブラリ

Page 93: How to build 1 hour mashup site

$ rails onsen -d sqlite3$ cd onsen$ script/plugin install \ svn://rubyforge.org/var/svn/ym4r/Plugins/GM/trunk/ym4r_gm$ ./script/generate controller onsen index

Page 94: How to build 1 hour mashup site

さっきのOnsenクラスはlib/onsen.rbに保存

Page 95: How to build 1 hour mashup site

class OnsenController < ApplicationController def index @map = GMap.new("map_div") @map.control_init :large_map => true, :map_type => true @map.center_zoom_init([42.808783,140.684566], 11) endend

Page 96: How to build 1 hour mashup site

<html><head><%= GMap.header %><%= @map.to_html %></head><body><%= @map.div(:width => 600, :height => 400) %></body></html>

Page 97: How to build 1 hour mashup site

これだけで地図表示

Page 98: How to build 1 hour mashup site
Page 99: How to build 1 hour mashup site

これにじゃらんでゲットした温泉をピンで打つ

Page 100: How to build 1 hour mashup site

Google Mapsでピンを打つには緯度経度が

必要

Page 101: How to build 1 hour mashup site

じゃらんAPIでは住所しか持ってない

Page 102: How to build 1 hour mashup site

そこでジオコーディング

Page 103: How to build 1 hour mashup site

住所から緯度経度を割り出す

Page 104: How to build 1 hour mashup site

これもGoogle Maps API

の一つ

Page 105: How to build 1 hour mashup site

YM4R/GMを使えばそれも楽々

Page 106: How to build 1 hour mashup site

ニセコ駅の緯度経度を調べる

Page 107: How to build 1 hour mashup site

irb> niseko = Geocoding.get(‘ニセコ駅’)

irb> niseko.first.latlon=> [40.34575, -3.816734]

Page 108: How to build 1 hour mashup site

Onsenクラスにコレをくっつける

Page 109: How to build 1 hour mashup site

class Onsen ~中略~ def latlon Geocoding.get(@address).first.latlon endend

Page 110: How to build 1 hour mashup site

これで2つのAPIをあっさりMashup

Page 111: How to build 1 hour mashup site

これを地図に放り込む

Page 112: How to build 1 hour mashup site

class OnsenController < ApplicationController

def index @map = GMap.new("map_div") @map.control_init(:large_map => true, :map_type => true) @map.center_zoom_init([42.808783,140.684566], 11)

Onsen.find(:count => 10, :s_area => '010802').each do |o| marker = GMarker.new( o.latlon, :title => o.name, :info_window => render_to_string(:partial => 'point', :locals => { :onsen => o })) @map.overlay_init(marker) end endend

Page 113: How to build 1 hour mashup site

吹き出しのHTMLも

Page 114: How to build 1 hour mashup site

<div><strong><%=h onsen.name %></strong></div><div><%=h onsen.address %></div>

Page 115: How to build 1 hour mashup site

できあがり

Page 116: How to build 1 hour mashup site
Page 117: How to build 1 hour mashup site

つまらない・・・

Page 118: How to build 1 hour mashup site

温泉の写真も貼ろう

Page 119: How to build 1 hour mashup site

写真と言えばFlickr

Page 120: How to build 1 hour mashup site
Page 121: How to build 1 hour mashup site

もちろんWebAPI公開

Page 122: How to build 1 hour mashup site

Ruby用バインドも複数公開

Page 123: How to build 1 hour mashup site

$ cd lib$ wget http://redgreenblu.com/flickr/flickr.rb$ vi flickr.rb # 57行目のAPIKEYを変更$ cd ..

Page 124: How to build 1 hour mashup site

試しに五色温泉の写真を取得

Page 125: How to build 1 hour mashup site

irb> flickr = Flickr.newirb> photo = flickr.photos(:text => ‘ニセコ五色温泉’).first

irb> photo.source('Thumbnail') =>http://farm1.static.flickr.com/136/328193836_725a658789_t.jpg

Page 126: How to build 1 hour mashup site

これもOnsenクラスにいれちゃう

Page 127: How to build 1 hour mashup site

class Onsen ~中略~ def photo(size='Thumbnail') Flickr.new.photos(:text => @name.gsub(/(.*/,'')).first.source(size)

endend

Page 128: How to build 1 hour mashup site

これで写真も取得できちゃう

Page 129: How to build 1 hour mashup site

最後にこれをマッピング

Page 130: How to build 1 hour mashup site

<div><strong><%=h onsen.name %></strong></div><div><%=h onsen.address %></div><%= image_tag(onsen.photo.source(‘Thumbnail’)) rescue ‘No photo’ %>

Page 131: How to build 1 hour mashup site

これで吹き出しに写真が出た

Page 132: How to build 1 hour mashup site
Page 133: How to build 1 hour mashup site

写真合ってない・・・

Page 134: How to build 1 hour mashup site

ひとまずこれで完成

Page 135: How to build 1 hour mashup site

不満点が沢山

Page 136: How to build 1 hour mashup site

遅い!

Page 137: How to build 1 hour mashup site

キャッシュで改善

Page 138: How to build 1 hour mashup site

ニセコ以外は?

Page 139: How to build 1 hour mashup site

選べるようにしましょう

Page 140: How to build 1 hour mashup site

コメントとかは?

Page 141: How to build 1 hour mashup site

acts_as_commentableで

Page 142: How to build 1 hour mashup site

携帯は?

Page 143: How to build 1 hour mashup site

jpmobileで

Page 144: How to build 1 hour mashup site

これを改善して自分温泉地図を作りませんか?

Page 145: How to build 1 hour mashup site

スライドとソースはhttp://blog.masuidrive.jp/