Created
December 20, 2012 01:47
-
-
Save keating/4342341 to your computer and use it in GitHub Desktop.
Soap with Ruby gem Savon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fetch_gps | |
| $client ||= Savon.client("http://...ip.../GPSInfo/Service.asmx?WSDL") | |
| data_hash, data_qty = {}, 0 | |
| @equipments.each do |equ_no| | |
| begin | |
| response = $client.request "getGPSInfoByID" do | |
| $client.http.headers["Content-Type"] = "text/xml; charset=utf-8" | |
| $client.http.headers["SOAPAction"] = "http://tempuri.org/getGPSInfoByID" | |
| soap.body = {:id => equ_no} | |
| end | |
| gps_data = response.body[:get_gps_info_by_id_response][:get_gps_info_by_id_result][:diffgram][:new_data_set] | |
| if gps_data | |
| gps_data = gps_data[:ds] | |
| one_data = gps_data[:update_time].strftime("%d%m%y,%H%M%S.%L").to_s | |
| if @gps_time[equ_no] != one_data | |
| @gps_time[equ_no] = one_data.dup | |
| one_data << ","+(gps_data[:latitude]).to_s+",N,"+(gps_data[:longitude]).to_s+",E,"+gps_data[:speed].to_s+","+(gps_data[:direction]).to_s+";" | |
| data_hash[@vehicles_hash[gps_data[:device_id]]] = one_data | |
| data_qty += 1 | |
| end | |
| end | |
| rescue => e | |
| logger.error "抓取数据异常(设备号#{equ_no}):#{e.message}" | |
| next | |
| end | |
| end | |
| data_hash["count"] = data_qty | |
| data_hash["page"] = 1 | |
| data_hash | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment