Skip to content

Commit 1ba58da

Browse files
committed
Add a basic sample
1 parent 26dc5f1 commit 1ba58da

3 files changed

Lines changed: 52 additions & 1 deletion

File tree

sample/build.gradle

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apply plugin: 'java'
2+
apply plugin: 'application'
3+
4+
mainClassName = "me.proxer.sample.News"
5+
6+
run {
7+
standardInput = System.in
8+
}
9+
10+
dependencies {
11+
implementation project(':library')
12+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package me.proxer.sample;
2+
3+
import me.proxer.library.api.ProxerApi;
4+
import me.proxer.library.api.ProxerException;
5+
6+
import java.util.Scanner;
7+
import java.util.stream.Collectors;
8+
9+
/**
10+
* @author Ruben Gees
11+
*/
12+
public class News {
13+
14+
public static void main(String[] args) {
15+
ProxerApi api = new ProxerApi.Builder(readApiKey()).build();
16+
17+
try {
18+
final String news = api.notifications().news()
19+
.build()
20+
.execute()
21+
.stream()
22+
.map(newsArticle -> newsArticle.getSubject() + " written by " + newsArticle.getAuthor())
23+
.collect(Collectors.joining("\n"));
24+
25+
System.out.println();
26+
System.out.println("These are the latest news:\n" + news);
27+
} catch (ProxerException exception) {
28+
System.out.println("Something went wrong: " + exception.getMessage());
29+
}
30+
}
31+
32+
private static String readApiKey() {
33+
System.out.print("Please pass your api key: ");
34+
35+
try (final Scanner scanner = new Scanner(System.in)) {
36+
return scanner.next();
37+
}
38+
}
39+
}

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include ':library'
1+
include ':library', ':sample'

0 commit comments

Comments
 (0)