Class: ImageBam::Image

Inherits:
Object
  • Object
show all
Includes:
MIME
Defined in:
lib/image.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Image

Returns a new instance of Image.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/image.rb', line 6

def initialize(args)
  @api_key_dev      = args[:api_key_dev] 
  @api_key_user     = args[:api_key_user]
  @api_dev_secret   = args[:api_dev_secret] 
  @api_user_secret  = args[:api_user_secret]
  @salt             = args[:salt] || Digest::MD5.hexdigest(Time.now.to_i.to_s + 'splahdow!')
  @content_type     = args[:content_type] || 0
  @allow_concurrent_uploads = false
  @file_pattern     = args[:file_pattern] || /.*/
  @gallery       = args[:gallery] || nil
  
  # Handle a directory of images
  if(!args[:file_path].is_a?(Array) && File.directory?(args[:file_path]))
    @file_path = filter_images_in_dir(args[:file_path], @file_pattern)
  else
    @file_path = args[:file_path]
  end        
  
  validate_args
end

Instance Attribute Details

#allow_concurrent_uploadsObject

Returns the value of attribute allow_concurrent_uploads.



4
5
6
# File 'lib/image.rb', line 4

def allow_concurrent_uploads
  @allow_concurrent_uploads
end

#api_dev_secretObject

Returns the value of attribute api_dev_secret.



4
5
6
# File 'lib/image.rb', line 4

def api_dev_secret
  @api_dev_secret
end

#api_key_devObject

Returns the value of attribute api_key_dev.



4
5
6
# File 'lib/image.rb', line 4

def api_key_dev
  @api_key_dev
end

#api_key_userObject

Returns the value of attribute api_key_user.



4
5
6
# File 'lib/image.rb', line 4

def api_key_user
  @api_key_user
end

#api_user_secretObject

Returns the value of attribute api_user_secret.



4
5
6
# File 'lib/image.rb', line 4

def api_user_secret
  @api_user_secret
end

#content_typeObject

Returns the value of attribute content_type.



4
5
6
# File 'lib/image.rb', line 4

def content_type
  @content_type
end

#file_pathObject

Returns the value of attribute file_path.



4
5
6
# File 'lib/image.rb', line 4

def file_path
  @file_path
end

#file_patternObject

Returns the value of attribute file_pattern.



4
5
6
# File 'lib/image.rb', line 4

def file_pattern
  @file_pattern
end

#saltObject

Returns the value of attribute salt.



4
5
6
# File 'lib/image.rb', line 4

def salt
  @salt
end

Instance Method Details



40
41
42
43
44
# File 'lib/image.rb', line 40

def gallery_url
  if(@gallery)
    "http://www.imagebam.com/gallery/#{@gallery}"
  end
end

#upload!Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/image.rb', line 27

def upload!
  boundary  = '42424242424242424242424242424242424242424242424242424242'
  if(@file_path.is_a? Array)
    return upload_many(@file_path)
  else
    query     = content_headers.map {|p| '--' + boundary + "\r\n" + p}.join('') + "--" + boundary + "--\r\n"    
    puts query
    response  = Net::HTTP.start(ImageBam::POST_URL.host).post2(ImageBam::POST_URL.path, query, "Content-type" => "multipart/form-data; boundary=" + boundary)
    return ImageBam::Response.new( response.body, 'image' ).response          
  end  
end