xcurl 1.0.7 → 1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/bin/console +11 -0
- data/lib/log.rb +41 -0
- data/lib/xcurl.rb +83 -19
- data/xcurl.gemspec +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00dbbfa82619c1c3f8277f83f3f40517e9bf80dd004f30d93b61178a9e8b1dea
|
4
|
+
data.tar.gz: 8a71222f33550a6c107fbf55ca366a2d10e75bc39f3939de62ea766cd33091b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69e9152ede089f4253656b3b96ef9feeda084ac19c1b33bc90278ea547bca5e75c45ab5b07ab01be6ed83a364ffec5f1ae11b735a2c0cecccbb9d27fdc0dd925
|
7
|
+
data.tar.gz: 308ab10c2fa45968f11163b3fef1d65a4fe9dd18dcb98f53f6f64be0e2c5696470319d3f67b3258a66cfa3d13188800b17e34799695a48e3c5d961367f802559
|
data/Gemfile.lock
CHANGED
data/bin/console
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "xcurl"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
require "irb"
|
11
|
+
IRB.start(__FILE__)
|
data/lib/log.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'pastel'
|
2
|
+
|
3
|
+
class Log
|
4
|
+
def initialize
|
5
|
+
@p = Pastel.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def deleted(d)
|
9
|
+
puts @p.green("part deleted #{@p.yellow(d)}")
|
10
|
+
end
|
11
|
+
|
12
|
+
def url_set(u)
|
13
|
+
puts @p.green("url set #{@p.yellow(u)}")
|
14
|
+
end
|
15
|
+
|
16
|
+
def added(a)
|
17
|
+
puts @p.green("added #{@p.yellow(a)}")
|
18
|
+
end
|
19
|
+
|
20
|
+
def show_current_session(session)
|
21
|
+
puts @p.green.bold("URL:\n #{@p.yellow(session['url'])}")
|
22
|
+
puts @p.green.bold("Parts:")
|
23
|
+
session['parts'].each_with_index do |part, index|
|
24
|
+
puts " #{@p.blue(index)} - #{@p.yellow(part)}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def result(cmd, data)
|
29
|
+
puts @p.cyan("==> #{cmd}")
|
30
|
+
puts ''
|
31
|
+
puts @p.green(data)
|
32
|
+
puts ''
|
33
|
+
end
|
34
|
+
|
35
|
+
def error(cmd, data)
|
36
|
+
puts @p.cyan("==> #{cmd}")
|
37
|
+
puts ''
|
38
|
+
puts @p.red(data)
|
39
|
+
puts ''
|
40
|
+
end
|
41
|
+
end
|
data/lib/xcurl.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'ostruct'
|
4
|
+
require 'open3'
|
5
|
+
require 'json'
|
6
|
+
require_relative './log'
|
4
7
|
|
5
8
|
class Xcurl
|
6
|
-
def self.start(
|
7
|
-
|
8
|
-
|
9
|
-
current_session = session || 'untitled'
|
10
|
-
parts = []
|
9
|
+
def self.start(session_id = nil)
|
10
|
+
log = Log.new
|
11
|
+
session = load_session(session_id || 'untitled')
|
11
12
|
|
12
13
|
while true
|
13
|
-
print "[#{
|
14
|
+
print "[#{session['id']}] "
|
14
15
|
|
15
16
|
cmd = gets.chomp
|
16
17
|
|
@@ -18,29 +19,92 @@ class Xcurl
|
|
18
19
|
when 'quit'
|
19
20
|
break
|
20
21
|
|
21
|
-
when /
|
22
|
-
|
22
|
+
when /save /
|
23
|
+
new_id = cmd.scan(/save (.*)/).flatten.first
|
24
|
+
|
25
|
+
session = save_session(new_id, session)
|
26
|
+
|
27
|
+
when /load /
|
28
|
+
id = cmd.scan(/load (.*)/).flatten.first
|
29
|
+
|
30
|
+
session = load_session(id)
|
23
31
|
|
24
32
|
when 'show'
|
25
|
-
|
26
|
-
puts "#{pastel.blue(index)} - #{pastel.green("'#{pastel.bold(part)}'")}"
|
27
|
-
end
|
33
|
+
log.show_current_session(session)
|
28
34
|
|
29
|
-
when
|
35
|
+
when /^delete /
|
30
36
|
index_part = cmd.scan(/delete (.*)/).flatten.first.to_i
|
31
37
|
|
32
|
-
parts.delete_at(index_part)
|
38
|
+
deleted = session['parts'].delete_at(index_part)
|
39
|
+
|
40
|
+
log.deleted(deleted)
|
41
|
+
|
42
|
+
when /^url /
|
43
|
+
url = cmd.scan(/url (.*)/).flatten.first
|
33
44
|
|
34
|
-
|
45
|
+
session['url'] = url
|
46
|
+
|
47
|
+
log.url_set(url)
|
48
|
+
|
49
|
+
when /^add /
|
35
50
|
part = cmd.scan(/add (.*)/).flatten.first
|
36
51
|
|
37
|
-
parts << part
|
52
|
+
session['parts'] << part
|
53
|
+
|
54
|
+
log.added(part)
|
55
|
+
|
56
|
+
when /^curl /
|
57
|
+
path = cmd.scan(/curl (.*)/).flatten.first
|
38
58
|
|
39
|
-
|
59
|
+
curl_cmd = "curl #{session['url']}/#{path} #{session['parts'].join(' ')}"
|
40
60
|
|
41
|
-
|
42
|
-
|
61
|
+
out, err, status = Open3.capture3(curl_cmd)
|
62
|
+
|
63
|
+
if status.success?
|
64
|
+
data =
|
65
|
+
begin
|
66
|
+
JSON.pretty_generate(JSON.parse(out))
|
67
|
+
rescue JSON::ParserError => e
|
68
|
+
out
|
69
|
+
end
|
70
|
+
|
71
|
+
log.result(curl_cmd, data)
|
72
|
+
else
|
73
|
+
log.error(curl_cmd, data)
|
74
|
+
end
|
43
75
|
end
|
44
76
|
end
|
45
77
|
end
|
78
|
+
|
79
|
+
def self.load_session(id)
|
80
|
+
ensure_home
|
81
|
+
|
82
|
+
if File.exist?("#{dir}/#{id}")
|
83
|
+
JSON.parse(File.read("#{dir}/#{id}"))
|
84
|
+
else
|
85
|
+
{
|
86
|
+
'id' => 'untitled',
|
87
|
+
'url' => nil,
|
88
|
+
'parts' => []
|
89
|
+
}
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.save_session(id, session)
|
94
|
+
ensure_home
|
95
|
+
|
96
|
+
session['id'] = id
|
97
|
+
|
98
|
+
File.write("#{dir}/#{id}", JSON.pretty_generate(session))
|
99
|
+
|
100
|
+
session
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.dir
|
104
|
+
"#{ENV['HOME']}/.xcurl"
|
105
|
+
end
|
106
|
+
|
107
|
+
def self.ensure_home
|
108
|
+
Dir.mkdir(dir) unless Dir.exist?(dir)
|
109
|
+
end
|
46
110
|
end
|
data/xcurl.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xcurl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew S Aguiar
|
@@ -41,9 +41,11 @@ files:
|
|
41
41
|
- LICENSE.txt
|
42
42
|
- README.md
|
43
43
|
- Rakefile
|
44
|
+
- bin/console
|
44
45
|
- bin/setup
|
45
46
|
- bin/xcurl
|
46
47
|
- generate-gem
|
48
|
+
- lib/log.rb
|
47
49
|
- lib/xcurl.rb
|
48
50
|
- xcurl.gemspec
|
49
51
|
homepage: https://github.com/andrewaguiar/xcurl
|