Skip to content

Commit

Permalink
avatar api updates
Browse files Browse the repository at this point in the history
  • Loading branch information
MrRefactoring committed Oct 14, 2023
1 parent 9cc1695 commit 860874c
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 25 deletions.
25 changes: 17 additions & 8 deletions examples/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"license": "MIT",
"devDependencies": {
"@types/node": "^20.8.2",
"@types/node": "^20.8.6",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
},
Expand Down
33 changes: 25 additions & 8 deletions src/version2/avatars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export class Avatars {
y: parameters.y,
size: parameters.size,
},
data: parameters.avatar,
};

return this.client.sendRequest(config, callback);
Expand Down Expand Up @@ -172,7 +173,7 @@ export class Avatars {
*
* **[Permissions](https://developer.atlassian.com/cloud/jira/platform/rest/v2/intro/#permissions) required:** None.
*/
async getAvatarImageByType<T = unknown>(
async getAvatarImageByType<T = Models.AvatarWithDetails>(
parameters: Parameters.GetAvatarImageByType | string,
callback: Callback<T>,
): Promise<void>;
Expand All @@ -183,11 +184,11 @@ export class Avatars {
*
* **[Permissions](https://developer.atlassian.com/cloud/jira/platform/rest/v2/intro/#permissions) required:** None.
*/
async getAvatarImageByType<T = unknown>(
async getAvatarImageByType<T = Models.AvatarWithDetails>(
parameters: Parameters.GetAvatarImageByType | string,
callback?: never,
): Promise<T>;
async getAvatarImageByType<T = unknown>(
async getAvatarImageByType<T = Models.AvatarWithDetails>(
parameters: Parameters.GetAvatarImageByType | string,
callback?: Callback<T>,
): Promise<void | T> {
Expand All @@ -196,13 +197,21 @@ export class Avatars {
const config: RequestConfig = {
url: `/rest/api/2/universal_avatar/view/type/${type}`,
method: 'GET',
responseType: 'arraybuffer',
params: {
size: typeof parameters !== 'string' && parameters.size,
format: typeof parameters !== 'string' && parameters.format,
},
};

return this.client.sendRequest(config, callback);
const {
data: avatar,
headers: { 'content-type': contentTypeWithEncoding },
} = await this.client.sendRequestFullResponse<T>(config);

const contentType = contentTypeWithEncoding.split(';')[0].trim();

return this.client.handleSuccessResponse({ contentType, avatar }, callback);
}

/**
Expand Down Expand Up @@ -276,7 +285,7 @@ export class Avatars {
* - For custom issue type avatars, _Browse projects_ [project permission](https://confluence.atlassian.com/x/yodKLg)
* for at least one project the issue type is used in.
*/
async getAvatarImageByOwner<T = unknown>(
async getAvatarImageByOwner<T = Models.AvatarWithDetails>(
parameters: Parameters.GetAvatarImageByOwner,
callback: Callback<T>,
): Promise<void>;
Expand All @@ -293,20 +302,28 @@ export class Avatars {
* - For custom issue type avatars, _Browse projects_ [project permission](https://confluence.atlassian.com/x/yodKLg)
* for at least one project the issue type is used in.
*/
async getAvatarImageByOwner<T = unknown>(parameters: Parameters.GetAvatarImageByOwner, callback?: never): Promise<T>;
async getAvatarImageByOwner<T = unknown>(
async getAvatarImageByOwner<T = Models.AvatarWithDetails>(parameters: Parameters.GetAvatarImageByOwner, callback?: never): Promise<T>;
async getAvatarImageByOwner<T = Models.AvatarWithDetails>(
parameters: Parameters.GetAvatarImageByOwner,
callback?: Callback<T>,
): Promise<void | T> {
const config: RequestConfig = {
url: `/rest/api/2/universal_avatar/view/type/${parameters.type}/owner/${parameters.entityId}`,
method: 'GET',
responseType: 'arraybuffer',
params: {
size: parameters.size,
format: parameters.format,
},
};

return this.client.sendRequest(config, callback);
const {
data: avatar,
headers: { 'content-type': contentTypeWithEncoding },
} = await this.client.sendRequestFullResponse<T>(config);

const contentType = contentTypeWithEncoding.split(';')[0].trim();

return this.client.handleSuccessResponse({ contentType, avatar }, callback);
}
}
1 change: 1 addition & 0 deletions src/version2/parameters/storeAvatar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export interface StoreAvatar {
y?: number;
/** The length of each side of the crop region. */
size: number;
avatar: any;
}
33 changes: 25 additions & 8 deletions src/version3/avatars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export class Avatars {
y: parameters.y,
size: parameters.size,
},
data: parameters.avatar,
};

return this.client.sendRequest(config, callback);
Expand Down Expand Up @@ -172,7 +173,7 @@ export class Avatars {
*
* **[Permissions](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#permissions) required:** None.
*/
async getAvatarImageByType<T = unknown>(
async getAvatarImageByType<T = Models.AvatarWithDetails>(
parameters: Parameters.GetAvatarImageByType | string,
callback: Callback<T>,
): Promise<void>;
Expand All @@ -183,11 +184,11 @@ export class Avatars {
*
* **[Permissions](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#permissions) required:** None.
*/
async getAvatarImageByType<T = unknown>(
async getAvatarImageByType<T = Models.AvatarWithDetails>(
parameters: Parameters.GetAvatarImageByType | string,
callback?: never,
): Promise<T>;
async getAvatarImageByType<T = unknown>(
async getAvatarImageByType<T = Models.AvatarWithDetails>(
parameters: Parameters.GetAvatarImageByType | string,
callback?: Callback<T>,
): Promise<void | T> {
Expand All @@ -196,13 +197,21 @@ export class Avatars {
const config: RequestConfig = {
url: `/rest/api/3/universal_avatar/view/type/${type}`,
method: 'GET',
responseType: 'arraybuffer',
params: {
size: typeof parameters !== 'string' && parameters.size,
format: typeof parameters !== 'string' && parameters.format,
},
};

return this.client.sendRequest(config, callback);
const {
data: avatar,
headers: { 'content-type': contentTypeWithEncoding },
} = await this.client.sendRequestFullResponse<T>(config);

const contentType = contentTypeWithEncoding.split(';')[0].trim();

return this.client.handleSuccessResponse({ contentType, avatar }, callback);
}

/**
Expand Down Expand Up @@ -276,7 +285,7 @@ export class Avatars {
* - For custom issue type avatars, _Browse projects_ [project permission](https://confluence.atlassian.com/x/yodKLg)
* for at least one project the issue type is used in.
*/
async getAvatarImageByOwner<T = unknown>(
async getAvatarImageByOwner<T = Models.AvatarWithDetails>(
parameters: Parameters.GetAvatarImageByOwner,
callback: Callback<T>,
): Promise<void>;
Expand All @@ -293,20 +302,28 @@ export class Avatars {
* - For custom issue type avatars, _Browse projects_ [project permission](https://confluence.atlassian.com/x/yodKLg)
* for at least one project the issue type is used in.
*/
async getAvatarImageByOwner<T = unknown>(parameters: Parameters.GetAvatarImageByOwner, callback?: never): Promise<T>;
async getAvatarImageByOwner<T = unknown>(
async getAvatarImageByOwner<T = Models.AvatarWithDetails>(parameters: Parameters.GetAvatarImageByOwner, callback?: never): Promise<T>;
async getAvatarImageByOwner<T = Models.AvatarWithDetails>(
parameters: Parameters.GetAvatarImageByOwner,
callback?: Callback<T>,
): Promise<void | T> {
const config: RequestConfig = {
url: `/rest/api/3/universal_avatar/view/type/${parameters.type}/owner/${parameters.entityId}`,
method: 'GET',
responseType: 'arraybuffer',
params: {
size: parameters.size,
format: parameters.format,
},
};

return this.client.sendRequest(config, callback);
const {
data: avatar,
headers: { 'content-type': contentTypeWithEncoding },
} = await this.client.sendRequestFullResponse<T>(config);

const contentType = contentTypeWithEncoding.split(';')[0].trim();

return this.client.handleSuccessResponse({ contentType, avatar }, callback);
}
}
1 change: 1 addition & 0 deletions src/version3/parameters/storeAvatar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export interface StoreAvatar {
y?: number;
/** The length of each side of the crop region. */
size: number;
avatar: any;
}

0 comments on commit 860874c

Please sign in to comment.