Git Product home page Git Product logo

pokekotlin's Introduction


PokeAPI

build status data status deploy status License Backers on Open Collective Sponsors on Open Collective



A RESTful API for Pokémon - pokeapi.co

Beta GraphQL support is rolling out! Check out the GraphQL paragraph for more info.

Setup   pyVersion310

  • Download this source code into a working directory, be sure to use the flag --recurse-submodules to clone also our submodules.

  • Install the requirements using pip:

    make install
    # This will install all the required packages and libraries for using PokeAPI
  • Set up the local development environment using the following command:

    make setup
  • Run the server on port 8000 using the following command:

    make serve

Database setup

To build or rebuild the database by applying any CSV file update, run

make build-db

Visit localhost:8000/api/v2/ to see the running API!

Each time the build-db script is run, it will iterate over each table in the database, wipe it, and rewrite each row using the data found in data/v2/csv.

If you ever need to wipe the database use this command:

make wipe-sqlite-db

If the database schema has changed, generate any outstanding migrations and apply them

make make-migrations
make migrate

Run make help to see all tasks.

Docker and Compose   docker hub

There is also a multi-container setup, managed by Docker Compose V2. This setup allows you to deploy a production-like environment, with separate containers for each service, and is recommended if you need to simply spin up PokéAPI.

Start everything by

make docker-setup

If you don't have make on your machine you can use the following commands

docker compose up -d
docker compose exec -T app python manage.py migrate --settings=config.docker-compose
docker compose exec -T app sh -c 'echo "from data.v2.build import build_all; build_all()" | python manage.py shell --settings=config.docker-compose'

Browse localhost/api/v2/ or localhost/api/v2/pokemon/bulbasaur/ on port 80.

To rebuild the database and apply any CSV file updates, run

make docker-build-db

If the database schema has changed, generate the migrations and apply those

make docker-make-migrations
make docker-migrate

GraphQL  

When you start PokéAPI with the above Docker Compose setup, an Hasura Engine server is started as well. It's possible to track all the PokeAPI tables and foreign keys by simply

# hasura cli needs to be installed and available in your $PATH: https://hasura.io/docs/latest/graphql/core/hasura-cli/install-hasura-cli.html
# hasura cli's version has to greater than v2.0.8
make hasura-apply

When finished browse http://localhost:8080 and you will find the admin console. The GraphQL endpoint will be hosted at http://localhost:8080/v1/graphql.

A free public GraphiQL console is browsable at the address https://beta.pokeapi.co/graphql/console/. The relative GraphQL endpoint is accessible at https://beta.pokeapi.co/graphql/v1beta

A set of examples is provided in the directory /graphql/examples of this repository.

Kubernetes   Build Docker image and create k8s with it

Kustomize files are provided in the folder https://github.com/PokeAPI/pokeapi/tree/master/Resources/k8s/kustomize/base/. Create and change your secrets:

cp Resources/k8s/kustomize/base/secrets/postgres.env.sample Resources/k8s/kustomize/base/secrets/postgres.env
cp Resources/k8s/kustomize/base/secrets/graphql.env.sample Resources/k8s/kustomize/base/secrets/graphql.env
cp Resources/k8s/kustomize/base/config/pokeapi.env.sample Resources/k8s/kustomize/base/config/pokeapi.env
# Edit the newly created files

Configure kubectl to point to a cluster and then run the following commands to start a PokéAPI service.

kubectl apply -k Resources/k8s/kustomize/base/
kubectl config set-context --current --namespace pokeapi # (Optional) Set pokeapi ns as the working ns
# Wait for the cluster to spin up
kubectl exec --namespace pokeapi deployment/pokeapi -- python manage.py migrate --settings=config.docker-compose # Migrate the DB
kubectl exec --namespace pokeapi deployment/pokeapi -- sh -c 'echo "from data.v2.build import build_all; build_all()" | python manage.py shell --settings=config.docker-compose' # Build the db
kubectl wait --namespace pokeapi --timeout=120s --for=condition=complete job/load-graphql # Wait for Graphql configuration job to finish

This k8s setup creates all k8s resources inside the Namespace pokeapi, run kubectl delete namespace pokeapi to delete them. It also creates a Service of type LoadBalancer which is exposed on port 80 and 443. Data is persisted on 12Gi of ReadWriteOnce volumes.

Wrappers

