@@ -16,12 +16,12 @@ func (c *Client) getTokenBaseEndpoint(accountid, channelid string) string {
1616 return fmt .Sprintf ("%s/%s/channel/%s/api-token" , c .getChanelBaseEndpoint (), accountid , channelid )
1717}
1818
19- // ChannelsRequest hold data for get channels request
19+ // ChannelsRequest hold data for get channels request for a particular account
2020type ChannelsRequest struct {
2121 AccountID string `json:"accountid"`
2222}
2323
24- // ChannelsReply hold data for get channels reply
24+ // ChannelsReply hold data for get channels reply. It is a list of channel's detail
2525type ChannelsReply struct {
2626 Channels []struct {
2727 ID string `json:"id"`
@@ -75,7 +75,10 @@ type ChannelReply struct {
7575 } `json:"access_tokens"`
7676}
7777
78- // ChannelUpdateRequest hold data for update channel request
78+ // ChannelUpdateRequest hold data for update channel request.
79+ // The request contains the account and channel identification,
80+ // And the properties values to be updated. These properties defines
81+ // common permission for the channel
7982type ChannelUpdateRequest struct {
8083 AccountID string `json:"accountid"`
8184 ChannelID string `json:"channelid"`
@@ -85,19 +88,23 @@ type ChannelUpdateRequest struct {
8588}
8689
8790// ChannelUpdateReply hold data for update channel reply
91+ // If successful, the reply contains the confirmed updated properties
8892type ChannelUpdateReply struct {
8993 PublicRead bool `json:"public_read"`
9094 PublicWrite bool `json:"public_write"`
9195 Locked bool `json:"locked"`
9296}
9397
9498// ChannelDeleteRequest hold data for delete channel request
99+ // The request contains the account and channel identification
95100type ChannelDeleteRequest struct {
96101 AccountID string `json:"accountid"`
97102 ChannelID string `json:"channelid"`
98103}
99104
100105// ChannelCreateRequest hold data for create channel request
106+ // The request should contain the account id, and optionally some
107+ // channel properties to be initialised.
101108type ChannelCreateRequest struct {
102109 AccountID string `json:"accountid"`
103110 PublicRead bool `json:"public_read"`
@@ -111,6 +118,9 @@ type ChannelCreateRequest struct {
111118}
112119
113120// ChannelCreateReply hold data for create channel reply
121+ // It contains the new channel id, it's properties and the first
122+ // default created token to allow authentification the communication
123+ // on this channel
114124type ChannelCreateReply struct {
115125 ID string `json:"id"`
116126 Href string `json:"href"`
@@ -134,13 +144,20 @@ type ChannelCreateReply struct {
134144}
135145
136146// TokenRequest hold data for get token request
147+ // A token belong to a particular channel, which again belong to a particular account.
148+ // To identify a token, it needs to provide account id, channel id, and token id
137149type TokenRequest struct {
138150 AccountID string `json:"accountid"`
139151 ChannelID string `json:"channelid"`
140152 TokenID string `json:"tokenid"`
141153}
142154
143155// TokenReply hold data for get token reply
156+ // The reply contains
157+ //
158+ // - token id (a number which is uniquely identified in the database)
159+ // - token value, which will be used for authentification to read/write messages on the channel
160+ // - some permission properties attached to the token
144161type TokenReply struct {
145162 ID string `json:"id"`
146163 Token string `json:"token"`
@@ -150,22 +167,27 @@ type TokenReply struct {
150167}
151168
152169// TokenDeleteRequest hold data for delete token request
170+ // A token belong to a particular channel, which again belong to a particular account.
171+ // To identify a token, it needs to provide account id, channel id, and token id
153172type TokenDeleteRequest struct {
154173 AccountID string `json:"accountid"`
155174 ChannelID string `json:"channelid"`
156175 TokenID string `json:"tokenid"`
157176}
158177
159178// TokensRequest hold data for get tokens request
179+ // The request contains the account id and channel id.
160180type TokensRequest struct {
161181 AccountID string `json:"accountid"`
162182 ChannelID string `json:"channelid"`
163183}
164184
165- // TokensReply hold data for get tokens reply
185+ // TokensReply hold data for get tokens reply. It is a list of detail for tokens
166186type TokensReply []TokenReply
167187
168188// TokenCreateRequest hold data for create token request
189+ // The request should contains existing account and channel id,
190+ // with optionally some description and permission properties attached to the token
169191type TokenCreateRequest struct {
170192 AccountID string `json:"accountid"`
171193 ChannelID string `json:"channelid"`
@@ -175,6 +197,7 @@ type TokenCreateRequest struct {
175197}
176198
177199// TokenCreateReply hold data for create token reply
200+ // It hold the id and value of the new token, and some of the token's properties
178201type TokenCreateReply struct {
179202 ID string `json:"id"`
180203 Token string `json:"token"`
@@ -183,7 +206,7 @@ type TokenCreateReply struct {
183206 CanWrite bool `json:"can_write"`
184207}
185208
186- // Channels get the list of channels
209+ // Channels get the list of channels with detail for a particular account
187210func (c * Client ) Channels (ctx context.Context , r ChannelsRequest ) (* ChannelsReply , error ) {
188211 req , err := http .NewRequestWithContext (
189212 ctx ,
@@ -203,7 +226,7 @@ func (c *Client) Channels(ctx context.Context, r ChannelsRequest) (*ChannelsRepl
203226 return & res , nil
204227}
205228
206- // Channel get the channel
229+ // Channel get single channel's detail for a particular account
207230func (c * Client ) Channel (ctx context.Context , r ChannelRequest ) (* ChannelReply , error ) {
208231 req , err := http .NewRequestWithContext (
209232 ctx ,
@@ -224,7 +247,7 @@ func (c *Client) Channel(ctx context.Context, r ChannelRequest) (*ChannelReply,
224247 return & res , nil
225248}
226249
227- // ChannelUpdate update the channel
250+ // ChannelUpdate update the channel's properties.
228251func (c * Client ) ChannelUpdate (ctx context.Context , r ChannelUpdateRequest ) (* ChannelUpdateReply , error ) {
229252 payload , err := json .Marshal (r )
230253 if err != nil {
@@ -250,7 +273,7 @@ func (c *Client) ChannelUpdate(ctx context.Context, r ChannelUpdateRequest) (*Ch
250273 return & res , nil
251274}
252275
253- // ChannelDelete delete the channel
276+ // ChannelDelete delete the channel a particular channel. It return nothing, which is a 204 http code (No Content)
254277func (c * Client ) ChannelDelete (ctx context.Context , r ChannelDeleteRequest ) error {
255278 req , err := http .NewRequestWithContext (
256279 ctx ,
@@ -266,7 +289,7 @@ func (c *Client) ChannelDelete(ctx context.Context, r ChannelDeleteRequest) erro
266289 return c .sendRequest (req , nil )
267290}
268291
269- // ChannelCreate create a channel
292+ // ChannelCreate create a new channel for a particular account
270293func (c * Client ) ChannelCreate (ctx context.Context , r ChannelCreateRequest ) (* ChannelCreateReply , error ) {
271294 payload , err := json .Marshal (r )
272295 if err != nil {
@@ -292,7 +315,7 @@ func (c *Client) ChannelCreate(ctx context.Context, r ChannelCreateRequest) (*Ch
292315 return & res , nil
293316}
294317
295- // Token get the token
318+ // Token get the token's detail.
296319func (c * Client ) Token (ctx context.Context , r TokenRequest ) (* TokenReply , error ) {
297320 req , err := http .NewRequestWithContext (
298321 ctx ,
@@ -313,7 +336,13 @@ func (c *Client) Token(ctx context.Context, r TokenRequest) (*TokenReply, error)
313336 return & res , nil
314337}
315338
316- // TokenDelete delate the token
339+ // TokenDelete delete a particular token
340+ //
341+ // It is typically used when an admin create a temporary
342+ // communication capability for a particular user on a channel,
343+ //
344+ // After the user has finished he usage of the channel,
345+ // the admin then delete the token
317346func (c * Client ) TokenDelete (ctx context.Context , r TokenDeleteRequest ) error {
318347 req , err := http .NewRequestWithContext (ctx ,
319348 http .MethodDelete ,
@@ -328,7 +357,8 @@ func (c *Client) TokenDelete(ctx context.Context, r TokenDeleteRequest) error {
328357 return c .sendRequest (req , nil )
329358}
330359
331- // Tokens get the list of tokens
360+ // Tokens get the list of tokens. It return a full list of tokens
361+ // for a particular account id and channel id
332362func (c * Client ) Tokens (ctx context.Context , r TokensRequest ) (* TokensReply , error ) {
333363 req , err := http .NewRequestWithContext (ctx , http .MethodGet , c .getTokenBaseEndpoint (r .AccountID , r .ChannelID ), nil )
334364 if err != nil {
@@ -343,7 +373,13 @@ func (c *Client) Tokens(ctx context.Context, r TokensRequest) (*TokensReply, err
343373 return & res , nil
344374}
345375
346- // TokenCreate create a token
376+ // TokenCreate create a new token for a particular account and channel
377+ //
378+ // It is typically used when and admin/orchestrator need to create
379+ // a communication channel for a group of 2 or more peers.
380+ //
381+ // He then create a channel and a list of token, then give the tokens
382+ // to each peers so they can communicate through the channel
347383func (c * Client ) TokenCreate (ctx context.Context , r TokenCreateRequest ) (* TokenCreateReply , error ) {
348384 payload , err := json .Marshal (r )
349385 if err != nil {
0 commit comments