forked from sfreiberg/gotwilio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
usage_test.go
92 lines (86 loc) · 4.18 KB
/
usage_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
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
90
91
92
package gotwilio
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
)
func TestGetUsage(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, testUsageResponse)
}))
defer srv.Close()
twilio := NewTwilioClient("", "")
twilio.BaseUrl = srv.URL
usage, exc, err := twilio.GetUsage("", "", "", false)
if err != nil {
t.Fatal(err)
}
if exc != nil {
t.Fatal(exc)
}
if len(usage.UsageRecords) != 2 {
t.Errorf("Expected 2 records, got %d", len(usage.UsageRecords))
}
}
// Example from https://www.twilio.com/docs/usage/api/usage-record:
const testUsageResponse = `
{
"first_page_uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Usage/Records.json?Page=0&PageSize=50",
"previous_page_uri": null,
"uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Usage/Records.json",
"page_size": 50,
"usage_records": [
{
"category": "calleridlookups",
"count": "0",
"price_unit": "usd",
"subresource_uris": {
"yearly": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Usage/Records/Yearly.json?Category=calleridlookups",
"last_month": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Usage/Records/LastMonth.json?Category=calleridlookups",
"monthly": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Usage/Records/Monthly.json?Category=calleridlookups",
"yesterday": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Usage/Records/Yesterday.json?Category=calleridlookups",
"daily": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Usage/Records/Daily.json?Category=calleridlookups",
"all_time": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Usage/Records/AllTime.json?Category=calleridlookups",
"this_month": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Usage/Records/ThisMonth.json?Category=calleridlookups",
"today": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Usage/Records/Today.json?Category=calleridlookups"
},
"description": "Caller ID Lookups",
"end_date": "2012-10-13",
"usage_unit": "lookups",
"price": "0",
"uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Usage/Records.json?Category=calleridlookups&StartDate=2012-08-15&EndDate=2012-10-13",
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"usage": "0",
"start_date": "2012-08-15",
"count_unit": "lookups"
},
{
"category": "calls",
"count": "21",
"price_unit": "usd",
"subresource_uris": {
"yearly": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Usage/Records/Yearly.json?Category=calls",
"last_month": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Usage/Records/LastMonth.json?Category=calls",
"monthly": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Usage/Records/Monthly.json?Category=calls",
"yesterday": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Usage/Records/Yesterday.json?Category=calls",
"daily": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Usage/Records/Daily.json?Category=calls",
"all_time": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Usage/Records/AllTime.json?Category=calls",
"this_month": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Usage/Records/ThisMonth.json?Category=calls",
"today": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Usage/Records/Today.json?Category=calls"
},
"description": "Total Calls",
"end_date": "2012-10-13",
"usage_unit": "minutes",
"price": "0.38",
"uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Usage/Records.json?Category=calls&StartDate=2012-08-15&EndDate=2012-10-13",
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"usage": "21",
"start_date": "2012-08-15",
"count_unit": "calls"
}
],
"next_page_uri": null,
"page": 0
}
`