Class: HCUtil::Paster
Instance Method Summary collapse
-
#initialize(thing, options = {}) ⇒ Paster
constructor
A new instance of Paster.
- #paste ⇒ Object
Methods inherited from OpBase
Constructor Details
#initialize(thing, options = {}) ⇒ Paster
Returns a new instance of Paster.
8 9 10 11 12 13 14 |
# File 'lib/hcutil/paster.rb', line 8 def initialize(thing, = {}) super() @thing = thing @room = [:room] @ticket = [:ticket] @summary = [:summary] end |
Instance Method Details
#paste ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/hcutil/paster.rb', line 16 def paste if @thing == '-' thing_contents = $stdin.read elsif File.exists?(@thing) thing_contents = File.read(@thing) else thing_contents = @thing end if @ticket ticket_text = "ticket ##{@ticket} - " end unless ticket_text.nil_or_empty? and @summary.nil_or_empty? paste_header = "#{ticket_text}#{@summary}\n" end = <<"EOT" #{paste_header} #{thing_contents} EOT post_data = { :message_format => 'text', :color => 'purple', :message => } header_args = { :content_type => :json, :accept => :json, :authorization => "Bearer #{@auth.auth_token}" } room_esc = URI.escape(@room.to_s) uri = "https://api.hipchat.com/v2/room/#{room_esc}/notification" post_request(uri, post_data.to_json, header_args) end |