Government Data Integration
-
Upload
felicia-clay -
Category
Documents
-
view
24 -
download
1
description
Transcript of Government Data Integration
![Page 2: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/2.jpg)
วั�ตถุ�ประสงค์�
• เข้�าใจสถุาป�ตยกรรม SOA
• เข้�าใจ Web Services
• การอ่�านข้�อ่ม�ลจากหน�าเวั�บ• พั�ฒนา Web Services แบบ REST
2
![Page 3: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/3.jpg)
RESTRepresentational State Transfer
3
![Page 4: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/4.jpg)
API Directory
• http://www.programmableweb.com/apis/directory
• http://www.webmashup.com
• http://www.webapi.org/
• http://www.webservicelist.com/
4
![Page 5: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/5.jpg)
Basic HTML
5
![Page 6: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/6.jpg)
Web Document
PresentationStructure Layer Behavior
HTML CSS JavaScript
6
![Page 7: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/7.jpg)
HTML
<html>
<head><title>gdi</title></head>
<body>Hello, world</body>
</html>
7
![Page 8: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/8.jpg)
CSS
<html>
<head><title>gdi</title></head>
<body>
<div style="color:red;">Hello, world</div>
</body>
</html>
8
![Page 9: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/9.jpg)
JavaScript
<html>
<head><title>gdi</title></head>
<body>
<div onClick="alert('you click');">Hello, world</div>
</body>
</html>
9
![Page 10: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/10.jpg)
Scrapper
10
![Page 11: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/11.jpg)
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 << "<b>#{link.content}</b> #{link['href']}"
end
render :text => t.join("<br/>")
end
11
![Page 12: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/12.jpg)
• http://scrubyt.org/
• sudo gem install scrubyt
• sudo gem install firewatir
12
![Page 13: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/13.jpg)
Googlerequire 'rubygems'
require 'scrubyt'
google_data = Scrubyt::Extractor.define do
fetch 'http://www.google.com/search?hl=en&q=ruby'
link_title "//a[@class='l']", :write_text => true do
link_url
end
end
p google_data.to_hash
13
![Page 14: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/14.jpg)
Ebayebay_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
![Page 15: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/15.jpg)
ScRUBYt Installation
• sudo gem install hpricot
• sudo gem install mechanize
• sudo gem install scrubyt
15
![Page 16: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/16.jpg)
Lab: ตลาดหล�กทร�พัย�แห�งประเทศไทย
• http://marketdata.set.or.th/mkt/stockquotation.do?symbol=pttep
16
![Page 17: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/17.jpg)
Lab: Twitter
• สร�างเวั�บเซอ่ร�วั(สท)*ร �บชื่,*อ่ผู้��ใชื่� Twitter แล�วัส�งข้�อ่ม�ลอ่อ่กในร�ปแบบ XML
• ชื่,*อ่• ท)*อ่ย��• เวั�บไซท�• ประวั�ต(• ทดสอ่บก�บชื่,*อ่เหล�าน). songrit, iamnadia,
algore, BarackObama17
![Page 18: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/18.jpg)
REST using RoR
ความร��เบื้��องต�นเก��ยวก�บื้ Web Services
18
![Page 19: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/19.jpg)
ActiveRecord#to_xml
• print Book.first.to_xml• :only=>[...]• :skip_instruct=>true• :root=>'books'• :indent=>4• :dasherize=>false• :skip_types=>true• :include=>chapters
19
![Page 20: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/20.jpg)
Hash
print ({:name=>'song', :lname=>'lee'}.to_xml)
20
![Page 21: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/21.jpg)
Hash.from_xml
• h = Hash.from_xml(File.new("abc.xml"))
21
![Page 22: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/22.jpg)
Labx = <<-EOT
<export>
<mineral>20_000</mineral>
<electronic>300_000</electronic>
<fishery>50_000</fishery>
</export>
EOT
Hash.from_xml(x)22
![Page 23: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/23.jpg)
Builderxml.instruct!
xml.comment! "a comment"
xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do
xml.title "My Atom Feed"
xml.subtitle h(@feed.subtitle), "type" => 'html'
xml.link url_for( :only_path => false, :controller => 'feed', :action => 'atom' )
xml.updated @updated.iso8601
@entries.each 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
end
end
23
![Page 24: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/24.jpg)
Yahoo API
http://developer.yahoo.com/search/web/V1/webSearch.html
24
![Page 25: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/25.jpg)
http://search.yahoo.com/search?p=gdi
25
![Page 26: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/26.jpg)
http://api.search.yahoo.com/WebSearchService/V1/webSearch?appid=songrit_gdi&query=gdi
26
![Page 27: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/27.jpg)
Controllerclass 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 = Net::HTTP.get(URI(url))
@doc = REXML::Document.new result
end
end
27
![Page 28: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/28.jpg)
View
<% @doc.root.each_element do |res| %>
<b>Title:</b> <%= res[0].text.to_s %><br>
<b>Summary:</b> <%= res[1].text.to_s %><br>
<b>Link:</b> <a href="<%= res[2].text.to_s %>"><%= res[2].text.to_s % />
<br><br>
<% end %>
28
![Page 29: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/29.jpg)
Lab
• http://sites.google.com/site/songrit/Home/my-files/rexml_lab.xml
29
![Page 30: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/30.jpg)
Lab: create new REXML::Document
require "rexml/document“
file = File.new( "rexml_lab.xml" )
doc = REXML::Document.new file
30
![Page 31: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/31.jpg)
Accessing Elementsdoc.elements.each("inventory/section") { |element|
puts element.attributes["name"]
}
31
![Page 32: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/32.jpg)
root = doc.root
puts root.attributes["title"]
puts root.elements["section/item[@stock='44']"].attributes["upc"]
32
![Page 33: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/33.jpg)
Google Maps
• ruby script/plugin install git://github.com/joergbattermann/gmaps_on_rails.git
• signup at http://www.google.com/apis/maps/signup.html
33
![Page 34: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/34.jpg)
environment.rb
• localhost:3000
• GOOGLE_APPLICATION_ID = "ABQIAAAA3HdfrnxFAPWyY-aiJUxmqRTJQa0g3IQ9GZqIMmInSLzwtGDKaBQ0KYLwBEKSM7F9gCevcsIf6WPuIQ"
34
![Page 35: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/35.jpg)
View<% map = GoogleMap.new
map.markers << GoogleMapMarker.new(
:map => map, :lat => 47.6597,
:lng => -122.318, :html => 'My House') %>
<%= map.to_html %>
<div style="width: 500px; height: 500px;"> <%= map.div %> </div>
35
![Page 36: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/36.jpg)
• <script type=‘’ src=‘aa.js’>
• </script>
36
![Page 37: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/37.jpg)
Google Map V3
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false">
</script>
37
![Page 38: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/38.jpg)
<script type="text/javascript">
function initialize() {
var latLng = new google.maps.LatLng(14, 100);
var map = new google.maps.Map(document.getElementById('mapCanvas'), {
zoom: 8,
center: latLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
38
![Page 39: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/39.jpg)
var marker = new google.maps.Marker({
position: latLng,
title: 'Point A',
map: map,
draggable: true
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
39
![Page 40: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/40.jpg)
<style>
#mapCanvas {
width: 500px;
height: 500px;
}
</style>
<div id="mapCanvas"></div>
40
![Page 41: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/41.jpg)
Lab
• All districts in Nontaburi
41
![Page 42: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/42.jpg)
Lab
• get data from http://www.fedspending.org/apidoc.php
• display top 10 contractors and amount for state of California
42
![Page 43: Government Data Integration](https://reader035.fdocuments.net/reader035/viewer/2022062721/56813611550346895d9d898f/html5/thumbnails/43.jpg)
StatXML
43