Code Monkey home page Code Monkey logo

marvel's Introduction

marvel_api

Build Status Coverage Status

Ruby bindings for the Marvel API. In active development. Feel free to contribute! Need Ruby 1.9.2 support or don't like Faraday? Check out the marvelite gem for an alternative. (-:

Installation

gem install 'marvel_api' or add gem 'marvel_api' to your Gemfile and bundle.

Configuration

You'll need an API key — get yours here. Configure like so:

@client = Marvel::Client.new

@client.configure do |config|
  config.api_key = 'YOUR_API_KEY'
  config.private_key = 'YOUR_PRIVATE_KEY'
end

Usage

Descriptions and examples of the supported actions are below. Note, all methods currently return an Array of Hashie::Mash objects if successful; otherwise, a Marvel::Response::Error is returned. For a more detailed explanation of available actions and an exhaustive list of acceptable query parameters, see Marvel's own developer documentation. Each method described below links to the associated call in Marvel's interactive API tester.

Characters

@client.characters
@client.characters(name: 'Thanos')
@client.characters(nameStartsWith: 'Th', orderBy: 'modified')
@client.character(1009652)
@client.character_comics(1009652)
@client.character_comics(1009652, titleStartsWith: 'Infinity', hasDigitalIssue: true)
@client.character_events(1009652)
@client.character_events(1009652, name: 'Infinity Gauntlet')
@client.character_series(1009652)
@client.character_series(1009652, contains: 'hardcover')
@client.character_stories(1009652)
@client.character_stories(1009652, limit: 50)

Comics

@client.comics
@client.comics(title: 'Daredevil')
@client.comics(startYear: 1950, issueNumber: 1)
@client.comic(29380)
@client.comic_characters(34249)
@client.comic_characters(34249, orderBy: 'name')
@client.comic_creators(34249)
@client.comic_creators(34249, lastNameStartsWith: 'V')
@client.comic_events(27272)
@client.comic_events(27272, orderBy: '-startDate')
@client.comic_stories(27272)
@client.comic_stories(27272, creators: [600, 801])

Creators

@client.creators
@client.creators(firstName: 'Frank', lastName: 'Miller')
@client.creators(lastNameStartsWith: 'Mo', limit: 20, offset: 20)
@client.creator(15)
@client.creator_comics(15)
@client.creator_comics(15, format: 'trade paperback')
@client.creator_events(30)
@client.creator_events(30, nameStartsWith: 'Civil')
@client.creator_series(30)
@client.creator_series(30, seriesType: 'limited')
@client.creator_stories(30)
@client.creator_stories(30, limit: 40, offset: 7750)

Events

@client.events
@client.events(name: 'Infinity Gauntlet')
@client.events(characters: [1009156, 1009652])
@client.event(227)
@client.event_characters(227)
@client.event_characters(227, modifiedSince: '2014-04-29')
@client.event_comics(227)
@client.event_comics(227, hasDigitalIssue: true, orderBy: 'onsaleDate')
@client.event_creators(227)
@@client.event_creators(227, lastNameStartsWith: 'Lar')
@client.event_series(227)
@client.event_series(227, startYear: 1995, seriesType: 'limited')
@client.event_stories(227)
@client.event_stories(227, orderBy: 'id', limit: 30, offset: 20)

Series

@client.series
@client.series(title: 'Uncanny X-Men')
@client.series(titleStartsWith: 'Astonishing', orderBy: 'startYear', limit: 100)
@client.serie(354)
@client.series_characters(354)
@client.series_characters(354, nameStartsWith: 'Iron')
@client.series_comics(354)
@client.series_comics(354, issueNumber: 1)
@client.series_creators(354)
@client.series_creators(354, lastName: 'Kirby')
@client.series_events(354)
@client.series_events(354, orderBy: 'startDate')
@client.series_stories(354)
@client.series_stories(354, modifiedSince: '2013-06-01')

Stories

