xcurl 1.0.6 → 1.0.8
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 +82 -18
- 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: 6db538ae75b6f2038a6e73b2a46fe2574cf93056ca022075f704a479af1b885d
|
4
|
+
data.tar.gz: a2ca6ae2b4a9a57c2572001311ab8e69dff7b74e52b4aec475c23893cd6db058
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 706f6e2b5dc70e76713fc185f2352d72342982fc977bf73fa498ab39fd416c9c3abc4897d1bb429a5df4fc0c43c59119693ca993c6e300217e9de85185876585
|
7
|
+
data.tar.gz: 0d1f09b3f28435c0a3d627f2d8816bd01326422f2487c42c3850b62926e9e3bfa746536c136a628c9ebd8b161ac024c6f7a8aab4ae7c7a32c0e4fd22efff70b4
|
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,24 +19,87 @@ 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
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
session = save_session(new_id, session)
|
26
|
+
|
27
|
+
when 'show'
|
28
|
+
log.show_current_session(session)
|
29
|
+
|
30
|
+
when /^delete /
|
31
|
+
index_part = cmd.scan(/delete (.*)/).flatten.first.to_i
|
32
|
+
|
33
|
+
deleted = session['parts'].delete_at(index_part)
|
34
|
+
|
35
|
+
log.deleted(deleted)
|
36
|
+
|
37
|
+
when /^url /
|
38
|
+
url = cmd.scan(/url (.*)/).flatten.first
|
28
39
|
|
29
|
-
|
40
|
+
session['url'] = url
|
41
|
+
|
42
|
+
log.url_set(url)
|
43
|
+
|
44
|
+
when /^add /
|
30
45
|
part = cmd.scan(/add (.*)/).flatten.first
|
31
46
|
|
32
|
-
parts << part
|
47
|
+
session['parts'] << part
|
48
|
+
|
49
|
+
log.added(part)
|
50
|
+
|
51
|
+
when /^curl /
|
52
|
+
path = cmd.scan(/curl (.*)/).flatten.first
|
33
53
|
|
34
|
-
|
54
|
+
curl_cmd = "curl #{session['url']}/#{path} #{session['parts'].join(' ')}"
|
35
55
|
|
36
|
-
|
37
|
-
|
56
|
+
out, err, status = Open3.capture3(curl_cmd)
|
57
|
+
|
58
|
+
if status.success?
|
59
|
+
data =
|
60
|
+
begin
|
61
|
+
JSON.pretty_generate(JSON.parse(out))
|
62
|
+
rescue JSON::ParserError => e
|
63
|
+
out
|
64
|
+
end
|
65
|
+
|
66
|
+
log.result(curl_cmd, data)
|
67
|
+
else
|
68
|
+
log.error(curl_cmd, data)
|
69
|
+
end
|
38
70
|
end
|
39
71
|
end
|
40
72
|
end
|
73
|
+
|
74
|
+
def self.load_session(id)
|
75
|
+
ensure_home
|
76
|
+
|
77
|
+
if File.exist?("#{dir}/#{id}")
|
78
|
+
JSON.parse(File.read("#{dir}/#{id}"))
|
79
|
+
else
|
80
|
+
{
|
81
|
+
'id' => 'untitled',
|
82
|
+
'url' => nil,
|
83
|
+
'parts' => []
|
84
|
+
}
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.save_session(id, session)
|
89
|
+
ensure_home
|
90
|
+
|
91
|
+
session['id'] = id
|
92
|
+
|
93
|
+
File.write("#{dir}/#{id}", JSON.pretty_generate(session))
|
94
|
+
|
95
|
+
session
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.dir
|
99
|
+
"#{ENV['HOME']}/.xcurl"
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.ensure_home
|
103
|
+
Dir.mkdir(dir) unless Dir.exist?(dir)
|
104
|
+
end
|
41
105
|
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.8
|
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
|