Class: Lita::Extensions::ShipToPastebin

Inherits:
Object
  • Object
show all
Defined in:
lib/lita/extensions/ship_to_pastebin.rb

Constant Summary collapse

API_KEY_DEFAULT =
'd88582e90ba06b60569dc55ab5b678ce'
PASTEBIN_URL =
'https://pastebin.com/api/api_post.php'.freeze
PasteBinError =
Class.new(StandardError)

Instance Method Summary collapse

Instance Method Details

#save_to_pastebin(message, title: "Lita's Wall of Text", api_key: API_KEY_DEFAULT) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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