Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trycf/819eb1b6690c890a753d2c75e2355e2d to your computer and use it in GitHub Desktop.
Save trycf/819eb1b6690c890a753d2c75e2355e2d to your computer and use it in GitHub Desktop.
TryCF Gist
<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