forked from saintpete/twilio-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transcription.go
89 lines (77 loc) · 2.85 KB
/
transcription.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package twilio
import (
"context"
"net/url"
)
const transcriptionPathPart = "Transcriptions"
type TranscriptionService struct {
client *Client
}
type Transcription struct {
Sid string `json:"sid"`
TranscriptionText string `json:"transcription_text"`
DateCreated TwilioTime `json:"date_created"`
DateUpdated TwilioTime `json:"date_updated"`
Duration TwilioDuration `json:"duration"`
Price string `json:"price"`
PriceUnit string `json:"price_unit"`
RecordingSid string `json:"recording_sid"`
Status Status `json:"status"`
Type string `json:"type"`
AccountSid string `json:"account_sid"`
APIVersion string `json:"api_version"`
URI string `json:"uri"`
}
type TranscriptionPage struct {
Page
Transcriptions []*Transcription
}
// FriendlyPrice flips the sign of the Price (which is usually reported from
// the API as a negative number) and adds an appropriate currency symbol in
// front of it. For example, a PriceUnit of "USD" and a Price of "-1.25" is
// reported as "$1.25".
func (t *Transcription) FriendlyPrice() string {
if t == nil {
return ""
}
return price(t.PriceUnit, t.Price)
}
// Get returns a single Transcription or an error.
func (c *TranscriptionService) Get(ctx context.Context, sid string) (*Transcription, error) {
transcription := new(Transcription)
err := c.client.GetResource(ctx, transcriptionPathPart, sid, transcription)
return transcription, err
}
// Delete the Transcription with the given sid. If the Transcription has
// already been deleted, or does not exist, Delete returns nil. If another
// error or a timeout occurs, the error is returned.
func (c *TranscriptionService) Delete(ctx context.Context, sid string) error {
return c.client.DeleteResource(ctx, transcriptionPathPart, sid)
}
func (c *TranscriptionService) GetPage(ctx context.Context, data url.Values) (*TranscriptionPage, error) {
iter := c.GetPageIterator(data)
return iter.Next(ctx)
}
type TranscriptionPageIterator struct {
p *PageIterator
}
// GetPageIterator returns a TranscriptionPageIterator with the given page
// filters. Call iterator.Next() to get the first page of resources (and again to
// retrieve subsequent pages).
func (c *TranscriptionService) GetPageIterator(data url.Values) *TranscriptionPageIterator {
iter := NewPageIterator(c.client, data, transcriptionPathPart)
return &TranscriptionPageIterator{
p: iter,
}
}
// Next returns the next page of resources. If there are no more resources,
// NoMoreResults is returned.
func (c *TranscriptionPageIterator) Next(ctx context.Context) (*TranscriptionPage, error) {
cp := new(TranscriptionPage)
err := c.p.Next(ctx, cp)
if err != nil {
return nil, err
}
c.p.SetNextPageURI(cp.NextPageURI)
return cp, nil
}