Simple wrapper to communicate with the Marvel Comics API.
Important: This is a work in progress. There's only two endpoints to connect to. I am working into incorporating all of Marvel Comics API endpoints.
Add this line to your application's Gemfile:
gem 'marvelite'
And then execute:
$ bundle
Or install it yourself as:
$ gem install marvelite
Please register first in the Marvel Comics Developer Portal to get your API credentials (a public key and a private key, you'll need them both to configure and instantiate a client).
client = Marvelite::API::Client.new(:public_key => 'abcd1234', :private_key => '5678efgh')
Method | Description |
---|---|
#characters | Fetches a list of comic characters. |
#character | Fetches a single character resource. |
#character_comics | Fetches a list of comics containing a specific character. |
#character_events | Fetches a list of events in which a specific character appears. |
#character_series | Fetches a list of comic series in which a specific character appears. |
#character_stories | Fetches a list of comic stories featuring a specific character. |
Fetches a list of comic characters. Can receive optional params.
client.characters
client.characters(:name => 'Spider-Man')
client.characters(:limit => 10, :offset => 400, :orderBy => 'name')
See the Marvel Comics Interactive API Tester for a complete list of params that you can pass to the #characters
method.
Fetches a single character resource. Accepts an integer or string value as character id.
client.character(1009610)
client.character('Spider-Man')
Fetches a list of comics containing a specific character. Requires a character id value (integer). Accepts optional params.
client.character_comics(1009610)
client.character_comics(
1009610,
{ :format => 'graphic novel', :limit => 10, :orderBy => 'title' }
)
See the Marvel Comics Interactive API Tester for a complete list of params that you can pass to the #character_comics
method.
Fetches a list of events in which a specific character appears. Requires a character id value (integer). Accepts optional params.
client.character_events(1009610)
client.character_events(
1009610,
{ :limit => 10, :orderBy => 'name' }
)
See the Marvel Comics Interactive API Tester for a complete list of params that you can pass to the #character_events
method.
Fetches a list of comic series in which a specific character appears. Requires a character id value (integer). Accepts optional params.
client.character_series(1009610)
client.character_series(
1009610,
{ :seriesType => 'ongoing', :limit => 10, :orderBy => 'title' }
)
See the Marvel Comics Interactive API Tester for a complete list of params that you can pass to the #character_series
method.
Fetches a list of comic stories featuring a specific character. Requires a character id value (integer). Accepts optional params.
client.character_stories(1009610)
client.character_stories(1009610, { :limit => 10, :offset => 20 })
See the Marvel Comics Interactive API Tester for a complete list of params that you can pass to the #character_stories
method.
All requests to the API, return a Marvelite::API::Response
object, that is nothing more than the raw API response enhanced with Hashie methods.
This way you gain several adavantages to manipulate the response, like:
# HashWithIndifferentAccess like functionality
response[:data][:results][0][:name]
response["data"]["results"][0]["name"]
# Top level methods
response.data
response.data[:results]
- Add more endpoints
- Fork it
- 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 new Pull Request