1
1
//
2
- // Copyright (c) 2014 MessageBird B.V.
2
+ // Copyright (c) 2022 MessageBird B.V.
3
3
// All rights reserved.
4
4
//
5
5
// Author: Maurice Nonnekes <[email protected] >
@@ -20,13 +20,12 @@ import (
20
20
"net/url"
21
21
"runtime"
22
22
"strings"
23
- "sync"
24
23
"time"
25
24
)
26
25
27
26
const (
28
27
// ClientVersion is used in User-Agent request header to provide server with API level.
29
- ClientVersion = "8.0 .0"
28
+ ClientVersion = "8.1 .0"
30
29
31
30
// Endpoint points you to MessageBird REST API.
32
31
Endpoint = "https://rest.messagebird.com"
@@ -40,20 +39,22 @@ const (
40
39
41
40
var (
42
41
// ErrUnexpectedResponse is used when there was an internal server error and nothing can be done at this point.
43
- ErrUnexpectedResponse = errors .New ("The MessageBird API is currently unavailable" )
42
+ ErrUnexpectedResponse = errors .New ("the MessageBird API is currently unavailable" )
44
43
)
45
44
46
45
// A Feature can be enabled
47
46
type Feature int
48
47
48
+ type MessageBirdClient interface {
49
+ Request (v interface {}, method , path string , data interface {}) error
50
+ }
51
+
49
52
// Client is used to access API with a given key.
50
53
// Uses standard lib HTTP client internally, so should be reused instead of created as needed and it is safe for concurrent use.
51
54
type Client struct {
52
- AccessKey string // The API access key.
53
- HTTPClient * http.Client // The HTTP client to send requests on.
54
- DebugLog * log.Logger // Optional logger for debugging purposes.
55
- features map [Feature ]bool // Enabled features.
56
- featuresMutex sync.RWMutex // Mutex for accessing feature map.
55
+ AccessKey string // The API access key.
56
+ HTTPClient * http.Client // The HTTP client to send requests on.
57
+ DebugLog * log.Logger // Optional logger for debugging purposes.
57
58
}
58
59
59
60
type contentType string
@@ -76,7 +77,6 @@ func New(accessKey string) *Client {
76
77
HTTPClient : & http.Client {
77
78
Timeout : httpClientTimeout ,
78
79
},
79
- features : make (map [Feature ]bool ),
80
80
}
81
81
}
82
82
@@ -86,30 +86,6 @@ func SetVoiceErrorReader(r errorReader) {
86
86
voiceErrorReader = r
87
87
}
88
88
89
- // EnableFeatures enables a feature.
90
- func (c * Client ) EnableFeatures (feature Feature ) {
91
- c .featuresMutex .Lock ()
92
- defer c .featuresMutex .Unlock ()
93
- c .features [feature ] = true
94
- }
95
-
96
- // DisableFeatures disables a feature.
97
- func (c * Client ) DisableFeatures (feature Feature ) {
98
- c .featuresMutex .Lock ()
99
- defer c .featuresMutex .Unlock ()
100
- c .features [feature ] = false
101
- }
102
-
103
- // IsFeatureEnabled checks if a feature is enabled.
104
- func (c * Client ) IsFeatureEnabled (feature Feature ) bool {
105
- c .featuresMutex .RLock ()
106
- defer c .featuresMutex .RUnlock ()
107
- if enabled , ok := c .features [feature ]; ok {
108
- return enabled
109
- }
110
- return false
111
- }
112
-
113
89
// Request is for internal use only and unstable.
114
90
func (c * Client ) Request (v interface {}, method , path string , data interface {}) error {
115
91
if ! strings .HasPrefix (path , "https://" ) && ! strings .HasPrefix (path , "http://" ) {
@@ -162,7 +138,7 @@ func (c *Client) Request(v interface{}, method, path string, data interface{}) e
162
138
}
163
139
164
140
switch response .StatusCode {
165
- case http .StatusOK , http .StatusCreated :
141
+ case http .StatusOK , http .StatusCreated , http . StatusAccepted :
166
142
// Status codes 200 and 201 are indicative of being able to convert the
167
143
// response body to the struct that was specified.
168
144
if err := json .Unmarshal (responseBody , & v ); err != nil {
0 commit comments