forked from saintpete/twilio-go
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
318 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ Maksym Pavlenko <[email protected]> | |
Marcus Westin <[email protected]> | ||
Minko Gechev <[email protected]> | ||
Scott Gose <[email protected]> | ||
Tomasz Tomalak <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package twilio | ||
|
||
import ( | ||
"context" | ||
"net/url" | ||
) | ||
|
||
const roomPathPart = "Rooms" | ||
|
||
type RoomService struct { | ||
client *Client | ||
} | ||
|
||
type Room struct { | ||
Sid string `json:"sid"` | ||
AccountSid string `json:"account_sid"` | ||
Type string `json:"type"` | ||
EnableTurn bool `json:"enable_turn"` | ||
UniqueName string `json:"unique_name"` | ||
StatusCallback string `json:"status_callback"` | ||
StatusCallbackMethod string `json:"status_callback_method"` | ||
MaxParticipants uint `json:"max_participants"` | ||
RecordParticipantsOnConnect bool `json:"record_participants_on_connect"` | ||
Duration uint `json:"duration"` | ||
MediaRegion string `json:"media_region"` | ||
Status Status `json:"status"` | ||
DateCreated TwilioTime `json:"date_created"` | ||
DateUpdated TwilioTime `json:"date_updated"` | ||
EndTime TwilioTime `json:"end_time"` | ||
URL string `json:"url"` | ||
Links map[string]string `json:"links"` | ||
} | ||
|
||
type RoomPage struct { | ||
Meta Meta `json:"meta"` | ||
Rooms []*Room `json:"rooms"` | ||
} | ||
|
||
type RoomPageIterator struct { | ||
p *PageIterator | ||
} | ||
|
||
// Get finds a single Room resource by its sid or unique name, or returns an error. | ||
func (r *RoomService) Get(ctx context.Context, sidOrUniqueName string) (*Room, error) { | ||
room := new(Room) | ||
err := r.client.GetResource(ctx, roomPathPart, sidOrUniqueName, room) | ||
return room, err | ||
} | ||
|
||
// Complete an in-progress Room with the given sid. All connected | ||
// Participants will be immediately disconnected from the Room. | ||
func (r *RoomService) Complete(sid string) (*Room, error) { | ||
room := new(Room) | ||
v := url.Values{} | ||
v.Set("Status", string(StatusCompleted)) | ||
err := r.client.UpdateResource(context.Background(), roomPathPart, sid, v, room) | ||
return room, err | ||
} | ||
|
||
// Create a room with the given url.Values. For more information on valid values, | ||
// see https://www.twilio.com/docs/api/video/rooms-resource#post-parameters or use the | ||
func (r *RoomService) Create(ctx context.Context, data url.Values) (*Room, error) { | ||
room := new(Room) | ||
err := r.client.CreateResource(ctx, roomPathPart, data, room) | ||
return room, err | ||
} | ||
|
||
// Returns a list of rooms. For more information on valid values, | ||
// see https://www.twilio.com/docs/api/video/rooms-resource#get-list-resource | ||
func (r *RoomService) GetPage(ctx context.Context, data url.Values) (*RoomPage, error) { | ||
return r.GetPageIterator(data).Next(ctx) | ||
} | ||
|
||
// GetPageIterator returns an iterator which can be used to retrieve pages. | ||
func (r *RoomService) GetPageIterator(data url.Values) *RoomPageIterator { | ||
iter := NewPageIterator(r.client, data, roomPathPart) | ||
return &RoomPageIterator{ | ||
p: iter, | ||
} | ||
} | ||
|
||
// Next returns the next page of resources. If there are no more resources, | ||
// NoMoreResults is returned. | ||
func (r *RoomPageIterator) Next(ctx context.Context) (*RoomPage, error) { | ||
rp := new(RoomPage) | ||
err := r.p.Next(ctx, rp) | ||
if err != nil { | ||
return nil, err | ||
} | ||
r.p.SetNextPageURI(rp.Meta.NextPageURL) | ||
return rp, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package twilio | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
) | ||
|
||
func TestGetRoom(t *testing.T) { | ||
t.Parallel() | ||
client, server := getServer(roomResponse) | ||
defer server.Close() | ||
room, err := client.Video.Rooms.Get(context.Background(), "RMca86cf94c7d4f89e0bd45bfa7d9b9e7d") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if room.Sid != "RMca86cf94c7d4f89e0bd45bfa7d9b9e7d" { | ||
t.Errorf("room: got sid %q, want %q", room.Sid, "RMca86cf94c7d4f89e0bd45bfa7d9b9e7d") | ||
} | ||
if room.Status != StatusInProgress { | ||
t.Errorf("room: got status %q, want %q", room.Status, StatusInProgress) | ||
} | ||
if room.Type != RoomTypePeerToPeer { | ||
t.Errorf("room: got type %q, want %q", room.Type, RoomTypePeerToPeer) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package twilio | ||
|
||
import ( | ||
"context" | ||
"net/url" | ||
"strings" | ||
) | ||
|
||
type VideoRecordingService struct { | ||
client *Client | ||
} | ||
|
||
const videoRecordingsPathPart = "Recordings" | ||
|
||
func videoMediaPathPart(recordingSid string) string { | ||
return strings.Join([]string{videoRecordingsPathPart, recordingSid, "Media"}, "/") | ||
} | ||
|
||
type VideoRecording struct { | ||
Sid string `json:"sid"` | ||
Duration uint `json:"duration"` | ||
Status Status `json:"status"` | ||
DateCreated TwilioTime `json:"date_created"` | ||
SourceSid string `json:"source_sid"` | ||
URI string `json:"uri"` | ||
Size uint `json:"size"` | ||
Type string `json:"type"` | ||
ContainerFormat string `json:"container_format"` | ||
Codec string `json:"codec"` | ||
GroupingSids map[string]string `json:"grouping_sids"` | ||
Links map[string]string `json:"links"` | ||
} | ||
|
||
type VideoMedia struct { | ||
Location string `json:"location"` | ||
} | ||
|
||
type VideoRecordingPage struct { | ||
Meta Meta `json:"meta"` | ||
Recordings []*VideoRecording `json:"recordings"` | ||
} | ||
|
||
type VideoRecordingPageIterator struct { | ||
p *PageIterator | ||
} | ||
|
||
// When you make a request to this URL, Twilio will generate a temporary URL for accessing | ||
// this binary data, and issue an HTTP 302 redirect response to your request. The Recording | ||
// will be returned in the format as described in the metadata. | ||
func (vr *VideoRecordingService) Media(ctx context.Context, sid string) (*VideoMedia, error) { | ||
media := new(VideoMedia) | ||
path := videoMediaPathPart(sid) | ||
err := vr.client.ListResource(ctx, path, nil, media) | ||
return media, err | ||
} | ||
|
||
// Returns the VideoRecording with the given sid. | ||
func (vr *VideoRecordingService) Get(ctx context.Context, sid string) (*VideoRecording, error) { | ||
recording := new(VideoRecording) | ||
err := vr.client.GetResource(ctx, videoRecordingsPathPart, sid, recording) | ||
return recording, err | ||
} | ||
|
||
// Delete the VideoRecording with the given sid. If the VideoRecording has already been | ||
// deleted, or does not exist, Delete returns nil. If another error or a | ||
// timeout occurs, the error is returned. | ||
func (vr *VideoRecordingService) Delete(ctx context.Context, sid string) error { | ||
return vr.client.DeleteResource(ctx, videoRecordingsPathPart, sid) | ||
} | ||
|
||
// Returns a list of recordings. For more information on valid values, | ||
// see https://www.twilio.com/docs/api/video/recordings-resource#recordings-list-resource | ||
func (vr *VideoRecordingService) GetPage(ctx context.Context, data url.Values) (*VideoRecordingPage, error) { | ||
return vr.GetPageIterator(data).Next(ctx) | ||
} | ||
|
||
// GetPageIterator returns an iterator which can be used to retrieve pages. | ||
func (vr *VideoRecordingService) GetPageIterator(data url.Values) *VideoRecordingPageIterator { | ||
iter := NewPageIterator(vr.client, data, videoRecordingsPathPart) | ||
return &VideoRecordingPageIterator{ | ||
p: iter, | ||
} | ||
} | ||
|
||
// Next returns the next page of resources. If there are no more resources, | ||
// NoMoreResults is returned. | ||
func (vr *VideoRecordingPageIterator) Next(ctx context.Context) (*VideoRecordingPage, error) { | ||
vrp := new(VideoRecordingPage) | ||
err := vr.p.Next(ctx, vrp) | ||
if err != nil { | ||
return nil, err | ||
} | ||
vr.p.SetNextPageURI(vrp.Meta.NextPageURL) | ||
return vrp, nil | ||
} |
Oops, something went wrong.