dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README

dashedit.rb (3050B)


      1 #!/usr/bin/env ruby
      2 require 'json'
      3 require 'rest-client'
      4 
      5 class DashSubmit
      6     attr_accessor :deliverable_id
      7 
      8     def initialize deliverable_id
      9         @deliverable_id = deliverable_id
     10         @base_uri = "https://submit.dashnet.tech"
     11         @bearer_code = ENV['DASHNET_CODE']
     12         @user = ENV['DASHNET_USER']
     13         @headers = {
     14             "Accept": "application/json, text/plain, */*",
     15             "Authorization": @bearer_code,
     16             "Origin": "https://dashnet.tech"
     17         }
     18     end
     19 
     20     def get_status
     21         puts "#{@base_uri}/user/#{@user}/submissions"
     22         response = RestClient.get(
     23             "#{@base_uri}/user/#{@user}/submissions",
     24             @headers
     25         )
     26         response = JSON.parse(response)
     27 
     28         if response["success"]
     29             data = response["data"][0]
     30             puts "Waiting..."
     31             while data['test_status'] == "waiting"
     32                 response = RestClient.get(
     33                     "#{@base_uri}/user/#{@user}/submissions",
     34                     @headers
     35                 )
     36                 response = JSON.parse(response)
     37                 data = response["data"][0]
     38             end
     39             puts "Filename: #{data["filename"]}"
     40             puts "Attempt: #{data['attempt']}"
     41             puts "Result: #{data["test_status"]}"
     42             puts "Output:"
     43             puts data["test_output"]
     44         else
     45             puts "Request fucked up."
     46         end
     47     end
     48     def submit path
     49         extra_headers = {
     50             "Content-Type": "multipart/form-data; boundary=---011000010111000001101001",
     51         }
     52         request = RestClient::Request.new(
     53             method: :post,
     54             url: "#{@base_uri}/deliverables/#{@deliverable_id}",
     55             headers: @headers.merge(extra_headers),
     56             payload: {
     57                 multipart: true,
     58                 file: File.new(path, "rb")
     59             })
     60         response = JSON.parse(request.execute)
     61 
     62         if response["success"]
     63             data = response["data"]
     64             puts "Submitted successfully!"
     65             puts "File: #{path}"
     66             puts "Filename: #{data["filename"]}"
     67             puts "Checksum: #{data["checksum"]}"
     68         end
     69     end
     70 end
     71 
     72 if ENV['DASHNET_CODE'].nil?
     73     puts "Please set the $DASHNET_CODE environment variable in your profile."
     74     puts "You can find this using the Web Inspector in your browser. Record the XHR request, find the 'authorization' field, and copy the string starting with 'Bearer'."
     75 elsif ENV['DASHNET_USER'].nil?
     76     puts "Please set the $DASHNET_USER environment variable in your profile to your DashNet username (VUnet ID)."
     77 else
     78     deliverable_id = "13356ed0-e21d-42a2-804d-301102b5b40b"
     79     submitter = DashSubmit.new(deliverable_id)
     80     if ARGV[0] == "status"
     81         submitter.get_status
     82     elsif ARGV[0] == "submit"
     83         if !ARGV[1].nil?
     84             submitter.submit ARGV[1]
     85         else
     86             puts "Please provide a path."
     87         end
     88     else
     89         puts "Usage:"
     90         puts "  dashedit submit $path"
     91         puts "  dashedit status"
     92     end
     93 end
     94