Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NOISSUE - Updating Things and Channels Service #9

Merged
merged 17 commits into from
Apr 5, 2024
Merged
202 changes: 202 additions & 0 deletions examples/channels.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
// Import the SDK class from the mainflux-sdk package
import SDK from '../src/sdk'

const defaultUrl = 'http://localhost'

const mySdk = new SDK({
thingsUrl: defaultUrl + ':9000',
usersUrl: defaultUrl + ':9002'
})

// Channels.ts examples.

const token = '<token>'

mySdk.channels
.CreateChannel({ name: '<channelId>' }, token)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.CreateChannel({ name: '<channelId>' }, token)
.CreateChannel({ name: '<channelName>' }, token)

.then((response: any) => {
console.log('response:', response)
})
.catch((error) => {
console.log(error)
})

mySdk.channels
.Channel('<channelID>', token)
.then((response: any) => {
console.log(response)
})
.catch((error: any) => {
console.log(error)
})

mySdk.channels
.Channels({ offset: 0, limit: 10 }, token)
.then((response: any) => {
console.log('response:', response)
})
.catch((error) => {
console.log(error)
})

mySdk.channels
.UpdateChannel(
{ id: '<channelId>', name: '<channelName>' },
token
)
.then((response: any) => {
console.log('response:', response)
})
.catch((error) => {
console.log(error)
})

mySdk.channels
.Disable({ id: '<channelId>' }, token)
.then((response: any) => {
console.log('response:', response)
})
.catch((error) => {
console.log(error)
})

mySdk.channels
.Enable({ id: '<channelId>' }, token)
.then((response: any) => {
console.log('response: ', response)
})
.catch((error) => {
console.log(error)
})

mySdk.channels
.ChannelsByThing(
'<thingId>',
{ offset: 0, limit: 5 },
token
)
.then((response: any) => {
console.log('response:', response)
})
.catch((error) => {
console.log(error)
})

mySdk.channels
.ConnectThing(
'<thingId>',
'<channelId>',
token
)
.then((response: any) => {
console.log('response: ', response)
})
.catch((error) => {
console.log(error)
})

mySdk.channels
.DisconnectThing(
'<thingId>',
'<channelId>',
token
)
.then((response: any) => {
console.log('response: ', response)
})
.catch((error) => {
console.log(error)
})

mySdk.channels
.Connect(
'<thingId>',
'<channelId>',
token
)
.then((response: any) => {
console.log('response:', response)
})
.catch((error) => {
console.log(error)
})

mySdk.channels
.Disconnect(
'<thingId>',
'<channelId>',
token
)
.then((response: any) => {
console.log('response: ', response)
})
.catch((error) => {
console.log(error)
})

mySdk.channels
.ListChannelUsers(
'<channelId>',
{ offset: 0, limit: 5 },
token
)
.then((response: any) => {
console.log('response: ', response)
})
.catch((error: any) => {
console.log(error)
})

mySdk.channels
.ListChannelUsersGroups(
'<channelId>',
{ offset: 0, limit: 5 },
token
)
.then((response: any) => {
console.log('response: ', response)
})
.catch((error: any) => {
console.log(error)
})

mySdk.channels
.ChannelPermissions('<channelId>', token)
.then((response: any) => {
console.log('response: ', response)
})
.catch((error) => {
console.log(error)
})

mySdk.channels
.AddUserToChannel(
'<channelId>',
[
'<thingId>', '<thingId>'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'<thingId>', '<thingId>'
'<userId>', '<userId>'

],
'editor',
token
)
.then((response: any) => {
console.log('response: ', response)
})
.catch((error) => {
console.log(error)
})

mySdk.channels
.RemoveUserFromChannel(
'<channelId>',
[
'<thingId>', '<thingId>'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'<thingId>', '<thingId>'
'<userId>', '<userId>'

],
'editor',
token
)
.then((response: any) => {
console.log('response: ', response)
})
.catch((error) => {
console.log(error)
})
180 changes: 180 additions & 0 deletions examples/things.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
// Import the SDK class from the mainflux-sdk package
import SDK from '../src/sdk'

const defaultUrl = 'http://localhost'

const mySdk = new SDK({
thingsUrl: defaultUrl + ':9000',
usersUrl: defaultUrl + ':9002'
})

// Things.ts examples.

const token = '<token>'

mySdk.things
.Create(
{ name: '<thingName>' }, token
)
.then((response: any) => {
console.log('response:', response)
})
.catch((error) => {
console.log(error)
})

mySdk.things
.Disable({ id: '<thingId>' }, token)
.then((response: any) => {
console.log('response:', response)
})
.catch((error) => {
console.error(error)
})

mySdk.things
.Enable({ id: '<thingId>' }, token)
.then((response: any) => {
console.log('response:', response)
})
.catch((error) => {
console.error(error)
})

mySdk.things
.UpdateThing(
{ id: '<thingId>', name: '<thingName>' }, token)
.then((response: any) => {
console.log('response:', response)
})
.catch((error) => {
console.log(error)
})

mySdk.things
.UpdateThingSecret({ id: '<thingId>', credentials: { secret: 'newSecret' } }, token
)
.then((response: any) => {
console.log(response)
})
.catch((error) => {
console.log(error)
})

mySdk.things
.UpdateThingTags(
{ id: '<thingId>', tags: ['<tag1>', '<tag2>'] },
token
)
.then((response: any) => {
console.log(response)
})
.catch((error) => {
console.log(error)
})

mySdk.things
.ThingsByChannel('<channelId>', { offset: 0, limit: 5 }, token)
.then((response: any) => {
console.log(response)
})
.catch((error) => {
console.log(error)
})

mySdk.things
.Things({ offset: 0, limit: 10 }, token)
.then((response: any) => {
console.log('response:', response)
})
.catch((error) => {
console.log(error)
})

mySdk.things
.Thing('<thingId>', token)
.then((response: any) => {
console.log('response: ', response)
})
.catch((error) => {
console.log(error)
})

mySdk.things
.ThingsPermissions('<thingId>', token)
.then((response: any) => {
console.log('response: ', response)
})
.catch((error) => {
console.log(error)
})

mySdk.things
.IdentifyThing('<thingKey>')
.then((response: any) => {
console.log('response: ', response)
})
.catch((error) => {
console.log(error)
})

mySdk.things
.ShareThing(
'<thingId>',

'administrator',
wambui-pixel marked this conversation as resolved.
Show resolved Hide resolved
[
'<userId1>', '<userId2>'
], token)
.then((response: any) => {
console.log('response: ', response)
})
.catch((error) => {
console.log(error)
})

mySdk.things
.UnShareThing(
'<thingId>',
'<relation>',

[
'<userId1>', '<userId2>'
], token)
.then((response: any) => {
console.log('response:', response)
})
.catch((error) => {
console.log(error)
})

mySdk.things
.ListThingUsers(
'<thingId>',
{ offset: 0, limit: 10 },
token
)
.then((response: any) => {
console.log('response:', response)
})
.catch((error) => {
console.log(error)
})

mySdk.things
.DeleteThing({ id: '<thingId>' }, token)
.then((response: any) => {
console.log('response: ', response)
})
.catch((error) => {
console.log(error)
})

mySdk.things
.CreateThings([{ name: '<thingName>' }, { name: '<thingName>' }], token)
.then((response: any) => {
console.log('response:', response)
})
.catch((error) => {
console.log(error)
})
Loading
Loading