<commit_before>package main

import (
    "appengine"
    "appengine/urlfetch"
    "net/http"
    "io/ioutil"
    "errors"
    "encoding/json"
    "regexp"
)

type VineRequest struct {
	Context appengine.Context
}

const (
    VINE_API = "https://api.vineapp.com"
)

func (v *VineRequest) get(url string) (map[string]interface{}, error) {
	if v.Context == nil {
		return nil, errors.New("Google AppEngine Context Required")
	} else {
		c := v.Context
		client := urlfetch.Client(c)
		req, _ := http.NewRequest("GET", VINE_API + url, nil)
		req.Header.Set("x-vine-client", "vinewww/1.0")
		resp, err := client.Do(req)
		if err == nil {
			jsonData, _ := ioutil.ReadAll(resp.Body)
			var data interface{}
			err = json.Unmarshal(jsonData, &data)
			d := data.(map[string]interface{})
			return d["data"].(map[string]interface{}), nil
		} else {
			return nil, err
		}
	}
}

func (v *VineRequest) GetUser(userId string) (map[string]interface{}, error) {
    url := "/users/profiles/"
    match, _ := regexp.MatchString("[0-9]+", userId)
    
    if match {
        url += userId   
    } else {
        url += "vanity/" + userId   
    }
    
    data, err := v.get(url)<commit_msg>Added nonexistent user error handling.<commit_after>package main

import (
    "appengine"
    "appengine/urlfetch"
    "net/http"
    "io/ioutil"
    "errors"
    "encoding/json"
    "regexp"
)

type VineRequest struct {
	Context appengine.Context
}

var (
    ErrUserDoesntExist = errors.New("That record doesn't exist.")
)

const (
    VINE_API = "https://api.vineapp.com"
)

func (v *VineRequest) get(url string) (map[string]interface{}, error) {
	if v.Context == nil {
		return nil, errors.New("Google AppEngine Context Required")
	} else {
		c := v.Context
		client := urlfetch.Client(c)
		req, _ := http.NewRequest("GET", VINE_API + url, nil)
		req.Header.Set("x-vine-client", "vinewww/1.0")
		resp, err := client.Do(req)
		if err == nil {
			jsonData, _ := ioutil.ReadAll(resp.Body)
			var data interface{}
			err = json.Unmarshal(jsonData, &data)
			d := data.(map[string]interface{})
			 if d["success"].(bool) {
			    return d["data"].(map[string]interface{}), nil
			 } else {
			    return nil, errors.New(d["error"].(string))
			 }
		} else {
			return nil, err
		}
	}
}

func (v *VineRequest) GetUser(userId string) (map[string]interface{}, error) {
    url := "/users/profiles/"
    match, _ := regexp.MatchString("[0-9]+", userId)

    if match {
        url += userId   
    } else {
        url += "vanity/" + userId   
    }
    
    data, err := v.get(url)
{'fraction_non_alphanumeric': 0.16542823621431366, 'fraction_numerical': 0.003128666405944466, 'mean_word_length': 2.9353846153846153, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '702939', 'n_tokens_mistral': 979, 'n_tokens_neox': 919, 'n_words': 199}