Last active
February 19, 2016 07:28
-
-
Save tomohiro/e2699a0f93211c165bed to your computer and use it in GitHub Desktop.
Marvel Characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- Iron Man | |
- Spider-Man | |
- Hulk | |
- Thor | |
- Captain Marvel | |
- Black Widow | |
- Captain America | |
- Black Panther | |
- Falcon | |
- Hawkeye | |
- Quicksilver | |
- Scarlet Witch | |
- Vision | |
- Wasp | |
- Hank Pym | |
- Winter Soldier | |
- Dr. Strange | |
- Angel | |
- Beast | |
- Colossus | |
- Cyclops | |
- Emma Frost | |
- Gambit | |
- Iceman | |
- Jean Grey | |
- Kitty Pryde | |
- Nightcrawler | |
- Rogue | |
- Storm | |
- Wolverine | |
- Human Torch | |
- Invisible Woman | |
- Thing | |
- Drax | |
- Gamora | |
- Groot | |
- Rocket Raccoon | |
- Star-Load | |
- Daredevil | |
- Blade |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Gem::Specification.new do |s| | |
s.name = 'marvel-characters' | |
s.version = '0.0.1' | |
s.authors = ['Tomohiro TAIRA'] | |
s.email = ['[email protected]'] | |
s.summary = 'Marvel characters' | |
s.homepage = 'https://gist.github.com/Tomohiro/' | |
s.license = 'MIT' | |
s.require_paths = ['.'] | |
s.add_runtime_dependency 'marvel_api' | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'yaml' | |
require 'singleton' | |
require 'forwardable' | |
require 'marvel_api' | |
module Marvel | |
class Characters | |
include Singleton | |
extend SingleForwardable | |
def_delegators :instance, :search, :random | |
CHARACTER_URL = 'https://gist.githubusercontent.com/Tomohiro/e2699a0f93211c165bed/raw/characters.yml' | |
def initialize | |
@client = Marvel::Client.new | |
@client.configure do |config| | |
config.api_key = ENV['MARVEL_APP_TOKEN'] | |
config.private_key = ENV['MARVEL_APP_SECRET'] | |
end | |
@characters = YAML.load(open(CHARACTER_URL)) | |
end | |
def search(name: '') | |
@client.characters(nameStartsWith: name).first | |
end | |
def random | |
search(name: @characters.sample) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment