1時間で作るマッシュアップサービス(関西版)

4,554 views

Published on

OSC2007で話した内容

Published in: Technology
0 Comments
6 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,554
On SlideShare
0
From Embeds
0
Number of Embeds
38
Actions
Shares
0
Downloads
136
Comments
0
Likes
6
Embeds 0
No embeds

No notes for slide

1時間で作るマッシュアップサービス(関西版)

  1. 1. ↓Macbook pro
  2. 2. ↓Macbook pro Not
  3. 3. 1
  4. 4. Rails
  5. 5. Mashup
  6. 6. Mashup
  7. 7. Remix
  8. 8. Remix
  9. 9. Mashup
  10. 10. Mashup
  11. 11. Mashup
  12. 12. HTML
  13. 13. API
  14. 14. Web2.0
  15. 15. WebAPI
  16. 16. WebAPI
  17. 17. 3
  18. 18. RSS Amazon Web Service Google net
  19. 19. →MP3
  20. 20. Google Maps NIFTY Timeline API
  21. 21. API MVC M V
  22. 22. Controller
  23. 23. PHP, Perl, Ruby, Java....
  24. 24. PHP
  25. 25. Ruby on Rails
  26. 26. Web2.0
  27. 27. WebAPI ActiveResource
  28. 28. Rails2.0
  29. 29. Rails2.0
  30. 30. ActiveResource
  31. 31. Rails Rails
  32. 32. Mashup
  33. 33. OSC-Do blog
  34. 34. WebAPI
  35. 35. Kansai
  36. 36. API
  37. 37. API
  38. 38. API URL
  39. 39. http://jws.jalan.net/APICommon/ OnsenSearch/V1/? key=**********&l_area=010802 &count=1&xml_ptn=1
  40. 40. XML
  41. 41. Rails
  42. 42. 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[quot;OnsenIDquot;].text, el.elements[quot;OnsenNamequot;].text, el.elements [quot;OnsenAddressquot;].text) end results end def self.url(params) params[:key] = KEY URI.parse(URL+((params.map { |key,value| quot;#{key}=#{CGI::escape(value.to_s)}quot;}).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 end end
  43. 43. API
  44. 44. Web
  45. 45. irb> puts Onsen.find(:count => 10, :pref => '260000').map{|o| o.name}.join(',') => , , , , , , , , ,
  46. 46. Google Map
  47. 47. Ruby
  48. 48. YM4R/GM
  49. 49. GoogleMaps API Rails
  50. 50. $ 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
  51. 51. Onsen lib/onsen.rb
  52. 52. class OnsenController < ApplicationController def index @map = GMap.new(quot;map_divquot;) @map.control_init :large_map => true, :map_type => true @map.center_zoom_init([35.400245,135.42572], 9) end end
  53. 53. <html> <head> <%= GMap.header %> <%= @map.to_html %> </head> <body> <%= @map.div(:width => 600, :height => 400) %> </body> </html>
  54. 54. Google Maps
  55. 55. API
  56. 56. Google Maps API
  57. 57. YM4R/GM
  58. 58. irb> kyoto = Geocoding.get(‘ ’) irb> kyoto.first.latlon => [34.985458, 135.757755]
  59. 59. Onsen
  60. 60. class Onsen def latlon Geocoding.get(@address).first.latlon end end
  61. 61. Google
  62. 62. class Onsen def latlon Geocoding.get(@address.gsub(/( | | ).{1,5} /,'¥¥1')).first.latlon end end
  63. 63. 2 API Mashup
  64. 64. class OnsenController < ApplicationController def index @map = GMap.new(quot;map_divquot;) @map.control_init(:large_map => true, :map_type => true) @map.center_zoom_init([35.400245,135.42572], 9) return Onsen.find(:count => 50, :pref => '260000').each do |o| begin marker = GMarker.new( o.latlon, :title => o.name, :info_window => render_to_string( :partial => 'point', :locals => { :onsen => o }) ) @map.overlay_init(marker) rescue end end end
  65. 65. HTML
  66. 66. <div><strong><%=h onsen.name %></strong></div> <div><%=h onsen.address %></div>
  67. 67. Flickr
  68. 68. WebAPI
  69. 69. Ruby
  70. 70. API
  71. 71. Yahoo Web
  72. 72. http://api.search.yahoo.co.jp/ ImageSearchService/V1/ imageSearch? appid=YahooDemo&results=1& query=
  73. 73. Onsen
  74. 74. class Onsen def photo Onsen.get({ :appid=>'kyotoonsen', :query=>@name.gsub(/ ¥(.*/,''), :results => 1}, quot;http://api.searc........rch?quot; ).elements['/ResultSet/Result/Thumbnail/ Url'].text end end
  75. 75. <div><strong><%=h onsen.name %></strong></div> <div><%=h onsen.address %></div> <div style=quot;height: 120pxquot;> <%= image_tag(onsen.photo) rescue 'No photo' %> </div>
  76. 76. acts_as_commentable
  77. 77. jpmobile
  78. 78. http://blog.masuidrive.jp/

×