Class: Pastebin
- Inherits:
-
Object
- Object
- Pastebin
- 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
-
#get_raw(link) ⇒ Object
This method takes a link from a previous paste and returns the raw text.
-
#initialize(options) ⇒ Pastebin
constructor
The only option required is ‘paste_code’, which holds your string.
-
#paste ⇒ Object
This POSTs the paste and returns the link.
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() = ["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 |
#paste ⇒ Object
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 .has_key?("api_paste_code") if ["api_paste_code"] == "-" ["api_paste_code"] = $stdin.read else File.open(["api_paste_code"]) do |file| ["api_paste_code"] = file.read end end #else # puts "You must specify a file or '-' for STDIN" # exit end ["api_option"] = "paste" Net::HTTP.post_form(URI.parse("#{BASE_URL}/api/api_post.php"), ).body end |