Created
January 12, 2019 18:27
-
-
Save trycf/819eb1b6690c890a753d2c75e2355e2d to your computer and use it in GitHub Desktop.
TryCF Gist
This file contains 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
<cfscript> | |
component | |
accessors="true" | |
output="false" | |
{ | |
pageencoding "utf-8"; | |
property name="appId" type="string"; | |
property name="ClientId" type="string"; | |
property name="ClientSecret" type="string"; | |
this.API_URL = "https://weather-ydn-yql.media.yahoo.com/forecastrss"; | |
public yahooWeather function init( string client_id="", string client_secret="" ){ | |
this.setappId(arguments.appId); | |
this.setClientId(arguments.client_id); | |
this.setClientSecret(arguments.client_secret); | |
return(this); | |
} | |
public any function callAPI( string _location="", string details="*", string format="json" ){ | |
if (compare(arguments.details,"*")) | |
arguments.details = 'item.' & arguments.details; | |
var yql_query = "select " & arguments.details & " from weather.forecast where u='c' and woeid in (select woeid from geo.places(1) where text='" & arguments._location & "')"; | |
var httpService = new http( method="GET", charset="utf-8" ); | |
local.httpService.setUrl( this.API_URL ); | |
local.httpService.addParam( type="URL", name="q", value="#local.yql_query#" ); | |
local.httpService.addParam( type="URL", name="format", value="#arguments.format#" ); | |
var result = httpService.send().getPrefix(); | |
if (val(local.result.statusCode) neq 200) | |
return( "Error in Response HTTP : " & local.result.statusCode ); | |
else if (not isJSON(local.result.fileContent)) | |
return( "Response Format Error" ); | |
json = deserializeJSON(local.result.fileContent); | |
if (!val(json.query.count)) | |
return( "No results" ); | |
else | |
return( json.query.results.channel ); | |
} | |
} | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment