Skip to content

Commit bdf6d9d

Browse files
author
marcel corso gonzalez
authored
Merge pull request #121 from vallerion/fresh-conversation
Fresh conversation API
2 parents 926e6f1 + 5f78f5d commit bdf6d9d

25 files changed

+1152
-364
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BSD 2-Clause License
22

3-
Copyright (c) 2014-2015, MessageBird
3+
Copyright (c) 2014-2022, MessageBird
44
All rights reserved.
55

66
Redistribution and use in source and binary forms, with or without

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ MessageBird's REST API for Go
22
=============================
33
This repository contains the open source Go client for MessageBird's REST API. Documentation can be found at: https://developers.messagebird.com.
44

5-
[![Build Status](https://travis-ci.org/messagebird/go-rest-api.svg?branch=master)](https://travis-ci.org/messagebird/go-rest-api) [![PkgGoDev](https://pkg.go.dev/badge/github.com/messagebird/go-rest-api/v7)](https://pkg.go.dev/github.com/messagebird/go-rest-api/v7)
5+
[![Build Status](https://travis-ci.org/messagebird/go-rest-api.svg?branch=master)](https://travis-ci.org/messagebird/go-rest-api) [![PkgGoDev](https://pkg.go.dev/badge/github.com/messagebird/go-rest-api/v8)](https://pkg.go.dev/github.com/messagebird/go-rest-api/v8)
66

77
Requirements
88
------------
@@ -15,15 +15,15 @@ Installation
1515
The easiest way to use the MessageBird API in your Go project is to install it using *go get*:
1616

1717
```
18-
$ go get github.com/messagebird/go-rest-api/v7
18+
$ go get github.com/messagebird/go-rest-api/v8
1919
```
2020

2121
Examples
2222
--------
2323
Here is a quick example on how to get started. Assuming the **go get** installation worked, you can import the messagebird package like this:
2424

2525
```go
26-
import "github.com/messagebird/go-rest-api/v7"
26+
import "github.com/messagebird/go-rest-api/v8"
2727
```
2828

2929
Then, create an instance of **messagebird.Client**. It can be used to access the MessageBird APIs.
@@ -69,8 +69,8 @@ For this reason, errors returned by the `voice` package are of type `voice.Error
6969
An example of "simple" error handling is shown in the example above. Let's look how we can gain more in-depth insight in what exactly went wrong:
7070

7171
```go
72-
import "github.com/messagebird/go-rest-api/v7"
73-
import "github.com/messagebird/go-rest-api/v7/sms"
72+
import "github.com/messagebird/go-rest-api/v8"
73+
import "github.com/messagebird/go-rest-api/v8/sms"
7474

7575
// ...
7676

@@ -91,7 +91,7 @@ if err != nil {
9191
`voice.ErrorResponse` is very similar, except that it holds `voice.Error` structs - those contain only `Code` and `Message` (not description!) fields:
9292

9393
```go
94-
import "github.com/messagebird/go-rest-api/v7/voice"
94+
import "github.com/messagebird/go-rest-api/v8/voice"
9595

9696
// ...
9797

UPGRADING.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,11 @@ As v7 introduces support for using the Verify API with email recipients, the `Ve
108108
### Update SMS API
109109
Added [missed fields](https://github.com/messagebird/go-rest-api/pull/119/commits/f9331269238f1518dd35d798a0fbf251bb04bb62) in SMS API.
110110
Updated `sms.Delete` method so now in return only error or nil as result.
111+
112+
## `v8.0.0` -> `v8.1.0`
113+
### Update Conversations API
114+
* Replaced `conversations.CreateMessage` with `conversations.Reply` which send a new message to an existing conversation.
115+
* Replaced `conversations.ListMessages` with `conversations.ListConversationMessages` which fetch messages in indicated conversation.
116+
* Added `conversations.SendMessage` to send a message to a specific recipient in a specific platform.
117+
* Added `conversations.ListByContact` to retrieves the list of conversation IDs of a specific contact ID.
118+
* Now `conversations.ListMessages` retrieves a list of messages given a list of message IDs or a timestamp (not both).

client.go

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright (c) 2014 MessageBird B.V.
2+
// Copyright (c) 2022 MessageBird B.V.
33
// All rights reserved.
44
//
55
// Author: Maurice Nonnekes <[email protected]>
@@ -20,13 +20,12 @@ import (
2020
"net/url"
2121
"runtime"
2222
"strings"
23-
"sync"
2423
"time"
2524
)
2625

2726
const (
2827
// ClientVersion is used in User-Agent request header to provide server with API level.
29-
ClientVersion = "8.0.0"
28+
ClientVersion = "8.1.0"
3029

3130
// Endpoint points you to MessageBird REST API.
3231
Endpoint = "https://rest.messagebird.com"
@@ -40,20 +39,22 @@ const (
4039

4140
var (
4241
// 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")
4443
)
4544

4645
// A Feature can be enabled
4746
type Feature int
4847

48+
type MessageBirdClient interface {
49+
Request(v interface{}, method, path string, data interface{}) error
50+
}
51+
4952
// Client is used to access API with a given key.
5053
// Uses standard lib HTTP client internally, so should be reused instead of created as needed and it is safe for concurrent use.
5154
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.
5758
}
5859

5960
type contentType string
@@ -76,7 +77,6 @@ func New(accessKey string) *Client {
7677
HTTPClient: &http.Client{
7778
Timeout: httpClientTimeout,
7879
},
79-
features: make(map[Feature]bool),
8080
}
8181
}
8282

@@ -86,30 +86,6 @@ func SetVoiceErrorReader(r errorReader) {
8686
voiceErrorReader = r
8787
}
8888

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-
11389
// Request is for internal use only and unstable.
11490
func (c *Client) Request(v interface{}, method, path string, data interface{}) error {
11591
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
162138
}
163139

164140
switch response.StatusCode {
165-
case http.StatusOK, http.StatusCreated:
141+
case http.StatusOK, http.StatusCreated, http.StatusAccepted:
166142
// Status codes 200 and 201 are indicative of being able to convert the
167143
// response body to the struct that was specified.
168144
if err := json.Unmarshal(responseBody, &v); err != nil {

0 commit comments

Comments
 (0)