forked from Esri/arcgis-rest-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into add-ssl-flag
- Loading branch information
Showing
26 changed files
with
899 additions
and
698 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
|
||
import { | ||
request, | ||
IRequestOptions, | ||
getPortalUrl | ||
} from "@esri/arcgis-rest-request"; | ||
|
||
import { IGroupAdd } from "@esri/arcgis-rest-common-types"; | ||
|
||
import { serializeGroup } from "./helpers"; | ||
|
||
export interface IGroupAddRequestOptions extends IRequestOptions { | ||
group: IGroupAdd; | ||
} | ||
|
||
/** | ||
* Create a new Group. | ||
* Note: The group name must be unique within the user's organization. | ||
* @param requestOptions - Options for the request, including a group object | ||
* @returns A Promise that will resolve with the success/failure status of the request | ||
*/ | ||
export function createGroup( | ||
requestOptions: IGroupAddRequestOptions | ||
): Promise<any> { | ||
const url = `${getPortalUrl(requestOptions)}/community/createGroup`; | ||
const options: IGroupAddRequestOptions = { | ||
...requestOptions | ||
}; | ||
// serialize the group into something Portal will accept | ||
options.params = serializeGroup(requestOptions.group); | ||
return request(url, options); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
|
||
import { | ||
request, | ||
IRequestOptions, | ||
getPortalUrl | ||
} from "@esri/arcgis-rest-request"; | ||
|
||
import { IPagingParams, IGroup, IItem } from "@esri/arcgis-rest-common-types"; | ||
|
||
export interface IPagingParamsRequestOptions extends IRequestOptions { | ||
paging: IPagingParams; | ||
} | ||
|
||
export interface IGroupContentResult { | ||
total: number; | ||
start: number; | ||
num: number; | ||
nextStart: number; | ||
items: IItem[]; | ||
} | ||
|
||
export interface IGroupUsersResult { | ||
owner: string; | ||
admins: string[]; | ||
users: string[]; | ||
} | ||
|
||
/** | ||
* | ||
* @param id - Group Id | ||
* @param requestOptions - Options for the request | ||
* @returns A Promise that will resolve with the data from the response. | ||
*/ | ||
export function getGroup( | ||
id: string, | ||
requestOptions?: IRequestOptions | ||
): Promise<IGroup> { | ||
const url = `${getPortalUrl(requestOptions)}/community/groups/${id}`; | ||
// default to a GET request | ||
const options: IRequestOptions = { | ||
...{ httpMethod: "GET" }, | ||
...requestOptions | ||
}; | ||
return request(url, options); | ||
} | ||
|
||
/** | ||
* Returns the content of a Group. Since the group may contain 1000s of items | ||
* the requestParams allow for paging. | ||
* @param id - Group Id | ||
* @param requestOptions - Options for the request, including paging parameters. | ||
* @returns A Promise that will resolve with the content of the group. | ||
*/ | ||
export function getGroupContent( | ||
id: string, | ||
requestOptions?: IPagingParamsRequestOptions | ||
): Promise<IGroup> { | ||
const url = `${getPortalUrl(requestOptions)}/content/groups/${id}`; | ||
|
||
// default to a GET request | ||
const options: IRequestOptions = { | ||
...{ httpMethod: "GET" }, | ||
params: { start: 1, num: 100 }, | ||
...requestOptions | ||
} as IPagingParamsRequestOptions; | ||
|
||
// is this the most concise way to mixin with the defaults above? | ||
if (requestOptions && requestOptions.paging) { | ||
options.params = { ...requestOptions.paging }; | ||
} | ||
|
||
return request(url, options); | ||
} | ||
|
||
/** | ||
* Get the usernames of the admins and members. Does not return actual 'User' objects. Those must be | ||
* retrieved via separate calls to the User's API. | ||
* @param id - Group Id | ||
* @param requestOptions - Options for the request | ||
* @returns A Promise that will resolve with arrays of the group admin usernames and the member usernames | ||
*/ | ||
export function getGroupUsers( | ||
id: string, | ||
requestOptions?: IRequestOptions | ||
): Promise<IGroupUsersResult> { | ||
const url = `${getPortalUrl(requestOptions)}/community/groups/${id}/users`; | ||
// default to a GET request | ||
const options: IRequestOptions = { | ||
...{ httpMethod: "GET" }, | ||
...requestOptions | ||
}; | ||
return request(url, options); | ||
} |
Oops, something went wrong.