Class: Pastebinrb::Pastebin

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

Constant Summary collapse

BASE_URL =
"https://pastebin.com"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(devkey) ⇒ Pastebin

Returns a new instance of Pastebin.



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

def initialize( devkey )
  @devkey = devkey
end

Instance Attribute Details

#devkeyObject (readonly)

Returns the value of attribute devkey.



9
10
11
# File 'lib/pastebinrb.rb', line 9

def devkey
  @devkey
end

Instance Method Details

#get_raw(link) ⇒ Object



27
28
29
# File 'lib/pastebinrb.rb', line 27

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

#paste_content(content, **options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pastebinrb.rb', line 15

def paste_content( content, **options )
  params = {
    :api_dev_key => @devkey,
    :api_option => "paste",
    :api_paste_name => options[:title],
    :api_paste_format => options[:format],
    :api_paste_expire_date => options[:expire_delay],
    :api_paste_code => content
  }
  Net::HTTP.post_form(URI.parse("#{BASE_URL}/api/api_post.php"), params).body
end