Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #36 from aerogear/AEROGEAR-10241
Browse files Browse the repository at this point in the history
Added app rename feature
  • Loading branch information
ziccardi authored Apr 16, 2020
2 parents 8574d16 + 2f80ba1 commit e79e598
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ const app = upsadm.applications.create('newApp')
```
The returned `app` object will have all the `id` and `pushApplicationId` fields populated by the server.

To rename an application we will use the `rename` method:

```typescript
const apps = upsadm.applications.rename(appId, newName)
```

#### Managing variants

All the methods to be used to manage variants can be found inside the `variants` namespace.
Expand All @@ -106,11 +112,22 @@ The find method takes as parameter the owner application id and, optionally, a f
**NOTE** You are not limited to use only one key when filtering: if more than one is specified, they are all applied. The only
exception is the `id` filter: if the `id` is specified, all the other filters are ignored.

To create an variant we will use the `create` method:
To create a variant we will use the `create` method:
```typescript
const newVariant: AndroidVariant = {
...
};
const variant = upsadm.variants.create(appId, newVariant)
```
The returned `variant` object will have all the `id` fields populated by the server.

To delete variants, we will use the `delete` method:

```typescript
const apps = upsadm.variants.delete(appId, filter)
```

The `delete` method takes as parameter the owner application id and, optionally, a filter parameter. The filter is optional
and has the same syntax as the filter used to find variants.

All the variants matching the filter will be deleted.
2 changes: 1 addition & 1 deletion 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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aerogear/unifiedpush-admin-client",
"version": "0.1.6",
"version": "0.1.7",
"description": "Client library used to admin UPS with code",
"author": "AeroGear Team<aerogear@googlegroups.com>",
"homepage": "http://aerogear.org",
Expand Down
15 changes: 14 additions & 1 deletion src/UnifiedPushAdminClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,22 @@ export class UnifiedPushAdminClient {
this.applicationsAdmin.find(await this.auth(), filter),
/**
* Creates an application in the UPS
* @param app the application to be created
* @param name the name of the application to be created
*/
create: async (name: string): Promise<PushApplication> => this.applicationsAdmin.create(await this.auth(), name),

/**
* Rename an application
* @param pushApplicationID id of the app to be renamed
* @param newName
*/
rename: async (pushApplicationID: string, newName: string) => {
const app = (await this.applications.find({ pushApplicationID }))[0];
app.name = newName;
// Remove the variants
app.variants = undefined;
return this.applicationsAdmin.update(await this.auth(), app);
},
};

readonly variants = {
Expand Down
4 changes: 4 additions & 0 deletions src/applications/ApplicationsAdmin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,8 @@ export class ApplicationsAdmin {
async create(api: AxiosInstance, name: string): Promise<PushApplication> {
return (await api.post(`/applications`, { name })).data;
}

async update(api: AxiosInstance, pushApplication: PushApplication) {
await api.put(`/applications/${pushApplication.pushApplicationID}`, pushApplication);
}
}

0 comments on commit e79e598

Please sign in to comment.