-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstarships-pilots.rb
executable file
·73 lines (62 loc) · 2.11 KB
/
starships-pilots.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env ruby
# Tested with Ruby 1.9.3
# Load Bundler for Gem Files
require 'bundler/setup'
Bundler.require(:default)
puts '======================================'
puts ' _____ _ _ ___ ______ _____'
puts '/ ___|| | | | / _ \ | ___ \_ _|'
puts '\ `--. | | | | / /_\ \| |_/ / | |'
puts ' `--. \| |/\| | | _ || __/ | |'
puts '/\__/ /\ /\ / | | | || | _| |_'
puts '\____/ \/ \/ \_| |_/\_| \___/'
puts "Starhips-Pilots"
puts '======================================'
puts "Starting"
# ----------------------------------------------
# Get List of StarShips
starships = Array.new
page = JSON.parse(RestClient.get 'http://swapi.co/api/starships/')
starships.concat page['results']
puts "Processing Starships, Count: #{page['count']}"
while page['next']
#puts "Pagination: Starting Next(#{page['next']})"
nextpage = JSON.parse(RestClient.get page['next'])
starships.concat nextpage['results']
page = nextpage
#puts page['next']
end
# ----------------------------------------------
# Get List of People
people = Hash.new
page = JSON.parse(RestClient.get 'http://swapi.co/api/people/')
page['results'].each {|p| people[p['url']] = p}
puts "Processing Pilots, Count: #{page['count']}"
while page['next']
#puts "Pagination: Starting Next(#{page['next']})"
nextpage = JSON.parse(RestClient.get page['next'])
page = nextpage
page['results'].each {|p| people[p['url']] = p}
#puts page['next']
end
# ----------------------------------------------
# Render List
starships.each do |starship|
puts "Name: #{starship['name']}"
# Skip Repetitive
puts "Model: #{starship['model']}" unless starship['model'] == starship['name']
puts "Class: #{starship['starship_class'].capitalize}"
puts "Manufacturer: #{starship['manufacturer']}"
puts "Crew: #{starship['crew']}"
puts "Maximum Atmospheric Speed: #{starship['max_atmosphering_speed']}"
puts "Cargo: #{starship['cargo_capacity']}"
if starship['pilots'].count == 0
puts "Pilots: Unknown"
else
puts "Pilots:"
starship['pilots'].each do |pilot|
puts " " + people[pilot]['name']
end
end
puts "------------------------------"
end