<commit_before>#!/usr/bin/env ruby
# title:  check-dell-warranty.rb
# descr:  gets expiration dates for one or more service tags
# author: <NAME>
# date:   2016

require 'net/http'
require 'json'
require 'date'

# enter your dell api key here
@apikey = '849e027f476027a394edd656eaef4842'

# look up the service tag via dell's api
def get_expiration(svctag)
  exp_date = nil
  uri = URI("https://api.dell.com/support/v2/assetinfo/warranty/tags.json?svctags=#{svctag}&apikey=#{@apikey}")
  res = Net::HTTP.get_response(uri)
  
  if res.code != '200'
    puts "Call to Dell API for #{svctag} failed: #{res.message}"
    exit 1
  end
  
  json = JSON.parse(res.body)
  top_level = json['GetAssetWarrantyResponse']['GetAssetWarrantyResult']['Response']['DellAsset']
  description = top_level['MachineDescription']
  warranties = top_level['Warranties']['Warranty']
  
  warranties.each do |w|
    if w['EntitlementType'].downcase == 'extended' && w['ServiceLevelCode'].downcase == 'nd'
      exp_date = Date.parse(w['EndDate']).strftime("%m/%d/%Y")
      break
    # recently purchased hardware doesn't have an extended entitlement just yet  
    elsif w['EntitlementType'].downcase == 'initial' && w['ServiceLevelCode'].downcase == 'nd'
      exp_date = Date.parse(w['EndDate']).strftime("%m/%d/%Y")
      break
    else
      next
    end
  end

  if ! exp_date.nil?
    return "#{exp_date} -- #{description}"
  else
    return "Unable to determine expiration date"
  end
end

# make sure that something is being passed in
if ARGV.empty?
  puts "usage: $ ./check-dell-warranty.rb <service tag 1> [service tag N] ..."
  exit 1
end

# run through each service tag passed in
ARGV.each do |svctag|
  puts "#{svctag}: #{get_expiration(svctag)}"
end<commit_msg>Rewrite using new API<commit_after>#!/usr/bin/env ruby
# title:  check-dell-warranty.rb
# descr:  gets expiration dates for one or more service tags
# author: <NAME>
# date:   2016

require 'net/http'
require 'json'
require 'date'

# enter your dell api key here
@apikey = ''

# look up the service tag via dell's api
def get_expiration(svctag)
  exp_date = nil
  uri = URI("https://sandbox.api.dell.com/support/assetinfo/v4/getassetwarranty/#{svctag}?apikey=#{@apikey}")
  res = Net::HTTP.get_response(uri)
  
  if res.code != '200'
    puts "Call to Dell API for #{svctag} failed: #{res.message}"
    exit 1
  end
  
  json = JSON.parse(res.body)
  description = json['AssetWarrantyResponse'][0]['AssetHeaderData']['MachineDescription']
  json['AssetWarrantyResponse'][0]['AssetEntitlementData'].each do |w|
    if w['EntitlementType'].downcase == 'extended' && ( w['ServiceLevelCode'].downcase == 'nd' || w['ServiceLevelCode'].downcase == 'np' )
      exp_date = Date.parse(w['EndDate']).strftime("%m/%d/%Y")
      break
    # recently purchased hardware doesn't have an extended entitlement just yet  
    elsif w['EntitlementType'].downcase == 'initial' && ( w['ServiceLevelCode'].downcase == 'nd' || w['ServiceLevelCode'].downcase == 'np' )
      exp_date = Date.parse(w['EndDate']).strftime("%m/%d/%Y")
      break
    else
      next
    end
  end

  if ! exp_date.nil?
    return "#{exp_date} -- #{description}"
  else
    return "Unable to determine expiration date"
  end
end
  
# make sure that something is being passed in
if ARGV.empty?
  puts "usage: $ ./check-dell-warranty.rb <service tag 1> [service tag N] ..."
  exit 1
end

# run through each service tag passed in
ARGV.each do |svctag|
  puts "#{svctag}: #{get_expiration(svctag)}"
end
{'fraction_non_alphanumeric': 0.14880273660205245, 'fraction_numerical': 0.013112884834663626, 'mean_word_length': 3.9353023909985936, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5965430', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1207, 'n_words': 309}