xcurl 1.0.10 → 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: 8401e6c12d458031a65994b3d1702a38c27c4a6d6faeb706c7fbba71b86ec8a3
4
- data.tar.gz: c3a1f31fed1328d5ddabd64c90338ca95040325e5f1590d00bd3bab7ce0ca610
3
+ metadata.gz: 98cc4b306bc2f9a3adabed89c1b02ddb30fc8dede6014bd3b4954225a117f10a
4
+ data.tar.gz: fce824351babef049d78e2c01f6195afc0806caabfdd45c509b09c685074d85b
5
5
  SHA512:
6
- metadata.gz: bd60c94d0f237538a7fd6eab01b77d0a368c5f2752bc2deca04a44e2abc9f8b943bc010d05f68190a7f9ac5aebfe575ec382ac7de71d68907c129263cd47ef83
7
- data.tar.gz: 2649c741bb92aa9abe63e52a68f6cb143caabf7132178bff19c7adef6744850fd358b5a35ca28edd624d8756d9f6b17b2d8e220827e78db0cfce7536bad5ccaf
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,16 +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)
10
18
  puts "// loading '#{session_id}'" if session_id
11
19
 
12
20
  log = Log.new
13
- session = load_session(session_id || 'untitled')
21
+ sessions = Sessions.new
22
+
23
+ session = sessions.load_session(session_id || 'untitled')
14
24
 
15
25
  while true
16
26
  print "[#{session['id']}] "
@@ -18,95 +28,33 @@ class Xcurl
18
28
  cmd = gets.chomp
19
29
 
20
30
  case cmd
31
+ when 'exit'
32
+ break
33
+
21
34
  when 'quit'
22
35
  break
23
36
 
24
37
  when /save /
25
- new_id = cmd.scan(/save (.*)/).flatten.first
26
-
27
- session = save_session(new_id, session)
38
+ session = SaveCommand.new.execute(sessions, session, cmd)
28
39
 
29
40
  when /load /
30
- id = cmd.scan(/load (.*)/).flatten.first
31
-
32
- session = load_session(id)
41
+ session = LoadCommand.new.execute(sessions, cmd)
33
42
 
34
43
  when 'show'
35
- log.show_current_session(session)
44
+ ShowCommand.new.execute(session, log)
36
45
 
37
46
  when /^delete /
38
- index_part = cmd.scan(/delete (.*)/).flatten.first.to_i
39
-
40
- deleted = session['parts'].delete_at(index_part)
41
-
42
- log.deleted(deleted)
47
+ DeletePartCommand.new.execute(session, cmd, log)
43
48
 
44
49
  when /^url /
45
- url = cmd.scan(/url (.*)/).flatten.first
46
-
47
- session['url'] = url
48
-
49
- log.url_set(url)
50
+ SetUrlCommand.new.execute(session, cmd, log)
50
51
 
51
52
  when /^add /
52
- part = cmd.scan(/add (.*)/).flatten.first
53
-
54
- session['parts'] << part
55
-
56
- log.added(part)
53
+ AddPartCommand.new.execute(session, cmd, log)
57
54
 
58
55
  when /^curl /
59
- path = cmd.scan(/curl (.*)/).flatten.first
60
-
61
- curl_cmd = "curl #{session['url']}/#{path} #{session['parts'].join(' ')}"
62
-
63
- out, err, status = Open3.capture3(curl_cmd)
64
-
65
- if status.success?
66
- data =
67
- begin
68
- JSON.pretty_generate(JSON.parse(out))
69
- rescue JSON::ParserError => e
70
- out
71
- end
72
-
73
- log.result(curl_cmd, data)
74
- else
75
- log.error(curl_cmd, data)
76
- end
56
+ ExecuteCommand.new.execute(session, cmd, log)
77
57
  end
78
58
  end
79
59
  end
80
-
81
- def self.load_session(id)
82
- ensure_home
83
-
84
- if File.exist?("#{dir}/#{id}")
85
- JSON.parse(File.read("#{dir}/#{id}"))
86
- else
87
- {
88
- 'id' => 'untitled',
89
- 'url' => nil,
90
- 'parts' => []
91
- }
92
- end
93
- end
94
-
95
- def self.save_session(id, session)
96
- ensure_home
97
-
98
- session['id'] = id
99
-
100
- File.write("#{dir}/#{id}", JSON.pretty_generate(session))
101
-
102
- session
103
- end
104
-
105
- def self.dir
106
- "#{ENV['HOME']}/.xcurl"
107
- end
108
-
109
- def self.ensure_home
110
- Dir.mkdir(dir) unless Dir.exist?(dir)
111
- end
112
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.10'
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.10
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