Crystal implementation of the Rick and Morty API.
- Add the dependency to your
shard.yml
:
dependencies:
rick_and_morty_api:
github: michalgritzbach/rick_and_morty_api
- Run
shards install
First step is to require the library and initialize the client.
require "rick_and_morty_api"
client = RickAndMortyApi::Client.new # or RickAndMortyApi.client
After that, you can call methods on client
. There are four methods with the same signature for getting characters, episodes and locations.
# List all characters
client.all_characters
# => [RickAndMortyApi::Character{}, …]
# Single character
client.character(1)
# => RickAndMortyApi::Character{}
# Multiple characters by IDs
client.characters(1, 2, 3)
# => [RickAndMortyApi::Character{}, …]
# Multiple characters filtered by params
client.characters(name: "Rick")
# => [RickAndMortyApi::Character{}, …]
# List all episodes
client.all_episodes
# => [RickAndMortyApi::Episode{}, …]
# Single episode
client.episode(1)
# => RickAndMortyApi::Episode{}
# Multiple episodes by IDs
client.episodes(1, 2, 3)
# => [RickAndMortyApi::Episode{}, …]
# Multiple episodes filtered by params
client.episodes(name: "Pilot")
# => [RickAndMortyApi::Episode{}, …]
# List all locations
client.all_locations
# => [RickAndMortyApi::Location{}, …]
# Single location
client.location(1)
# => RickAndMortyApi::Location{}
# Multiple locations by IDs
client.locations(1, 2, 3)
# => [RickAndMortyApi::Location{}, …]
# Multiple locations filtered by params
client.locations(name: "Earth")
# => [RickAndMortyApi::Location{}, …]
- Load and return associated records (e.g.
residents
fromLocation
)
After forking the repo, don't forget to run shards install
to install its dependencies. Very simple client specs are in specs
folder, don't forget to run crystal spec
to confirm that its working state.
To release a new version, bump the VERSION
constant in src/rick_and_morty_api.cr
and shard.yml
.
- Fork it (https://github.com/michalgritzbach/rick_and_morty_api/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
- Michal Gritzbach - creator and maintainer