Official wrapper Repository Features
Node server-side PokeAPI/pokedex-promise-v2 Auto caching
Browser client-side PokeAPI/pokeapi-js-wrapper Auto caching, Image caching
Java/Kotlin PokeAPI/pokekotlin
Python 2/3 PokeAPI/pokepy Auto caching
Python 3 PokeAPI/pokebase Auto caching, Image caching
Wrapper Repository Features
.Net Standard mtrdp642/PokeApiNet Auto caching
Dart prathanbomb/pokedart
Go mtslzr/pokeapi-go Auto caching
PHP lmerotta/phpokeapi Auto caching, lazy loading
PowerShell Celerium/PokeAPI-PowerShellWrapper
Python beastmatser/aiopokeapi Auto caching, asynchronous
Ruby rdavid1099/poke-api-v2
Rust lunik1/pokerust Auto caching
Scala juliano/pokeapi-scala Auto caching
Spring Boot dlfigueira/spring-pokeapi Auto caching
Swift kinkofer/PokemonAPI
Typescript server-side/client-side Gabb-c/Pokenode-ts Auto caching

Donations

Help to keep PokéAPI running! If you're using PokéAPI as a teaching resource or for a project, consider sending us a donation to help keep the service up. We get 1+ billion requests a month!

Thank you to all our backers! Become a backer

Join Us On Slack!

Warning Currently no maintainer has enough free time to support the community on Slack. Our Slack is in an unmaintained status.

Have a question or just want to discuss new ideas and improvements? Hit us up on Slack. Consider talking with us here before creating a new issue. This way we can keep issues here a bit more organized and helpful in the long run. Be excellent to each other 😄

Sign up easily!

Once you've signed up visit PokéAPI on Slack

Contributing

This project exists thanks to all the people who contribute

All contributions are welcome: bug fixes, data contributions, and recommendations.

Please see the issues on GitHub before you submit a pull request or raise an issue, someone else might have beat you to it.

To contribute to this repository:

  • Fork the project to your own GitHub profile

  • Download the forked project using git clone:

    git clone --recurse-submodules [email protected]:<YOUR_USERNAME>/pokeapi.git
  • Create a new branch with a descriptive name:

    git checkout -b my_new_branch
  • Write some code, fix something, and add a test to prove that it works. No pull request will be accepted without tests passing, or without new tests if new features are added.

  • Commit your code and push it to GitHub

  • Open a new pull request and describe the changes you have made.

  • We'll accept your changes after review.

Simple!

Deprecation

As of October 2018, the v1 API has been removed from PokéAPI. For more information, see pokeapi.co/docs/v1.html.

pokekotlin's People

Contributors

cbruegg avatar chitvan14 avatar naramsim avatar r0adkll avatar sargunv avatar semigradsky avatar stocky37 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pokekotlin's Issues

JsonDataException when requesting Pokemon in Java

I am getting a JSONDataException from com.squareup.moshi were it expects a string but it is getting a BEGIN_OBJECT.

The code I am using to make the call is as follows:

Call<Pokemon> pokemonCall = PokeApi.INSTANCE.getPokemon(nationalDexNumber);
pokemonCall.enqueue(new Callback<Pokemon>() {
    @Override
    public void onResponse(Call<Pokemon> call, retrofit2.Response<Pokemon> response) {
        Pokemon pokemon = response.body();
        for (LocationAreaEncounter encounter : pokemon.getLocation_area_encounters()) {
            ApiResource<LocationArea> areaApiResource = encounter.getLocation_area();
            areaEncounterList.add(areaApiResource.getUrl());
        }
    }

    @Override
    public void onFailure(Call<Pokemon> call, Throwable t) {
        Log.e(String.format("PokeApi.getPokemon(%d)", nationalDexNumber), "Failed to get Pokémon", t);
    }
});

Relevant Data

  • Test Device: Samsung Galaxy S6+
  • Editor: Android Studio 2.1
  • minSdkVersion: 15
  • targetSdkVersion: 23

Code generation

Much of the client code is repetitive, and could probably make use of code generation. Maybe a custom Kobalt task could help here?

EDIT 2016/06/24: There's a new Kapt coming with Kotlin 1.0.4. Looks like Kobalt may support this better than the current Kapt, so this should be put on hold until then. Once that's out, we can use annotation processing instead of a custom Kobalt task to implement the code generation.

PokeKotlin Integration Issue.

Hi,

