rick_and_morty_api v0.1.0
Rick and Morty API shard
Crystal implementation of the Rick and Morty API.
Installation
- Add the dependency to your
shard.yml
:
dependencies:
rick_and_morty_api:
github: michalgritzbach/rick_and_morty_api
- Run
shards install
Usage
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.
Characters
# 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{}, …]
Episodes
# 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{}, …]
Locations
# 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{}, …]
TODO
- Load and return associated records (e.g.
residents
fromLocation
)
Development
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
.
Contributing
- 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
Contributors
- Michal Gritzbach - creator and maintainer
Repository
rick_and_morty_api
Owner
Statistic
- 0
- 0
- 0
- 0
- 4
- almost 4 years ago
- August 29, 2020
License
MIT License
Links
Synced at
Fri, 08 Nov 2024 07:02:27 GMT
Languages