@client.stories
@client.stories(creators: 15)
@client.stories(characters: [1009156, 1009652], orderBy: '-modified')
@client.story(6320)
@client.story_characters(14410)
@client.story_characters(14410, nameStartsWith: 'D')
@client.story_comics(126)
@client.story_comics(126, format: 'trade paperback')
@client.story_creators(126)
@client.story_creators(126, lastNameStartsWith: 'S')
@client.story_events(12964)
@client.story_events(12964, orderBy: 'name')
@client.story_series(126)
@client.story_series(126, titleStartsWith: 'Infinity')

Etags

Most successful responses contain an etag attribute that can be used to check whether the content of the requested resource has remained the same since the last request.

thanos = @client.character(1009652)
@client.character(1009652, etag: thanos.etag)

If the content has not changed, a Marvel::Response::Error with code 304 and status 'Not Modified' is returned and you can use your cached content knowing that it is up-to-date and that you saved some bandwidth. If the content has changed or the Etag is invalid, the resource you requested will be returned.

Contributing to marvel_api

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
  • Fork the project.
  • Start a feature/bugfix branch.
  • Commit and push until you are happy with your contribution.
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright

Copyright (c) 2014 Rahul Horé. See LICENSE.txt for further details.

marvel's People

Contributors

laurasimmons30 avatar o-i avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

marvel's Issues

Fix/update Travis build

I think the current convention is only to declare development dependencies for a Ruby gem in the Gemfile (but research). There is an issue with some of these dependencies and the Ruby versions no longer being compatible. Investigate the Travis failures and update accordingly.

Removing faraday ~> 0.8.9 dependency causes crash

I thought I could relax the dependency. Apparently not:

/Users/Raevynheart/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:2000:in raise_if_conflicts': Unable to activate faraday_middleware-0.9.0, because faraday-0.9.0 conflicts with faraday (< 0.9, >= 0.7.4) (Gem::LoadError) from /Users/Raevynheart/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1238:inactivate'
from /Users/Raevynheart/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems.rb:194:in rescue in try_activate' from /Users/Raevynheart/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems.rb:191:intry_activate'
from /Users/Raevynheart/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:132:in rescue in require' from /Users/Raevynheart/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:144:inrequire'
from /Users/Raevynheart/Code/marvel/lib/marvel/connection.rb:1:in <top (required)>' from lib/marvel/client.rb:6:inrequire_relative'
from lib/marvel/client.rb:6:in `

'

Fixing...

Add support for Etags

Most successful results will contain an “etag” attribute and ETag HTTP header with a digest of the returned content. In order to save bandwidth and make your application more performant, you may optionally pass an “if-none-match” HTTP header with that digest for subsequent requests to the same URL. If the content has not changed since the last request, the response code will return with an empty body and a 304/Not Modified HTTP header and you can use a previously-stored value for the content.

Key Conflict

When I attempt to run my program, I am getting the following:

You are setting a key that conflicts with a built-in method Hashie::Mash#count defined in Enumerable

Not sure what I am doing wrong.

Expose raw response in request.rb

Allow the user to configure the client to get the raw JSON response returned by the Marvel API if desired. Additionally, a flag to exclude pagination metadata (limit, offset, count, total) would be nice. Again, instagram-ruby-gem (specifically, request.rb) seems to be a good role model for implementing this.

Doing Anything with Output

This may sound like a silly question, but for those of us who aren't as familiar with the output of an API call, what exactly are we supposed to do with the material returned? If I want to actually get something useful out of this, what do I do with the output? I see everything is returned as some "Hashie::Mash" but how do I make that usable?

Return Marvel::<Entity> objects

Instead of returning an array of Hashie::Mash objects for every successful request, return the corresponding Marvel Entity. For example, if I make a call to v1/public/characters, I should get an array of Marvel::Character objects back.

Rspec tests crashing

There appears to be a problem with either gem dependencies or just how Rspec is set up in the gem. In any case, running rake spec returns

/Users/Raevynheart/Code/marvel/lib/marvel/connection.rb:1:in `require': cannot load such file -- faraday_middleware (LoadError)

as currently set up. Troubleshooting...

Gem not loading when using Ruby 2.1.1

This just may be an issue with how I'm using RVM, but I get a LoadError when trying to require 'marvel_api':

/Users/Raevynheart/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- marvel_api (LoadError)
from /Users/Raevynheart/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from test.rb:1:in `<main>'

Investigating...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.