Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 24 additions & 116 deletions docs-snippets/basic-usage/app-context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import PubNub, { PubNubError } from '../../lib/types';
import PubNub from '../../lib/types';

const pubnub = new PubNub({
publishKey: 'demo',
Expand All @@ -14,11 +14,7 @@ async function getAllUUIDMetadata() {
const response = await pubnub.objects.getAllUUIDMetadata();
console.log('getAllUUIDMetadata response:', response);
} catch (error) {
console.error(
`Get all UUID metadata error: ${error}.${
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
}`,
);
console.error(`Get all UUID metadata error: ${error}`);
}
}

Expand All @@ -32,11 +28,7 @@ try {
const response = await pubnub.objects.getUUIDMetadata();
console.log('getUUIDMetadata response:', response);
} catch (error) {
console.error(
`Get UUID metadata error: ${error}.${
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
}`,
);
console.error(`Get UUID metadata error: ${error}`);
}

// Using the passed in UUID
Expand All @@ -46,11 +38,7 @@ try {
});
console.log('getUUIDMetadata response:', response);
} catch (error) {
console.error(
`Get UUID metadata error: ${error}.${
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
}`,
);
console.error(`Get UUID metadata error: ${error}`);
}
// snippet.end

Expand All @@ -64,11 +52,7 @@ try {
});
console.log('setUUIDMetadata response:', response);
} catch (error) {
console.error(
`Set UUID metadata error: ${error}.${
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
}`,
);
console.error(`Set UUID metadata error: ${error}`);
}

// Using the passed in UUID
Expand All @@ -81,11 +65,7 @@ try {
});
console.log('setUUIDMetadata response:', response);
} catch (error) {
console.error(
`Set UUID metadata error: ${error}.${
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
}`,
);
console.error(`Set UUID metadata error: ${error}`);
}
// snippet.end

Expand All @@ -94,11 +74,7 @@ try {
try {
const response = await pubnub.objects.removeUUIDMetadata();
} catch (error) {
console.error(
`Remove UUID metadata error: ${error}.${
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
}`,
);
console.error(`Remove UUID metadata error: ${error}`);
}

// Using the passed in UUID
Expand All @@ -107,11 +83,7 @@ try {
uuid: 'myUuid',
});
} catch (error) {
console.error(
`Remove UUID metadata error: ${error}.${
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
}`,
);
console.error(`Remove UUID metadata error: ${error}`);
}
// snippet.end

Expand All @@ -124,11 +96,7 @@ try {
},
});
} catch (error) {
console.error(
`Get all channel metadata error: ${error}.${
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
}`,
);
console.error(`Get all channel metadata error: ${error}`);
}

// Get all channels with the filter option. To get all channel which has Id ending 'Team'.
Expand All @@ -138,11 +106,7 @@ try {
});
console.log('Get all channel metadata response:', response);
} catch (error) {
console.error(
`Get all channel metadata error: ${error}.${
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
}`,
);
console.error(`Get all channel metadata error: ${error}`);
}
// snippet.end

Expand All @@ -154,11 +118,7 @@ try {
});
console.log('Get channel metadata response:', response);
} catch (error) {
console.error(
`Get channel metadata error: ${error}.${
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
}`,
);
console.error(`Get channel metadata error: ${error}`);
}
// snippet.end

Expand All @@ -179,11 +139,7 @@ try {
});
console.log('Set channel metadata response:', response);
} catch (error) {
console.error(
`Set channel metadata error: ${error}.${
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
}`,
);
console.error(`Set channel metadata error: ${error}`);
}
// snippet.end

Expand All @@ -193,11 +149,7 @@ try {
channel: 'team.red',
});
} catch (error) {
console.error(
`Remove channel metadata error: ${error}.${
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
}`,
);
console.error(`Remove channel metadata error: ${error}`);
}
// snippet.end

Expand All @@ -206,11 +158,7 @@ try {
try {
const response = await pubnub.objects.getMemberships();
} catch (error) {
console.error(
`Get memberships error: ${error}.${
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
}`,
);
console.error(`Get memberships error: ${error}`);
}

// Using the passed in UUID
Expand All @@ -222,11 +170,7 @@ try {
},
});
} catch (error) {
console.error(
`Get memberships with channels fields included error: ${error}.${
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
}`,
);
console.error(`Get memberships with channels fields included error: ${error}`);
}

