Skip to content

Commit

Permalink
fix: stablelise the repo
Browse files Browse the repository at this point in the history
  • Loading branch information
tomMoulard committed Apr 24, 2024
1 parent 982734e commit 351ec78
Show file tree
Hide file tree
Showing 17 changed files with 148 additions and 45 deletions.
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ representative at an online or offline event.

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
pellared@hotmail.com.
tom@moulard.org.
All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the
Expand Down
2 changes: 2 additions & 0 deletions FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: [tommoulard]
custom: ["https://www.paypal.me/tommoulard"]
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,63 @@
[![Build Status](https://img.shields.io/github/actions/workflow/status/tomMoulard/sendbird-go/build.yml?branch=main)](https://github.com/tomMoulard/sendbird-go/actions?query=workflow%3Abuild+branch%3Amain)
[![Go Report Card](https://goreportcard.com/badge/github.com/tomMoulard/sendbird-go)](https://goreportcard.com/report/github.com/tomMoulard/sendbird-go)

Yet another go client for the [Sendbird](https://sendbird.com) chat API.

`Star` this repository if you find it valuable and worth maintaining.

👁 `Watch` this repository to get notified about new releases, issues, etc.

## User Guide

### Installation

```bash
go get github.com/tomMoulard/sendbird-go
```

### Usage

```go
package main

import (
"context"
"fmt"
"log"
"os"

"github.com/tomMoulard/sendbird-go/pkg/client"
"github.com/tomMoulard/sendbird-go/pkg/user"
)

func main() {
opts := []client.Option{
client.WithAPPID(os.Getenv("SENDBIRD_APP_ID")),
client.WithAPIKey(os.Getenv("SENDBIRD_API_KEY")),
}
client := client.NewClient(opts...)

// To create a user
userClient := user.NewUser(client)

u := user.CreateUserRequest{
UserID: "user-id",
Nickname: "nickname",
}
createdUser, err := userClient.Create(context.Background(), u)
if err != nil {
if errors.Is(err, client.ErrTooManyRequests) {
log.Fatalf("rate limit exceeded: %v", err)
return
}
log.Fatalf("failed to create user: %v", err)
}
fmt.Printf("created user: %v\n", createdUser)
}
```

See available methods in the corresponding package documentation.

## Build

### Terminal
Expand Down
19 changes: 19 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Security Policy

## Supported Versions

Use this section to tell people about which versions of your project are
currently being supported with security updates.

| Version | Supported |
| ------- | ------------------ |
| 0.0.x | :white_check_mark: |

<!-- ## Reporting a Vulnerability
Use this section to tell people how to report a vulnerability.
Tell them where to go, how often they can expect to get an update on a
reported vulnerability, what to expect if the vulnerability is accepted or
declined, etc.
-->
14 changes: 14 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# API
- [X] channel
- [X] CreateGroupChannel
- [X] UpdateGroupChannel
- [ ] GetGroupChannels -> ListGroupChannels
- [X] message
- [X] SendMessage
- [X] GetMessages -> ListMessages
- [X] user
- [X] CreateUser
- [X] UpdateUser
- [X] GetSessionToken
- [X] GetUserUnreadMessages
- [X] GetUserJoinedChannelCount
16 changes: 0 additions & 16 deletions cmd/sendbird/sendbird.go

This file was deleted.

3 changes: 3 additions & 0 deletions pkg/channel/channel.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Package channel package provides the interface for the channel service.
// It provides the methods to interact with the sendbird API.
// See https://sendbird.com/docs/chat/platform-api/v3/channel/channel-overview.
package channel

import (
Expand Down
8 changes: 4 additions & 4 deletions pkg/channel/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/url"
"strconv"

"github.com/tomMoulard/sendbird-go/pkg/utils/strings"
strconvStlice "github.com/tomMoulard/sendbird-go/pkg/utils/strconv"
)

// https://sendbird.com/docs/chat/platform-api/v3/channel/listing-channels-in-an-application/list-group-channels
Expand Down Expand Up @@ -311,7 +311,7 @@ func ListChannelRequestToMap(lcr ListChannelRequest) map[string]string {
}

if len(lcr.ChannelURLs) > 0 {
m["channel_urls"] = strings.SliceToCSV(lcr.ChannelURLs)
m["channel_urls"] = strconvStlice.FormatSliceToCSV(lcr.ChannelURLs)
}

if lcr.Name != "" {
Expand Down Expand Up @@ -351,7 +351,7 @@ func ListChannelRequestToMap(lcr ListChannelRequest) map[string]string {
}

if len(lcr.MetadataValues) > 0 {
m["metadata_values"] = strings.SliceToCSV(lcr.MetadataValues)
m["metadata_values"] = strconvStlice.FormatSliceToCSV(lcr.MetadataValues)
}

if lcr.MetadataValueStartswith != "" {
Expand All @@ -363,7 +363,7 @@ func ListChannelRequestToMap(lcr ListChannelRequest) map[string]string {
}

if len(lcr.MetacounterValues) > 0 {
m["metacounter_values"] = strings.SliceToCSV(lcr.MetacounterValues)
m["metacounter_values"] = strconvStlice.FormatSliceToCSV(lcr.MetacounterValues)
}

if lcr.MetacounterValuesGT != "" {
Expand Down
3 changes: 2 additions & 1 deletion pkg/client/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// This package is for the client of the sendbird API
// Package client package provides the interface for the client of the sendbird
// API. It provides the methods to call the sendbird API.
package client

import (
Expand Down
9 changes: 9 additions & 0 deletions pkg/client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,12 @@ func WithAPIToken(apiToken string) Option {
return client
}
}

// WithAPPID is the option for the app id of the client.
func WithAPPID(appID string) Option {
return func(client *client) *client {
client.baseURL.Host = fmt.Sprintf("api-%s.sendbird.com", appID)

return client
}
}
10 changes: 10 additions & 0 deletions pkg/client/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,13 @@ func TestWithAPIToken(t *testing.T) {
assert.Equal(t, "api-token", client.header.Get("api-token"))
assert.Len(t, client.header, 2)
}

func TestWithAPPID(t *testing.T) {
t.Parallel()

client := &client{}
client.SetDefault()

client = WithAPPID("api-id")(client)
assert.Equal(t, "api-api-id.sendbird.com", client.baseURL.Host)
}
4 changes: 2 additions & 2 deletions pkg/message/list_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/url"
"strconv"

"github.com/tomMoulard/sendbird-go/pkg/utils/strings"
strconvSlice "github.com/tomMoulard/sendbird-go/pkg/utils/strconv"
)

// https://sendbird.com/docs/chat/platform-api/v3/message/messaging-basics/list-messages
Expand Down Expand Up @@ -157,7 +157,7 @@ func listMessagesRequestToMap(lmr ListMessagesRequest) map[string]string {
}

if len(lmr.SenderIDs) > 0 {
m["sender_ids"] = strings.SliceToCSV(lmr.SenderIDs)
m["sender_ids"] = strconvSlice.FormatSliceToCSV(lmr.SenderIDs)
}

if lmr.OperatorFilter != "" {
Expand Down
3 changes: 3 additions & 0 deletions pkg/message/message.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Package message package provides the interface for the message service.
// It provides the methods to interact with the sendbird API.
// See https://sendbird.com/docs/chat/platform-api/v3/message/message-overview.
package message

import (
Expand Down
3 changes: 3 additions & 0 deletions pkg/user/user.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Package user package provides the interface for the user service.
// It provides the methods to interact with the sendbird API.
// See https://sendbird.com/docs/chat/platform-api/v3/user/user-overview.
package user

import (
Expand Down
18 changes: 18 additions & 0 deletions pkg/utils/strconv/slice.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Package strconv formats primitive types to strings.
package strconv

// FormatSliceToCSV converts a slice of strings to a Comma Separated Values
// string.
func FormatSliceToCSV(s []string) string {
var csvString string

for i, v := range s {
if i > 0 {
csvString += ","
}

csvString += v
}

return csvString
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package strings
package strconv

import (
"fmt"
Expand All @@ -7,14 +7,14 @@ import (
"github.com/stretchr/testify/assert"
)

func ExampleSliceToCSV() {
func ExampleFormatSliceToCSV() {
s := []string{"foo", "bar", "baz"}
csv := SliceToCSV(s)
csv := FormatSliceToCSV(s)
fmt.Println(csv)
// Output: foo,bar,baz
}

func TestSliceToCSVStrings(t *testing.T) {
func TestFormatSliceToCSV(t *testing.T) {
t.Parallel()

tests := []struct {
Expand Down Expand Up @@ -43,7 +43,7 @@ func TestSliceToCSVStrings(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
t.Parallel()

actual := SliceToCSV(test.s)
actual := FormatSliceToCSV(test.s)
assert.Equal(t, test.expected, actual)
})
}
Expand Down
16 changes: 0 additions & 16 deletions pkg/utils/strings/slice.go

This file was deleted.

0 comments on commit 351ec78

Please sign in to comment.