Continuing with the examples shown in our webinar on Webservice APIs below I demonstrate how to use OpenWeatherMap’s API.
Here is the code I reviewed in the video demonstrating the various API calls.
IniRead, API_Token ,Auth.ini,API, Token ;~ Endpoint:="http://api.openweathermap.org/data/2.5/weather" ; Review http://openweathermap.org/api Endpoint:="http://api.openweathermap.org/data/2.5/forecast/daily" ; ;~ QueryString:=QueryString_Builder({"zip":"75019,us","APPID":API_Token}) ;~ QueryString:=QueryString_Builder({"lat":"32.9915376","lon":"-96.9799073","APPID":API_Token}) QueryString:=QueryString_Builder({"mode":"xml","cnt":"16","units":"imperial","id":"4683217","APPID":API_Token}) ;******API call************************ HTTP := ComObjCreate("WinHttp.WinHttpRequest.5.1") ;Create COM Object HTTP.Open("GET", Endpoint . QueryString) ;GET & POST are most frequent, Make sure you UPPERCASE HTTP.Send() Response_Data:= HTTP.ResponseText ;Save the text that is returned ;~ SciTE_Output(Response_Data) ;Text,Clear=1,LineBreak=1,Exit=0 Response_Data:=sXML_Pretty(Response_Data," ") SciTE_Output(Response_Data) ;Text,Clear=1,LineBreak=1,Exit=0 ;~ Response_Data:=formatjson(Response_Data) ;~ gui,Response_Text_Gui:Destroy ;even if it doesn't exist it is a good habit to get into ;~ gui,Response_Text_Gui:Default ;set as default ;~ gui,+AlwaysOnTop ;~ gui, font, s11 cBlue q5, Courier New ;~ gui,Add,Edit,w800 h600 -Wrap HScroll,%Response_Data% ;~ gui,show,x+10 y20 , Response Text ;************Query String builders********* QueryString_Builder(kvp){ for key, value in kvp queryString.=((A_Index="1")?(url "?"):("&")) key "=" value return queryString }