// Get all memberships that are starred by the user
Expand All @@ -236,11 +180,7 @@ try {
filter: 'custom.starred == true',
});
} catch (error) {
console.error(
`Get filtered memberships error: ${error}.${
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
}`,
);
console.error(`Get filtered memberships error: ${error}`);
}
// snippet.end

Expand All @@ -255,11 +195,7 @@ try {
});
console.log('Set memberships response:', response);
} catch (error) {
console.error(
`Set memberships error: ${error}.${
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
}`,
);
console.error(`Set memberships error: ${error}`);
}

// Using the passed in UUID
Expand All @@ -277,11 +213,7 @@ try {
});
console.log('Set memberships response:', response);
} catch (error) {
console.error(
`Set memberships error: ${error}.${
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
}`,
);
console.error(`Set memberships error: ${error}`);
}
// snippet.end

Expand All @@ -292,11 +224,7 @@ try {
channels: ['ch-1', 'ch-2'],
});
} catch (error) {
console.error(
`Remove memberships error: ${error}.${
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
}`,
);
console.error(`Remove memberships error: ${error}`);
}

// Using the passed in UUID
Expand All @@ -306,11 +234,7 @@ try {
channels: ['ch-1', 'ch-2'],
});
} catch (error) {
console.error(
`Remove memberships for given uuids error: ${error}.${
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
}`,
);
console.error(`Remove memberships for given uuids error: ${error}`);
}
// snippet.end

Expand All @@ -324,11 +248,7 @@ try {
});
console.log('getChannelMembers response:', response);
} catch (error) {
console.error(
`Get channel members error: ${error}.${
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
}`,
);
console.error(`Get channel members error: ${error}`);
}

// Get all channel members with "admin" in the description
Expand All @@ -339,11 +259,7 @@ try {
});
console.log('getChannelMembers response:', response);
} catch (error) {
console.error(
`Get channel members error: ${error}.${
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
}`,
);
console.error(`Get channel members error: ${error}`);
}
// snippet.end

Expand All @@ -355,11 +271,7 @@ try {
});
console.log('setChannelMembers response:', response);
} catch (error) {
console.error(
`Set channel members error: ${error}.${
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
}`,
);
console.error(`Set channel members error: ${error}`);
}
// snippet.end

Expand All @@ -370,10 +282,6 @@ try {
uuids: ['uuid-1', 'uuid-2'],
});
} catch (error) {
console.error(
`Remove channel members error: ${error}.${
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
}`,
);
console.error(`Remove channel members error: ${error}`);
}
// snippet.end
28 changes: 6 additions & 22 deletions docs-snippets/basic-usage/channel-groups.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import PubNub, { PubNubError } from '../../lib/types';
import PubNub from '../../lib/types';

const pubnub = new PubNub({
publishKey: 'demo',
Expand All @@ -14,11 +14,7 @@ try {
});
console.log('addChannels to Group response:', response);
} catch (error) {
console.error(
`Add channels to group error: ${error}.${
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
}`,
);
console.error(`Add channels to group error: ${error}`);
}
// snippet.end

Expand All @@ -30,15 +26,11 @@ try {
channelGroup: 'myChannelGroup',
});
console.log('Listing push channels for the device:', response);
response.channels.forEach((channel: string) => {
response.channels.forEach((channel) => {
console.log(channel);
});
} catch (error) {
console.error(
`List channels of group error: ${error}.${
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
}`,
);
console.error(`List channels of group error: ${error}`);
}
// snippet.end

Expand All @@ -52,11 +44,7 @@ try {
});
console.log('removeChannels from group response:', response);
} catch (error) {
console.error(
`Remove channels from group error: ${error}.${
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
}`,
);
console.error(`Remove channels from group error: ${error}`);
}
// snippet.end

Expand All @@ -69,10 +57,6 @@ try {
});
console.log('deleteChannelGroup response:', response);
} catch (error) {
console.error(
`Delete channel group error: ${error}.${
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
}`,
);
console.error(`Delete channel group error: ${error}`);
}
// snippet.end
Loading
Loading