xcurl 1.0.9 → 1.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00dbbfa82619c1c3f8277f83f3f40517e9bf80dd004f30d93b61178a9e8b1dea
4
- data.tar.gz: 8a71222f33550a6c107fbf55ca366a2d10e75bc39f3939de62ea766cd33091b0
3
+ metadata.gz: 98cc4b306bc2f9a3adabed89c1b02ddb30fc8dede6014bd3b4954225a117f10a
4
+ data.tar.gz: fce824351babef049d78e2c01f6195afc0806caabfdd45c509b09c685074d85b
5
5
  SHA512:
6
- metadata.gz: 69e9152ede089f4253656b3b96ef9feeda084ac19c1b33bc90278ea547bca5e75c45ab5b07ab01be6ed83a364ffec5f1ae11b735a2c0cecccbb9d27fdc0dd925
7
- data.tar.gz: 308ab10c2fa45968f11163b3fef1d65a4fe9dd18dcb98f53f6f64be0e2c5696470319d3f67b3258a66cfa3d13188800b17e34799695a48e3c5d961367f802559
6
+ metadata.gz: 55a36d198d603eb23bc8586b1522b92ce0eef07292527e0c56e1da099f20bac3ea6ebb1fa3380b8417a3568c44dfc9c6137875b13a23856a8ee91eabd8adcc7b
7
+ data.tar.gz: b49335f6021f537c6e14f11ab59083e74b89b73b14b727f6f1748fe0b3b139717434e9e0f1a81f9e2a8563fc4e8586666b2cdd395798d08b74ec55a38514cac3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- xcurl (1.0.7)
4
+ xcurl (1.0.10)
5
5
  pastel (~> 0.8)
6
6
 
7
7
  GEM
@@ -0,0 +1,7 @@
1
+ class AddPartCommand < Command
2
+ def execute(session, cmd, log)
3
+ part = cmd.scan(/add (.*)/).flatten.first
4
+ session['parts'] << part
5
+ log.cmd_success('added', part)
6
+ end
7
+ end
data/lib/command.rb ADDED
@@ -0,0 +1,2 @@
1
+ class Command
2
+ end
@@ -0,0 +1,7 @@
1
+ class DeletePartCommand < Command
2
+ def execute(session, cmd, log)
3
+ index_part = cmd.scan(/delete (.*)/).flatten.first.to_i
4
+ deleted = session['parts'].delete_at(index_part)
5
+ log.cmd_success('part deleted', deleted)
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ class ExecuteCommand < Command
2
+ def execute(session, cmd, log)
3
+ path = cmd.scan(/curl (.*)/).flatten.first
4
+
5
+ curl_cmd = "curl #{session['url']}/#{path} #{session['parts'].join(' ')}"
6
+
7
+ out, err, status = Open3.capture3(curl_cmd)
8
+
9
+ log.log_cmd(curl_cmd)
10
+
11
+ if status.success?
12
+ data =
13
+ begin
14
+ JSON.pretty_generate(JSON.parse(out))
15
+ rescue JSON::ParserError => e
16
+ out
17
+ end
18
+
19
+ log.log_data_success(data)
20
+ else
21
+ log.log_data_error(err)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,6 @@
1
+ class LoadCommand < Command
2
+ def execute(sessions, cmd)
3
+ id = cmd.scan(/load (.*)/).flatten.first
4
+ sessions.load_session(id)
5
+ end
6
+ end
data/lib/log.rb CHANGED
@@ -5,35 +5,33 @@ class Log
5
5
  @p = Pastel.new
6
6
  end
7
7
 
8
- def deleted(d)
9
- puts @p.green("part deleted #{@p.yellow(d)}")
8
+ def cmd_success(label, value)
9
+ puts @p.green("#{label} #{@p.yellow(value)}")
10
10
  end
11
11
 
12
- def url_set(u)
13
- puts @p.green("url set #{@p.yellow(u)}")
12
+ def log_key_value(key, value)
13
+ puts @p.green.bold("#{key}: #{@p.yellow(value)}")
14
14
  end
15
15
 
16
- def added(a)
17
- puts @p.green("added #{@p.yellow(a)}")
18
- end
16
+ def log_key_values(key, values)
17
+ puts @p.green.bold(key)
19
18
 
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)}"
19
+ values.each_with_index do |value, index|
20
+ puts " #{@p.blue(index)} - #{@p.yellow(value)}"
25
21
  end
26
22
  end
27
23
 
28
- def result(cmd, data)
24
+ def log_cmd(cmd)
29
25
  puts @p.cyan("==> #{cmd}")
26
+ end
27
+
28
+ def log_data_success(data)
30
29
  puts ''
31
30
  puts @p.green(data)
32
31
  puts ''
33
32
  end
34
33
 
35
- def error(cmd, data)
36
- puts @p.cyan("==> #{cmd}")
34
+ def log_data_error(data)
37
35
  puts ''
38
36
  puts @p.red(data)
39
37
  puts ''
