Module: Utils

Defined in:
lib/ap_api_tools/utils.rb

Class Method Summary collapse

Class Method Details

.artist_products_menu(products) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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

.clearObject



11
12
13
# File 'lib/ap_api_tools/utils.rb', line 11

def self.clear
  system('clear') || system('cls')
end

.download(url, dir = nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# 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?Boolean

Returns:

  • (Boolean)


3
4
5
6
7
8
9
# File 'lib/ap_api_tools/utils.rb', line 3

def self.internet?
  begin
    true if open("http://www.google.com/")
  rescue
    false
  end
end