class MakersToolbelt::RandomizeBytes

Constants

RANDOMIZE_BYTES_PATH

Attributes

client[R]
interface[R]

Public Class Methods

new(client: nil, interface: nil) click to toggle source
# File lib/makers_toolbelt/randomize_bytes.rb, line 14
def initialize(client: nil, interface: nil)
  @interface = interface || CommandLine::Interface
  @client = client || HubClient.new
end

Public Instance Methods

run() click to toggle source
# File lib/makers_toolbelt/randomize_bytes.rb, line 19
def run
  @options = interface.ask_questions(:randomize_bytes)
  response = client.post(**options) 
  output(response)
end

Private Instance Methods

options() click to toggle source
# File lib/makers_toolbelt/randomize_bytes.rb, line 50
def options
  {
    path: RANDOMIZE_BYTES_PATH.call(@options[:cohort_id]),
    params: {number_of_bytes: @options[:number_of_bytes]},
    base_uri: @options[:base_uri]
  }
end
output(response) click to toggle source
# File lib/makers_toolbelt/randomize_bytes.rb, line 27
def output(response)
  return successful_output(response) if response.success?
  unsuccessful_output(response)
end
prettify(bytes) click to toggle source
# File lib/makers_toolbelt/randomize_bytes.rb, line 38
def prettify(bytes)
  bytes.each_with_index.inject("") do |aggregate, (byte, byte_number)| 
    string = "#{aggregate}Byte #{byte_number}\n======\n\n"
    byte.each{|student| string << "#{student["name"]}\n"}
    string << "\n"
  end 
end
successful_output(response) click to toggle source
# File lib/makers_toolbelt/randomize_bytes.rb, line 32
def successful_output(response)
  bytes = JSON.parse(response.body)
  output = prettify(bytes)
  print output
end
unsuccessful_output(response) click to toggle source
# File lib/makers_toolbelt/randomize_bytes.rb, line 46
def unsuccessful_output(response)
  print "\n#{response.code_type} #{response.code} #{response.msg}\n"
end