Gotta Code ’Em All!

within lies salvation
Pokémon TCG API by Andrew Backes

HTTParty On, Dudes!

def self.get_pokemon_data            #pulls data hash from URL
response = HTTParty.get(cards_url)
#converts JSON data into nested array that we'll call 'response'
data = response["cards"]
data.each do |pokemon_data| #assigns each array to new
PokemonClass.new(pokemon_data) #instance within the class Pokemon
end
end

Pry, Baby, Pry

self.name = pokemon_data["name"]
#=> "Snorlax"
self.pokedex_no = pokemon_data["nationalPokedexNumber"]
#l=> "403"
self.hp = pokemon_data["hp"]
#=> "120"
{"cards": [
{"attacks": [
{"cost": [
"Colorless"
],
"name": "Intelligence Gathering",
"text": "Draw cards until you have 6 cards in your hand.",
"damage": "10",
"convertedEnergyCost": 1 },
{"cost": ["Colorless",
"Colorless"],
"name": "Bee Revenge",
"text": "This attack does 10 more damage for each Pokémon in your discard pile.",
"damage": "20+",
"convertedEnergyCost": 2}

Let’s Hash It Out

class PokemonClass
def initialize(pokemon_data)
self.attacks = pokemon_data["attacks"]
end
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class Cli
def pokemon_attacks
if d.attacks == nil
puts "Attacks:".white + " There are no Attacks for this card.".green
else
@attack_array = []
d.attacks.each do |x|
@attack_array << x["name"]
end
puts "Attacks: #{@attack_array.join(", ").light_green}"
end
end
#=> "Attacks: Upstream, Tail Slap"

Takeaways

--

--

--

Current Software Engineer student at Flatiron School, 11 year Math Teacher, 20 year thespian.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Understanding Kotlin — Part 3

Implementing Drag & Drop in Flutter Web

The journey of creating a dapp on the Internet Computer

Picgram: Team Project with Flatiron Alums — Week 1

Software Hacking: Creation or Attack

Splash Image with title and Ellie the Elephant coding in the dark

Excited to learn Java!

Serum Newsletter #28

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ryan Bollettino

Ryan Bollettino

Current Software Engineer student at Flatiron School, 11 year Math Teacher, 20 year thespian.

More from Medium

CS373 Spring 2022: Christopher Carrasco — Week 9

20 Resources That’ll Make You Better at Passover Hotel

6 powerful psychological triggers designed to boost user activation

6 powerful psychological triggers designed to boost user activation

HippoInu is not just a meme token.