Class: Pastie

Inherits:
Object
  • Object
show all
Defined in:
lib/pastie.rb

Overview

:nodoc: all

Constant Summary collapse

PASTE_URL =
ENV['SAKE_PASTIE_URL'] || ENV['PASTIE_URL'] || 'http://pastie.caboo.se/pastes/create'

Class Method Summary collapse

Class Method Details

.paste(text) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pastie.rb', line 6

def self.paste(text)
  text_file = Tempfile.open('w+')
  text_file << text
  text_file.flush

  cmd = <<-EOS
  curl #{PASTE_URL} \
  -s -L -o /dev/null -w "%{url_effective}" \
  -H "Expect:" \
  -F "paste[parser]=ruby" \
  -F "paste[restricted]=0" \
  -F "paste[authorization]=burger" \
  -F "paste[body]=<#{text_file.path}" \
  -F "key=" \
  -F "x=27" \
  -F "y=27"
  EOS
  
  out = %x{
    #{cmd}
  }

  text_file.close(true)
  out
end