package lib

import (
	"encoding/json"
	"io/ioutil"
	"log"
	"net/http"
)

func curl(auth string) *UserData {

	req, err := http.NewRequest("POST", "http://208.97.141.22/api/sign/user_data", nil)

	if err != nil {
		return nil
	}

	req.Header.Set("Auth", auth)

	resp, err := http.DefaultClient.Do(req)

	if err != nil {
		log.Print(err)
		return nil
	}

	defer resp.Body.Close()

	body, _ := ioutil.ReadAll(resp.Body)

	// debug only
	//s := string(body[:])
	//fmt.Println(s)

	var userData UserData

	err = json.Unmarshal(body, &userData)

	//fmt.Printf("%+v\n", userData)

	if err != nil {
		log.Print(err)
		return nil
	}

	if len(userData.Errors) > 0 {
		return nil
	}

	return &userData
}
