示例#1
0
func main() {

	flag.Parse()

	if flag.NFlag() == 0 {
		flag.PrintDefaults()
	}

	if _, err := os.Stat(*filePath); os.IsNotExist(err) {
		//panic("File doesn't exist")
		fmt.Println("File doesn't exist")
		os.Exit(-1)
	}

	// Take all the necessary data
	appToken := os.Getenv("APP_TOKEN")
	appSecret := os.Getenv("APP_SECRET")
	accessToken := os.Getenv("ACCESS_TOKEN")
	accessSecret := os.Getenv("ACCESS_SECRET")

	// Create the client
	client, _ := copy.NewDefaultClient(appToken, appSecret, accessToken, accessSecret)
	fs := copy.NewFileService(client)
	fmt.Println(fs.UploadFile(*filePath, *uploadPath, true))
	os.Exit(0)
}
示例#2
0
func main() {

	flag.Parse()

	if flag.NFlag() == 0 {
		flag.PrintDefaults()
		os.Exit(-1)
	}

	// Take all the necessary data
	appToken := os.Getenv("APP_TOKEN")
	appSecret := os.Getenv("APP_SECRET")
	accessToken := os.Getenv("ACCESS_TOKEN")
	accessSecret := os.Getenv("ACCESS_SECRET")

	client, _ := copy.NewDefaultClient(appToken, appSecret, accessToken, accessSecret)
	fs := copy.NewFileService(client)

	r, _ := fs.GetFile(*downloadPath)
	fileBytes, _ := ioutil.ReadAll(r)

	err := ioutil.WriteFile(*writePath, fileBytes, 0644)
	if err != nil {
		panic(err)
	}
}
示例#3
0
func main() {
	//Prepare the neccesary data
	appToken := os.Getenv("APP_TOKEN")
	appSecret := os.Getenv("APP_SECRET")
	accessToken := os.Getenv("ACCESS_TOKEN")
	accessSecret := os.Getenv("ACCESS_SECRET")

	// Create the client
	client, err := copy.NewDefaultClient(appToken, appSecret, accessToken, accessSecret)
	if err != nil {
		fmt.Fprint(os.Stderr, "Could not create the client, review the auth params")
		os.Exit(-1)
	}

	//Create the service (in this case for a user)
	userService := copy.NewUserService(client)

	//Play with the lib :)
	user, err := userService.Get()
	if err != nil {
		fmt.Fprint(os.Stderr, "Could not retrieve the user")
		os.Exit(-1)
	}

	byteToMegabyte := math.Pow(1024, 2)
	fmt.Printf("User: %v %v\n", user.FirstName, user.LastName)
	fmt.Printf("Email: %v\n", user.Email)
	fmt.Printf("Stored(MB): %G of %G\n",
		float64(user.Storage.Used)/byteToMegabyte, float64(user.Storage.Quota)/byteToMegabyte)

	// We are going to change the name
	fmt.Println("Inser name: ")
	fmt.Scan(&(user.FirstName))
	fmt.Println("Inser surname: ")
	fmt.Scan(&(user.LastName))

	err = userService.Update(user)
	if err != nil {
		fmt.Fprint(os.Stderr, "Could not update the user")
		os.Exit(-1)
	}

	// Get again the user
	user, err = userService.Get()
	if err != nil {
		fmt.Fprint(os.Stderr, "Could not retrieve the user")
		os.Exit(-1)
	}
	fmt.Printf("User: %v %v\n", user.FirstName, user.LastName)

}