示例#1
0
// Return an existing device client given a deviceId
func NewDeviceClient(c *api.Client, deviceId string) (*DeviceClient, error) {
	body, _, err := c.GetDeviceMetadata(deviceId)
	if err != nil {
		return nil, err
	}
	device := Device{}
	err = json.Unmarshal(body, &device)
	return &DeviceClient{c, device}, err
}
示例#2
0
// Retrieve a list of SharedFolder member descriptors
// TODO : Should an Etag be return for each one?
func ListSharedFolders(c *api.Client, sid string, etags []string) ([]SharedFolder, error) {
	body, _, err := c.ListSharedFolders(sid, etags)
	if err != nil {
		return nil, err
	}
	sfs := []SharedFolder{}
	err = json.Unmarshal(body, &sfs)
	if err != nil {
		return nil, errors.New("Unable to demarshal the list of retrieved SharedFolders")
	}
	return sfs, nil
}
示例#3
0
// List all groups
func ListGroups(c *api.Client, offset, results int) (*[]Group, error) {
	body, _, err := c.ListGroups(offset, results)
	if err != nil {
		return nil, err
	}
	groups := []Group{}
	err = json.Unmarshal(body, &groups)
	if err != nil {
		return nil, errors.New("Unable to unmarshal list of groups")
	}

	return &groups, nil
}
示例#4
0
// Return an existing SFMemberClient given its shared folder and user email
func GetSFMemberClient(c *api.Client, sid, email string, etags []string) (*SFMemberClient, error) {
	body, header, err := c.GetSFMember(sid, email, etags)
	if err != nil {
		return nil, err
	}
	sfmClient := SFMemberClient{APIClient: c, Etag: header.Get("ETag"), Desc: SFMember{Sid: sid, Email: email}}
	err = json.Unmarshal(body, &sfmClient.Desc)
	if err != nil {
		return nil, errors.New("Unable to unmarshal retrieved SFMember")
	}

	return &sfmClient, nil
}
示例#5
0
// Retrieve a list of existing Device descriptors
func ListDevices(c *api.Client, email string) ([]Device, error) {
	body, _, err := c.ListDevices(email)
	if err != nil {
		return nil, err
	}

	devices := []Device{}
	err = json.Unmarshal(body, &devices)
	if err != nil {
		return nil, errors.New("Unable to demarshal list of devices")
	}
	return devices, err
}
示例#6
0
// Retrieve an existing shared folder
func GetSharedFolderClient(c *api.Client, sid string, etags []string) (*SharedFolderClient, error) {
	body, header, err := c.ListSharedFolderMetadata(sid, etags)
	if err != nil {
		return nil, err
	}
	sfClient := SharedFolderClient{APIClient: c}
	err = json.Unmarshal(body, &sfClient.Desc)
	if err != nil {
		return nil, errors.New("Unable to unmarshal retrieved Shared Folder")
	}
	sfClient.Etag = header.Get("ETag")
	return &sfClient, nil
}
示例#7
0
// Get a list of existing user descriptors
func ListUsers(client *api.Client, limit int) (*[]User, error) {
	body, _, err := client.ListUsers(limit, nil, nil)
	if err != nil {
		return nil, err
	}

	userResp := userListResponse{}
	err = json.Unmarshal(body, &userResp)
	if err != nil {
		return nil, errors.New("Unable to unmarshal a retrieved list of users")
	}
	return &userResp.Users, nil
}
示例#8
0
// Create a group
func CreateGroupClient(c *api.Client, groupName string) (*GroupClient, error) {
	body, _, err := c.CreateGroup(groupName)
	if err != nil {
		return nil, err
	}

	g := GroupClient{APIClient: c}
	err = json.Unmarshal(body, &g.Desc)
	if err != nil {
		return nil, errors.New("Unable to unmarshal created group")
	}

	return &g, nil
}
示例#9
0
// Retrieve an existing group
func NewGroupClient(c *api.Client, groupId string) (*GroupClient, error) {
	body, _, err := c.GetGroup(groupId)
	if err != nil {
		return nil, err
	}

	g := GroupClient{APIClient: c}
	err = json.Unmarshal(body, &g.Desc)
	if err != nil {
		return nil, errors.New("Unable to unmarshal existing group")
	}

	return &g, nil
}
示例#10
0
// Create a new shared folder and return a client associated with it
func CreateSharedFolderClient(c *api.Client, name string) (*SharedFolderClient, error) {
	body, _, err := c.CreateSharedFolder(name)
	if err != nil {
		return nil, err
	}

	sfClient := SharedFolderClient{APIClient: c}
	err = json.Unmarshal(body, &sfClient.Desc)
	if err != nil {
		return nil, errors.New("Unable to unmarshal retrieved SharedFolder")
	}

	return &sfClient, nil
}
示例#11
0
// Create a new user and return a UserClient tied to the APIClient argument
func CreateUserClient(client *api.Client, email, firstName, lastName string) (*UserClient, error) {
	body, _, err := client.CreateUser(email, firstName, lastName)
	if err != nil {
		return nil, err
	}

	u := User{}
	err = json.Unmarshal(body, &u)
	if err != nil {
		return nil, errors.New("Unable to unmarshal new User")
	}

	return &UserClient{client, u}, nil
}
示例#12
0
// Retrieve a list of SharedFolder member descriptors
// TOD : Should an Etag be return for each one?
func ListSFMember(c *api.Client, sid string, etags []string) ([]SFMember, error) {
	body, _, err := c.ListSFMembers(sid, etags)
	if err != nil {
		return nil, err
	}
	sfmembers := []SFMember{}
	err = json.Unmarshal(body, &sfmembers)
	if err != nil {
		return nil, errors.New("Unable to demarshal the list of retrieved SharedFolder members")
	}
	for _, v := range sfmembers {
		v.Sid = sid
	}
	return sfmembers, nil
}
示例#13
0
// Construct a FileClient given a file identifier and APIClient
func NewFileClient(c *api.Client, fileId string, fields []string) (*FileClient, error) {
	body, header, err := c.GetFileMetadata(fileId, fields)
	if err != nil {
		return nil, err
	}

	f := FileClient{APIClient: c, OnDemand: fields}
	err = json.Unmarshal(body, &f.Desc)

	if err != nil {
		return nil, errors.New("Unable to unmarshal existing File")
	}
	f.Desc.Etag = header.Get("ETag")
	return &f, nil
}
示例#14
0
// Given an existing user's email, return a client for said user
func GetUserClient(client *api.Client, email string) (*UserClient, error) {
	body, _, err := client.GetUser(email)
	if err != nil {
		return nil, err
	}

	u := UserClient{APIClient: client}
	err = json.Unmarshal(body, &u.Desc)
	if err != nil {
		fmt.Println(err)
		return nil, errors.New("Unable to unmarshal new User")
	}

	return &u, nil
}