forked from kevinburke/twilio-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_messages_test.go
41 lines (36 loc) · 1.01 KB
/
example_messages_test.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
package twilio_test
import (
"context"
"fmt"
"log"
"net/url"
"time"
twilio "github.com/kevinburke/twilio-go"
)
func ExampleMessageService_Get() {
client := twilio.NewClient("AC123", "123", nil)
message, _ := client.Messages.Get(context.TODO(), "SM123")
fmt.Println(message.Status)
}
func ExampleMessageService_GetMessagesInRange() {
// Get all messages between 10:34:00 Oct 26 and 19:25:59 Oct 27, NYC time.
nyc, _ := time.LoadLocation("America/New_York")
start := time.Date(2016, 10, 26, 22, 34, 00, 00, nyc)
end := time.Date(2016, 10, 27, 19, 25, 59, 00, nyc)
client := twilio.NewClient("AC123", "123", nil)
iter := client.Messages.GetMessagesInRange(start, end, url.Values{})
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
for {
page, err := iter.Next(ctx)
if err == twilio.NoMoreResults {
break
}
if err != nil {
log.Fatal(err)
}
for i, message := range page.Messages {
fmt.Printf("%d: %s (%s)", i, message.Sid, message.DateCreated.Time)
}
}
}