Class: ImageBam::Image
Instance Attribute Summary collapse
-
#allow_concurrent_uploads ⇒ Object
Returns the value of attribute allow_concurrent_uploads.
-
#api_dev_secret ⇒ Object
Returns the value of attribute api_dev_secret.
-
#api_key_dev ⇒ Object
Returns the value of attribute api_key_dev.
-
#api_key_user ⇒ Object
Returns the value of attribute api_key_user.
-
#api_user_secret ⇒ Object
Returns the value of attribute api_user_secret.
-
#content_type ⇒ Object
Returns the value of attribute content_type.
-
#file_path ⇒ Object
Returns the value of attribute file_path.
-
#file_pattern ⇒ Object
Returns the value of attribute file_pattern.
-
#salt ⇒ Object
Returns the value of attribute salt.
Instance Method Summary collapse
- #gallery_url ⇒ Object
-
#initialize(args) ⇒ Image
constructor
A new instance of Image.
- #upload! ⇒ Object
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_uploads ⇒ Object
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_secret ⇒ Object
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_dev ⇒ Object
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_user ⇒ Object
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_secret ⇒ Object
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_type ⇒ Object
Returns the value of attribute content_type.
4 5 6 |
# File 'lib/image.rb', line 4 def content_type @content_type end |
#file_path ⇒ Object
Returns the value of attribute file_path.
4 5 6 |
# File 'lib/image.rb', line 4 def file_path @file_path end |
#file_pattern ⇒ Object
Returns the value of attribute file_pattern.
4 5 6 |
# File 'lib/image.rb', line 4 def file_pattern @file_pattern end |
#salt ⇒ Object
Returns the value of attribute salt.
4 5 6 |
# File 'lib/image.rb', line 4 def salt @salt end |
Instance Method Details
#gallery_url ⇒ Object
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 |