From cf7b4d23fb8299cd3d96875fd4f96dab2cfddca1 Mon Sep 17 00:00:00 2001 From: Michael Fross Date: Mon, 1 Feb 2021 08:48:56 -0600 Subject: [PATCH] Moved URLOps to the library impacting geturl and github update check --- pom.xml | 4 +- snap/snapcraft.yaml | 4 +- .../java/org/fross/quoter/FileExporter.java | 2 +- src/main/java/org/fross/quoter/Help.java | 2 +- .../org/fross/quoter/HistoricalQuotes.java | 5 +- src/main/java/org/fross/quoter/Index.java | 5 +- src/main/java/org/fross/quoter/Main.java | 5 +- src/main/java/org/fross/quoter/Prefs.java | 2 +- src/main/java/org/fross/quoter/Symbol.java | 5 +- src/main/java/org/fross/quoter/URLOps.java | 95 ------------------- 10 files changed, 19 insertions(+), 110 deletions(-) delete mode 100644 src/main/java/org/fross/quoter/URLOps.java diff --git a/pom.xml b/pom.xml index b28782f..45019bd 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.fross quoter - 2.4.1 + 2.4.2 jar quoter @@ -190,7 +190,7 @@ org.fross library - 2020.12.23 + 2021.02.01 diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 78d1bc4..696d878 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,5 +1,5 @@ name: quoter -version: '2.4.1' +version: '2.4.2' summary: Command line utility to pull stock and index quotes description: | Quote fetches stock quotes and index data from IEXCloud.IO. @@ -23,7 +23,7 @@ parts: plugin: maven source: https://github.com/frossm/library.git source-type: git - source-tag: 'v2020.12.23' + source-tag: 'v2021.02.01' maven-options: [install] quoter: diff --git a/src/main/java/org/fross/quoter/FileExporter.java b/src/main/java/org/fross/quoter/FileExporter.java index 58293bd..1d0866f 100644 --- a/src/main/java/org/fross/quoter/FileExporter.java +++ b/src/main/java/org/fross/quoter/FileExporter.java @@ -3,7 +3,7 @@ * * Quoter is a command line program that display stock quotes and index data. * - * Copyright (c) 2019 Michael Fross + * Copyright (c) 2019-2021 Michael Fross * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/org/fross/quoter/Help.java b/src/main/java/org/fross/quoter/Help.java index d537f88..c747fc1 100644 --- a/src/main/java/org/fross/quoter/Help.java +++ b/src/main/java/org/fross/quoter/Help.java @@ -3,7 +3,7 @@ * * Quoter is a command line program that display stock quotes and index data. * - * Copyright (c) 2019 Michael Fross + * Copyright (c) 2019-2021 Michael Fross * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/org/fross/quoter/HistoricalQuotes.java b/src/main/java/org/fross/quoter/HistoricalQuotes.java index 2272364..504135d 100644 --- a/src/main/java/org/fross/quoter/HistoricalQuotes.java +++ b/src/main/java/org/fross/quoter/HistoricalQuotes.java @@ -3,7 +3,7 @@ * * Quoter is a command line program that display stock quotes and index data. * - * Copyright (c) 2019 Michael Fross + * Copyright (c) 2019-2021 Michael Fross * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -30,6 +30,7 @@ import java.util.TreeMap; import org.fross.library.Output; +import org.fross.library.URLOperations; import org.fusesource.jansi.Ansi; import com.google.gson.Gson; @@ -56,7 +57,7 @@ public static Map getHistoricalQuotes(String symb, String token) // Query IEXCloud's REST API and get the historical security information in JSON format try { - rawChartData = URLOps.ReadURL(quoteURL); + rawChartData = URLOperations.ReadURL(quoteURL); } catch (Exception ex) { Output.fatalError("Could not query historical data from IEXCloud", 3); } diff --git a/src/main/java/org/fross/quoter/Index.java b/src/main/java/org/fross/quoter/Index.java index b7b76a0..46b4c52 100644 --- a/src/main/java/org/fross/quoter/Index.java +++ b/src/main/java/org/fross/quoter/Index.java @@ -3,7 +3,7 @@ * * Quoter is a command line program that display stock quotes and index data. * - * Copyright (c) 2019 Michael Fross + * * Copyright (c) 2019-2021 Michael Fross * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -32,6 +32,7 @@ import org.fross.library.Debug; import org.fross.library.Output; +import org.fross.library.URLOperations; import org.fusesource.jansi.Ansi; public class Index { @@ -68,7 +69,7 @@ protected static String[] getIndex(String idx) { try { // Download the web page with - idxPage = URLOps.ReadURL(URL); + idxPage = URLOperations.ReadURL(URL); // Define the regular expression patterns to look for in the URL provided above searchPatterns[1] = "\"last\":\"(.*?)\""; diff --git a/src/main/java/org/fross/quoter/Main.java b/src/main/java/org/fross/quoter/Main.java index 70d2d33..5541a8a 100644 --- a/src/main/java/org/fross/quoter/Main.java +++ b/src/main/java/org/fross/quoter/Main.java @@ -3,7 +3,7 @@ * * Quoter is a command line program that display stock quotes and index data. * - * Copyright (c) 2019 Michael Fross + * Copyright (c) 2019-2021 Michael Fross * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -35,6 +35,7 @@ import java.util.Scanner; import org.fross.library.Debug; +import org.fross.library.GitHub; import org.fross.library.Output; import org.fusesource.jansi.Ansi; @@ -138,7 +139,7 @@ public static void main(String[] args) { case 'v': Output.printColorln(Ansi.Color.WHITE, "Quoter Version: v" + VERSION); Output.printColorln(Ansi.Color.CYAN, COPYRIGHT); - Output.printColorln(Ansi.Color.WHITE, "\nLatest Release on GitHub: " + URLOps.updateCheck("quoter")); + Output.printColorln(Ansi.Color.WHITE, "\nLatest Release on GitHub: " + GitHub.updateCheck("quoter")); Output.printColorln(Ansi.Color.CYAN, "HomePage: https://github.com/frossm/quoter"); System.exit(0); break; diff --git a/src/main/java/org/fross/quoter/Prefs.java b/src/main/java/org/fross/quoter/Prefs.java index 456b15f..fddaf3a 100644 --- a/src/main/java/org/fross/quoter/Prefs.java +++ b/src/main/java/org/fross/quoter/Prefs.java @@ -3,7 +3,7 @@ * * Quoter is a command line program that display stock quotes and index data. * - * Copyright (c) 2019 Michael Fross + * Copyright (c) 2019-2021 Michael Fross * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/org/fross/quoter/Symbol.java b/src/main/java/org/fross/quoter/Symbol.java index af779b8..8d41e3f 100644 --- a/src/main/java/org/fross/quoter/Symbol.java +++ b/src/main/java/org/fross/quoter/Symbol.java @@ -3,7 +3,7 @@ * * Quoter is a command line program that display stock quotes and index data. * - * Copyright (c) 2019 Michael Fross + * Copyright (c) 2019-2021 Michael Fross * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -37,6 +37,7 @@ import org.fross.library.Debug; import org.fross.library.Format; import org.fross.library.Output; +import org.fross.library.URLOperations; import org.fusesource.jansi.Ansi; import com.google.gson.Gson; @@ -157,7 +158,7 @@ private static HashMap getQuote(String symb, String token) { // Query IEXCloud's REST API and get the security information in JSON format try { - quoteDetail = URLOps.ReadURL(quoteURL); + quoteDetail = URLOperations.ReadURL(quoteURL); } catch (Exception ex) { returnData.put("symbol", symb); diff --git a/src/main/java/org/fross/quoter/URLOps.java b/src/main/java/org/fross/quoter/URLOps.java deleted file mode 100644 index 00501be..0000000 --- a/src/main/java/org/fross/quoter/URLOps.java +++ /dev/null @@ -1,95 +0,0 @@ -/************************************************************************************************************** - * Quoter.jar - * - * Quoter is a command line program that display stock quotes and index data. - * - * Copyright (c) 2019 Michael Fross - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - ***************************************************************************************************************/ -package org.fross.quoter; - -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.net.URL; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class URLOps { - - /** - * ReadURL: Retrieve data from a website - * - * @param urlString - * @return - * @throws Exception - */ - public static String ReadURL(String urlString) throws Exception { - BufferedReader Reader = null; - - try { - URL url = new URL(urlString); - Reader = new BufferedReader(new InputStreamReader(url.openStream())); - StringBuilder buffer = new StringBuilder(); - int read; - char[] chars = new char[1024]; - while ((read = Reader.read(chars)) != -1) { - buffer.append(chars, 0, read); - } - - return buffer.toString(); - - } finally { - if (Reader != null) { - Reader.close(); - } - } - } - - /** - * updateCheck(): Query GitHub's tag API and determine the latest version of the application - * - * @param app - * @return - */ - public static String updateCheck(String app) { - String GITHUB_URL = "https://api.github.com/repos/frossm/" + app + "/tags"; - String returnString = null; - - try { - // Read the tags from the GitHub Tags API - String githubPage = URLOps.ReadURL(GITHUB_URL); - - // Pull out the latest version - Pattern pattern = Pattern.compile("name.: *\"(.*?)\"", Pattern.CASE_INSENSITIVE); - Matcher matcher = pattern.matcher(githubPage); - - if (matcher.find()) { - returnString = matcher.group(1); - } else { - throw new Exception(); - } - } catch (Exception ex) { - returnString = "Unable to determine latest release"; - } - - return returnString; - } -}