rack_curler 0.0.1 → 0.0.2
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 +8 -8
- data/lib/rack_curler.rb +7 -5
- data/lib/rack_curler/version.rb +1 -1
- data/spec/rack_curler_spec.rb +44 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YzUyN2I1ZWU5YjlkZDYwOTQ3NDcyMDVhOTc0MTRiYzZlMGUyMmM0Nw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZmZmMTI1YWJkNzg3OGNmMDgxYzRjNTI0NjljNzFmMjc0ZWE3MjU1OA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Nzk0OTgxNTk3YjU1YmMxNGFhMmNhZWNkY2UyNDI1MDMxOTQyY2E0MTczZGYw
|
10
|
+
ZTc0MWY0NmY1ZWNmZDI0OTM2ZjdmMzQ0YmNiZGRiMzljNTVlMWQ2YzE2ZGE5
|
11
|
+
NTBiZmM5ZWM1MGExZmYwOTBiOWJmMzAyYzUwZjVhNmE4NGI0OTc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YjU3MDhjOGU1NDBkYzE0ZTJmYTk4Njc3NTNmODJhNDI0MTQxNDgwYTQ2NzRm
|
14
|
+
M2Q3YzE4ZGVkMWU3YTlkYTQ4OTZmOGIxNmY3NmQzOTA4YTgwNDZiN2M4Mjdh
|
15
|
+
NTk0MmRkZWU2ZDVhMGVlODk4MTM3ZDliZjRlOWYxNjhkNTFjOWI=
|
data/lib/rack_curler.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "rack_curler/version"
|
2
2
|
|
3
3
|
module RackCurler
|
4
|
-
def self.to_curl(env)
|
4
|
+
def self.to_curl(env, options={})
|
5
5
|
|
6
6
|
headers_to_drop = [
|
7
7
|
'Version', # make your life easy and let curl set this
|
@@ -31,13 +31,15 @@ module RackCurler
|
|
31
31
|
end
|
32
32
|
|
33
33
|
url = Rack::Request.new(env).url
|
34
|
-
|
34
|
+
|
35
|
+
line_prefix = options[:pretty] ? " \\\n " : ' '
|
36
|
+
|
35
37
|
curl_command = "curl '#{url}'"
|
36
|
-
curl_command << "
|
38
|
+
curl_command << line_prefix << "-X #{env['REQUEST_METHOD']}" unless ['GET', 'POST'].member?(env['REQUEST_METHOD'])
|
37
39
|
headers.each_pair do |header, value|
|
38
|
-
curl_command << "
|
40
|
+
curl_command << line_prefix << "-H '#{header}: #{value}'"
|
39
41
|
end
|
40
|
-
curl_command << "
|
42
|
+
curl_command << line_prefix << "--data '#{body}'" if body && !body.empty?
|
41
43
|
|
42
44
|
curl_command
|
43
45
|
end
|
data/lib/rack_curler/version.rb
CHANGED
data/spec/rack_curler_spec.rb
CHANGED
@@ -68,6 +68,20 @@ describe RackCurler do
|
|
68
68
|
@output.should match /-H 'Accept: something specific'/
|
69
69
|
end
|
70
70
|
end
|
71
|
+
|
72
|
+
it "does not have backslash-newline formatting" do
|
73
|
+
@output.should_not match /\\\n/
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'with pretty formatting' do
|
77
|
+
before(:each) do
|
78
|
+
@output = RackCurler.to_curl(@env, :pretty => true)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "has leading backslashes and newlines preceding -H (so it appears on its own line)" do
|
82
|
+
@output.should match /\s\\\n(\s+)-H/
|
83
|
+
end
|
84
|
+
end
|
71
85
|
end
|
72
86
|
|
73
87
|
shared_examples_for "a request for http://foo.example.com without a body" do
|
@@ -89,6 +103,16 @@ describe RackCurler do
|
|
89
103
|
@output.should match /--data 'some body'/
|
90
104
|
end
|
91
105
|
|
106
|
+
describe "with pretty formatting" do
|
107
|
+
before(:each) do
|
108
|
+
@output = RackCurler.to_curl(@env, :pretty => true)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "precedes --data with a backslash and newline" do
|
112
|
+
@output.should match /\s\\\n(\s+)--data/
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
92
116
|
describe 'with non-default Content-Type' do
|
93
117
|
before(:each) do
|
94
118
|
@env['CONTENT_TYPE'] = 'hello'
|
@@ -127,6 +151,16 @@ describe RackCurler do
|
|
127
151
|
it "specifies -X DELETE" do
|
128
152
|
@output.should match /-X DELETE/
|
129
153
|
end
|
154
|
+
|
155
|
+
describe "with pretty formatting" do
|
156
|
+
before(:each) do
|
157
|
+
@output = RackCurler.to_curl(@env, :pretty => true)
|
158
|
+
end
|
159
|
+
|
160
|
+
it "precedes -X with a backslash and newline" do
|
161
|
+
@output.should match /\s\\\n(\s+)-X/
|
162
|
+
end
|
163
|
+
end
|
130
164
|
end
|
131
165
|
|
132
166
|
describe 'for a PUT to http://foo.example.com' do
|
@@ -138,6 +172,16 @@ describe RackCurler do
|
|
138
172
|
it_behaves_like "a request for http://foo.example.com"
|
139
173
|
it_behaves_like "a request for http://foo.example.com with a body"
|
140
174
|
|
175
|
+
describe "with pretty formatting" do
|
176
|
+
before(:each) do
|
177
|
+
@output = RackCurler.to_curl(@env, :pretty => true)
|
178
|
+
end
|
179
|
+
|
180
|
+
it "precedes -X with a backslash and newline" do
|
181
|
+
@output.should match /\s\\\n(\s+)-X/
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
141
185
|
it "specifies -X PUT" do
|
142
186
|
@output.should match /-X PUT/
|
143
187
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack_curler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Speed
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11
|
11
|
+
date: 2013-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|