hipchat-s3 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Justin
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,55 @@
1
+ h1. Hipchat S3
2
+
3
+ A way to send file uploads to your hipchat channel using s3
4
+
5
+ Uses the "hipchat gem":https://github.com/mojotech/hipchat and the "aws-s3":https://github.com/marcel/aws-s3
6
+
7
+ h2. Usage
8
+
9
+ bc.. hipchat_s3 = HipchatS3.new({:s3 => {:access_key_id => 'your-key', :secret_access_key => 'your-secret', :bucket => 'bucket'}, :hipchat => {:api_token => 'your-token'}})
10
+ hipchat_s3.s3_bucket = "another_bucket" # you can change your bucket name whenever you need
11
+
12
+ # displays thumbnail in chat that links to full size image
13
+ hipchat_s3.create_inline_image('image_path.jpg', hipchat_room_id, {:thumbnail_path => "thumb_path.jpg", :username => "Magic", :message => "message", :color => "green"})
14
+
15
+ # displays full size image, no thumbnail, directly in the chat
16
+ hipchat_s3.create_inline_image('image_path.jpg', hipchat_room_id)
17
+
18
+ # compresses a directory or file and uploads a tar.gz, linked to the room
19
+ hipchat_s3.create_compressed_upload(path_to_compress, hipchat_room_id, {:message => "Files Compressed", :color => "green"})
20
+
21
+ # uploads an uncompressed file to s3, displays link in chat
22
+ hipchat_s3.create_file_upload(file_path, hipchat_room_id, {:username => "FileManager"})
23
+
24
+ # you can also access the chat object directly
25
+ hipchat_s3.hipchat_client[hipchat_room_id].send("Enforcer", "Failure! You can't do that!!!", :notify => true, :color => "red")
26
+
27
+ h2. Methods
28
+
29
+ bc.. create_compressed_upload(path, room, options={})
30
+ create_file_upload(file_path, room, options={})
31
+ create_inline_image(image_path, room, options={})
32
+
33
+ # Default options
34
+ {:username => 'fileuploader', :message => "File Uploaded", :color => 'yellow'}
35
+
36
+ # Default options for create_inline_image
37
+ {:thumbnail_path => nil, :username => 'fileuploader', :message => "Image Uploaded", :color => 'yellow'}
38
+
39
+ h2. Rspec hook
40
+
41
+ bc.. config.after(:each) do
42
+ if example.exception
43
+
44
+ message = "#{example.full_description} <br/> #{example.location}"
45
+ hipchat_s3 ||= HipchatS3.new(HIPCHAT_S3)
46
+
47
+ if example.metadata[:type] == :acceptance && example.metadata[:js] == true
48
+ page.driver.browser.save_screenshot("failure.jpg")
49
+ hipchat_s3.create_inline_image("failure.jpg", hipchat_id, {:message => message, :username => "Failmaster", :color => "red"})
50
+ else
51
+ hipchat_s3.hipchat_client[hipchat_id].send("Enforcer", "Failure! YOU BROKE THE BUILD <br/> #{message}", :notify => true, :color => "red")
52
+ end
53
+
54
+ end
55
+ end
data/Rakefile ADDED
@@ -0,0 +1,33 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "hipchat-s3"
8
+ gem.summary = %Q{Ruby library to upload files to s3 and alert users in hipchat with a link}
9
+ gem.description = %Q{Ruby library to upload files to s3 and alert users in hipchat with a link}
10
+ gem.email = "jd@stinware.com"
11
+ gem.homepage = "http://github.com/jstin/hipchat-s3"
12
+ gem.authors = ["Justin"]
13
+ gem.add_dependency "hipchat"
14
+ gem.add_dependency "aws-s3"
15
+ gem.add_development_dependency "rspec", "~> 2.0"
16
+ gem.add_development_dependency "rr", "~> 1.0"
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
+ end
22
+
23
+ task :default => :spec
24
+
25
+ require 'rake/rdoctask'
26
+ Rake::RDocTask.new do |rdoc|
27
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
28
+
29
+ rdoc.rdoc_dir = 'rdoc'
30
+ rdoc.title = "hipchat-s3 #{version}"
31
+ rdoc.rdoc_files.include('README*')
32
+ rdoc.rdoc_files.include('lib/**/*.rb')
33
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,54 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "hipchat-s3"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Justin"]
12
+ s.date = "2012-05-04"
13
+ s.description = "Ruby library to upload files to s3 and alert users in hipchat with a link"
14
+ s.email = "jd@stinware.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.textile"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "LICENSE",
22
+ "README.textile",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "hipchat-s3.gemspec",
26
+ "lib/hipchat-s3.rb"
27
+ ]
28
+ s.homepage = "http://github.com/jstin/hipchat-s3"
29
+ s.require_paths = ["lib"]
30
+ s.rubygems_version = "1.8.15"
31
+ s.summary = "Ruby library to upload files to s3 and alert users in hipchat with a link"
32
+
33
+ if s.respond_to? :specification_version then
34
+ s.specification_version = 3
35
+
36
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
37
+ s.add_runtime_dependency(%q<hipchat>, [">= 0"])
38
+ s.add_runtime_dependency(%q<aws-s3>, [">= 0"])
39
+ s.add_development_dependency(%q<rspec>, ["~> 2.0"])
40
+ s.add_development_dependency(%q<rr>, ["~> 1.0"])
41
+ else
42
+ s.add_dependency(%q<hipchat>, [">= 0"])
43
+ s.add_dependency(%q<aws-s3>, [">= 0"])
44
+ s.add_dependency(%q<rspec>, ["~> 2.0"])
45
+ s.add_dependency(%q<rr>, ["~> 1.0"])
46
+ end
47
+ else
48
+ s.add_dependency(%q<hipchat>, [">= 0"])
49
+ s.add_dependency(%q<aws-s3>, [">= 0"])
50
+ s.add_dependency(%q<rspec>, ["~> 2.0"])
51
+ s.add_dependency(%q<rr>, ["~> 1.0"])
52
+ end
53
+ end
54
+
data/lib/hipchat-s3.rb ADDED
@@ -0,0 +1,78 @@
1
+ require 'hipchat'
2
+ require 'aws/s3'
3
+
4
+ class HipchatS3
5
+
6
+ attr_reader :hipchat_client
7
+ attr_accessor :s3_bucket
8
+
9
+ def initialize(options = {})
10
+
11
+ s3_creds = options.fetch(:s3, {:access_key_id => 'your-key', :secret_access_key => 'your-secret', :bucket => 'bucket'}).symbolize_keys
12
+ hipchat_creds = options.fetch(:hipchat, {:api_token => 'your-token'}).symbolize_keys
13
+
14
+ @s3_bucket = s3_creds.delete(:bucket)
15
+
16
+ @hipchat_client = HipChat::Client.new(hipchat_creds[:api_token])
17
+ AWS::S3::Base.establish_connection!(s3_creds)
18
+
19
+ end
20
+
21
+ def create_compressed_upload(path, room, options={})
22
+ options = {:username => 'fileuploader', :message => "File Uploaded", :color => 'yellow'}.merge(options)
23
+
24
+ unless tar_exists?
25
+ @hipchat_client[room].send(username, "You don't have tar installed on host", :notify => true, :color => color)
26
+ return
27
+ end
28
+
29
+ file = tar_with_path(path)
30
+ basename = "#{Time.now.strftime("%Y_%m_%d_%H_%M_%S")}/#{File.basename(file)}"
31
+
32
+ AWS::S3::S3Object.store(basename, open(file), @s3_bucket, :access => :public_read)
33
+ @hipchat_client[room].send(options[:username], "#{options[:message]} :: <a href=\"https://s3.amazonaws.com/#{@s3_bucket}/#{basename}\">#{basename}</a>", :notify => true, :color => options[:color])
34
+ end
35
+
36
+ def create_file_upload(file_path, room, options={})
37
+ options = {:username => 'fileuploader', :message => "File Uploaded", :color => 'yellow'}.merge(options)
38
+ basename = "#{Time.now.strftime("%Y_%m_%d_%H_%M_%S")}/#{File.basename(file_path)}"
39
+
40
+ AWS::S3::S3Object.store(basename, open(file_path), @s3_bucket, :access => :public_read)
41
+ @hipchat_client[room].send(options[:username], "#{options[:message]} :: <a href=\"https://s3.amazonaws.com/#{@s3_bucket}/#{basename}\">#{basename}</a>", :notify => true, :color => options[:color])
42
+ end
43
+
44
+ def create_inline_image(image_path, room, options={})
45
+ options = {:thumbnail_path => nil, :username => 'fileuploader', :message => "Image Uploaded", :color => 'yellow'}.merge(options)
46
+
47
+ timestamp = Time.now.strftime("%Y_%m_%d_%H_%M_%S")
48
+ basename = File.basename(image_path)
49
+
50
+ AWS::S3::S3Object.store("#{timestamp}/#{basename}", open(image_path), @s3_bucket, :access => :public_read)
51
+
52
+ uri = "https://s3.amazonaws.com/#{@s3_bucket}/#{timestamp}/#{basename}"
53
+ display_uri = uri
54
+
55
+ if options[:thumbnail_path]
56
+ thumb_basename = File.basename(options[:thumbnail_path])
57
+ AWS::S3::S3Object.store("#{timestamp}/#{thumb_basename}", open(options[:thumbnail_path]), @s3_bucket, :access => :public_read)
58
+ display_uri = "https://s3.amazonaws.com/#{@s3_bucket}/#{timestamp}/#{thumb_basename}"
59
+ end
60
+
61
+ @hipchat_client[room].send(options[:username], "#{options[:message]} <br/> <a href=\"#{uri}\"><img src=\"#{display_uri}\" /></a>", :notify => true, :color => options[:color])
62
+ end
63
+
64
+
65
+ private
66
+
67
+ def tar_exists?
68
+ `which tar`.strip != ""
69
+ end
70
+
71
+ def tar_with_path(path)
72
+ cmd_path = `which tar`.strip
73
+ tarred_path = "#{path}.tar.gz"
74
+ `#{cmd_path} czf #{tarred_path} #{path}`
75
+ tarred_path
76
+ end
77
+
78
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hipchat-s3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Justin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: hipchat
16
+ requirement: &70277358834080 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70277358834080
25
+ - !ruby/object:Gem::Dependency
26
+ name: aws-s3
27
+ requirement: &70277358832700 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70277358832700
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70277358848120 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '2.0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70277358848120
47
+ - !ruby/object:Gem::Dependency
48
+ name: rr
49
+ requirement: &70277358846940 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70277358846940
58
+ description: Ruby library to upload files to s3 and alert users in hipchat with a
59
+ link
60
+ email: jd@stinware.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files:
64
+ - LICENSE
65
+ - README.textile
66
+ files:
67
+ - .document
68
+ - LICENSE
69
+ - README.textile
70
+ - Rakefile
71
+ - VERSION
72
+ - hipchat-s3.gemspec
73
+ - lib/hipchat-s3.rb
74
+ homepage: http://github.com/jstin/hipchat-s3
75
+ licenses: []
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 1.8.15
95
+ signing_key:
96
+ specification_version: 3
97
+ summary: Ruby library to upload files to s3 and alert users in hipchat with a link
98
+ test_files: []