hastebin 0.1.0 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/hastebin +92 -0
  3. data/lib/hastebin.rb +92 -13
  4. metadata +19 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6ccfcceb6e6f58bf8f5af578d63fd59eeeddb9ab18d9bbcb84e2a91a0ce6fad
4
- data.tar.gz: 22b0489f0d97ec7d814c6ae9ebcbd0fa52800db478d0e1863405246ea4a9c287
3
+ metadata.gz: bda8eb25466d5c906ed5a6b45e6d233e01b589a1b64249520a9497a2249b963f
4
+ data.tar.gz: 76273ab537ea43a023712c657364a5c95087c082e2eaa856f23b384f6a37b7d8
5
5
  SHA512:
6
- metadata.gz: cee253010c6640eea8faa03cbd95ccbc084c7df584ceec948fca146a3911d4415285a026e0f53d2287df709a7b09bd9cfd226181bdb52ad225c254094240bd0d
7
- data.tar.gz: 7d4723a10b92b13c435068fe0ced66620c1bd48675144fa153cf22a2c720ff80620725a836226455eb120b423f74a0884f9a20cc4a647b7fc186aaa6c7fc9bb2
6
+ metadata.gz: b1791073d1df4ad1bcc8cf4bef4cf5705a26654acaf2a825e34806d1c85a6b01e87acd9f6fa5481219b57589413b1b312dce9c4e81e668f4d197f1c20b8c9e09
7
+ data.tar.gz: 6fc9a027136bd9d227c6b1abb78f9284cc17ce27bb847578a59b3ecac9fb9a1ea1907907edd5cd95494aacb5ca50257129ab6db6f054d9ac875499874432afa8
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ require "uri"
4
+ require "net/http"
5
+ require "hastebin"
6
+ require "colorize"
7
+
8
+ opts = OptionParser.new do |opts|
9
+ opts.banner = "\n«««««««««««««««««»»»»»»»»»»»»»»»»»»»"
10
+ opts.separator "««««««««««« Hastebin CLI »»»»»»»»»»»"
11
+ opts.separator "«««««««««««««««««»»»»»»»»»»»»»»»»»»»"
12
+ opts.separator ""
13
+ opts.separator 'Usage: hastebin --write "script" -> write'
14
+ opts.separator 'Usage: hastebin --up "/path/to/file" -> upload file'
15
+ opts.separator 'Usage: hastebin --download "key or key.rb" -> download via hasteb.in'
16
+ opts.separator 'Usage: hastebin --run "key or key.rb" -> run ruby via hasteb.in'
17
+ opts.separator 'Usage: hastebin --read "key or key.rb" -> Read files via hasteb.in'
18
+ opts.separator ""
19
+ opts.separator "Examples:"
20
+ opts.separator ' hastebin --write "puts("hello")"'
21
+ opts.separator ' hastebin --up "./text.txt"'
22
+ opts.separator ' hastebin --download "oquluqic"'
23
+ opts.separator ' hastebin --run "oquluqic"'
24
+ opts.separator ' hastebin --download "oquluqic"'
25
+ opts.separator ""
26
+ opts.separator "Options:"
27
+
28
+ opts.on("--write script") do |a|
29
+
30
+ puts "View in: https://hasteb.in/#{Hastebin.write(a)}"
31
+
32
+ exit
33
+ end
34
+
35
+ opts.on("--up file") do |a|
36
+ file = File.open(a)
37
+ data = []
38
+ file.each do |line|
39
+ data.push(line)
40
+ $text = data.join("")
41
+ end
42
+ puts "View in: https://hasteb.in/#{Hastebin.write($text)}"
43
+
44
+ exit
45
+ end
46
+
47
+ opts.on("--download key") do |key|
48
+ https = Net::HTTP.new('hasteb.in', 443)
49
+
50
+ https.use_ssl = true
51
+
52
+ res = https.get("/raw/#{key}")
53
+
54
+ File.open("#{key}", 'w') do |line|
55
+ line.puts(res.body)
56
+ end
57
+
58
+ exit
59
+ end
60
+
61
+ opts.on("--run key") do |key|
62
+
63
+ https = Net::HTTP.new('hasteb.in', 443)
64
+ https.use_ssl = true
65
+
66
+ res = https.get("/raw/#{key}")
67
+
68
+ File.open("#{key}.rb", 'w') do |line|
69
+ line.puts(res.body)
70
+ end
71
+
72
+ require("./#{key}")
73
+
74
+ require("./#{key}")
75
+ File.delete("./#{key}.rb")
76
+
77
+ exit
78
+ end
79
+
80
+ opts.on("--read key") do |key|
81
+ https = Net::HTTP.new('hasteb.in', 443)
82
+
83
+ https.use_ssl = true
84
+
85
+ res = https.get("/raw/#{key}")
86
+
87
+ puts res.body
88
+
89
+ exit
90
+ end
91
+ end
92
+ opts.parse!
@@ -1,30 +1,109 @@
1
1
  require "uri"
