Exemple #1
0
func main() {
	dropbox.Debug = true

	client, err := dropbox.NewClient(dropbox.ClientOptions{
		Key:    config.Application.Key,
		Secret: config.Application.Secret,
		Token:  config.BearerToken.Token,
		Uid:    config.BearerToken.UserId,
		Root:   "sandbox",
	})

	failIf(err)

	datastoreManager := client.GetDatastoreManager()

	{ // demo OpenDefaultDatastore
		println("calling datastoreManager.OpenDefaultDatastore")
		ds, err := datastoreManager.OpenDefaultDatastore()
		failIf(err)
		spew.Dump(ds)
		print("\n\n")
	}

	{ // demo ListDatastores
		println("calling datastoreManager.ListDatastores")
		infos, err := datastoreManager.ListDatastores()
		failIf(err)
		spew.Dump(infos)
		print("\n\n")
	}

	{ // demo DeleteDatastore
		println("calling datastoreManager.DeleteDatastore")
		err = datastoreManager.DeleteDatastore("default")
		failIf(err)
		print("\n\n")
	}

	{ // demo CreateDatastore and DeleteDatastore
		println("calling datastoreManager.CreateDatastore")
		ds, err := datastoreManager.CreateDatastore()
		failIf(err)
		spew.Dump(ds)

		println("calling datastoreManager.DeleteDatastore")
		err = datastoreManager.DeleteDatastore(ds.GetId())
		failIf(err)

		print("\n\n")
	}

	println("DatastoreManager smoke test finished!")
}
Exemple #2
0
func newClient() dropbox.Client {
	c, e := dropbox.NewClient(dropbox.ClientOptions{
		Key:    config.Application.Key,
		Secret: config.Application.Secret,
		Token:  config.BearerToken.Token,
		Uid:    config.BearerToken.UserId,
		Root:   "sandbox",
	})

	failIf(e)

	return c
}
func main() {
	dropbox.Debug = true

	// Available Root:
	// Expected 'root' to be 'dropbox', 'sandbox', or 'auto'
	client, err := dropbox.NewClient(dropbox.ClientOptions{
		Key:    "my_app_key",
		Secret: "my_app_secret",
		Token:  "my_acess_token-wcaqw",
		Uid:    "my_user_id",
		Root:   "dropbox",
	})

	failIf(err)

	{ // demo GetAccountInfo
		println("calling client.GetAccountInfo")
		info, err := client.GetAccountInfo()
		failIf(err)
		spew.Dump(info)
		print("\n\n")
	}

	{ // demo Mkdir, ReadDir and Delete
		const path = "hello-directory"

		println("calling client.Mkdir")
		stat, err := client.Mkdir(path)
		failIf(err)
		spew.Dump(stat)

		println("calling client.Mkdir (again)")
		stat, err = client.Mkdir(path + "/foobar")
		failIf(err)
		spew.Dump(stat)

		// println("calling client.Copy")
		// stat, err = client.Copy(path+"/foobar", path+"/binbar")
		// failIf(err)
		// spew.Dump(stat)

		// println("calling client.Stat")
		// stat, err = client.Stat(path, nil)
		// failIf(err)
		// spew.Dump(stat)

		// println("calling client.ReadDir")
		// entryNames, dirStat, entryStats, err := client.ReadDir(path, nil)
		// failIf(err)
		// spew.Dump(entryNames, dirStat, entryStats)

		// println("calling client.Delete")
		// stat, err = client.Delete(path)
		// failIf(err)
		// spew.Dump(stat)

		print("\n\n")
	}

	{ // demo WriteFile, Stat, ReadFile and Delete
		const path = "hello-file"

		file, err := ioutil.TempFile(os.TempDir(), "dropbox-sdk-go")
		failIf(err)
		defer func(f *os.File) {
			f.Close()
			failIf(os.Remove(f.Name()))
		}(file)

		{ // write to local tempfile;
			_, err = file.WriteString("Hello World!\n")
			failIf(err)

			_, err = file.Seek(0, 0)
			failIf(err)
			failIf(file.Sync())
		}

		println("calling client.WriteFile")
		stat, err := client.WriteFile(path, file, nil)
		failIf(err)
		spew.Dump(stat)

		println("calling client.Stat")
		stat, err = client.Stat(path, nil)
		failIf(err)
		spew.Dump(stat)

		println("calling client.ReadFile")
		var buffer bytes.Buffer
		stat, err = client.ReadFile(path, &buffer, nil)
		failIf(err)
		printf("File contents: %s", buffer.Bytes())
		spew.Dump(stat)

		// println("calling client.Delete")
		// stat, err = client.Delete(path)
		// failIf(err)
		// spew.Dump(stat)

		print("\n\n")
	}

	println("Client smoke test finished!")
}
Exemple #4
0
func main() {
	client, err := dropbox.NewClient(dropbox.ClientOptions{
		Key:    config.Application.Key,
		Secret: config.Application.Secret,
		Token:  config.BearerToken.Token,
		Uid:    config.BearerToken.UserId,
		Root:   "sandbox",
	})

	failIf(err)

	{ // demo GetAccountInfo
		println("calling client.GetAccountInfo")
		info, err := client.GetAccountInfo()
		failIf(err)
		spew.Dump(info)
		print("\n\n")
	}

	{ // demo Mkdir, ReadDir and Delete
		const path = "hello-directory"

		println("calling client.Mkdir")
		stat, err := client.Mkdir(path)
		failIf(err)
		spew.Dump(stat)

		println("calling client.Mkdir (again)")
		stat, err = client.Mkdir(path + "/foobar")
		failIf(err)
		spew.Dump(stat)

		println("calling client.Copy")
		stat, err = client.Copy(path+"/foobar", path+"/binbar")
		failIf(err)
		spew.Dump(stat)

		println("calling client.Stat")
		stat, err = client.Stat(path, nil)
		failIf(err)
		spew.Dump(stat)

		println("calling client.ReadDir")
		entryNames, dirStat, entryStats, err := client.ReadDir(path, nil)
		failIf(err)
		spew.Dump(entryNames, dirStat, entryStats)

		println("calling client.Delete")
		stat, err = client.Delete(path)
		failIf(err)
		spew.Dump(stat)

		print("\n\n")
	}

	{ // demo WriteFile, Stat, ReadFile and Delete
		const path = "hello-file"

		file, err := ioutil.TempFile(os.TempDir(), "dropbox-sdk-go")
		failIf(err)
		defer func(f *os.File) {
			f.Close()
			failIf(os.Remove(f.Name()))
		}(file)

		{ // write to local tempfile;
			_, err = file.WriteString("Hello World!\n")
			failIf(err)

			_, err = file.Seek(0, 0)
			failIf(err)
			failIf(file.Sync())
		}

		println("calling client.WriteFile")
		stat, err := client.WriteFile(path, file, nil)
		failIf(err)
		spew.Dump(stat)

		println("calling client.Stat")
		stat, err = client.Stat(path, nil)
		failIf(err)
		spew.Dump(stat)

		println("calling client.ReadFile")
		var buffer bytes.Buffer
		stat, err = client.ReadFile(path, &buffer, nil)
		failIf(err)
		printf("File contents: %s", buffer.Bytes())
		spew.Dump(stat)

		println("calling client.Delete")
		stat, err = client.Delete(path)
		failIf(err)
		spew.Dump(stat)

		print("\n\n")
	}

	println("Client smoke test finished!")
}