<commit_before>require 'net/http'
{{#body.has_json_body}}
require 'json'
{{/body.has_json_body}}
{{#body.has_multipart_body}}
# gem install multipart-post
# Adds multipart POST capability to net/http
require 'net/http/post/multipart'
{{/body.has_multipart_body}}

def send_request
    # {{{request.name}}} ({{{request.method}}} {{{url.base}}})
    
    begin
        uri = URI('{{{url.fullpath}}}')
        
        # Create client          
        http = Net::HTTP.new(uri.host, uri.port)

        {{#body.has_raw_body}}
        body = "{{{body.raw_body}}}"
        {{/body.has_raw_body}}
        {{! ----- }}
        {{#body.has_long_body}}
        body = "" # set your body string
        {{/body.has_long_body}}
        {{! ----- }}
        {{#body.has_url_encoded_body}}
        data = {
        {{#body.url_encoded_body}}
            "{{{name}}}" => "{{{value}}}",
        {{/body.url_encoded_body}}
        }
        body = URI.encode_www_form(data)
        {{/body.has_url_encoded_body}}
        {{! ----- }}
        {{#body.has_multipart_body}}
        body = {
        {{#body.multipart_body}}
            "{{{name}}}" => "{{{value}}}",
        {{/body.multipart_body}}
        }
        {{/body.has_multipart_body}}
        {{! ----- }}
        {{#body.has_json_body}}
        dict = {{{body.json_body_object}}}
        body = JSON.dump(dict)
        {{/body.has_json_body}}
        
        {{! ----- }}
        # Create Request
        req =  Net::HTTP::{{{method}}}{{#body.has_multipart_body}}::Multipart{{/body.has_multipart_body}}.new(uri{{#body.has_multipart_body}}, body{{/body.has_multipart_body}})
        {{! ----- }}
        {{#headers.has_headers}}
        {{#headers.header_list}}
        # Add headers
        req.add_field "{{{header_name}}}", "{{{header_value}}}"
        {{/headers.header_list}}
        {{/headers.has_headers}}
        {{! ----- }}
        {{#body.has_json_body}}
        # Set header and body
        req.add_field "Content-Type", "application/json"
        req.body = body
        {{/body.has_json_body}}
        {{#body.has_raw_body}}
        # Set header and body
        req.add_field "Content-Type", "plain/text"
        req.body = body
        {{/body.has_raw_body}}
        {{! ----- }}
        {{#body.has_url_encoded_body}}
        # Set header and body
        req.body = body
        {{/body.has_url_encoded_body}}
        
        # Fetch Request
        res = http.request(req)
        puts "Response HTTP Status Code: #{res.code}"
        puts "Response HTTP Response Body: #{res.body}"
    rescue Exception => e
        puts "HTTP Request failed (#{e.message})"
    end
end<commit_msg>Prefer soft-tabs with a two space indent.<commit_after>require 'net/http'
{{#body.has_json_body}}
require 'json'
{{/body.has_json_body}}
{{#body.has_multipart_body}}
# gem install multipart-post
# Adds multipart POST capability to net/http
require 'net/http/post/multipart'
{{/body.has_multipart_body}}

def send_request
  # {{{request.name}}} ({{{request.method}}} {{{url.base}}})

  begin
    uri = URI('{{{url.fullpath}}}')

    # Create client
    http = Net::HTTP.new(uri.host, uri.port)

    {{#body.has_raw_body}}
    body = "{{{body.raw_body}}}"
    {{/body.has_raw_body}}
    {{! ----- }}
    {{#body.has_long_body}}
    body = "" # set your body string
    {{/body.has_long_body}}
    {{! ----- }}
    {{#body.has_url_encoded_body}}
    data = {
    {{#body.url_encoded_body}}
      "{{{name}}}" => "{{{value}}}",
    {{/body.url_encoded_body}}
    }
    body = URI.encode_www_form(data)
    {{/body.has_url_encoded_body}}
    {{! ----- }}
    {{#body.has_multipart_body}}
    body = {
    {{#body.multipart_body}}
      "{{{name}}}" => "{{{value}}}",
    {{/body.multipart_body}}
    }
    {{/body.has_multipart_body}}
    {{! ----- }}
    {{#body.has_json_body}}
    dict = {{{body.json_body_object}}}
    body = JSON.dump(dict)
    {{/body.has_json_body}}

    {{! ----- }}
    # Create Request
    req =  Net::HTTP::{{{method}}}{{#body.has_multipart_body}}::Multipart{{/body.has_multipart_body}}.new(uri{{#body.has_multipart_body}}, body{{/body.has_multipart_body}})
    {{! ----- }}
    {{#headers.has_headers}}
    {{#headers.header_list}}
    # Add headers
    req.add_field "{{{header_name}}}", "{{{header_value}}}"
    {{/headers.header_list}}
    {{/headers.has_headers}}
    {{! ----- }}
    {{#body.has_json_body}}
    # Set header and body
    req.add_field "Content-Type", "application/json"
    req.body = body
    {{/body.has_json_body}}
    {{#body.has_raw_body}}
    # Set header and body
    req.add_field "Content-Type", "plain/text"
    req.body = body
    {{/body.has_raw_body}}
    {{! ----- }}
    {{#body.has_url_encoded_body}}
    # Set header and body
    req.body = body
    {{/body.has_url_encoded_body}}

    # Fetch Request
    res = http.request(req)
    puts "Response HTTP Status Code: #{res.code}"
    puts "Response HTTP Response Body: #{res.body}"
  rescue Exception => e
    puts "HTTP Request failed (#{e.message})"
  end
end
{'fraction_non_alphanumeric': 0.19952210274790919, 'fraction_numerical': 0.0, 'mean_word_length': 2.405423728813559, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '599722', 'n_tokens_mistral': 1735, 'n_tokens_neox': 1728, 'n_words': 275}