-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from Muhin007/wp-6
Wp 6 CompletableFuture
- Loading branch information
Showing
12 changed files
with
217 additions
and
328 deletions.
There are no files selected for viewing
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
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
7 changes: 0 additions & 7 deletions
7
src/main/java/com/github/muhin007/iWeatherProvider/weatherAdaptor/WeatherAdaptor.java
This file was deleted.
Oops, something went wrong.
37 changes: 0 additions & 37 deletions
37
...n/java/com/github/muhin007/iWeatherProvider/weatherAdaptor/aerisapi/TempFromAerisapi.java
This file was deleted.
Oops, something went wrong.
36 changes: 25 additions & 11 deletions
36
.../com/github/muhin007/iWeatherProvider/weatherAdaptor/aerisapi/WeatherAdaptorAerisapi.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,34 @@ | ||
package com.github.muhin007.iWeatherProvider.weatherAdaptor.aerisapi; | ||
|
||
import com.github.muhin007.iWeatherProvider.weatherAdaptor.WeatherAdaptor; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.github.muhin007.iWeatherProvider.weatherAdaptor.JSONReadProcess; | ||
import com.github.muhin007.iWeatherProvider.weatherAdaptor.aerisapi.JSONClass.Period; | ||
import com.github.muhin007.iWeatherProvider.weatherAdaptor.aerisapi.JSONClass.Response; | ||
import com.github.muhin007.iWeatherProvider.weatherAdaptor.aerisapi.JSONClass.Temp; | ||
|
||
public class WeatherAdaptorAerisapi extends WeatherAdaptor { | ||
TempFromAerisapi tempFromAerisapi = new TempFromAerisapi(); | ||
import java.io.IOException; | ||
|
||
private int tempAerisapi; | ||
public class WeatherAdaptorAerisapi{ | ||
private int tempFromAerisapi; | ||
|
||
@Override | ||
public void requestTempAPI() { | ||
tempAerisapi = tempFromAerisapi.getTempFromAerisapi(); | ||
} | ||
public int getTempFromAerisapi(String cityName) { | ||
|
||
public double getTempAerisapi() { | ||
requestTempAPI(); | ||
return tempAerisapi; | ||
String request = "https://api.aerisapi.com/forecasts/" + cityName + ",?format=json&filter=day&limit=1&client_id=a04yWLdF5v83ZGGqanosb&client_secret=2moGBj8LBRIlJdhaufg9qCxN7IPLCokJ3OjamuKK"; | ||
String result = JSONReadProcess.performRequest(request); | ||
ObjectMapper mapper = new ObjectMapper(); | ||
Temp temp = null; | ||
try { | ||
temp = mapper.readValue(result, Temp.class); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
assert temp != null; | ||
for (Response response : temp.getResponse()) { | ||
for (Period period : response.getPeriods()) { | ||
tempFromAerisapi = (int) period.getMaxTempC(); | ||
} | ||
} | ||
return tempFromAerisapi; | ||
} | ||
|
||
} |
69 changes: 0 additions & 69 deletions
69
src/main/java/com/github/muhin007/iWeatherProvider/weatherAdaptor/apixu/TempFromApixu.java
This file was deleted.
Oops, something went wrong.
70 changes: 60 additions & 10 deletions
70
...n/java/com/github/muhin007/iWeatherProvider/weatherAdaptor/apixu/WeatherAdaptorApixu.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,67 @@ | ||
package com.github.muhin007.iWeatherProvider.weatherAdaptor.apixu; | ||
|
||
import com.github.muhin007.iWeatherProvider.weatherAdaptor.WeatherAdaptor; | ||
import org.w3c.dom.Document; | ||
import org.xml.sax.SAXException; | ||
|
||
public class WeatherAdaptorApixu extends WeatherAdaptor { | ||
TempFromApixu tempFromApixu = new TempFromApixu(); | ||
import javax.xml.parsers.DocumentBuilder; | ||
import javax.xml.parsers.DocumentBuilderFactory; | ||
import javax.xml.parsers.ParserConfigurationException; | ||
import javax.xml.transform.*; | ||
import javax.xml.transform.dom.DOMSource; | ||
import javax.xml.transform.stream.StreamResult; | ||
import java.io.IOException; | ||
import java.io.StringWriter; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
|
||
private int tempApixu; | ||
@Override | ||
public void requestTempAPI() { | ||
tempApixu = tempFromApixu.getTempFromApixu(); | ||
public class WeatherAdaptorApixu { | ||
|
||
public int getTempFromApixu(String cityName) { | ||
String uri = "http://api.apixu.com/v1/current.xml?key=d85bbc64aab34428894192757192306&q=" + cityName; | ||
|
||
String output = getString(uri); | ||
return Integer.parseInt(output.split("<temp_c>")[1].split("</temp_c>")[0]); | ||
} | ||
public double getTempApixu() { | ||
requestTempAPI(); | ||
return tempApixu; | ||
|
||
public String getString(String uri) { | ||
URL url = null; | ||
try { | ||
url = new URL(uri); | ||
} catch (MalformedURLException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); | ||
DocumentBuilder db = null; | ||
try { | ||
db = dbf.newDocumentBuilder(); | ||
} catch (ParserConfigurationException e) { | ||
e.printStackTrace(); | ||
} | ||
Document doc = null; | ||
try { | ||
assert db != null; | ||
assert url != null; | ||
doc = db.parse(url.openStream()); | ||
} catch (SAXException | IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
TransformerFactory tf = TransformerFactory.newInstance(); | ||
Transformer transformer = null; | ||
try { | ||
transformer = tf.newTransformer(); | ||
} catch (TransformerConfigurationException e) { | ||
e.printStackTrace(); | ||
} | ||
assert transformer != null; | ||
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); | ||
StringWriter writer = new StringWriter(); | ||
try { | ||
transformer.transform(new DOMSource(doc), new StreamResult(writer)); | ||
} catch (TransformerException e) { | ||
e.printStackTrace(); | ||
} | ||
return writer.getBuffer().toString().replaceAll("[\n\r]", ""); | ||
} | ||
} |
69 changes: 0 additions & 69 deletions
69
...hin007/iWeatherProvider/weatherAdaptor/worldweatheronline/TempFromWorldweatheronline.java
This file was deleted.
Oops, something went wrong.
20 changes: 7 additions & 13 deletions
20
.../iWeatherProvider/weatherAdaptor/worldweatheronline/WeatherAdaptorWorldweatheronline.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,13 @@ | ||
package com.github.muhin007.iWeatherProvider.weatherAdaptor.worldweatheronline; | ||
|
||
import com.github.muhin007.iWeatherProvider.weatherAdaptor.WeatherAdaptor; | ||
import com.github.muhin007.iWeatherProvider.weatherAdaptor.apixu.WeatherAdaptorApixu; | ||
|
||
public class WeatherAdaptorWorldweatheronline extends WeatherAdaptor { | ||
public class WeatherAdaptorWorldweatheronline{ | ||
private WeatherAdaptorApixu wAA = new WeatherAdaptorApixu(); | ||
|
||
TempFromWorldweatheronline tempFromWorldweatheronline = new TempFromWorldweatheronline(); | ||
private int tempWorldweatheronline; | ||
|
||
@Override | ||
public void requestTempAPI() { | ||
tempWorldweatheronline = tempFromWorldweatheronline.getTempWorldweatheronline(); | ||
} | ||
|
||
public double getTempFromWorldweatheronline() { | ||
requestTempAPI(); | ||
return tempWorldweatheronline; | ||
public int getTempFromWorldweatheronline(String cityName) { | ||
String uri = "http://api.worldweatheronline.com/premium/v1/weather.ashx?key=bc27cfec9d314543bdf70006191806&q=" + cityName + "&format=xml&num_of_days=1&lang=ru"; | ||
String output = wAA.getString(uri); | ||
return Integer.parseInt(output.split("<temp_C>")[1].split("</temp_C>")[0]); | ||
} | ||
} |
Oops, something went wrong.