ikoene / marvel-api-bundle
A Symfony bundle that provides a Marvel API client service.
Installs: 53
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 1
Open Issues: 0
Type:symfony-bundle
Requires
- guzzlehttp/guzzle: ^6.3
- jms/serializer: ^1.11
Requires (Dev)
- doctrine/collections: ^1.5
- symfony/console: ^4.0
- symfony/framework-bundle: ^3.4
- symfony/phpunit-bridge: ^4.0
- symfony/yaml: ^4.0
This package is not auto-updated.
Last update: 2024-11-02 01:18:59 UTC
README
Marvel API bundle
The Marvel Comics API allows developers everywhere to access information about Marvel's vast library of comics—from what's coming up, to 70 years ago. This Marvel API bundle helps you explore the Marvel universe with great ease.
Requirements
- PHP 7.1.0
- Marvel API key
- Love for Marvel
Installation
Applications that use Symfony Flex
Open a command console, enter your project directory and execute:
$ composer require ikoene/marvel-api-bundle
Applications that don't use Symfony Flex
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require ikoene/marvel-api-bundle
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php
file of your project:
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new Ikoene\MarvelApiBundle\IkoeneMarvelApiBundle(), ); // ... } // ... }
Step 3: Configure the Bundle
# You will need a public and private api key from https://developers.marvel.com. # Set the keys as environment variables in the .env file. ikoene_marvel_api: public_api_key: "%env(MARVEL_PUBLIC_API_KEY)%" private_api_key: "%env(MARVEL_PRIVATE_API_KEY)%"
Usage
<?php
$client = $this->get('ikoene_marvel_api_client');
$response = $client->getCharacter(1009610);
var_dump($response);
Endpoints
You can call every endpoint with an explicitly defined method. So if you, for example, want a list of comics containing a specific character, you can call getComicsForCharacter()
.
$response = $client->getComicsForCharacter(1009610);
Optional filters
It's also possible to add optional filters to the calls. Let's get all comics for 'Spider-Man' which title starts with 'Age of Ultron' and order the results by 'title'.
$comicFilter = new Ikoene\MarvelApiBundle\Entity\ComicFilter();
$comicFilter->setTitleStartsWith('Age of Ultron');
$comicFilter->setOrderBy('title');
$response = $client->getComicsForCharacter(1009610, $comicFilter);
Pretty easy, right?