Skip to content

Instantly share code, notes, and snippets.

@mchail
Created April 20, 2020 17:42
Show Gist options
  • Save mchail/ddb0b9addb52135a870875c277502607 to your computer and use it in GitHub Desktop.
Save mchail/ddb0b9addb52135a870875c277502607 to your computer and use it in GitHub Desktop.
require 'json'
Disc = Struct.new(
:plastic,
:weight,
:color,
:quantity,
)
WIDTH = 16
REKO_MODEL_ID = '16569'
curl = %{
curl --silent 'https://infinitediscs.com/Default.aspx/fnLoadPlasticInventory' \
-H 'content-type: application/json; charset=UTF-8' \
--data-binary '{"model_id":"#{REKO_MODEL_ID}","plastic_id":"","sort":"Weight Low-High"}' \
}.strip
response = %x[#{curl}]
response = JSON.parse(JSON.parse(response)['d'])
discs = response['inventory'].map do |item|
Disc.new(
item['E_PlasticName'],
item['E_Weight'].to_i,
item['E_Color'],
item['E_Available'].to_i,
)
end
discs = discs.sort do |disc, other|
[
-(disc.plastic <=> other.plastic),
-(disc.weight <=> other.weight),
-(disc.quantity <=> other.quantity),
(disc.color <=> other.color),
].find do |key|
key != 0
end || 0
end
header = Disc.members.map do |column|
column.to_s.upcase.center(WIDTH)
end.join('|')
puts header
puts '-' * header.size
discs.each do |disc|
disc_row = disc.values.map do |value|
value.to_s.center(WIDTH)
end.join('|')
puts disc_row
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment