github.com/twilio/twilio-go@v1.20.1/rest/video/v1/rooms_participants_subscribe_rules.go (about)

     1  /*
     2   * This code was generated by
     3   * ___ _ _ _ _ _    _ ____    ____ ____ _    ____ ____ _  _ ____ ____ ____ ___ __   __
     4   *  |  | | | | |    | |  | __ |  | |__| | __ | __ |___ |\ | |___ |__/ |__|  | |  | |__/
     5   *  |  |_|_| | |___ | |__|    |__| |  | |    |__] |___ | \| |___ |  \ |  |  | |__| |  \
     6   *
     7   * Twilio - Video
     8   * This is the public Twilio REST API.
     9   *
    10   * NOTE: This class is auto generated by OpenAPI Generator.
    11   * https://openapi-generator.tech
    12   * Do not edit the class manually.
    13   */
    14  
    15  package openapi
    16  
    17  import (
    18  	"encoding/json"
    19  	"net/url"
    20  	"strings"
    21  )
    22  
    23  // Returns a list of Subscribe Rules for the Participant.
    24  func (c *ApiService) FetchRoomParticipantSubscribeRule(RoomSid string, ParticipantSid string) (*VideoV1RoomParticipantSubscribeRule, error) {
    25  	path := "/v1/Rooms/{RoomSid}/Participants/{ParticipantSid}/SubscribeRules"
    26  	path = strings.Replace(path, "{"+"RoomSid"+"}", RoomSid, -1)
    27  	path = strings.Replace(path, "{"+"ParticipantSid"+"}", ParticipantSid, -1)
    28  
    29  	data := url.Values{}
    30  	headers := make(map[string]interface{})
    31  
    32  	resp, err := c.requestHandler.Get(c.baseURL+path, data, headers)
    33  	if err != nil {
    34  		return nil, err
    35  	}
    36  
    37  	defer resp.Body.Close()
    38  
    39  	ps := &VideoV1RoomParticipantSubscribeRule{}
    40  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
    41  		return nil, err
    42  	}
    43  
    44  	return ps, err
    45  }
    46  
    47  // Optional parameters for the method 'UpdateRoomParticipantSubscribeRule'
    48  type UpdateRoomParticipantSubscribeRuleParams struct {
    49  	// A JSON-encoded array of subscribe rules. See the [Specifying Subscribe Rules](https://www.twilio.com/docs/video/api/track-subscriptions#specifying-sr) section for further information.
    50  	Rules *interface{} `json:"Rules,omitempty"`
    51  }
    52  
    53  func (params *UpdateRoomParticipantSubscribeRuleParams) SetRules(Rules interface{}) *UpdateRoomParticipantSubscribeRuleParams {
    54  	params.Rules = &Rules
    55  	return params
    56  }
    57  
    58  // Update the Subscribe Rules for the Participant
    59  func (c *ApiService) UpdateRoomParticipantSubscribeRule(RoomSid string, ParticipantSid string, params *UpdateRoomParticipantSubscribeRuleParams) (*VideoV1RoomParticipantSubscribeRule, error) {
    60  	path := "/v1/Rooms/{RoomSid}/Participants/{ParticipantSid}/SubscribeRules"
    61  	path = strings.Replace(path, "{"+"RoomSid"+"}", RoomSid, -1)
    62  	path = strings.Replace(path, "{"+"ParticipantSid"+"}", ParticipantSid, -1)
    63  
    64  	data := url.Values{}
    65  	headers := make(map[string]interface{})
    66  
    67  	if params != nil && params.Rules != nil {
    68  		v, err := json.Marshal(params.Rules)
    69  
    70  		if err != nil {
    71  			return nil, err
    72  		}
    73  
    74  		data.Set("Rules", string(v))
    75  	}
    76  
    77  	resp, err := c.requestHandler.Post(c.baseURL+path, data, headers)
    78  	if err != nil {
    79  		return nil, err
    80  	}
    81  
    82  	defer resp.Body.Close()
    83  
    84  	ps := &VideoV1RoomParticipantSubscribeRule{}
    85  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
    86  		return nil, err
    87  	}
    88  
    89  	return ps, err
    90  }