module Utils

Public Class Methods

artist_products_menu(products) click to toggle source
# File lib/ap_api_tools/utils.rb, line 15
def self.artist_products_menu(products)
  line_items=[]
  products.each do |product|
    obj_p=Product.new(product)
    if obj_p.has_images
      obj_p.images.each do |img|
        line_items << { id: product[:id], name: product[:name], num_img: product[:master][:images].count, image_id: img[:id], file_name: img[:attachment_file_name] }
      end
    else
      line_items << { id: product[:id], name: product[:name ], num_img: product[:master][:images].count, image_id: '', file_name: 'NO ARTWORK' }
    end
  end
  line_items
end
clear() click to toggle source
# File lib/ap_api_tools/utils.rb, line 11
def self.clear
  system('clear') || system('cls')
end
download(url, dir=nil) click to toggle source
# File lib/ap_api_tools/utils.rb, line 30
def self.download(url, dir=nil)
  if dir.nil? || dir == ''
    dir = File.join(Dir.home,"Downloads")
  end

  file=File.basename(url)
  File.open(File.join(dir,file), "w") do |f|
    f.write(HTTP.get(url).body)
  f.close
  end
end
internet?() click to toggle source
# File lib/ap_api_tools/utils.rb, line 3
def self.internet?
  begin
    true if open("http://www.google.com/")
  rescue
    false
  end
end