poke-your-api 0.2.7 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/poke/commands/curl.rb +9 -10
- data/lib/poke/commands/speed.rb +9 -11
- data/lib/poke/curl_parser.rb +156 -0
- data/lib/poke/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6a613b0c63a4be50edfad9b34c11a1848646d47dc46a56e4acffe2cdc92ef4d
|
4
|
+
data.tar.gz: 1e1dbd044df43b89665c309ad6e0852a45be81ba2cb2f3892bd453a06cb902a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbaf6b1dc9d4d05fe70790aefe912cf2c045bbf7ad4f9806783873c1f6f2440a77b457c928f7b5c68ff8ac43c221c704c6c4b83874dde5e5b0ffb786c65e8dcd
|
7
|
+
data.tar.gz: 4f91178f36bc0783745696d19d7701a7d6205cb0b841c4247718ec679c921968a279f67e9e703cf6fbf6036c05c2294376ed9f8d83a0b4082abe9396fbc7114d
|
data/lib/poke/commands/curl.rb
CHANGED
@@ -5,6 +5,7 @@ require_relative '../group'
|
|
5
5
|
require_relative '../config'
|
6
6
|
require_relative '../paint'
|
7
7
|
require_relative '../last_recently_used'
|
8
|
+
require_relative '../curl_parser'
|
8
9
|
|
9
10
|
require 'pathname'
|
10
11
|
require 'pastel'
|
@@ -96,16 +97,14 @@ module Poke
|
|
96
97
|
end
|
97
98
|
|
98
99
|
def build_command(path)
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
[command_lines.join(" \\\n "), comments]
|
100
|
+
content = File.read(path)
|
101
|
+
parser = CurlParser.new(content)
|
102
|
+
|
103
|
+
# Add our additional curl parameters
|
104
|
+
parser.add_argument("-o #{Poke::Config.response_path}")
|
105
|
+
parser.add_argument('-w "%{json}"')
|
106
|
+
|
107
|
+
[parser.to_command_with_line_continuation, parser.comments.join("\n")]
|
109
108
|
end
|
110
109
|
|
111
110
|
# rubocop:disable Style/FormatStringToken
|
data/lib/poke/commands/speed.rb
CHANGED
@@ -5,6 +5,7 @@ require_relative '../group'
|
|
5
5
|
require_relative '../config'
|
6
6
|
require_relative '../paint'
|
7
7
|
require_relative '../last_recently_used'
|
8
|
+
require_relative '../curl_parser'
|
8
9
|
|
9
10
|
require 'pathname'
|
10
11
|
require 'pastel'
|
@@ -76,18 +77,15 @@ module Poke
|
|
76
77
|
errors << "Run count: #{count}\nAverage time: #{format('%.2fms', (times.sum / times.size * 1000))}\n\n"
|
77
78
|
end
|
78
79
|
|
79
|
-
# extract
|
80
80
|
def build_command(path)
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
[command_lines.join(" \\\n "), comments]
|
81
|
+
content = File.read(path)
|
82
|
+
parser = CurlParser.new(content)
|
83
|
+
|
84
|
+
# Add our additional curl parameters
|
85
|
+
parser.add_argument("-o #{Poke::Config.response_path}")
|
86
|
+
parser.add_argument('-w "%{json}"')
|
87
|
+
|
88
|
+
[parser.to_command_with_line_continuation, parser.comments.join("\n")]
|
91
89
|
end
|
92
90
|
|
93
91
|
# rubocop:disable Style/FormatStringToken
|
@@ -0,0 +1,156 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Poke
|
6
|
+
class CurlParser
|
7
|
+
attr_reader :comments, :arguments, :url
|
8
|
+
|
9
|
+
def initialize(content)
|
10
|
+
@content = content
|
11
|
+
@comments = []
|
12
|
+
@arguments = []
|
13
|
+
@url = nil
|
14
|
+
parse
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_command
|
18
|
+
parts = ['curl']
|
19
|
+
parts.concat(@arguments)
|
20
|
+
parts << @url if @url
|
21
|
+
parts.join(' ')
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_command_with_line_continuation
|
25
|
+
parts = ['curl']
|
26
|
+
parts.concat(@arguments)
|
27
|
+
parts << @url if @url
|
28
|
+
|
29
|
+
# Join with line continuation for better readability
|
30
|
+
parts.join(" \\\n ")
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_argument(arg)
|
34
|
+
@arguments << arg
|
35
|
+
end
|
36
|
+
|
37
|
+
def remove_argument(pattern)
|
38
|
+
@arguments.reject! { |arg| arg.match?(pattern) }
|
39
|
+
end
|
40
|
+
|
41
|
+
def replace_argument(pattern, replacement)
|
42
|
+
@arguments.map! do |arg|
|
43
|
+
arg.match?(pattern) ? replacement : arg
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def parse
|
50
|
+
# Normalize line endings and ensure content ends with newline
|
51
|
+
content = @content.gsub(/\r\n/, "\n").gsub(/\r/, "\n")
|
52
|
+
content += "\n" unless content.end_with?("\n")
|
53
|
+
|
54
|
+
# First, extract comments
|
55
|
+
extract_comments(content)
|
56
|
+
|
57
|
+
# Then parse the curl command
|
58
|
+
parse_curl_content(content)
|
59
|
+
end
|
60
|
+
|
61
|
+
def extract_comments(content)
|
62
|
+
content.each_line do |line|
|
63
|
+
stripped = line.strip
|
64
|
+
@comments << stripped if stripped.start_with?('#')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def parse_curl_content(content)
|
69
|
+
# Remove comments and empty lines
|
70
|
+
curl_lines = content.lines.reject do |line|
|
71
|
+
line.strip.empty? || line.strip.start_with?('#')
|
72
|
+
end
|
73
|
+
|
74
|
+
return if curl_lines.empty?
|
75
|
+
|
76
|
+
# Join lines with continuations
|
77
|
+
curl_content = join_continuations(curl_lines)
|
78
|
+
|
79
|
+
# Parse the curl command
|
80
|
+
parse_curl_command(curl_content)
|
81
|
+
end
|
82
|
+
|
83
|
+
def join_continuations(lines)
|
84
|
+
result = ""
|
85
|
+
i = 0
|
86
|
+
|
87
|
+
while i < lines.length
|
88
|
+
line = lines[i].chomp
|
89
|
+
|
90
|
+
# Check if this line ends with continuation
|
91
|
+
if line.end_with?('\\')
|
92
|
+
result += line[0...-1] + " "
|
93
|
+
i += 1
|
94
|
+
else
|
95
|
+
result += line + " "
|
96
|
+
i += 1
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
result.strip
|
101
|
+
end
|
102
|
+
|
103
|
+
def parse_curl_command(content)
|
104
|
+
# Remove 'curl' command if present
|
105
|
+
content = content.sub(/^\s*curl\s+/, '')
|
106
|
+
|
107
|
+
# Split arguments while preserving quoted strings
|
108
|
+
args = split_arguments(content)
|
109
|
+
|
110
|
+
args.each do |arg|
|
111
|
+
if arg.start_with?('-')
|
112
|
+
@arguments << arg
|
113
|
+
elsif @url.nil?
|
114
|
+
@url = arg
|
115
|
+
else
|
116
|
+
# Additional arguments after URL
|
117
|
+
@arguments << arg
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def split_arguments(line)
|
123
|
+
args = []
|
124
|
+
current_arg = ""
|
125
|
+
in_quotes = false
|
126
|
+
quote_char = nil
|
127
|
+
i = 0
|
128
|
+
|
129
|
+
while i < line.length
|
130
|
+
char = line[i]
|
131
|
+
|
132
|
+
if !in_quotes && char.match?(/\s/)
|
133
|
+
if !current_arg.empty?
|
134
|
+
args << current_arg
|
135
|
+
current_arg = ""
|
136
|
+
end
|
137
|
+
elsif !in_quotes && (char == '"' || char == "'")
|
138
|
+
in_quotes = true
|
139
|
+
quote_char = char
|
140
|
+
current_arg += char
|
141
|
+
elsif in_quotes && char == quote_char
|
142
|
+
in_quotes = false
|
143
|
+
quote_char = nil
|
144
|
+
current_arg += char
|
145
|
+
else
|
146
|
+
current_arg += char
|
147
|
+
end
|
148
|
+
|
149
|
+
i += 1
|
150
|
+
end
|
151
|
+
|
152
|
+
args << current_arg unless current_arg.empty?
|
153
|
+
args
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
data/lib/poke/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: poke-your-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Bator
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pastel
|
@@ -132,6 +132,7 @@ files:
|
|
132
132
|
- lib/poke/commands/response.rb
|
133
133
|
- lib/poke/commands/speed.rb
|
134
134
|
- lib/poke/config.rb
|
135
|
+
- lib/poke/curl_parser.rb
|
135
136
|
- lib/poke/group.rb
|
136
137
|
- lib/poke/group_config.rb
|
137
138
|
- lib/poke/last_recently_used.rb
|