Im trying to integrate PokeKotlin into my android project which using build.gradle.kts file for adding dependencies, The readMe file and the release section are showing different ways to integrate the Library, as per my understanding it is no longer hosted in bintray so tried to integrate using this dependency : implementation("me.sargunvohra.lib:pokekotlin:2.4.0"), but im facing the following error : "Failed to resolve: me.sargunvohra.lib:pokekotlin:2.4.0"

Is this repository still being maintained?

Test: Pokemon

  • Ability
  • Characteristic
  • Egg group
  • Gender
  • Growth rate
  • Nature
  • Pokeathlon stat
  • Pokemon
  • Pokemon color
  • Pokemon form
  • Pokemon habitat
  • Pokemon shape
  • Pokemon species
  • Stat
  • Type

Test: Moves

  • Move
  • Move ailment
  • Move battle style
  • Move category
  • Move damage class
  • Move learn method
  • Move target

Test: Items

  • Item
  • Item attribute
  • Item category
  • Item fling effect
  • Item pocket

Convenience method for lists

Code like this is very common:

client.getMoveList(offset = 0, limit = service.getMoveList(0, 0).count)

There should be a convenience function for each resource list that takes no parameters and returns the full list via the above.

fun getMoveList() = getMoveList(0, getMoveList(0, 0).count)

Java Application exits if calling PokeAPI with invalid argument

Dear Developers,

I am facing a usability problem when using pokekotlin.
This is my situation:
I am writing a Java application and want to cache all abilities. My first intention was to call getAbility() until I get no more abilities:

        boolean continueLoop = true;
        for (int i = 1; continueLoop; i++) {
            Ability ability = pokeApi.getAbility(i);
            if (ability == null) {
                continueLoop = false;
            }
            else {
                //do somthing
            }
        }

However as soon as i reaches a value PokeAPI returns a 404 for, my application exits with this exception:

Exception in thread "main" me.sargunvohra.lib.pokekotlin.client.ErrorResponse: (404) Not Found
at me.sargunvohra.lib.pokekotlin.client.PokeApiClient.result(PokeApiClient.kt:13)
at me.sargunvohra.lib.pokekotlin.client.PokeApiClient.getAbility(PokeApiClient.kt:251)

I tried to catch the exception. This didn't work.
My next thought was to use the method getAbilityList(). This is working for me, but to get the actual Ability object I have to extract the id from the NamedApiResource and then do the getAbility() call with this id. This approach works but, I assume, PokeAPI is called twice for every ability. I would prefer not doing so.

I don't know nothing about kotlin and thus can't tell if this behaviour is intended or not. Also I have no idea how to prevent my application from exiting.

Wouldn't it be possible to just return null in case a HTTP call returns no result/404 error?

Regards
Adrian

P.S.: Nevertheless you are doing a great job. Kudos to you!

Parallel tests

Edit the TestNG config to make the tests run in parallel.

Add encounters to the bulk test

Location area encounters have been left out of the bulk test since they were changed to be a subresource. It should be added as a new test inside the bulk test class.

Documentation

This library should have a more detailed documentation and some examples.

EDIT: Should do this after 2.0.0

Restructure data model

Kotlin 1.1 is coming soon, which will include data class inheritance. The resource models can probably be reworked with this new feature, which will cause some minor breaking changes in edge cases.

Since there will be another major version bump for this, it's probably also a good time to see if there's any more breaking refactoring that should be done (although most of that was taken care of with 2.0.0).

Should see if NamedApiResource and ApiResource can get a generic parameter for the type of resource it's pointing to. Also should make NamedApiResource extend from ApiResource. Should also add a base class for all API objects since they all include an id and name.

ErrorResponse: (503)

The test in web give me:

Caused by: me.sargunvohra.lib.pokekotlin.client.ErrorResponse: (503)

What's the problem?

Thanks.

Models not compatible with Jackson

Hi, I'm trying to use the models with a Jackson/Jaxrs client, but get errors since the id and category fields on ApiResource and NamedApiResource don't actually exist on the incoming JSON.

I could implement something similar to your ApiResourceAdapter, but for Jackson, but I thought default, lazy values on the classes would make more sense so they can be used as-is more widely. Ideally, this would also let us be able to remove the custom adapters in this repo, but it looks like Gson has issues with default values on kotlin classes.

HTTPS issues

Add dependencies pom.xml of my project:

