<commit_before>package gogithub

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

// A Client represents a GitHub API client.
type Client struct {
	ID          string
	Secret      string
	AccessToken string
}

// SetAccessToken calls access token API, gets an access token and sets it to the client.
func (c *Client) SetAccessToken(code string) error {
	param := map[string]string{"client_id": c.ID, "client_secret": c.Secret, "code": code}
	b, err := json.Marshal(param)
	if err != nil {
		return err
	}
	res, err := http.Post(AccessTokenURL, "application/json", bytes.NewReader(b))
	if err != nil {
		return err
	}
	m := map[string]string{}
	if err := parseResponse(res, &m); err != nil {
		return err
	}
	accessToken, prs := m[ParamKeyAccessToken]
	if !prs {
		return fmt.Errorf("could not get an access token. [response: %+v]", m)
	}
	c.AccessToken = accessToken
	return nil
}

// GetAuthenticatedUser gets the authenticated user and returns it.
func (c *Client) GetAuthenticatedUser() (*User, error) {
	if c.AccessToken == "" {
		return nil, fmt.Errorf("access token is not set to the client.")
	}
	res, err := http.Get(AuthenticatedUserURL + c.AccessTokenURLParam())
	if err != nil {
		return nil, err
	}
	u := &User{}
	if err := parseResponse(res, u); err != nil {
		return nil, err
	}
	return u, nil
}

// GetContents gets the contents of the specified path.
func (c *Client) GetContents(owner string, repo string, path string) (*Contents, error) {
	res, err := http.Get(fmt.Sprintf(GetContentsPath, owner, repo, path) + c.AccessTokenURLParam())
	if err != nil {
		return nil, err
	}
	contents := &Contents{}
	if err := parseResponse(res, contents); err != nil {
		return nil, err
	}
	return contents, nil
}

// GetContent gets the content of the specified path.
func (c *Client) GetContent(owner, repo, branch, path string) (string, error) {
	res, err := http.Get(fmt.Sprintf(GetContentPath, owner, repo, branch, path))
	if err != nil {
		return "", err
	}
	if code := res.StatusCode; code != http.StatusOK {
		return "", fmt.Errorf("response status code is not OK. [status code: %d]", code)
	}
	b, err := ioutil.ReadAll(res.Body)
	res.Body.Close()
	if err != nil {
		return "", err
	}
	return string(b), nil
}

// AccessTokenURLParam returns the access token url parameter.
func (c *Client) AccessTokenURLParam() string {
	if c.AccessToken == "" {
		return ""
	}
	return URLParamPrefix + ParamKeyAccessToken + "=" + c.AccessToken
}

// NewClient generates a client and returns it.
func NewClient(id string, secret string) *Client {
	return &Client{ID: id, Secret: secret}
}
<commit_msg>Updated client.go.<commit_after>package gogithub

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

// A Client represents a GitHub API client.
type Client struct {
	ID          string
	Secret      string
	AccessToken string
}

// SetAccessToken calls access token API, gets an access token and sets it to the client.
func (c *Client) SetAccessToken(code string) error {
	param := map[string]string{"client_id": c.ID, "client_secret": c.Secret, "code": code}
	b, err := json.Marshal(param)
	if err != nil {
		return err
	}
	res, err := http.Post(AccessTokenURL, "application/json", bytes.NewReader(b))
	if err != nil {
		return err
	}
	m := map[string]string{}
	if err := parseResponse(res, &m); err != nil {
		return err
	}
	accessToken, prs := m[ParamKeyAccessToken]
	if !prs {
		return fmt.Errorf("could not get an access token. [response: %+v]", m)
	}
	c.AccessToken = accessToken
	return nil
}

// GetAuthenticatedUser gets the authenticated user and returns it.
func (c *Client) GetAuthenticatedUser() (*User, error) {
	if c.AccessToken == "" {
		return nil, fmt.Errorf("access token is not set to the client.")
	}
	res, err := http.Get(AuthenticatedUserURL + c.AccessTokenURLParam())
	if err != nil {
		return nil, err
	}
	u := &User{}
	if err := parseResponse(res, u); err != nil {
		return nil, err
	}
	return u, nil
}

// GetContents gets the contents of the specified path.
func (c *Client) GetContents(owner string, repo string, path string) (*Contents, error) {
	res, err := http.Get(fmt.Sprintf(GetContentsPath, owner, repo, path) + c.AccessTokenURLParam())
	if err != nil {
		return nil, err
	}
	contents := &Contents{}
	if err := parseResponse(res, contents); err != nil {
		return nil, err
	}
	return contents, nil
}

// GetContent gets the content of the specified path.
func (c *Client) GetContent(owner, repo, branch, path string) (string, int, error) {
	res, err := http.Get(fmt.Sprintf(GetContentPath, owner, repo, branch, path))
	if err != nil {
		return "", 0, err
	}
	b, err := ioutil.ReadAll(res.Body)
	res.Body.Close()
	if err != nil {
		return "", res.StatusCode, err
	}
	return string(b), res.StatusCode, nil
}

// AccessTokenURLParam returns the access token url parameter.
func (c *Client) AccessTokenURLParam() string {
	if c.AccessToken == "" {
		return ""
	}
	return URLParamPrefix + ParamKeyAccessToken + "=" + c.AccessToken
}

// NewClient generates a client and returns it.
func NewClient(id string, secret string) *Client {
	return &Client{ID: id, Secret: secret}
}

{'fraction_non_alphanumeric': 0.13518770667185373, 'fraction_numerical': 0.00019451468585878233, 'mean_word_length': 3.9111747851002865, 'pattern_counts': {'":': 6, '<': 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': '7162379', 'n_tokens_mistral': 1743, 'n_tokens_neox': 1717, 'n_words': 569}