22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/pastiepacker/upload.rb', line 22
def paste(body, format='ruby', is_private=false)
raise InvalidParser unless valid_parser?(format)
http = Net::HTTP.new(PASTIE_URI)
query_string = { :paste => {
:body => CGI.escape(body),
:parser => CGI.escape(format),
:restricted => is_private,
:authorization => 'burger'
}}.to_query_string
resp, body = http.start { |http|
http.post('/pastes', query_string)
}
if resp.code == '302'
return resp['location']
else
raise Error, "#{resp.code} - #{query_string.inspect} - #{resp.inspect}"
end
end
|