459521 (1) [Avatar] Offline
#1
Hi all,

Me, as a Java Developer, love to work through this book, combining Java- with Groovy-skills. Working through chapter 5, I found the Yahoo-API Endpoint as used in the example broken, in detail the suggested endpoint
http://weather.yahooapis.com/forecastrss?
is not public anymore.... smilie

I spent some time to work through that issue and found a workarround using the Yahoo Query Language (YQL) endpoint
https://query.yahooapis.com/v1/public/yql?
and query
yql_query = "select * from weather.forecast where woeid=$woeid and u='c'"
to fix the Maven - Example, for now.

Also, parsing the elements for constructing the Weather-object needed hands-on adjustments.

The FIXED class:

package mjg

class YahooParser {
final static String BASE = 'https://query.yahooapis.com/v1/public/yql?'
Weather getWeather(String woeid) {
def yql_query = "select * from weather.forecast where woeid=$woeid and u='c'"
def root = new XmlSlurper().parse(BASE + "q=" + yql_query + "&format=xml")

Weather w = new Weather(
city:root.results.channel.location.@city,
region:root.results.channel.location.@region,
country:root.results.channel.location.@country,
condition:root.results.channel.item.condition.@text,
temp:root.results.channel.item.condition.@temp,
chill:root.results.channel.wind.@chill,
humidity:root.results.channel.atmosphere.@humidity
)
}
}


Some adjustments were necessary, in the pom.xml as well
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlnssmiliesi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>mjg</groupId>
<artifactId>weather</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>weather</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.9.2-01</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.codehaus.groovy/groovy-eclipse-batch -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>2.4.3-01</version>
</dependency>

</dependencies>
</plugin>
</plugins>
</build>
</project>