2023-10-16 12:43:33 +03:00
|
|
|
// Copyright (c) Mainflux
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2018-10-14 16:44:21 +02:00
|
|
|
package sdk
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2023-06-14 12:40:37 +02:00
|
|
|
"time"
|
2020-04-15 23:41:31 +02:00
|
|
|
|
2020-06-03 15:16:19 +02:00
|
|
|
"github.com/mainflux/mainflux/pkg/errors"
|
2018-10-14 16:44:21 +02:00
|
|
|
)
|
|
|
|
|
2022-06-24 17:31:12 +03:00
|
|
|
const (
|
2023-06-14 12:40:37 +02:00
|
|
|
thingsEndpoint = "things"
|
|
|
|
connectEndpoint = "connect"
|
|
|
|
disconnectEndpoint = "disconnect"
|
|
|
|
identifyEndpoint = "identify"
|
NOISSUE: Listing of shared things with users & Update SDK (#1923)
* NOISSUE - Fix Bugs (#20)
* fix bugs
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix bugs
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* Add Connect Disconnect endpoints (#23)
* fix bugs
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix bugs
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix list of things in a channel and Add connect disconnect endpoint
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix list of things in a channel and Add connect disconnect endpoint
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* Add: Things share with users (#25)
* fix list of things in a channel and Add connect disconnect endpoint
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add: things share with other users
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* Add: Listing of things, channels, groups, users (#26)
* add: listing of channels, users, groups, things
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add: listing of channels, users, groups, things
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add: listing of channels, users, groups, things
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add: listing of channels, users, groups, things
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* Add: List of user groups & removed repeating code in groups (#29)
* removed repeating code in list groups
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add: list of user group
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix: otel handler operator name for endpoints
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* add: listing of shared things and users
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix: listing of shared things and users
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add: new SDK
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add: new SDK
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix: comment
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix: sdk function names
Signed-off-by: Arvindh <arvindh91@gmail.com>
* update: api spec
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix: channels connect request
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix: listing of clients and groups
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix: CLI
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix: array len comparision
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix: nginx
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Co-authored-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
2023-10-17 19:08:06 +05:30
|
|
|
shareEndpoint = "share"
|
|
|
|
unshareEndpoint = "unshare"
|
2022-06-24 17:31:12 +03:00
|
|
|
)
|
|
|
|
|
2023-06-14 12:40:37 +02:00
|
|
|
// Thing represents mainflux thing.
|
|
|
|
type Thing struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
Credentials Credentials `json:"credentials"`
|
|
|
|
Tags []string `json:"tags,omitempty"`
|
|
|
|
Owner string `json:"owner,omitempty"`
|
|
|
|
Metadata map[string]interface{} `json:"metadata,omitempty"`
|
|
|
|
CreatedAt time.Time `json:"created_at,omitempty"`
|
|
|
|
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
|
|
|
Status string `json:"status,omitempty"`
|
2022-06-24 17:31:12 +03:00
|
|
|
}
|
2018-10-14 16:44:21 +02:00
|
|
|
|
2023-06-14 12:40:37 +02:00
|
|
|
func (sdk mfSDK) CreateThing(thing Thing, token string) (Thing, errors.SDKError) {
|
|
|
|
data, err := json.Marshal(thing)
|
2018-10-14 16:44:21 +02:00
|
|
|
if err != nil {
|
2023-06-14 12:40:37 +02:00
|
|
|
return Thing{}, errors.NewSDKError(err)
|
2018-10-14 16:44:21 +02:00
|
|
|
}
|
2023-06-14 12:40:37 +02:00
|
|
|
|
2021-08-11 16:58:10 +02:00
|
|
|
url := fmt.Sprintf("%s/%s", sdk.thingsURL, thingsEndpoint)
|
2018-10-24 11:21:03 +02:00
|
|
|
|
2023-08-01 18:03:18 +03:00
|
|
|
_, body, sdkerr := sdk.processRequest(http.MethodPost, url, token, data, nil, http.StatusCreated)
|
2022-12-15 07:24:19 -08:00
|
|
|
if sdkerr != nil {
|
2023-06-14 12:40:37 +02:00
|
|
|
return Thing{}, sdkerr
|
|
|
|
}
|
|
|
|
|
|
|
|
thing = Thing{}
|
|
|
|
if err := json.Unmarshal(body, &thing); err != nil {
|
|
|
|
return Thing{}, errors.NewSDKError(err)
|
2018-10-14 16:44:21 +02:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:40:37 +02:00
|
|
|
return thing, nil
|
2018-10-14 16:44:21 +02:00
|
|
|
}
|
|
|
|
|
2022-12-15 07:24:19 -08:00
|
|
|
func (sdk mfSDK) CreateThings(things []Thing, token string) ([]Thing, errors.SDKError) {
|
2019-10-29 05:59:54 -06:00
|
|
|
data, err := json.Marshal(things)
|
|
|
|
if err != nil {
|
2022-12-15 07:24:19 -08:00
|
|
|
return []Thing{}, errors.NewSDKError(err)
|
2019-10-29 05:59:54 -06:00
|
|
|
}
|
|
|
|
|
2021-08-11 16:58:10 +02:00
|
|
|
url := fmt.Sprintf("%s/%s/%s", sdk.thingsURL, thingsEndpoint, "bulk")
|
2019-10-29 05:59:54 -06:00
|
|
|
|
2023-08-01 18:03:18 +03:00
|
|
|
_, body, sdkerr := sdk.processRequest(http.MethodPost, url, token, data, nil, http.StatusOK)
|
2022-12-15 07:24:19 -08:00
|
|
|
if sdkerr != nil {
|
|
|
|
return []Thing{}, sdkerr
|
2019-10-29 05:59:54 -06:00
|
|
|
}
|
|
|
|
|
2020-04-14 11:04:33 +02:00
|
|
|
var ctr createThingsRes
|
|
|
|
if err := json.Unmarshal(body, &ctr); err != nil {
|
2022-12-15 07:24:19 -08:00
|
|
|
return []Thing{}, errors.NewSDKError(err)
|
2019-10-29 05:59:54 -06:00
|
|
|
}
|
|
|
|
|
2020-04-14 11:04:33 +02:00
|
|
|
return ctr.Things, nil
|
2019-10-29 05:59:54 -06:00
|
|
|
}
|
|
|
|
|
2023-01-05 19:20:05 +03:00
|
|
|
func (sdk mfSDK) Things(pm PageMetadata, token string) (ThingsPage, errors.SDKError) {
|
2022-06-17 18:32:23 +03:00
|
|
|
url, err := sdk.withQueryParams(sdk.thingsURL, thingsEndpoint, pm)
|
2018-10-14 16:44:21 +02:00
|
|
|
if err != nil {
|
2022-12-15 07:24:19 -08:00
|
|
|
return ThingsPage{}, errors.NewSDKError(err)
|
2018-10-14 16:44:21 +02:00
|
|
|
}
|
|
|
|
|
2023-08-01 18:03:18 +03:00
|
|
|
_, body, sdkerr := sdk.processRequest(http.MethodGet, url, token, nil, nil, http.StatusOK)
|
2022-12-15 07:24:19 -08:00
|
|
|
if sdkerr != nil {
|
|
|
|
return ThingsPage{}, sdkerr
|
2018-10-14 16:44:21 +02:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:40:37 +02:00
|
|
|
var cp ThingsPage
|
|
|
|
if err := json.Unmarshal(body, &cp); err != nil {
|
2022-12-15 07:24:19 -08:00
|
|
|
return ThingsPage{}, errors.NewSDKError(err)
|
2018-10-14 16:44:21 +02:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:40:37 +02:00
|
|
|
return cp, nil
|
2019-01-08 11:53:24 +01:00
|
|
|
}
|
|
|
|
|
2023-01-05 19:20:05 +03:00
|
|
|
func (sdk mfSDK) ThingsByChannel(chanID string, pm PageMetadata, token string) (ThingsPage, errors.SDKError) {
|
2023-06-14 12:40:37 +02:00
|
|
|
url, err := sdk.withQueryParams(sdk.thingsURL, fmt.Sprintf("channels/%s/%s", chanID, thingsEndpoint), pm)
|
2019-01-08 11:53:24 +01:00
|
|
|
if err != nil {
|
2023-01-05 19:20:05 +03:00
|
|
|
return ThingsPage{}, errors.NewSDKError(err)
|
|
|
|
}
|
2023-06-14 12:40:37 +02:00
|
|
|
|
2023-08-01 18:03:18 +03:00
|
|
|
_, body, sdkerr := sdk.processRequest(http.MethodGet, url, token, nil, nil, http.StatusOK)
|
2023-01-05 19:20:05 +03:00
|
|
|
if sdkerr != nil {
|
|
|
|
return ThingsPage{}, sdkerr
|
2019-01-08 11:53:24 +01:00
|
|
|
}
|
|
|
|
|
2020-03-07 05:02:26 +01:00
|
|
|
var tp ThingsPage
|
|
|
|
if err := json.Unmarshal(body, &tp); err != nil {
|
2022-12-15 07:24:19 -08:00
|
|
|
return ThingsPage{}, errors.NewSDKError(err)
|
2019-01-08 11:53:24 +01:00
|
|
|
}
|
|
|
|
|
2020-03-07 05:02:26 +01:00
|
|
|
return tp, nil
|
2018-10-14 16:44:21 +02:00
|
|
|
}
|
|
|
|
|
2022-12-15 07:24:19 -08:00
|
|
|
func (sdk mfSDK) Thing(id, token string) (Thing, errors.SDKError) {
|
2021-08-11 16:58:10 +02:00
|
|
|
url := fmt.Sprintf("%s/%s/%s", sdk.thingsURL, thingsEndpoint, id)
|
2018-10-24 11:21:03 +02:00
|
|
|
|
2023-08-01 18:03:18 +03:00
|
|
|
_, body, sdkerr := sdk.processRequest(http.MethodGet, url, token, nil, nil, http.StatusOK)
|
2023-06-14 12:40:37 +02:00
|
|
|
if sdkerr != nil {
|
|
|
|
return Thing{}, sdkerr
|
2018-10-14 16:44:21 +02:00
|
|
|
}
|
|
|
|
|
2018-10-24 11:21:03 +02:00
|
|
|
var t Thing
|
2018-10-14 16:44:21 +02:00
|
|
|
if err := json.Unmarshal(body, &t); err != nil {
|
2022-12-15 07:24:19 -08:00
|
|
|
return Thing{}, errors.NewSDKError(err)
|
2018-10-14 16:44:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return t, nil
|
|
|
|
}
|
|
|
|
|
2023-06-14 12:40:37 +02:00
|
|
|
func (sdk mfSDK) UpdateThing(t Thing, token string) (Thing, errors.SDKError) {
|
2020-04-16 14:45:28 +02:00
|
|
|
data, err := json.Marshal(t)
|
2018-10-24 11:21:03 +02:00
|
|
|
if err != nil {
|
2023-06-14 12:40:37 +02:00
|
|
|
return Thing{}, errors.NewSDKError(err)
|
2018-10-24 11:21:03 +02:00
|
|
|
}
|
|
|
|
|
2021-08-11 16:58:10 +02:00
|
|
|
url := fmt.Sprintf("%s/%s/%s", sdk.thingsURL, thingsEndpoint, t.ID)
|
2018-10-24 11:21:03 +02:00
|
|
|
|
2023-08-01 18:03:18 +03:00
|
|
|
_, body, sdkerr := sdk.processRequest(http.MethodPatch, url, token, data, nil, http.StatusOK)
|
2023-06-14 12:40:37 +02:00
|
|
|
if sdkerr != nil {
|
|
|
|
return Thing{}, sdkerr
|
|
|
|
}
|
2018-10-14 16:44:21 +02:00
|
|
|
|
2023-06-14 12:40:37 +02:00
|
|
|
t = Thing{}
|
|
|
|
if err := json.Unmarshal(body, &t); err != nil {
|
|
|
|
return Thing{}, errors.NewSDKError(err)
|
|
|
|
}
|
2018-10-24 11:21:03 +02:00
|
|
|
|
2023-06-14 12:40:37 +02:00
|
|
|
return t, nil
|
2018-10-14 16:44:21 +02:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:40:37 +02:00
|
|
|
func (sdk mfSDK) UpdateThingTags(t Thing, token string) (Thing, errors.SDKError) {
|
|
|
|
data, err := json.Marshal(t)
|
2023-05-25 06:02:46 +08:00
|
|
|
if err != nil {
|
2023-06-14 12:40:37 +02:00
|
|
|
return Thing{}, errors.NewSDKError(err)
|
2023-05-25 06:02:46 +08:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:40:37 +02:00
|
|
|
url := fmt.Sprintf("%s/%s/%s/tags", sdk.thingsURL, thingsEndpoint, t.ID)
|
2023-05-25 06:02:46 +08:00
|
|
|
|
2023-08-01 18:03:18 +03:00
|
|
|
_, body, sdkerr := sdk.processRequest(http.MethodPatch, url, token, data, nil, http.StatusOK)
|
2023-06-14 12:40:37 +02:00
|
|
|
if sdkerr != nil {
|
|
|
|
return Thing{}, sdkerr
|
2023-05-25 06:02:46 +08:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:40:37 +02:00
|
|
|
t = Thing{}
|
|
|
|
if err := json.Unmarshal(body, &t); err != nil {
|
|
|
|
return Thing{}, errors.NewSDKError(err)
|
|
|
|
}
|
2023-05-25 06:02:46 +08:00
|
|
|
|
2023-06-14 12:40:37 +02:00
|
|
|
return t, nil
|
2023-05-25 06:02:46 +08:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:40:37 +02:00
|
|
|
func (sdk mfSDK) UpdateThingSecret(id, secret, token string) (Thing, errors.SDKError) {
|
2023-08-11 02:30:25 -07:00
|
|
|
ucsr := updateThingSecretReq{Secret: secret}
|
2023-06-14 12:40:37 +02:00
|
|
|
|
|
|
|
data, err := json.Marshal(ucsr)
|
2022-06-24 17:31:12 +03:00
|
|
|
if err != nil {
|
2023-06-14 12:40:37 +02:00
|
|
|
return Thing{}, errors.NewSDKError(err)
|
2022-06-24 17:31:12 +03:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:40:37 +02:00
|
|
|
url := fmt.Sprintf("%s/%s/%s/secret", sdk.thingsURL, thingsEndpoint, id)
|
2022-06-24 17:31:12 +03:00
|
|
|
|
2023-08-01 18:03:18 +03:00
|
|
|
_, body, sdkerr := sdk.processRequest(http.MethodPatch, url, token, data, nil, http.StatusOK)
|
2022-12-15 07:24:19 -08:00
|
|
|
if sdkerr != nil {
|
2023-06-14 12:40:37 +02:00
|
|
|
return Thing{}, sdkerr
|
2022-06-24 17:31:12 +03:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:40:37 +02:00
|
|
|
var t Thing
|
|
|
|
if err = json.Unmarshal(body, &t); err != nil {
|
|
|
|
return Thing{}, errors.NewSDKError(err)
|
2022-06-24 17:31:12 +03:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:40:37 +02:00
|
|
|
return t, nil
|
2022-06-24 17:31:12 +03:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:40:37 +02:00
|
|
|
func (sdk mfSDK) UpdateThingOwner(t Thing, token string) (Thing, errors.SDKError) {
|
|
|
|
data, err := json.Marshal(t)
|
2023-05-25 06:02:46 +08:00
|
|
|
if err != nil {
|
2023-06-14 12:40:37 +02:00
|
|
|
return Thing{}, errors.NewSDKError(err)
|
2023-05-25 06:02:46 +08:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:40:37 +02:00
|
|
|
url := fmt.Sprintf("%s/%s/%s/owner", sdk.thingsURL, thingsEndpoint, t.ID)
|
2023-05-25 06:02:46 +08:00
|
|
|
|
2023-08-01 18:03:18 +03:00
|
|
|
_, body, sdkerr := sdk.processRequest(http.MethodPatch, url, token, data, nil, http.StatusOK)
|
2023-05-25 06:02:46 +08:00
|
|
|
if sdkerr != nil {
|
2023-06-14 12:40:37 +02:00
|
|
|
return Thing{}, sdkerr
|
2023-05-25 06:02:46 +08:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:40:37 +02:00
|
|
|
t = Thing{}
|
|
|
|
if err = json.Unmarshal(body, &t); err != nil {
|
|
|
|
return Thing{}, errors.NewSDKError(err)
|
2023-05-25 06:02:46 +08:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:40:37 +02:00
|
|
|
return t, nil
|
2023-05-25 06:02:46 +08:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:40:37 +02:00
|
|
|
func (sdk mfSDK) EnableThing(id, token string) (Thing, errors.SDKError) {
|
|
|
|
return sdk.changeThingStatus(id, enableEndpoint, token)
|
2023-05-25 06:02:46 +08:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:40:37 +02:00
|
|
|
func (sdk mfSDK) DisableThing(id, token string) (Thing, errors.SDKError) {
|
|
|
|
return sdk.changeThingStatus(id, disableEndpoint, token)
|
2019-11-21 04:29:37 -07:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:40:37 +02:00
|
|
|
func (sdk mfSDK) changeThingStatus(id, status, token string) (Thing, errors.SDKError) {
|
|
|
|
url := fmt.Sprintf("%s/%s/%s/%s", sdk.thingsURL, thingsEndpoint, id, status)
|
2023-08-01 18:03:18 +03:00
|
|
|
|
|
|
|
_, body, sdkerr := sdk.processRequest(http.MethodPost, url, token, nil, nil, http.StatusOK)
|
2023-06-14 12:40:37 +02:00
|
|
|
if sdkerr != nil {
|
|
|
|
return Thing{}, sdkerr
|
2023-05-25 06:02:46 +08:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:40:37 +02:00
|
|
|
t := Thing{}
|
|
|
|
if err := json.Unmarshal(body, &t); err != nil {
|
|
|
|
return Thing{}, errors.NewSDKError(err)
|
|
|
|
}
|
2023-05-25 06:02:46 +08:00
|
|
|
|
2023-06-14 12:40:37 +02:00
|
|
|
return t, nil
|
2023-05-25 06:02:46 +08:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:40:37 +02:00
|
|
|
func (sdk mfSDK) IdentifyThing(key string) (string, errors.SDKError) {
|
|
|
|
url := fmt.Sprintf("%s/%s", sdk.thingsURL, identifyEndpoint)
|
2023-08-01 18:03:18 +03:00
|
|
|
|
|
|
|
_, body, sdkerr := sdk.processRequest(http.MethodPost, url, ThingPrefix+key, nil, nil, http.StatusOK)
|
2023-06-14 12:40:37 +02:00
|
|
|
if sdkerr != nil {
|
|
|
|
return "", sdkerr
|
|
|
|
}
|
2023-05-25 06:02:46 +08:00
|
|
|
|
2023-06-14 12:40:37 +02:00
|
|
|
var i identifyThingResp
|
|
|
|
if err := json.Unmarshal(body, &i); err != nil {
|
|
|
|
return "", errors.NewSDKError(err)
|
|
|
|
}
|
2018-10-14 16:44:21 +02:00
|
|
|
|
2023-06-14 12:40:37 +02:00
|
|
|
return i.ID, nil
|
2018-10-14 16:44:21 +02:00
|
|
|
}
|
2023-05-25 06:02:46 +08:00
|
|
|
|
NOISSUE: Listing of shared things with users & Update SDK (#1923)
* NOISSUE - Fix Bugs (#20)
* fix bugs
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix bugs
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* Add Connect Disconnect endpoints (#23)
* fix bugs
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix bugs
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix list of things in a channel and Add connect disconnect endpoint
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix list of things in a channel and Add connect disconnect endpoint
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* Add: Things share with users (#25)
* fix list of things in a channel and Add connect disconnect endpoint
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add: things share with other users
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* Add: Listing of things, channels, groups, users (#26)
* add: listing of channels, users, groups, things
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add: listing of channels, users, groups, things
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add: listing of channels, users, groups, things
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add: listing of channels, users, groups, things
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* Add: List of user groups & removed repeating code in groups (#29)
* removed repeating code in list groups
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add: list of user group
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix: otel handler operator name for endpoints
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* add: listing of shared things and users
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix: listing of shared things and users
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add: new SDK
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add: new SDK
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix: comment
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix: sdk function names
Signed-off-by: Arvindh <arvindh91@gmail.com>
* update: api spec
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix: channels connect request
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix: listing of clients and groups
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix: CLI
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix: array len comparision
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix: nginx
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Co-authored-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
2023-10-17 19:08:06 +05:30
|
|
|
func (sdk mfSDK) ShareThing(thingID string, req UsersRelationRequest, token string) errors.SDKError {
|
|
|
|
data, err := json.Marshal(req)
|
|
|
|
if err != nil {
|
|
|
|
return errors.NewSDKError(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
url := fmt.Sprintf("%s/%s/%s/%s", sdk.thingsURL, thingsEndpoint, thingID, unshareEndpoint)
|
|
|
|
|
|
|
|
_, _, sdkerr := sdk.processRequest(http.MethodPost, url, token, data, nil, http.StatusOK)
|
|
|
|
return sdkerr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sdk mfSDK) UnshareThing(thingID string, req UsersRelationRequest, token string) errors.SDKError {
|
|
|
|
data, err := json.Marshal(req)
|
|
|
|
if err != nil {
|
|
|
|
return errors.NewSDKError(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
url := fmt.Sprintf("%s/%s/%s/%s", sdk.thingsURL, thingsEndpoint, thingID, shareEndpoint)
|
|
|
|
|
|
|
|
_, _, sdkerr := sdk.processRequest(http.MethodPost, url, token, data, nil, http.StatusOK)
|
|
|
|
return sdkerr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sdk mfSDK) ListThingUsers(thingID string, pm PageMetadata, token string) (UsersPage, errors.SDKError) {
|
|
|
|
url, err := sdk.withQueryParams(sdk.thingsURL, fmt.Sprintf("%s/%s/%s", thingsEndpoint, thingID, usersEndpoint), pm)
|
|
|
|
if err != nil {
|
|
|
|
return UsersPage{}, errors.NewSDKError(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, body, sdkerr := sdk.processRequest(http.MethodGet, url, token, nil, nil, http.StatusOK)
|
|
|
|
if sdkerr != nil {
|
|
|
|
return UsersPage{}, sdkerr
|
|
|
|
}
|
|
|
|
up := UsersPage{}
|
|
|
|
if err := json.Unmarshal(body, &up); err != nil {
|
|
|
|
return UsersPage{}, errors.NewSDKError(err)
|
2023-05-25 06:02:46 +08:00
|
|
|
}
|
|
|
|
|
NOISSUE: Listing of shared things with users & Update SDK (#1923)
* NOISSUE - Fix Bugs (#20)
* fix bugs
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix bugs
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* Add Connect Disconnect endpoints (#23)
* fix bugs
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix bugs
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix list of things in a channel and Add connect disconnect endpoint
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix list of things in a channel and Add connect disconnect endpoint
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* Add: Things share with users (#25)
* fix list of things in a channel and Add connect disconnect endpoint
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add: things share with other users
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* Add: Listing of things, channels, groups, users (#26)
* add: listing of channels, users, groups, things
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add: listing of channels, users, groups, things
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add: listing of channels, users, groups, things
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add: listing of channels, users, groups, things
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* Add: List of user groups & removed repeating code in groups (#29)
* removed repeating code in list groups
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add: list of user group
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix: otel handler operator name for endpoints
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* add: listing of shared things and users
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix: listing of shared things and users
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add: new SDK
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add: new SDK
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix: comment
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix: sdk function names
Signed-off-by: Arvindh <arvindh91@gmail.com>
* update: api spec
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix: channels connect request
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix: listing of clients and groups
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix: CLI
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix: array len comparision
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix: nginx
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Co-authored-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
2023-10-17 19:08:06 +05:30
|
|
|
return up, nil
|
2023-05-25 06:02:46 +08:00
|
|
|
}
|