Skip to content

Instantly share code, notes, and snippets.

@tomohiro
Last active February 19, 2016 07:28
Show Gist options
  • Save tomohiro/e2699a0f93211c165bed to your computer and use it in GitHub Desktop.
Save tomohiro/e2699a0f93211c165bed to your computer and use it in GitHub Desktop.
Marvel 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
Gem::Specification.new do |s|
s.name = 'marvel-characters'
s.version = '0.0.1'
s.authors = ['Tomohiro TAIRA']
s.email = ['tomohiro.t@gmail.com']
s.summary = 'Marvel characters'
s.homepage = 'https://gist.github.com/Tomohiro/'
s.license = 'MIT'
s.require_paths = ['.']
s.add_runtime_dependency 'marvel_api'
end
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