Skip to content

Didar-Bhullar/GameOfThronesClient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GameOfThronesClient

Build Status codecov License

Adds a java wrapper around the GoT API

Getting Started

Get the instance of the gameOfThronesClient

 public static void main(String[] args){
        GameOfThronesClient gotClient = getClient();
    }

You can get a version of the client with automatic caching instead if you want.
This will cache all the calls to whatever directory you supply as the cacheFile.

    public static void main(String[] args){
        File cacheFile = new File("cacheFile");
        int cacheSize = 10 * 1024 * 1024; // 10 MB

        GameOfThronesClient gotClient = getClientWithCache(cacheFile, cacheSize);
    }

Those two clients are interchangable. All the method calls to them work exactly the same

Hitting the endpoints

Every endpoint of the GoT API is available through these methods.
Take a look at the gameOfThronesClient javadocs for the methods available to you.

Whenever you use one of those methods, your either going get a list Models or just a Model itself.
These models have various getters on them for easily retreiving information.
Take a look at these model javadocs

Example: Getting all Books

public static void main(String[] args) throws IOException {
        GameOfThronesClient gotClient = getClient();

        List<Book> allBooks = gotClient.getAllBooks();  //Returns a list of Book objects

        // loop through each book
        // you have access to multiple getters to get information
        for(Book book: allBooks){
            System.out.println(book.getName());
            System.out.println(book.getCharacters());
            // and so on...
        }
    }

Example: Getting Character by id

public static void main(String[] args) throws IOException {
        GameOfThronesClient gotClient = getClient();

        Character character = gotClient.getCharacter(100);  //Returns a single character

        // use various getters to get information about this character
        System.out.println(character.getBorn());
        System.out.println(character.getAllegiances());

    }

Example: Searching for Books

Pass in null to search values you do not care for. Applies to all House, and Character searches as well.

In this case I only cared that the book Im searching for was made after 1990-01-01 and before 2002-01-01.
I did not care for the name.

    public static void main(String[] args) throws IOException {
        GameOfThronesClient gotClient = getClient();

        List<Book> bookList = gotClient.searchBooks(null, "1990-01-01", "2002-01-01"); 
        for(Book book: bookList){
            System.out.println(book.getName());
            System.out.println(book.getReleased());
        }

    }

Java Docs

Javadocs link can be found here