Skip to content

Commit a368f3c

Browse files
committed
Merge branch 'master' of github.com:ahmadnassri/httpsnippet
2 parents e5c2281 + 37e13e7 commit a368f3c

13 files changed

Lines changed: 36 additions & 34 deletions

File tree

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ Currently the following output [targets](/src/targets) are supported:
3636
- [Native](http://nodejs.org/api/http.html#http_http_request_options_callback)
3737
- [Request](https://github.com/request/request)
3838
- [Unirest](http://unirest.io/nodejs.html)
39-
- OCaml
40-
- [CoHTTP](https://github.com/mirage/ocaml-cohttp)
39+
- Ruby
40+
- [Native](http://ruby-doc.org/stdlib-2.2.1/libdoc/net/http/rdoc/Net/HTTP.html)
4141
- PHP
4242
- [ext-curl](http://php.net/manual/en/book.curl.php)
4343
- [pecl/http v1](http://php.net/manual/en/book.http.php)
@@ -46,7 +46,10 @@ Currently the following output [targets](/src/targets) are supported:
4646
- [Python 3](https://docs.python.org/3/library/http.client.html)
4747
- Objective-C
4848
- [NSURLSession](https://developer.apple.com/library/mac/documentation/Foundation/Reference/NSURLSession_class/index.html)
49-
- [Go](http://golang.org/pkg/net/http/#NewRequest)
49+
- Go
50+
- [Native](http://golang.org/pkg/net/http/#NewRequest)
51+
- OCaml
52+
- [CoHTTP](https://github.com/mirage/ocaml-cohttp)
5053

5154
## Installation
5255

src/targets/ruby/native.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ var util = require('util')
55
module.exports = function (source, options) {
66
var self = this
77
var code = []
8-
code.push('require \'uri\'')
9-
code.push('require \'net/http\'')
8+
code.push("require 'uri'")
9+
code.push("require 'net/http'")
1010
code.push(null)
1111

1212
// To support custom methods we check for the supported methods
@@ -15,10 +15,9 @@ module.exports = function (source, options) {
1515
var methods = ['GET', 'POST', 'HEAD', 'DELETE', 'PATCH', 'PUT', 'OPTIONS', 'COPY', 'LOCK', 'UNLOCK', 'MOVE', 'TRACE']
1616
var capMethod = method.charAt(0) + method.substring(1).toLowerCase()
1717
if (methods.indexOf(method) < 0) {
18-
code.push('class Net::HTTP::%s < Net::HTTPRequest')
1918
code.push(util.format('class Net::HTTP::%s < Net::HTTPRequest', capMethod))
20-
code.push(util.format(' METHOD = \'%s\'', method.toUpperCase()))
21-
code.push(util.format(' REQUEST_HAS_BODY = \'%s\'', self.source.postData.text ? 'true' : 'false'))
19+
code.push(util.format(" METHOD = '%s'", method.toUpperCase()))
20+
code.push(util.format(" REQUEST_HAS_BODY = '%s'", self.source.postData.text ? 'true' : 'false'))
2221
code.push(' RESPONSE_HAS_BODY = true')
2322
code.push('end')
2423
code.push(null)
@@ -28,7 +27,7 @@ module.exports = function (source, options) {
2827

2928
code.push(null)
3029

31-
code.push('conn = Net::HTTP.new(url.host, url.port)')
30+
code.push('http = Net::HTTP.new(url.host, url.port)')
3231

3332
if (source.uriObj.protocol === 'https:') {
3433
code.push('http.use_ssl = true')
@@ -52,7 +51,7 @@ module.exports = function (source, options) {
5251

5352
code.push(null)
5453

55-
code.push('response = conn.request(request)')
54+
code.push('response = http.request(request)')
5655
code.push('puts response.read_body')
5756

5857
return code.join('\n')
@@ -61,6 +60,6 @@ module.exports = function (source, options) {
6160
module.exports.info = {
6261
key: 'native',
6362
title: 'net::http',
64-
link: 'http://ruby-doc.org/stdlib-2.2.1/libdoc/net/http/rdoc/Net/HTTPGenericRequest.html',
65-
description: 'Ruby request client'
63+
link: 'http://ruby-doc.org/stdlib-2.2.1/libdoc/net/http/rdoc/Net/HTTP.html',
64+
description: 'Ruby HTTP client'
6665
}

test/fixtures/available-targets.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@
176176
{
177177
"key": "native",
178178
"title": "net::http",
179-
"link": "http://ruby-doc.org/stdlib-2.2.1/libdoc/net/http/rdoc/Net/HTTPGenericRequest.html",
180-
"description": "Ruby request client"
179+
"link": "http://ruby-doc.org/stdlib-2.2.1/libdoc/net/http/rdoc/Net/HTTP.html",
180+
"description": "Ruby HTTP client"
181181
}
182182
]
183183
}

test/fixtures/output/ruby/native/application-form-encoded.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
url = URI("http://mockbin.com/har")
55

6-
conn = Net::HTTP.new(url.host, url.port)
6+
http = Net::HTTP.new(url.host, url.port)
77

88
request = Net::HTTP::Post.new(url)
99
request["content-type"] = 'application/x-www-form-urlencoded'
1010
request.body = "foo=bar&hello=world"
1111

12-
response = conn.request(request)
12+
response = http.request(request)
1313
puts response.read_body

test/fixtures/output/ruby/native/application-json.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
url = URI("http://mockbin.com/har")
55

6-
conn = Net::HTTP.new(url.host, url.port)
6+
http = Net::HTTP.new(url.host, url.port)
77

88
request = Net::HTTP::Post.new(url)
99
request["content-type"] = 'application/json'
1010
request.body = "{\"number\": 1, \"string\": \"f\\\"oo\", \"arr\": [1, 2, 3], \"nested\": {\"a\": \"b\"}, \"arr_mix\": [1, \"a\", {\"arr_mix_nested\": {}}] }"
1111

12-
response = conn.request(request)
12+
response = http.request(request)
1313
puts response.read_body

test/fixtures/output/ruby/native/cookies.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
url = URI("http://mockbin.com/har")
55

6-
conn = Net::HTTP.new(url.host, url.port)
6+
http = Net::HTTP.new(url.host, url.port)
77

88
request = Net::HTTP::Post.new(url)
99
request["cookie"] = 'foo=bar; bar=baz'
1010

11-
response = conn.request(request)
11+
response = http.request(request)
1212
puts response.read_body

test/fixtures/output/ruby/native/full.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
url = URI("http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value")
55

6-
conn = Net::HTTP.new(url.host, url.port)
6+
http = Net::HTTP.new(url.host, url.port)
77

88
request = Net::HTTP::Post.new(url)
99
request["cookie"] = 'foo=bar; bar=baz'
1010
request["accept"] = 'application/json'
1111
request["content-type"] = 'application/x-www-form-urlencoded'
1212
request.body = "foo=bar"
1313

14-
response = conn.request(request)
14+
response = http.request(request)
1515
puts response.read_body

test/fixtures/output/ruby/native/headers.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
url = URI("http://mockbin.com/har")
55

6-
conn = Net::HTTP.new(url.host, url.port)
6+
http = Net::HTTP.new(url.host, url.port)
77

88
request = Net::HTTP::Get.new(url)
99
request["accept"] = 'application/json'
1010
request["x-foo"] = 'Bar'
1111

12-
response = conn.request(request)
12+
response = http.request(request)
1313
puts response.read_body

test/fixtures/output/ruby/native/multipart-data.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
url = URI("http://mockbin.com/har")
55

6-
conn = Net::HTTP.new(url.host, url.port)
6+
http = Net::HTTP.new(url.host, url.port)
77

88
request = Net::HTTP::Post.new(url)
99
request["content-type"] = 'multipart/form-data; boundary=---011000010111000001101001'
1010
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001--"
1111

12-
response = conn.request(request)
12+
response = http.request(request)
1313
puts response.read_body

test/fixtures/output/ruby/native/multipart-file.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
url = URI("http://mockbin.com/har")
55

6-
conn = Net::HTTP.new(url.host, url.port)
6+
http = Net::HTTP.new(url.host, url.port)
77

88
request = Net::HTTP::Post.new(url)
99
request["content-type"] = 'multipart/form-data; boundary=---011000010111000001101001'
1010
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--"
1111

12-
response = conn.request(request)
12+
response = http.request(request)
1313
puts response.read_body

0 commit comments

Comments
 (0)