Class: QuickMug::Upload

Inherits:
Object
  • Object
show all
Defined in:
lib/quickmug/upload.rb

Class Method Summary collapse

Class Method Details

.process(args) ⇒ Object

Raises:

  • (ArgumentError)


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/quickmug/upload.rb', line 3

def self.process(args)
  raise ArgumentError.new('You must specify an image') if args.empty?
  image = File.expand_path(args[0])
  caption = args[1..-1].join(' ')

  raise ArgumentError.new('The specified file does not exist') unless File.exists?(image)
  raise ArgumentError.new('You must specify album in ~/.quickmug') unless QuickMug.config['album']

  data = {:AlbumID => QuickMug.config['album']}

  if caption.length > 0
    data[:Caption] = caption
  end

  File.open(image, "rb") do |f|
    # Upload file to the album
    data = QuickMug.client.upload_media(data.merge(:file => f))
  end

  Image.fromApi(data)
end