<commit_before>package udnssdk

// udnssdk - a golang sdk for the ultradns REST service.
// 2015-07-03 - <EMAIL>

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"net/http"
	"time"

	"golang.org/x/oauth2"

	oauthPassword "github.com/Ensighten/udnssdk/password"
)

const (
	libraryVersion = "0.1"
	// DefaultTestBaseURL returns the URL for UltraDNS's test restapi endpoint
	DefaultTestBaseURL = "https://test-restapi.ultradns.com/"
	// DefaultLiveBaseURL returns the URL for UltraDNS's production restapi endpoint
	DefaultLiveBaseURL = "https://restapi.ultradns.com/"

	userAgent = "udnssdk-go/" + libraryVersion

	apiVersion = "v1"
)

// QueryInfo wraps a query request
type QueryInfo struct {
	Q       string `json:"q"`
	Sort    string `json:"sort"`
	Reverse bool   `json:"reverse"`
	Limit   int    `json:"limit"`
}

// ResultInfo wraps the list metadata for an index response
type ResultInfo struct {
	TotalCount    int `json:"totalCount"`
	Offset        int `json:"offset"`
	ReturnedCount int `json:"returnedCount"`
}

// Client wraps our general-purpose Service Client
type Client struct {
	// This is our client structure.
	HTTPClient *http.Client
	Config     *oauthPassword.Config

	BaseURL   string
	UserAgent string

	// Accounts API
	Accounts *AccountsService
	// Probe Alerts API
	Alerts *AlertsService
	// Directional Pools API
	DirectionalPools *DirectionalPoolsService
	// Events API
	Events *EventsService
	// Notifications API
	Notifications *NotificationsService
	// Probes API
	Probes *ProbesService
	// Resource Record Sets API
	RRSets *RRSetsService
	// Tasks API
	Tasks *TasksService
}

// NewClient returns a new ultradns API client.
func NewClient(username, password, BaseURL string) (*Client, error) {
	ctx := oauth2.NoContext
	conf := NewConfig(username, password, BaseURL)

	c := &Client{
		HTTPClient: conf.Client(ctx),
		BaseURL:    BaseURL,
		UserAgent:  userAgent,
		Config:     conf,
	}
	c.Accounts = &AccountsService{client: c}
	c.Alerts = &AlertsService{client: c}
	c.DirectionalPools = &DirectionalPoolsService{client: c}
	c.Events = &EventsService{client: c}
	c.Notifications = &NotificationsService{client: c}
	c.Probes = &ProbesService{client: c}
	c.RRSets = &RRSetsService{client: c}
	c.Tasks = &TasksService{client: c}
	return c, nil
}

// newStubClient returns a new ultradns API client.
func newStubClient(username, password, BaseURL, clientID, clientSecret string) (*Client, error) {
	c := &Client{
		HTTPClient: &http.Client{},
		BaseURL:    BaseURL,
		UserAgent:  userAgent,
	}
	c.Accounts = &AccountsService{client: c}
	c.Alerts = &AlertsService{client: c}
	c.DirectionalPools = &DirectionalPoolsService{client: c}
	c.Events = &EventsService{client: c}
	c.Notifications = &NotificationsService{client: c}
	c.Probes = &ProbesService{client: c}
	c.RRSets = &RRSetsService{client: c}
	c.Tasks = &TasksService{client: c}
	return c, nil
}

// NewRequest creates an API request.
// The path is expected to be a relative path and will be resolved
// according to the BaseURL of the Client. Paths should always be specified without a preceding slash.
func (c *Client) NewRequest(method, path string, payload interface{}) (*http.Request, error) {
	url := c.BaseURL + fmt.Sprintf("%s/%s", apiVersion, path)

	body := new(bytes.Buffer)
	if payload != nil {
		err := json.NewEncoder(body).Encode(payload)
		if err != nil {
			return nil, err
		}
	}

	req, err := http.NewRequest(method, url, body)
	if err != nil {
		return nil, err
	}

	req.Header.Set("Content-Type", "application/json")
	req.Header.Add("Accept", "application/json")
	req.Header.Add("User-Agent", c.UserAgent)

	return req, nil<commit_msg>Client.BaseURL: change to url.URL<commit_after>package udnssdk

// udnssdk - a golang sdk for the ultradns REST service.
// 2015-07-03 - <EMAIL>

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"net/http"
	"net/url"
	"time"

	"golang.org/x/oauth2"

	oauthPassword "github.com/Ensighten/udnssdk/password"
)

const (
	libraryVersion = "0.1"
	// DefaultTestBaseURL returns the URL for UltraDNS's test restapi endpoint
	DefaultTestBaseURL = "https://test-restapi.ultradns.com/"
	// DefaultLiveBaseURL returns the URL for UltraDNS's production restapi endpoint
	DefaultLiveBaseURL = "https://restapi.ultradns.com/"

	userAgent = "udnssdk-go/" + libraryVersion

	apiVersion = "v1"
)

// QueryInfo wraps a query request
type QueryInfo struct {
	Q       string `json:"q"`
	Sort    string `json:"sort"`
	Reverse bool   `json:"reverse"`
	Limit   int    `json:"limit"`
}

// ResultInfo wraps the list metadata for an index response
type ResultInfo struct {
	TotalCount    int `json:"totalCount"`
	Offset        int `json:"offset"`
	ReturnedCount int `json:"returnedCount"`
}

// Client wraps our general-purpose Service Client
type Client struct {
	// This is our client structure.
	HTTPClient *http.Client
	Config     *oauthPassword.Config

	BaseURL   *url.URL
	UserAgent string

	// Accounts API
	Accounts *AccountsService
	// Probe Alerts API
	Alerts *AlertsService
	// Directional Pools API
	DirectionalPools *DirectionalPoolsService
	// Events API
	Events *EventsService
	// Notifications API
	Notifications *NotificationsService
	// Probes API
	Probes *ProbesService
	// Resource Record Sets API
	RRSets *RRSetsService
	// Tasks API
	Tasks *TasksService
}

// NewClient returns a new ultradns API client.
func NewClient(username, password, baseURL string) (*Client, error) {
	ctx := oauth2.NoContext
	conf := NewConfig(username, password, baseURL)

	u, err := url.Parse(baseURL)
	if err != nil {
		return nil, err
	}

	c := &Client{
		HTTPClient: conf.Client(ctx),
		BaseURL:    u,
		UserAgent:  userAgent,
		Config:     conf,
	}
	c.Accounts = &AccountsService{client: c}
	c.Alerts = &AlertsService{client: c}
	c.DirectionalPools = &DirectionalPoolsService{client: c}
	c.Events = &EventsService{client: c}
	c.Notifications = &NotificationsService{client: c}
	c.Probes = &ProbesService{client: c}
	c.RRSets = &RRSetsService{client: c}
	c.Tasks = &TasksService{client: c}
	return c, nil
}

// newStubClient returns a new ultradns API client.
func newStubClient(username, password, baseURL, clientID, clientSecret string) (*Client, error) {
	u, err := url.Parse(baseURL)
	if err != nil {
		return nil, err
	}

	c := &Client{
		HTTPClient: &http.Client{},
		BaseURL:    u,
		UserAgent:  userAgent,
	}
	c.Accounts = &AccountsService{client: c}
	c.Alerts = &AlertsService{client: c}
	c.DirectionalPools = &DirectionalPoolsService{client: c}
	c.Events = &EventsService{client: c}
	c.Notifications = &NotificationsService{client: c}
	c.Probes = &ProbesService{client: c}
	c.RRSets = &RRSetsService{client: c}
	c.Tasks = &TasksService{client: c}
	return c, nil
}

// NewRequest creates an API request.
// The path is expected to be a relative path and will be resolved
// according to the BaseURL of the Client. Paths should always be specified without a preceding slash.
func (c *Client) NewRequest(method, path string, payload interface{}) (*http.Request, error) {
	url := c.BaseURL
	url.Path = url.Path + fmt.Sprintf("%s/%s", apiVersion, path)

	body := new(bytes.Buffer)
	if payload != nil {
		err := json.NewEncoder(body).Encode(payload)
		if err != nil {
			return nil, err
		}
	}

	req, err := http.NewRequest(method, url.String(), body)
	if err != nil {
		return nil, err
	}

	req.Header.Set("Content-Type", "application/json")
	req.Header.Add("Accept", "application/json")
	req.Header.Add("User-Agent", c.UserAgent)

	return req, nil
{'fraction_non_alphanumeric': 0.1206552137435078, 'fraction_numerical': 0.0034625116526834465, 'mean_word_length': 4.084631008801625, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, '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': '4060375', 'n_tokens_mistral': 2649, 'n_tokens_neox': 2560, 'n_words': 711}