<commit_before>package street

import (
	"bytes"
	"encoding/json"
	"net/http"

	"github.com/smartystreets/smartystreets-go-sdk"
)

// Client is responsible for sending batches of addresses to the us-street-api.
type Client struct {
	sender sdk.RequestSender
}

// NewClient creates a client with the provided sender.
func NewClient(sender sdk.RequestSender) *Client {
	return &Client{sender: sender}
}

// Ping returns an error if the service is not reachable or not responding.
func (c *Client) Ping() error {
	_, err := c.sender.Send(buildPingRequest())
	return err
}

// SendBatch sends the batch of inputs, populating the output for each input if the batch was successful.
func (c *Client) SendBatch(batch *Batch) error {
	if batch == nil || batch.Length() == 0 {
		return nil
	} else if response, err := c.sender.Send(buildRequest(batch)); err != nil {
		return err
	} else {
		return deserializeResponse(response, batch)
	}
}

func deserializeResponse(response []byte, batch *Batch) error {
	var candidates []*Candidate
	err := json.Unmarshal(response, &candidates)
	if err == nil {
		batch.attach(candidates)
	}
	return err
}

func buildRequest(batch *Batch) *http.Request {
	payload, _ := json.Marshal(batch.lookups)                                  // We control the types being serialized. This is safe.
	request, _ := http.NewRequest("POST", verifyURL, bytes.NewReader(payload)) // We control the method and the URL. This is safe.
	return request
}

func buildPingRequest() *http.Request {
	request, _ := http.NewRequest("GET", statusURL, nil)
	return request
}

var (
	verifyURL = "/street-address" // Remaining parts will be completed later by the sdk.BaseURLClient.
	statusURL = "/status"
)<commit_msg>Disable keep-alive. Not sure if this will become a config option later.<commit_after>package street

import (
	"bytes"
	"encoding/json"
	"net/http"

	"github.com/smartystreets/smartystreets-go-sdk"
)

// Client is responsible for sending batches of addresses to the us-street-api.
type Client struct {
	sender sdk.RequestSender
}

// NewClient creates a client with the provided sender.
func NewClient(sender sdk.RequestSender) *Client {
	return &Client{sender: sender}
}

// Ping returns an error if the service is not reachable or not responding.
func (c *Client) Ping() error {
	_, err := c.sender.Send(buildPingRequest())
	return err
}

// SendBatch sends the batch of inputs, populating the output for each input if the batch was successful.
func (c *Client) SendBatch(batch *Batch) error {
	if batch == nil || batch.Length() == 0 {
		return nil
	} else if response, err := c.sender.Send(buildRequest(batch)); err != nil {
		return err
	} else {
		return deserializeResponse(response, batch)
	}
}

func deserializeResponse(response []byte, batch *Batch) error {
	var candidates []*Candidate
	err := json.Unmarshal(response, &candidates)
	if err == nil {
		batch.attach(candidates)
	}
	return err
}

func buildRequest(batch *Batch) *http.Request {
	payload, _ := json.Marshal(batch.lookups)                                  // We control the types being serialized. This is safe.
	request, _ := http.NewRequest("POST", verifyURL, bytes.NewReader(payload)) // We control the method and the URL. This is safe.
	request.Close = true
	return request
}

func buildPingRequest() *http.Request {
	request, _ := http.NewRequest("GET", statusURL, nil)
	request.Close = true
	return request
}

var (
	verifyURL = "/street-address" // Remaining parts will be completed later by the sdk.BaseURLClient.
	statusURL = "/status"
)
{'fraction_non_alphanumeric': 0.11120543293718166, 'fraction_numerical': 0.0005659309564233164, 'mean_word_length': 3.862448418156809, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1843331', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1064, 'n_words': 365}