├── src ├── main │ ├── resources │ │ └── README.md │ └── java │ │ └── Application.java └── test │ └── resources │ └── README.md ├── target └── classes │ └── Application.class ├── .settings ├── org.eclipse.m2e.core.prefs └── org.eclipse.jdt.core.prefs ├── .github └── workflows │ └── maven.yml ├── pom.xml ├── .project ├── .classpath └── README.md /src/main/resources/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/test/resources/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /target/classes/Application.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/g1f1/NewsAPP/HEAD/target/classes/Application.class -------------------------------------------------------------------------------- /.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | name: Java CI with Maven 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | - name: Set up JDK 11 17 | uses: actions/setup-java@v2 18 | with: 19 | java-version: '11' 20 | distribution: 'temurin' 21 | cache: maven 22 | - name: Build with Maven 23 | run: mvn -B package --file pom.xml 24 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | gr.unipi 4 | NewsAPP 5 | 0.0.1-SNAPSHOT 6 | 7 | 8 | 9 | gr.unipi 10 | NewsAPI 11 | 0.0.1-SNAPSHOT 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | NewsAPP 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=1.7 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 13 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore 14 | org.eclipse.jdt.core.compiler.release=disabled 15 | org.eclipse.jdt.core.compiler.source=1.7 16 | -------------------------------------------------------------------------------- /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | The project is seperated in two parts. So, there are two repositories (NewsAPI and NewsAPP). 2 | The first part is about building the library NewsAPI and the second one is about building application named NewsAPP which is about getting top-headlines news or everything news according to specific criterias. 3 | 4 | The application «NewsAPP» can be found in this repository. 5 | 6 | User can see that there is a class named Application which includes a menu with specific choices about getting news and user has just to select one of the choices by typing the suitable number. When user types a specific choice from the menu, the results are displayed in a console inside the programm. 7 | 8 | Also, it is worth noting that the menu in application is separated to three parts. The first one is about getting top-headlines news either for user’s country by detecting automatically user’s country via IP Address or for another country or a specific category. The second one is about getting everything news according to specific criterias. The third one is about exiting the program when user finishes their tests. 9 | 10 | Last but not least, it has to be referred that when user types a choice of the menu, there are full and clear instructions to help them decide what parameters should type about the news they want to search for. 11 | 12 | P.S. Ιn order to run the project, user has to import both repositories «NewsAPI» and «NewsAPP» in their Java programm (I personally used the Eclipse IDE for Java Developers). Also, before running the programm, user has to write firstly their apiKey and ipv6 following the instructions in README of repository «NewsAPΙ». 13 | -------------------------------------------------------------------------------- /src/main/java/Application.java: -------------------------------------------------------------------------------- 1 | import java.util.List; 2 | import java.util.Scanner; 3 | 4 | import exception.NewsAPIException; 5 | import model.newsinfo; 6 | import model.thenewsdb.Location; 7 | import model.thenewsdb.LocationResult; 8 | import newsapi.LocationAPI; 9 | import newsapi.NewsAPI; 10 | import services.LocationbyIpDetection; 11 | import services.NewsAPIService; 12 | 13 | public class Application { 14 | //I created a menu of specific choices about news and user has just to select one of the choices by typing the suitable number 15 | //When user types a number, he/she is asked to type the required parameter(s) and then they can see in console the results of their choice in a list form 16 | 17 | public static void main(String[] args) throws NewsAPIException{ 18 | 19 | //it receives ApiKey and API_URL from class NewsAPI 20 | NewsAPIService newsAPIService= NewsAPI.getNewsAPIService(); 21 | System.out.println("Welcome to News APP!"); 22 | 23 | //menu with choices in numbers for the user 24 | //while(true) is created in order to repeat a choice (the same or another) 25 | while(true) { 26 | System.out.println("Select one of the following \n "); 27 | System.out.println("Show the top headlines"); 28 | System.out.println("1a. Show the top headlines for user's country according to IP Address:"); 29 | System.out.println("1b. Show the top headlines for another country:"); 30 | System.out.println("1c. Show the top headlines for a category: \n "); 31 | System.out.println("Search everything news according to criteria"); 32 | System.out.println("2a. Search Everything News about a query "); 33 | System.out.println("2b. Search Everything News about a source"); 34 | System.out.println("2c. Search Everything News about a language "); 35 | System.out.println("2d. Search Everything News about a query between specific date of publication \n"); 36 | System.out.println("3. Exit \n"); 37 | System.out.println("Your input"); 38 | 39 | //Scanner is used to ask user to type number of their choice or a parameter 40 | Scanner sc = new Scanner (System.in); 41 | String input = sc.nextLine(); 42 | 43 | System.out.println("Your input:" + input); 44 | //switch is used for the cases of user's possible choices 45 | switch(input) { 46 | //it returns top headlines from user's country according to IP Address 47 | case "1a": 48 | //it receives API_URL, apiKey and ipv6 from class LocationAPI 49 | final LocationbyIpDetection newsSearchService1= LocationAPI.getLocationbyIPDetection(); 50 | //it uses the method searchUserLocation which was created in class LocationbyIpDetection 51 | final LocationResult results2 = newsSearchService1.searchUserLocation(); 52 | //country is found using class getCountry in class Location 53 | String country2 = Location.getCountry(); 54 | System.out.println("Your country is: " + country2); 55 | System.out.println("According to documentation in https://newsapi.org/docs/endpoints/top-headlines,"); 56 | System.out.println("possible countries for endpoint (top-headlines)"); 57 | System.out.println("are these: ae-ar-at-au-be-bg-br-ca-ch-cn-co-cu-cz-de-eg-fr-gb-gr-hk-hu-id-ie-il-in-it-jp-kr-lt-lv-ma-mx-my-ng-nl-no-nz-ph-pl-pt-ro-rs-ru-sa-se-sg-si-sk-th-tr-tw-ua-us-ve and za"); 58 | System.out.println("So there is a possibility for user not to see top-headlines news for their country, if user does not live in one of the aforementioned countries"); 59 | try { 60 | final List results= newsAPIService.getTopHeadlinesForCountry(country2); 61 | System.out.println("Results are:"); 62 | System.out.println(results); 63 | } catch (NewsAPIException e){ 64 | System.err.println(e.getMessage()); 65 | } 66 | break; 67 | //it returns top-headline news from a country that user typed 68 | case "1b": 69 | System.out.println("To see top-headlines acccording to a country you have to type a country of your choice"); 70 | System.out.println("According to documentation in https://newsapi.org/docs/endpoints/top-headlines,"); 71 | System.out.println("possible countries for endpoint (top-headlines)"); 72 | System.out.println("are these: ae-ar-at-au-be-bg-br-ca-ch-cn-co-cu-cz-de-eg-fr-gb-gr-hk-hu-id-ie-il-in-it-jp-kr-lt-lv-ma-mx-my-ng-nl-no-nz-ph-pl-pt-ro-rs-ru-sa-se-sg-si-sk-th-tr-tw-ua-us-ve and za"); 73 | System.out.println("Enter the country of your choice:"); 74 | String country = sc.nextLine(); 75 | try { 76 | final List results = newsAPIService.getTopHeadlinesForCountry(country); 77 | System.out.println("Results are:"); 78 | System.out.println(results); 79 | } catch (NewsAPIException e){ 80 | System.err.println(e.getMessage()); 81 | } 82 | break; 83 | //it returns top-headline news about a category for a country that user typed 84 | case "1c": 85 | System.out.println("To see top-headlines according to category, you have to type firstly country of your choice and then the category you want"); 86 | System.out.println("According to documentation in https://newsapi.org/docs/endpoints/top-headlines,"); 87 | System.out.println("possible countries for endpoint (top-headlines)"); 88 | System.out.println("are these: ae-ar-at-au-be-bg-br-ca-ch-cn-co-cu-cz-de-eg-fr-gb-gr-hk-hu-id-ie-il-in-it-jp-kr-lt-lv-ma-mx-my-ng-nl-no-nz-ph-pl-pt-ro-rs-ru-sa-se-sg-si-sk-th-tr-tw-ua-us-ve and za"); 89 | System.out.println("Enter the country of your choice:"); 90 | String country1 = sc.nextLine(); 91 | System.out.println("possible categories for endpoint (top-headlines) are these: business, entertainment, general, health, science, sports and technology"); 92 | System.out.println("Enter the category of your choice:"); 93 | String category = sc.nextLine(); 94 | try { 95 | final List results = newsAPIService.getTopHeadlinesForCategory(country1,category); 96 | System.out.println("Results are:"); 97 | System.out.println(results); 98 | } catch (NewsAPIException e){ 99 | System.err.println(e.getMessage()); 100 | } 101 | break; 102 | //it returns everything news about a specific query that user typed 103 | case "2a": 104 | System.out.println("To see news acccording to a query, you have to type a query of your choice"); 105 | System.out.println("You can type whatever query you want"); 106 | System.out.println("Enter the query of your choice:"); 107 | String q = sc.nextLine(); 108 | try { 109 | final List results = newsAPIService.searchEverythingNewsForQuery(q); 110 | System.out.println("Results are:"); 111 | System.out.println(results); 112 | } catch (NewsAPIException e){ 113 | System.err.println(e.getMessage()); 114 | } 115 | break; 116 | //it returns everything news about a specific source that user typed 117 | case "2b": 118 | System.out.println("To see news according to sources, you must firstly type query of your choice "); 119 | System.out.println("Secondly, you have to type the language of your choice and then the source you want"); 120 | System.out.println("You can type whatever query you want"); 121 | System.out.println("Enter the query of your choice:"); 122 | String q1 = sc.nextLine(); 123 | System.out.println("According to documentation in https://newsapi.org/docs/endpoints/everything,"); 124 | System.out.println("possible languages for endpoint (everything)"); 125 | System.out.println("are these: ar-de-en-es-fr-he-it-nl-no-pt-ru-se-ud and zh"); 126 | System.out.println("That means, greek language is not supported"); 127 | System.out.println("Enter the language of your choice:"); 128 | String language = sc.nextLine(); 129 | System.out.println("You can type whatever sources you want"); 130 | System.out.println("Enter the source of your choice:"); 131 | String sources = sc.nextLine(); 132 | try { 133 | final List results = newsAPIService.searchEverythingNewsForSources(q1,language,sources); 134 | System.out.println("Results are:"); 135 | System.out.println(results); 136 | } catch (NewsAPIException e){ 137 | System.err.println(e.getMessage()); 138 | } 139 | break; 140 | //it returns everything news about a specific language that user typed 141 | case "2c": 142 | System.out.println("To see news according to language, you must firstly type query of your choice "); 143 | System.out.println("and then you have to type the language you want"); 144 | System.out.println("You can type whatever query you want"); 145 | System.out.println("Enter the query of your choice:"); 146 | String q2 = sc.nextLine(); 147 | System.out.println("According to documentation in https://newsapi.org/docs/endpoints/everything,"); 148 | System.out.println("possible languages for endpoint (everything)"); 149 | System.out.println("are these: ar-de-en-es-fr-he-it-nl-no-pt-ru-se-ud and zh"); 150 | System.out.println("That means, greek language is not supported"); 151 | System.out.println("Enter the language of your choice:"); 152 | String language1 = sc.nextLine(); 153 | try { 154 | final List results = newsAPIService.getSearchEverythingNewsForLanguage(q2,language1); 155 | System.out.println("Results are:"); 156 | System.out.println(results); 157 | } catch (NewsAPIException e){ 158 | System.err.println(e.getMessage()); 159 | } 160 | break; 161 | //it returns everything news between specific dates for a source and query that user typed 162 | case "2d": 163 | System.out.println("To see news according to date of publication, you must firstly type query of your choice "); 164 | System.out.println("Secondly, you have to type the language of your choice"); 165 | System.out.println("Thirdly, you have to type the sources of your choice and then the date of publication you want"); 166 | System.out.println("You can type whatever query you want"); 167 | System.out.println("Enter the query of your choice:"); 168 | String q3 = sc.nextLine(); 169 | System.out.println("According to documentation in https://newsapi.org/docs/endpoints/everything,"); 170 | System.out.println("possible languages for endpoint (everything)"); 171 | System.out.println("are these: ar-de-en-es-fr-he-it-nl-no-pt-ru-se-ud and zh"); 172 | System.out.println("That means, greek language is not supported"); 173 | System.out.println("Enter the language of your choice:"); 174 | String language2 = sc.nextLine(); 175 | System.out.println("You can type whatever sources you want"); 176 | System.out.println("Enter the source of your choice:"); 177 | String sources1 = sc.nextLine(); 178 | System.out.println(" You can also type whatever dates (from&to) you want to search for"); 179 | System.out.println("Enter the start date (from when) for the publications of your choice:"); 180 | String from = sc.nextLine(); 181 | System.out.println("Enter the end date (to when) for the publications of your choice:"); 182 | String to = sc.nextLine(); 183 | try { 184 | final List results = newsAPIService.searchEverythingNewsForDateOfPublication(q3,language2,sources1,from,to); 185 | System.out.println("Results are:"); 186 | System.out.println(results); 187 | } catch (NewsAPIException e){ 188 | System.err.println(e.getMessage()); 189 | } 190 | break; 191 | //exit of the programm 192 | case "3": 193 | System.out.println("End of programm "); 194 | System.exit(0); 195 | break; 196 | default: 197 | System.out.println("Invalid input. Please try again"); 198 | 199 | } 200 | 201 | } 202 | 203 | 204 | } 205 | 206 | } 207 | --------------------------------------------------------------------------------