Class: Pastebin

Inherits:
Object
  • Object
show all
Defined in:
lib/pastebin.rb,
lib/pastebin/version.rb

Constant Summary collapse

BASE_URL =
"https://pastebin.com"
DEVKEY =
"01fe34146583c731f3725fd8dde3992c"
VERSION =
"2.1.0"

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Pastebin

The only option required is ‘paste_code’, which holds your string.



11
12
13
14
# File 'lib/pastebin.rb', line 11

def initialize(options)
    @options = options
    @options["api_dev_key"] = DEVKEY
end

Instance Method Details

#get_raw(link) ⇒ Object

This method takes a link from a previous paste and returns the raw text.

pbin.get_raw("https://pastebin.com/xxxxxxx")    #=> "some text"


42
43
44
# File 'lib/pastebin.rb', line 42

def get_raw(link)
    Net::HTTP.get_response(URI.parse("#{BASE_URL}/raw/#{link[/[\w\d]+$/]}")).body
end

#pasteObject

This POSTs the paste and returns the link

pbin.paste    #=> "https://pastebin.com/xxxxxxx"


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/pastebin.rb', line 20

def paste
    if @options.has_key?("api_paste_code")
        if @options["api_paste_code"] == "-"
            @options["api_paste_code"] = $stdin.read
        else
            File.open(@options["api_paste_code"]) do |file|
                @options["api_paste_code"] = file.read
            end
        end
        #else
        #    puts "You must specify a file or '-' for STDIN"
        #    exit
    end
    @options["api_option"] = "paste"
    Net::HTTP.post_form(URI.parse("#{BASE_URL}/api/api_post.php"), @options).body
end