diff --git a/README.md b/README.md index be82c89..a0ab0b5 100644 --- a/README.md +++ b/README.md @@ -198,7 +198,7 @@ Kindly post bugs or feature requests at [OWM JAPIs Bugs/Requests][3] and I will ##Developer -**Ashutosh Kumar Singh** | [AKSingh.net][4] | me@aksingh.net +**Ashutosh Kumar Singh** | [AKSingh.net][4] | [me@aksingh.net][9] @@ -218,9 +218,9 @@ for reporting bugs, and even finding and sharing possible solutions for them. ##License -Copyright (c) 2013-2014 Ashutosh Kumar Singh +Copyright (c) 2013-2014 Ashutosh Kumar Singh `` -Released under the terms of [MIT license][7]. It's open source and developer-friendly. +Released under the terms of the [MIT license][7]. It's open source and developer-friendly. [1]: http://go.aksingh.net/owm-japis-downloads @@ -230,4 +230,5 @@ Released under the terms of [MIT license][7]. It's open source and developer-fri [5]: http://openweathermap.org/ [6]: http://www.json.org/java/index.html [7]: http://opensource.org/licenses/MIT - [8]: https://github.com/dvdme/forecastio-lib-java \ No newline at end of file + [8]: https://github.com/dvdme/forecastio-lib-java + [9]: mailto:me@aksingh.net \ No newline at end of file diff --git a/build.gradle b/build.gradle index 3ea97cf..3657ed9 100644 --- a/build.gradle +++ b/build.gradle @@ -1,23 +1,79 @@ apply plugin: 'java' -apply plugin: 'maven-publish' +apply plugin: 'maven' +apply plugin: 'signing' sourceCompatibility = 1.5 -group = 'net.aksingh.owmjapis' +group = 'net.aksingh' +archivesBaseName = "owm-japis" version = '2.5.0.3' repositories { mavenCentral() } -publishing { - publications { - mavenJava(MavenPublication) { - from components.java - } - } +dependencies { + testCompile group: 'junit', name: 'junit', version: '4.12' } -dependencies { - testCompile group: 'junit', name: 'junit', version: '4.+' +task javadocJar(type: Jar) { + classifier = 'javadoc' + from javadoc +} + +task sourcesJar(type: Jar) { + classifier = 'sources' + from sourceSets.main.allSource +} + +artifacts { + archives javadocJar, sourcesJar +} + +signing { + sign configurations.archives +} + +uploadArchives { + repositories { + mavenDeployer { + beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } + + repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { + authentication(userName: ossrhUsername, password: ossrhPassword) + } + + snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") { + authentication(userName: ossrhUsername, password: ossrhPassword) + } + + pom.project { + name 'OWM JAPIs' + packaging 'jar' + description 'Java Wrapper Library for OpenWeatherMap.org Web APIs' + url 'http://code.aksingh.net/owm-japis' + + scm { + connection 'scm:svn:http://foo.googlecode.com/svn/trunk/' + developerConnection 'scm:svn:https://foo.googlecode.com/svn/trunk/' + url 'http://foo.googlecode.com/svn/trunk/' + } + + licenses { + license { + name 'The MIT License (MIT)' + url 'http://opensource.org/licenses/MIT' + } + } + + developers { + developer { + id 'akapribot' + name 'Ashutosh Kumar Singh' + email 'me@aksingh.net' + } + } + } + } + } } \ No newline at end of file diff --git a/src/main/java/net/aksingh/owmjapis/OpenWeatherMap.java b/src/main/java/net/aksingh/owmjapis/OpenWeatherMap.java index 6b2d110..9a41b37 100644 --- a/src/main/java/net/aksingh/owmjapis/OpenWeatherMap.java +++ b/src/main/java/net/aksingh/owmjapis/OpenWeatherMap.java @@ -33,6 +33,8 @@ import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.util.zip.GZIPInputStream; +import java.util.zip.Inflater; +import java.util.zip.InflaterInputStream; /** *

@@ -614,21 +616,23 @@ public class OpenWeatherMap { connection.setUseCaches(false); connection.setDoInput(true); connection.setDoOutput(false); - connection.setRequestProperty("Accept-Encoding", "gzip"); + connection.setRequestProperty("Accept-Encoding", "gzip, deflate"); connection.connect(); if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) { + String encoding = connection.getContentEncoding(); + try { - if (connection.getRequestProperty("Accept-Encoding") != null) { + if (encoding != null && encoding.equalsIgnoreCase("gzip")) { reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(connection.getInputStream()))); - while ((s = reader.readLine()) != null) { - response = s; - } + } else if (encoding != null && encoding.equalsIgnoreCase("deflate")) { + reader = new BufferedReader(new InputStreamReader(new InflaterInputStream(connection.getInputStream(), new Inflater(true)))); } else { reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); - while ((s = reader.readLine()) != null) { - response = s; - } + } + + while ((s = reader.readLine()) != null) { + response = s; } } catch (IOException e) { System.err.println("Error: " + e.getMessage()); @@ -644,8 +648,9 @@ public class OpenWeatherMap { } else { // if HttpURLConnection is not okay try { reader = new BufferedReader(new InputStreamReader(connection.getErrorStream())); - while ((s = reader.readLine()) != null) + while ((s = reader.readLine()) != null) { response = s; + } } catch (IOException e) { System.err.println("Error: " + e.getMessage()); } finally { diff --git a/src/test/java/net/aksingh/owmjapis/CurrentWeatherTest.java b/src/test/java/net/aksingh/owmjapis/CurrentWeatherTest.java index 8179ebc..ea4d04e 100644 --- a/src/test/java/net/aksingh/owmjapis/CurrentWeatherTest.java +++ b/src/test/java/net/aksingh/owmjapis/CurrentWeatherTest.java @@ -43,6 +43,24 @@ public class CurrentWeatherTest { System.out.println("Reponse is inValid!"); } else { System.out.println("Reponse is Valid!"); + System.out.println(); + + if (cw.hasBaseStation()) { + System.out.println("Base station: " + cw.getBaseStation()); + } + if (cw.hasDateTime()) { + System.out.println("Date time: " + cw.getDateTime()); + } + System.out.println(); + + + if (cw.hasCityCode()) { + System.out.println("City code: " + cw.getCityCode()); + } + if (cw.hasCityName()) { + System.out.println("City name: " + cw.getCityName()); + } + System.out.println(); } } }