func New(config Config) (*PlugDJ, error) {
	if config.Log == nil {
		config.Log = log.New()
	}

	// make sure they gave us a valid email address
	if config.Email == "" {
		return nil, ErrAuthenticationRequired
	}

	// default base url
	if config.BaseURL == "" {
		config.BaseURL = "https://plug.dj"
	}

	// Double check the url...
	if _, err := url.Parse(config.BaseURL); err != nil {
		return nil, errors.New("plugapi: invalid url provided")
	}

	plug := &PlugDJ{
		config:     &config,
		Log:        config.Log,
		eventFuncs: make(map[Event]ProcessPayloadFunc),
		Room:       &Room{},
	}

	// a closer so that we can close any goroutines we have created
	plug.closer = make(chan struct{})

	// was this just used to uniquely get a fucking jar?!
	// hash := sha512.Sum512([]byte(config.Email + config.Password))
	// cookieHash := hex.EncodeToString(hash[:])
	// plug.Log.WithField("cookieHash", cookieHash).Info("from new")

	// create a cookie jar to make sure we can do further requests
	opts := cookiejar.Options{PublicSuffixList: publicsuffix.List}
	cookieJar, _ := cookiejar.New(&opts)

	// create our web client so that we can make REST requests
	plug.web = &http.Client{Jar: cookieJar}

	if err := plug.authenticateUser(); err != nil {
		return nil, err
	}

	plug.Log.Info("Running go-plugapi")
	return plug, nil
}
// New returns an authenticated User
New returns an authenticated User
// New returns an authenticated User
func New(config Config) (*PlugDJ, error) {
	if config.Log == nil {
		config.Log = log.New()
	}
	if config.Email == "" {
		return nil, ErrAuthenticationRequired
	}
	if config.BaseURL == "" {
		config.BaseURL = "https://plug.dj"
	}
	if _, err := url.Parse(config.BaseURL); err != nil {
		return nil, errors.New("plugapi: invalid url provided")
	}
	plug := &PlugDJ{
		config:     &config,
		Log:        config.Log,
		eventFuncs: make(map[Event]ProcessPayloadFunc),
		Room:       &Room{},
	}
	plug.closer = make(chan struct{})
	opts := cookiejar.Options{PublicSuffixList: publicsuffix.List}
	cookieJar, _ := cookiejar.New(&opts)
	plug.web = &http.Client{Jar: cookieJar}
	if err := plug.authenticateUser(); err != nil {
		return nil, err
	}
	plug.Log.Info("Running go-plugapi")
	return plug, nil
}
func New ( config Config ) ( * PlugDJ , error ) { if config . Log == nil { config . Log = log . New ( ) } if config . Email == " " { return nil , ErrAuthenticationRequired } if config . BaseURL == " " { config . BaseURL = " " } if _ , err := url . Parse ( config . BaseURL ) ; err != nil { return nil , errors . New ( " " ) } plug := & PlugDJ { config : & config , Log : config . Log , eventFuncs : make ( map [ Event ] ProcessPayloadFunc ) , Room : & Room { } , } plug . closer = make ( chan struct { } ) opts := cookiejar . Options { PublicSuffixList : publicsuffix . List } cookieJar , _ := cookiejar . New ( & opts ) plug . web = & http . Client { Jar : cookieJar } if err := plug . authenticateUser ( ) ; err != nil { return nil , err } plug . Log . Info ( " " ) return plug , nil }
New returns an authenticated User
New returns an authenticated User
// make sure they gave us a valid email address // default base url // Double check the url... // a closer so that we can close any goroutines we have created // was this just used to uniquely get a fucking jar?! // hash := sha512.Sum512([]byte(config.Email + config.Password)) // cookieHash := hex.EncodeToString(hash[:]) // plug.Log.WithField("cookieHash", cookieHash).Info("from new") // create a cookie jar to make sure we can do further requests // create our web client so that we can make REST requests