Presentation is loading. Please wait.

Presentation is loading. Please wait.

Government Data Integration หลักสูตรเบื้องต้นREST 083-788-7769 1.

Similar presentations


Presentation on theme: "Government Data Integration หลักสูตรเบื้องต้นREST 083-788-7769 1."— Presentation transcript:

1 Government Data Integration หลักสูตรเบื้องต้นREST

2 วัตถุประสงค์ เข้าใจสถาปัตยกรรม SOA เข้าใจ Web Services การอ่านข้อมูลจากหน้าเว็บ พัฒนา Web Services แบบ REST 2

3 REST Representational State Transfer 3

4 API Directory ectory 4

5 Basic HTML 5

6 Web Document PresentationStructure LayerBehavior HTMLCSSJavaScript 6

7 HTML gdi Hello, world 7

8 CSS gdi Hello, world 8

9 JavaScript gdi Hello, world 9

10 Scrapper 10

11 def test_nokogiri require 'nokogiri' require 'open-uri' doc = Nokogiri::HTML(open('http://www.google.com/search?q= ruby')) t=[] doc.css('a.l').each do |link| t #{link.content} #{link['href']}" end render :text => t.join(" ") end 11

12 sudo gem install scrubyt sudo gem install firewatir 12

13 Google require 'rubygems' require 'scrubyt' google_data = Scrubyt::Extractor.define do fetch 'http://www.google.com/search?hl=en&q=ruby' link_title :write_text => true do link_url end p google_data.to_hash 13

14 Ebay ebay_data = Scrubyt::Extractor.define do fetch 'http://www.ebay.com/‘ fill_textfield 'satitle', 'ipod‘ submit ; click_link 'Apple iPod‘ record do item_name 'APPLE NEW IPOD MINI 6GB MP3 PLAYER SILVER‘ price '$71.99‘ end next_page 'Next >', :limit => 5 end 14

15 ScRUBYt Installation sudo gem install hpricot sudo gem install mechanize sudo gem install scrubyt 15

16 Lab: ตลาดหลักทรัพย์แห่งประเทศ ไทย on.do?symbol=pttephttp://marketdata.set.or.th/mkt/stockquotati on.do?symbol=pttep 16

17 Lab: Twitter สร้างเว็บเซอร์วิสที่รับชื่อผู้ใช้ Twitter แล้วส่ง ข้อมูลออกในรูปแบบ XML ชื่อ ที่อยู่ เว็บไซท์ ประวัติ ทดสอบกับชื่อเหล่านี้ songrit, iamnadia, algore, BarackObama 17

18 REST using RoR ความรู้เบื้องต้นเกี่ยวกับ Web Services 18

19 ActiveRecord#to_xml print Book.first.to_xml :only=>[...] :skip_instruct=>true :root=>'books' :indent=>4 :dasherize=>false :skip_types=>true :include=>chapters 19

20 Hash print ({:name=>'song', :lname=>'lee'}.to_xml) 20

21 Hash.from_xml h = Hash.from_xml(File.new("abc.xml")) 21

22 Lab x = <<-EOT 20_ _000 50_000 EOT Hash.from_xml(x) 22

23 Builder xml.instruct! xml.comment! "a comment" xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do xml.title "My Atom Feed" xml.subtitle "type" => 'html' xml.link url_for( :only_path => false, :controller => 'feed', :action => 'atom' do |entry| xml.entry do xml.title entry.title xml.link "href" => url_for ( :only_path => false, :controller => 'entries', :action => 'show', :id => entry ) xml.id entry.urn xml.updated entry.updated.iso8601 xml.summary h(entry.summary) end 23

24 Yahoo API webSearch.html 24

25 25

26 1/webSearch?appid=songrit_gdi&query=gdi 26

27 Controller class CodeController < ApplicationController def yahootest query = CGI.escape("SEARCH TEXT") yahookey = "songrit_gdi" url = "http://api.search.yahoo.com/" + "WebSearchService/V1/webSearch?" + "appid=#{yahookey}&query=#{query}" + "&results=3&start=1" result = = REXML::Document.new result end 27

28 View Title: Summary: Link: "> 28

29 Lab my-files/rexml_lab.xmlhttp://sites.google.com/site/songrit/Home/ my-files/rexml_lab.xml 29

30 Lab: create new REXML::Document require "rexml/document“ file = File.new( "rexml_lab.xml" ) doc = REXML::Document.new file 30

31 Accessing Elements doc.elements.each("inventory/section") { |element| puts element.attributes["name"] } 31

32 root = doc.root puts root.attributes["title"] puts utes["upc"] 32

33 Google Maps ruby script/plugin install git://github.com/joergbattermann/gmaps_o n_rails.git signup at html 33

34 environment.rb localhost:3000 GOOGLE_APPLICATION_ID = "ABQIAAAA3HdfrnxFAPWyY- aiJUxmqRTJQa0g3IQ9GZqIMmInSLzwtG DKaBQ0KYLwBEKSM7F9gCevcsIf6WPuI Q" 34

35 View <% map = GoogleMap.new map.markers << GoogleMapMarker.new( :map => map, :lat => , :lng => , :html => 'My House') %> 35

36 36

37 Google Map V3 37

38 function initialize() { var latLng = new google.maps.LatLng(14, 100); var map = new google.maps.Map(document.getElementById('mapCanv as'), { zoom: 8, center: latLng, mapTypeId: google.maps.MapTypeId.ROADMAP }); 38

39 var marker = new google.maps.Marker({ position: latLng, title: 'Point A', map: map, draggable: true }); } google.maps.event.addDomListener(wind ow, 'load', initialize); 39

40 #mapCanvas { width: 500px; height: 500px; } 40

41 Lab All districts in Nontaburi 41

42 Lab get data from display top 10 contractors and amount for state of California 42

43 StatXML 43


Download ppt "Government Data Integration หลักสูตรเบื้องต้นREST 083-788-7769 1."

Similar presentations


Ads by Google