rick_and_morty_api v0.1.0

Crystal implementation of the Rick and Morty API.

Rick and Morty API shard

GitHub release Build Status

Crystal implementation of the Rick and Morty API.

Installation

  1. Add the dependency to your shard.yml:
dependencies:
  rick_and_morty_api:
    github: michalgritzbach/rick_and_morty_api
  1. 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 from Location)

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

  1. Fork it (https://github.com/michalgritzbach/rick_and_morty_api/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

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