class API

Public Class Methods

create_homeworld(planet) click to toggle source
# File lib/star_wars_finder/api.rb, line 23
def self.create_homeworld(planet)
    if planet.class == String
        planet.gsub!("https", "http")
        response = HTTParty.get("#{planet}")
        response["name"] = Planet.new(response)
    end
end
create_people_objects(people) click to toggle source
# File lib/star_wars_finder/api.rb, line 13
def self.create_people_objects(people)
    people.each {|hash| hash["name"] = Character.new(hash)}
end
create_species(species) click to toggle source
# File lib/star_wars_finder/api.rb, line 16
def self.create_species(species)
    if species.class == String
        species.gsub!("https", "http")
        response = HTTParty.get("#{species}")
        response["name"] = Species.new(response)
    end
end
get_characters() click to toggle source
# File lib/star_wars_finder/api.rb, line 2
def self.get_characters
    puts "\nLoading...\n\n"
    people = Array.new
    i = 1
    while i < 10 do
        response = HTTParty.get("http://swapi.co/api/people/?page=#{i}")
        response["results"].each{|obj| people << obj}
        i+=1
    end
    self.create_people_objects(people)
end