@@ -0,0 +1,6 @@
1
+ class SaveCommand < Command
2
+ def execute(sessions, session, cmd)
3
+ new_id = cmd.scan(/save (.*)/).flatten.first
4
+ sessions.save_session(new_id, session)
5
+ end
6
+ end
data/lib/sessions.rb ADDED
@@ -0,0 +1,35 @@
1
+ require 'pastel'
2
+
3
+ class Sessions
4
+ def load_session(id)
5
+ ensure_home
6
+
7
+ if File.exist?("#{dir}/#{id}")
8
+ JSON.parse(File.read("#{dir}/#{id}"))
9
+ else
10
+ {
11
+ 'id' => 'untitled',
12
+ 'url' => nil,
13
+ 'parts' => []
14
+ }
15
+ end
16
+ end
17
+
18
+ def save_session(id, session)
19
+ ensure_home
20
+
21
+ session['id'] = id
22
+
23
+ File.write("#{dir}/#{id}", JSON.pretty_generate(session))
24
+
25
+ session
26
+ end
27
+
28
+ def dir
29
+ "#{ENV['HOME']}/.xcurl"
30
+ end
31
+
32
+ def ensure_home
33
+ Dir.mkdir(dir) unless Dir.exist?(dir)
34
+ end
35
+ end
@@ -0,0 +1,7 @@
1
+ class SetUrlCommand < Command
2
+ def execute(session, cmd, log)
3
+ url = cmd.scan(/url (.*)/).flatten.first
4
+ session['url'] = url
5
+ log.cmd_success('url set', url)
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ class ShowCommand < Command
2
+ def execute(session, log)
3
+ log.log_key_value('URL', session['url'])
4
+ log.log_key_values('Parts', session['parts'])
5
+ end
6
+ end
data/lib/xcurl.rb CHANGED
@@ -1,14 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ostruct'
4
3
  require 'open3'
5
4
  require 'json'
6
5
  require_relative './log'
6
+ require_relative './sessions'
7
+ require_relative './command'
8
+ require_relative './save_command'
9
+ require_relative './load_command'
10
+ require_relative './show_command'
11
+ require_relative './delete_part_command'
12
+ require_relative './add_part_command'
13
+ require_relative './set_url_command'
14
+ require_relative './execute_command'
7
15
 
8
16
  class Xcurl
9
17
  def self.start(session_id = nil)
18
+ puts "// loading '#{session_id}'" if session_id
19
+
10
20
  log = Log.new
11
- session = load_session(session_id || 'untitled')
21
+ sessions = Sessions.new
22
+
23
+ session = sessions.load_session(session_id || 'untitled')
12
24
 
13
25
  while true
14
26
  print "[#{session['id']}] "
@@ -16,95 +28,33 @@ class Xcurl
16
28
  cmd = gets.chomp
17
29
 
18
30
  case cmd
31
+ when 'exit'
32
+ break
33
+
19
34
  when 'quit'
20
35
  break
21
36
 
22
37
  when /save /
23
- new_id = cmd.scan(/save (.*)/).flatten.first
24
-
25
- session = save_session(new_id, session)
38
+ session = SaveCommand.new.execute(sessions, session, cmd)
26
39
 
27
40
  when /load /
28
- id = cmd.scan(/load (.*)/).flatten.first
29
-
30
- session = load_session(id)
41
+ session = LoadCommand.new.execute(sessions, cmd)
31
42
 
32
43
  when 'show'
33
- log.show_current_session(session)
44
+ ShowCommand.new.execute(session, log)
34
45
 
35
46
  when /^delete /
36
- index_part = cmd.scan(/delete (.*)/).flatten.first.to_i
37
-
38
- deleted = session['parts'].delete_at(index_part)
39
-
40
- log.deleted(deleted)
47
+ DeletePartCommand.new.execute(session, cmd, log)
41
48
 
42
49
  when /^url /
43
- url = cmd.scan(/url (.*)/).flatten.first
44
-
45
- session['url'] = url
46
-
47
- log.url_set(url)
50
+ SetUrlCommand.new.execute(session, cmd, log)
48
51
 
49
52
  when /^add /
50
- part = cmd.scan(/add (.*)/).flatten.first
51
-
52
- session['parts'] << part
53
-
54
- log.added(part)
53
+ AddPartCommand.new.execute(session, cmd, log)
55
54
 
56
55
  when /^curl /
57
- path = cmd.scan(/curl (.*)/).flatten.first
58
-
59
- curl_cmd = "curl #{session['url']}/#{path} #{session['parts'].join(' ')}"
60
-
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
56
+ ExecuteCommand.new.execute(session, cmd, log)
75
57
  end
76
58
  end
77
59
  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
110
60
  end
data/xcurl.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "xcurl"
5
- spec.version = '1.0.9'
5
+ spec.version = '1.0.11'
6
6
  spec.authors = ["Andrew S Aguiar"]
7
7
  spec.email = ["andrewaguiar6@gmail.com"]
8
8
  spec.summary = "Convenient wrapper for curl"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xcurl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew S Aguiar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-19 00:00:00.000000000 Z
11
+ date: 2023-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pastel
@@ -45,7 +45,16 @@ files:
45
45
  - bin/setup
46
46
  - bin/xcurl
47
47
  - generate-gem
48
+ - lib/add_part_command.rb
49
+ - lib/command.rb
50
+ - lib/delete_part_command.rb
51
+ - lib/execute_command.rb
52
+ - lib/load_command.rb
48
53
  - lib/log.rb
54
+ - lib/save_command.rb
55
+ - lib/sessions.rb
56
+ - lib/set_url_command.rb
57
+ - lib/show_command.rb
49
58
  - lib/xcurl.rb
50
59
  - xcurl.gemspec
51
60
  homepage: https://github.com/andrewaguiar/xcurl