Class: HipchatS3
- Inherits:
-
Object
- Object
- HipchatS3
- Defined in:
- lib/hipchat-s3.rb
Instance Attribute Summary collapse
-
#hipchat_client ⇒ Object
readonly
Returns the value of attribute hipchat_client.
-
#s3_bucket ⇒ Object
Returns the value of attribute s3_bucket.
Instance Method Summary collapse
- #create_compressed_upload(path, room, options = {}) ⇒ Object
- #create_file_upload(file_path, room, options = {}) ⇒ Object
- #create_inline_image(image_path, room, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ HipchatS3
constructor
A new instance of HipchatS3.
Constructor Details
#initialize(options = {}) ⇒ HipchatS3
Returns a new instance of HipchatS3.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/hipchat-s3.rb', line 9 def initialize( = {}) s3_creds = .fetch(:s3, {:access_key_id => 'your-key', :secret_access_key => 'your-secret', :bucket => 'bucket'}).symbolize_keys hipchat_creds = .fetch(:hipchat, {:api_token => 'your-token'}).symbolize_keys @s3_bucket = s3_creds.delete(:bucket) @hipchat_client = HipChat::Client.new(hipchat_creds[:api_token]) AWS::S3::Base.establish_connection!(s3_creds) end |
Instance Attribute Details
#hipchat_client ⇒ Object (readonly)
Returns the value of attribute hipchat_client.
6 7 8 |
# File 'lib/hipchat-s3.rb', line 6 def hipchat_client @hipchat_client end |
#s3_bucket ⇒ Object
Returns the value of attribute s3_bucket.
7 8 9 |
# File 'lib/hipchat-s3.rb', line 7 def s3_bucket @s3_bucket end |
Instance Method Details
#create_compressed_upload(path, room, options = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/hipchat-s3.rb', line 21 def create_compressed_upload(path, room, ={}) = {:username => 'fileuploader', :message => "File Uploaded", :color => 'yellow'}.merge() unless tar_exists? @hipchat_client[room].send(username, "You don't have tar installed on host", :notify => true, :color => color) return end file = tar_with_path(path) basename = "#{Time.now.strftime("%Y_%m_%d_%H_%M_%S")}/#{File.basename(file)}" AWS::S3::S3Object.store(basename, open(file), @s3_bucket, :access => :public_read) @hipchat_client[room].send([:username], "#{[:message]} :: <a href=\"https://s3.amazonaws.com/#{@s3_bucket}/#{basename}\">#{basename}</a>", :notify => true, :color => [:color]) end |
#create_file_upload(file_path, room, options = {}) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/hipchat-s3.rb', line 36 def create_file_upload(file_path, room, ={}) = {:username => 'fileuploader', :message => "File Uploaded", :color => 'yellow'}.merge() basename = "#{Time.now.strftime("%Y_%m_%d_%H_%M_%S")}/#{File.basename(file_path)}" AWS::S3::S3Object.store(basename, open(file_path), @s3_bucket, :access => :public_read) @hipchat_client[room].send([:username], "#{[:message]} :: <a href=\"https://s3.amazonaws.com/#{@s3_bucket}/#{basename}\">#{basename}</a>", :notify => true, :color => [:color]) end |
#create_inline_image(image_path, room, options = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/hipchat-s3.rb', line 44 def create_inline_image(image_path, room, ={}) = {:thumbnail_path => nil, :username => 'fileuploader', :message => "Image Uploaded", :color => 'yellow'}.merge() = Time.now.strftime("%Y_%m_%d_%H_%M_%S") basename = File.basename(image_path) AWS::S3::S3Object.store("#{}/#{basename}", open(image_path), @s3_bucket, :access => :public_read) uri = "https://s3.amazonaws.com/#{@s3_bucket}/#{}/#{basename}" display_uri = uri if [:thumbnail_path] thumb_basename = File.basename([:thumbnail_path]) AWS::S3::S3Object.store("#{}/#{thumb_basename}", open([:thumbnail_path]), @s3_bucket, :access => :public_read) display_uri = "https://s3.amazonaws.com/#{@s3_bucket}/#{}/#{thumb_basename}" end @hipchat_client[room].send([:username], "#{[:message]} <br> <a href=\"#{uri}\"><img src=\"#{display_uri}\" /></a>", :notify => true, :color => [:color]) end |