Failed to collect dependencies for ... Could not transfer artifact ... from/to central ... Failed to transfer file ... Return code is: 501 , ReasonPhrase:HTTPS Required. -> [Help 1]
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany</groupId>
    <artifactId>PokemonProject</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    <repositories>
	<repository>
            <id>jitpack.io</id>
            <url>https://jitpack.io</url>
	</repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>com.github.PokeAPI</groupId>
            <artifactId>pokekotlin</artifactId>
            <version>2.3.1</version>
            <type>jar</type>
        </dependency>
    </dependencies>
</project>

When trying to run my project I get the error of:

Failed to execute goal on project PokemonProject: Could not resolve dependencies for project com.mycompany:PokemonProject:jar:1.0-SNAPSHOT: Failed to collect dependencies for [com.github.PokeAPI:pokekotlin:jar:2.3.1 (compile)]: Failed to read artifact descriptor for com.squareup.retrofit2:retrofit:jar:2.8.1: Could not transfer artifact com.squareup.retrofit2:retrofit:pom:2.8.1 from/to central (http://repo.maven.apache.org/maven2): Failed to transfer file: http://repo.maven.apache.org/maven2/com/squareup/retrofit2/retrofit/2.8.1/retrofit-2.8.1.pom. Return code is: 501 , ReasonPhrase:HTTPS Required. -> [Help 1]

Classes not identified

When trying to use the classes defined in the example case of the project:

PokeApi pokeApi = new PokeApiClient();

neither PokeApi nor PokeApiClient are being recognized as known classes

Auto-caching

Are there plans to add auto-caching to this wrapper? I am looking at using this and would like to cache the results, but preferably not have my own wrappers that cache the results. I'd look into doing this myself, but I am not familiar with Kotlin.

Instant crash using the Java example

Hello!

I've been wanting to create a VGC companion app for quite a while and was thinking of doing so now.

I imported your API and tried your example code, but it instantly crashes with a network error.

Is there a fix for this? Because i can't find any.

PS: this happened on android studio.

Don't hit the real PokeAPI with the tests

  • Use a local instance of PokeAPI to generate a copy of every JSON, and put it in src/test/resources
  • Make the current tests call a mock client that actually hits the local files instead of the live PokeAPI
  • Enable the BulkTest which is disabled now because it's a heavy test
  • Add one or two basic tests that still hit the real PokeAPI.

This will greatly speed up the tests. However, we should be sure to regenerate the local copy of the data periodically to ensure the tests remain relevant. Maybe automate this by setting up a server that pulls everything from PokeAPI once a week or so and creates a PR here automatically?

Eclipse installation

Hi there! I'm trying to integrate this tool into my eclipse workspace but i cant find any guide and cant figure it out myself. I've copied all the files into a new Kotlin project and created a new Java class to run the test code provided in the readme. However, when i try to execute it, it return the Error:
Exception in thread "main" java.lang.NoClassDefFoundError: me/sargunvohra/lib/pokekotlin/client/PokeApi
any idea what to do?

Appetite for alternate client implementations?

Hey guys, I'm just wondering what your appetite would be for the following:

  • A cleaner API that implements some oft-used use cases for clients
    • For example, something like:
      client.pokemon.byId(1) (returns Pokemon type)
      client.pokemon.list(offset=0, limit=20) (returns List<Pokemon>)
  • Alternate client implementations (i.e. JAX-RS), each in a separate module, so users can choose which type of client they would like to use
    • They should all implement the above interfaces, so can be swapped out with one another if necessary
    • Standard caching wrapper that can be used with any of the actual clients

I'm basically looking at doing this myself already (see stocky37/pokeapi-java-clients for very initial ideas), I'm just wondering if you would be interested in me contributing it here or would prefer me to keep it separate.

Crashes without internet

While using the example, I noticed that the code would crash my application if my device didn't have internet. There was also no callstack present. Should have some way to handle this case, and also something in the logging.

Call by name

Named resources should be retrievable by name too, not just by id.

Missing Model Version

When trying to clean and package my own programs, it says the POM is invalid. After enabling debugging, it says the model version is missing.

<modelVersion>4.0.0</modelVersion>

Rx not support

I am using 2.3.0.

Version 2.3.1 not in repository.
implementation "me.sargunvohra.lib:pokekotlin:2.3.1" (ERROR: Failed to resolve: me.sargunvohra.lib:pokekotlin:2.3.1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.