Module: Hastebin

Defined in:
lib/hastebin.rb

Class Method Summary collapse

Class Method Details

.base_urlObject



93
94
95
# File 'lib/hastebin.rb', line 93

def self.base_url
    return $base_url
end

.base_url=(url) ⇒ Object



86
87
88
89
90
91
# File 'lib/hastebin.rb', line 86

def self.base_url=(url)
     $base_url = url
     $domain = $base_url.gsub("https://","").gsub('/','')
     puts "[INFO] ".red+"URL switched to: ".green + url + " and domain switched to: ".green + $domain
     return url
end

.code(code) ⇒ Object

Warns



111
112
113
# File 'lib/hastebin.rb', line 111

def self.code(code)
    return "[INFO] ".red+"Please use " + "write".green + " instead of " + "code".red
end

.domainObject



97
98
99
# File 'lib/hastebin.rb', line 97

def self.domain
    return $domain
end

.download(key) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/hastebin.rb', line 73

def self.download(key)
    
    https = Net::HTTP.new($domain, 443)
        
    https.use_ssl = true
        
    res = https.get("/raw/#{key}")
        
    File.open("#{key}", 'w') do |line|
        line.puts(res.body)
    end
        
end

.pingObject



101
102
103
104
105
106
107
# File 'lib/hastebin.rb', line 101

def self.ping
    t = Time.now()
    uri = URI($base_url)
    res = Net::HTTP.get(uri)
    t = (Time.now().to_f - t.to_f) * 1000
    return t.to_i
end

.readRaw(key) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/hastebin.rb', line 38

def self.readRaw(key)
    
https = Net::HTTP.new($domain, 443)

https.use_ssl = true

res = https.get("/raw/#{key}")

if res.code.to_i == 404
    puts "[INFO] ".red+"#{JSON.parse(res.body)['message']}".red
else
    puts "[INFO] ".red+"Received with success".green
    return res.body
end

end

.run(key) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/hastebin.rb', line 55

def self.run(key)

https = Net::HTTP.new($domain, 443)

https.use_ssl = true

res = https.get("/raw/#{key}")

File.open("#{key}.rb", 'w') do |line|
    line.puts(res.body)
end

    require("./#{key}")
  
require("./#{key}")
File.delete("./#{key}.rb")
end

.sendFile(path) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/hastebin.rb', line 27

def self.sendFile(path)
    
    file = File.open(path)
    data = []
    file.each do |line|
    data.push(line)
    $text = data.join("")
    end
return write($text)
end

.write(code) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/hastebin.rb', line 12

def self.write(code)
    url = URI($base_url + "documents")

    https = Net::HTTP.new(url.host, url.port);
      https.use_ssl = true

    request = Net::HTTP::Post.new(url)
      request.body = code
puts "[INFO] ".red + "Sent with success".green
$res = https.request(request)

return JSON.parse($res.read_body)['key']
end