2
2
  require "net/http"
3
3
  require "json"
4
+ require "colorize"
4
5
 
5
6
  module Hastebin
6
7
 
8
+ $base_url = "https://hasteb.in/"
9
+ $domain = $base_url.gsub("https://","").gsub('/','')
7
10
 
8
- def self.code(code)
9
- url = URI("https://hasteb.in/documents")
10
11
 
11
- https = Net::HTTP.new(url.host, url.port);
12
- https.use_ssl = true
12
+ def self.write(code)
13
+ url = URI($base_url + "documents")
13
14
 
14
- request = Net::HTTP::Post.new(url)
15
- request["Connection"] = "keep-alive"
16
- request["Accept"] = "application/json, text/javascript, */*; q=0.01"
17
- request["X-Requested-With"] = "XMLHttpRequest"
18
- request["Content-Type"] = "application/json; charset=UTF-8"
19
- request["Origin"] = "https://hasteb.in"
20
- request["Referer"] = "https://hasteb.in/"
21
- request["Accept-Language"] = "pt-BR,pt;q=0.9,fr-FR;q=0.8,fr;q=0.7,en-US;q=0.6,en;q=0.5"
22
- request.body = code
15
+ https = Net::HTTP.new(url.host, url.port);
16
+ https.use_ssl = true
23
17
 
18
+ request = Net::HTTP::Post.new(url)
19
+ request.body = code
20
+ puts "[INFO] ".red + "Sent with success".green
24
21
  $res = https.request(request)
25
22
 
26
23
  return JSON.parse($res.read_body)['key']
27
24
  end
28
25
 
29
26
 
27
+ def self.sendFile(path)
28
+
29
+ file = File.open(path)
30
+ data = []
31
+ file.each do |line|
32
+ data.push(line)
33
+ $text = data.join("")
34
+ end
35
+ return write($text)
36
+ end
37
+
38
+ def self.readRaw(key)
39
+
40
+ https = Net::HTTP.new($domain, 443)
41
+
42
+ https.use_ssl = true
43
+
44
+ res = https.get("/raw/#{key}")
45
+
46
+ if res.code.to_i == 404
47
+ puts "[INFO] ".red+"#{JSON.parse(res.body)['message']}".red
48
+ else
49
+ puts "[INFO] ".red+"Received with success".green
50
+ return res.body
51
+ end
52
+
53
+ end
54
+
55
+ def self.run(key)
56
+
57
+ https = Net::HTTP.new($domain, 443)
58
+
59
+ https.use_ssl = true
60
+
61
+ res = https.get("/raw/#{key}")
62
+
63
+ File.open("#{key}.rb", 'w') do |line|
64
+ line.puts(res.body)
65
+ end
66
+
67
+ require("./#{key}")
68
+
69
+ require("./#{key}")
70
+ File.delete("./#{key}.rb")
71
+ end
72
+
73
+ def self.download(key)
74
+
75
+ https = Net::HTTP.new($domain, 443)
76
+
77
+ https.use_ssl = true
78
+
79
+ res = https.get("/raw/#{key}")
80
+
81
+ File.open("#{key}", 'w') do |line|
82
+ line.puts(res.body)
83
+ end
84
+
85
+ end
86
+ def self.base_url
87
+ return $base_url
88
+ end
89
+
90
+ def self.domain
91
+ return $domain
92
+ end
93
+
94
+ def self.ping
95
+ t = Time.now()
96
+ uri = URI($base_url)
97
+ res = Net::HTTP.get(uri)
98
+ t = (Time.now().to_f - t.to_f) * 1000
99
+ return t.to_i
100
+
101
+ end
102
+
103
+ # Warns
104
+
105
+ def self.code(code)
106
+ return "[INFO] ".red+"Please use " + "write".green + " instead of " + "code".red
107
+ end
108
+
30
109
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hastebin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Astin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-17 00:00:00.000000000 Z
11
+ date: 2020-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -24,13 +24,29 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: colorize
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  description: ''
28
42
  email:
29
43
  - ''
30
- executables: []
44
+ executables:
45
+ - hastebin
31
46
  extensions: []
32
47
  extra_rdoc_files: []
33
48
  files:
49
+ - bin/hastebin
34
50
  - lib/hastebin.rb
35
51
  homepage: https://rubygems.org/gems/discloud-status
36
52
  licenses: