<commit_before>package algoliasearch

import (
	"crypto/hmac"
	"crypto/sha256"
	"encoding/base64"
	"encoding/hex"
	"encoding/json"
	"strings"
	"time"
)

// Client is a representation of an Algolia application. Once initialized it
// allows manipulations over the indexes of the application as well as
// network related parameters.
type Client struct {
	transport *Transport
}

// NewClient creates a new Client from the provided `appID` and `apiKey`. The
// default hosts are used for the transport layer.
func NewClient(appID, apiKey string) Client {
	return Client{
		transport: NewTransport(appID, apiKey),
	}
}

// NewClientWithHosts creates a new Client from the provided `appID,` `apiKey`,
// and `hosts` used to connect to the Algolia servers.
func NewClientWithHosts(appID, apiKey string, hosts []string) Client {
	return Client{
		transport: NewTransportWithHosts(appID, apiKey, hosts),
	}
}

// SetExtraHeader allows to set custom headers while reaching out to
// Algolia servers.
func (c *Client) SetExtraHeader(key, value string) {
	c.transport.setExtraHeader(key, value)
}

// SetTimeout specifies timeouts to use with the HTTP connection.
func (c *Client) SetTimeout(connectTimeout, readTimeout int) {
	c.transport.setTimeout(time.Duration(connectTimeout)*time.Millisecond, time.Duration(readTimeout)*time.Millisecond)
}

// ListIndexes returns the list of all indexes belonging to this Algolia
// application.
func (c *Client) ListIndexes() (res []IndexRes, err error) {
	l := listIndexesRes{}
	err = c.request(&l, "GET", "/1/indexes", nil, read)
	res = l.items
	return
}

// InitIndex returns an Index object targeting `indexName`.
func (c *Client) InitIndex(name string) Index {
	return *NewIndex(name, c)
}

// ListKeys returns all the API keys available for this Algolia application.
func (c *Client) ListKeys() (res ListKeysRes, err error) {
	err = c.request(&res, "GET", "/1/keys", nil, read)
	return keys, err
}

// MoveIndex renames the index named `source` as `destination`.
func (c *Client) MoveIndex(source, destination string) (interface{}, error) {
	index := c.InitIndex(source)
	return index.Move(destination)
}

// CopyIndex duplicates the index named `source` as `destination`.
func (c *Client) CopyIndex(source, destination string) (interface{}, error) {
	index := c.InitIndex(source)
	return index.Copy(destination)
}

// AddKey creates a new API key from the supplied `ACL` and the specified<commit_msg>Minor compilation fix<commit_after>package algoliasearch

import (
	"crypto/hmac"
	"crypto/sha256"
	"encoding/base64"
	"encoding/hex"
	"encoding/json"
	"strings"
	"time"
)

// Client is a representation of an Algolia application. Once initialized it
// allows manipulations over the indexes of the application as well as
// network related parameters.
type Client struct {
	transport *Transport
}

// NewClient creates a new Client from the provided `appID` and `apiKey`. The
// default hosts are used for the transport layer.
func NewClient(appID, apiKey string) Client {
	return Client{
		transport: NewTransport(appID, apiKey),
	}
}

// NewClientWithHosts creates a new Client from the provided `appID,` `apiKey`,
// and `hosts` used to connect to the Algolia servers.
func NewClientWithHosts(appID, apiKey string, hosts []string) Client {
	return Client{
		transport: NewTransportWithHosts(appID, apiKey, hosts),
	}
}

// SetExtraHeader allows to set custom headers while reaching out to
// Algolia servers.
func (c *Client) SetExtraHeader(key, value string) {
	c.transport.setExtraHeader(key, value)
}

// SetTimeout specifies timeouts to use with the HTTP connection.
func (c *Client) SetTimeout(connectTimeout, readTimeout int) {
	c.transport.setTimeout(time.Duration(connectTimeout)*time.Millisecond, time.Duration(readTimeout)*time.Millisecond)
}

// ListIndexes returns the list of all indexes belonging to this Algolia
// application.
func (c *Client) ListIndexes() (res []IndexRes, err error) {
	l := listIndexesRes{}
	err = c.request(&l, "GET", "/1/indexes", nil, read)
	res = l.items
	return
}

// InitIndex returns an Index object targeting `indexName`.
func (c *Client) InitIndex(name string) Index {
	return *NewIndex(name, c)
}

// ListKeys returns all the API keys available for this Algolia application.
func (c *Client) ListKeys() (res ListKeysRes, err error) {
	err = c.request(&res, "GET", "/1/keys", nil, read)
	return
}

// MoveIndex renames the index named `source` as `destination`.
func (c *Client) MoveIndex(source, destination string) (interface{}, error) {
	index := c.InitIndex(source)
	return index.Move(destination)
}

// CopyIndex duplicates the index named `source` as `destination`.
func (c *Client) CopyIndex(source, destination string) (interface{}, error) {
	index := c.InitIndex(source)
	return index.Copy(destination)
}

// AddKey creates a new API key from the supplied `ACL` and the specified
{'fraction_non_alphanumeric': 0.11181780878128847, 'fraction_numerical': 0.002872384078785392, 'mean_word_length': 4.742049469964664, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1168489', 'n_tokens_mistral': 1493, 'n_tokens_neox': 1466, 'n_words': 533}