zyxt 0.0.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/zyxt +4 -0
- data/lib/request.rb +32 -0
- data/lib/request_client.rb +93 -0
- metadata +7 -4
- data/lib/zyxt.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7a31df54bffa5395e874ddf4cfff1bb129a9eec56a30cc351c94322a1cbf29a
|
4
|
+
data.tar.gz: 101c5573e5fada7d28d5fd7dbe59ddb5a893810aa2f7ac851d78d104241a54df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af0336b994f9ea27906fa4af93f19ba26554d4960af9e111e089349fdd4616f3db9f898b540aa083ee4c8624d529795231d9039833ea376b4dee809d894d5f5e
|
7
|
+
data.tar.gz: ec470652b15cda87f7d138f88cd8b49c59ed9a5b0292e7c0bb0ad6e8c022b402bf823ea5e6aa70fbb413ea54943e3a0588778d89d48129c452baba49a42926e3
|
data/bin/zyxt
ADDED
data/lib/request.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "uri"
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
module Request
|
6
|
+
class Http
|
7
|
+
def self.send_request(method, url, body = nil, headers = nil)
|
8
|
+
methods = { "get" => Net::HTTP::Get, "post" => Net::HTTP::Post, "delete" => Net::HTTP::Delete, "put" => Net::HTTP::Put }
|
9
|
+
uri = URI.parse(url)
|
10
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
11
|
+
http.use_ssl = (uri.scheme == "https")
|
12
|
+
request = methods[method].new(uri.request_uri)
|
13
|
+
request["User-Agent"] = "zyxt tool"
|
14
|
+
request["Accept"] = "*/*"
|
15
|
+
request["Content-Type"] = "application/json"
|
16
|
+
if !headers.nil?
|
17
|
+
headers.each do | key, value |
|
18
|
+
request[key] = value
|
19
|
+
end
|
20
|
+
end
|
21
|
+
if !body.nil?
|
22
|
+
request.body = body.to_json
|
23
|
+
end
|
24
|
+
response = http.request(request)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.log(response)
|
28
|
+
puts "Status Code: #{response.code}"
|
29
|
+
puts "Body: #{response.body}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require "thor"
|
2
|
+
require "json"
|
3
|
+
require "leveldb"
|
4
|
+
require "securerandom"
|
5
|
+
require_relative "./request"
|
6
|
+
|
7
|
+
module RequestClient
|
8
|
+
class Zyxt < Thor
|
9
|
+
attr_accessor :db
|
10
|
+
def self.exit_on_failure?
|
11
|
+
true
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "history", "show history of requests"
|
15
|
+
def history
|
16
|
+
@db = LevelDB::DB.new '/tmp/foo'
|
17
|
+
@db.each { |key, val| puts "Key: #{key}, Val: #{val}" }
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "get URL", "execute GET request to URL"
|
21
|
+
option :headers, :type => :hash, :desc => "Headers"
|
22
|
+
option :curl, :type => :boolean, :desc => "Print command as cURL"
|
23
|
+
def get(url)
|
24
|
+
if options[:curl]
|
25
|
+
puts "curl -X GET #{url}"
|
26
|
+
return nil
|
27
|
+
end
|
28
|
+
|
29
|
+
response = Request::Http.send_request("get", url, nil, options[:headers])
|
30
|
+
Request::Http.log(response)
|
31
|
+
save_request("get")
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "post URL", "execute POST request to URL"
|
35
|
+
option :body, :type => :hash, :desc => "Body of the request"
|
36
|
+
option :headers, :type => :hash, :desc => "Headers"
|
37
|
+
option :curl, :type => :boolean, :desc => "Print command as cURL"
|
38
|
+
def post(url)
|
39
|
+
if options[:curl]
|
40
|
+
puts "curl -X POST #{url} -H 'Content-Type: application/json' -d #{options[:body]}"
|
41
|
+
return nil
|
42
|
+
end
|
43
|
+
|
44
|
+
response = Request::Http.send_request("post", url, options[:body], options[:headers])
|
45
|
+
Request::Http.log(response)
|
46
|
+
save_request("post")
|
47
|
+
end
|
48
|
+
|
49
|
+
desc "put URL", "execute PUT request to URL"
|
50
|
+
option :body, :type => :hash, :desc => "Body of the request"
|
51
|
+
option :headers, :type => :hash, :desc => "Headers"
|
52
|
+
option :curl, :type => :boolean, :desc => "Print command as cURL"
|
53
|
+
def put(url)
|
54
|
+
if options[:curl]
|
55
|
+
puts "curl -X PUT #{url} -H 'Content-Type: application/json' -d #{options[:body]}"
|
56
|
+
return nil
|
57
|
+
end
|
58
|
+
|
59
|
+
response = Request::Http.send_request("put", url, options[:body], options[:headers])
|
60
|
+
Request::Http.log(response)
|
61
|
+
save_request("put")
|
62
|
+
end
|
63
|
+
|
64
|
+
desc "delete URL", "execute DELETE request to URL"
|
65
|
+
option :headers, :type => :hash, :desc => "Headers"
|
66
|
+
option :curl, :type => :boolean, :desc => "Print command as cURL"
|
67
|
+
def delete(url)
|
68
|
+
if options[:curl]
|
69
|
+
puts "curl -X DELETE #{url}"
|
70
|
+
return nil
|
71
|
+
end
|
72
|
+
|
73
|
+
response = Request::Http.send_request("delete", url, nil, options[:headers])
|
74
|
+
Request::Http.log(response)
|
75
|
+
save_request("delete")
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
no_commands do
|
80
|
+
def save_request(method)
|
81
|
+
if @db.nil?
|
82
|
+
@db = LevelDB::DB.new '/tmp/foo'
|
83
|
+
end
|
84
|
+
|
85
|
+
tempHash = {"hash" => "Command executed #{method}", "executed_at" => Time.now}
|
86
|
+
|
87
|
+
@db.put(SecureRandom.hex, tempHash)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
RequestClient::Zyxt.start(ARGV)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zyxt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rafael Matsumoto
|
@@ -10,13 +10,16 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2020-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: REST Client developed for
|
13
|
+
description: REST Client developed for academic reasons
|
14
14
|
email: rafaelmatsumoto43@gmail.com
|
15
|
-
executables:
|
15
|
+
executables:
|
16
|
+
- zyxt
|
16
17
|
extensions: []
|
17
18
|
extra_rdoc_files: []
|
18
19
|
files:
|
19
|
-
-
|
20
|
+
- bin/zyxt
|
21
|
+
- lib/request.rb
|
22
|
+
- lib/request_client.rb
|
20
23
|
homepage: https://rubygems.org/gems/zyxt
|
21
24
|
licenses:
|
22
25
|
- MIT
|