class Lita::Extensions::ShipToPastebin

Constants

API_KEY_DEFAULT
PASTEBIN_URL
PasteBinError

Public Instance Methods

save_to_pastebin(message, title: "Lita's Wall of Text", api_key: API_KEY_DEFAULT ) click to toggle source
# File lib/lita/extensions/ship_to_pastebin.rb, line 12
def save_to_pastebin(message, title: "Lita's Wall of Text",
                     api_key: API_KEY_DEFAULT )
  begin
    result = Faraday.post PASTEBIN_URL, {
      api_dev_key: api_key,
      api_paste_name: title,
      api_paste_code: message,
      api_paste_expire_date: '1D', # delete after a day
      api_option: 'paste'
    }
  rescue Faraday::Error => err
    raise ConnectionError, err.message
  end

  if !result.success? || result.body.include?('Bad API')
    raise PasteBinError,
      "Unable to deal with this Faraday response: [#{result.body}]"
  end

  result.body
end