Skip to content

Commit

Permalink
Use string for app secret (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferhatelmas authored Sep 24, 2020
1 parent f65446c commit 5f5ce09
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestClient_UpdateAppSettings(t *testing.T) {
// See https://getstream.io/chat/docs/app_settings_auth/ for
// more details.
func ExampleClient_UpdateAppSettings_disable_auth() {
client, err := NewClient("XXXXXXXXXXXX", []byte("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"))
client, err := NewClient("XXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
if err != nil {
log.Fatalf("Err: %v", err)
}
Expand All @@ -47,7 +47,7 @@ func ExampleClient_UpdateAppSettings_disable_auth() {
}

func ExampleClient_UpdateAppSettings_disable_permission() {
client, err := NewClient("XXXX", []byte("XXXX"))
client, err := NewClient("XXXX", "XXXX")
if err != nil {
log.Fatalf("Err: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ func ExampleChannel_Update() {
}

func (c *Client) ExampleClient_CreateChannel() {
client, _ := NewClient("XXXX", []byte("XXXX"))
client, _ := NewClient("XXXX", "XXXX")

channel, _ := client.CreateChannel("team", "stream", "tommaso", nil)
_, _ = channel.SendMessage(&Message{
Expand Down
6 changes: 3 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,17 +263,17 @@ func (c *Client) sendFile(link string, opts SendFileRequest) (string, error) {
}

// NewClient creates new stream chat api client.
func NewClient(apiKey string, apiSecret []byte) (*Client, error) {
func NewClient(apiKey, apiSecret string) (*Client, error) {
switch {
case apiKey == "":
return nil, errors.New("API key is empty")
case len(apiSecret) == 0:
case apiSecret == "":
return nil, errors.New("API secret is empty")
}

client := &Client{
apiKey: apiKey,
apiSecret: apiSecret,
apiSecret: []byte(apiSecret),
BaseURL: defaultBaseURL,
HTTP: &http.Client{
Timeout: defaultTimeout,
Expand Down
6 changes: 3 additions & 3 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func initClient(t *testing.T) *Client {
c, err := NewClient(APIKey, []byte(APISecret))
c, err := NewClient(APIKey, APISecret)
require.NoError(t, err, "new client")

// set hostname to client from env if present
Expand Down Expand Up @@ -42,7 +42,7 @@ func TestNewClient(t *testing.T) {
c := initClient(t)

assert.Equal(t, c.apiKey, APIKey)
assert.Equal(t, c.apiSecret, []byte(APISecret))
assert.Equal(t, string(c.apiSecret), APISecret)
assert.NotEmpty(t, c.authToken)
assert.Equal(t, defaultTimeout, c.HTTP.Timeout)
}
Expand Down Expand Up @@ -75,7 +75,7 @@ func TestClient_CreateToken(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
c, err := NewClient("key", []byte("secret"))
c, err := NewClient("key", "secret")
require.NoError(t, err)

got, err := c.CreateToken(tt.args.userID, tt.args.expire)
Expand Down
4 changes: 2 additions & 2 deletions device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func deviceIDExists(dev []*Device, id string) bool {
}

func ExampleClient_AddDevice() {
client, _ := NewClient("XXXX", []byte("XXXX"))
client, _ := NewClient("XXXX", "XXXX")

_ = client.AddDevice(&Device{
ID: "2ffca4ad6599adc9b5202d15a5286d33c19547d472cd09de44219cda5ac30207",
Expand All @@ -50,7 +50,7 @@ func ExampleClient_AddDevice() {
}

func ExampleClient_DeleteDevice() {
client, _ := NewClient("XXXX", []byte("XXXX"))
client, _ := NewClient("XXXX", "XXXX")

deviceID := "2ffca4ad6599adc9b5202d15a5286d33c19547d472cd09de44219cda5ac30207"
userID := "elon"
Expand Down
14 changes: 7 additions & 7 deletions user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func TestClient_PartialUpdateUsers(t *testing.T) {
}

func ExampleClient_UpdateUser() {
client, _ := NewClient("XXXX", []byte("XXXX"))
client, _ := NewClient("XXXX", "XXXX")

_, err := client.UpdateUser(&User{
ID: "tommaso",
Expand All @@ -174,32 +174,32 @@ func ExampleClient_UpdateUser() {
}

func ExampleClient_ExportUser() {
client, _ := NewClient("XXXX", []byte("XXXX"))
client, _ := NewClient("XXXX", "XXXX")

user, _ := client.ExportUser("userID", nil)
log.Printf("%#v", user)
}

func ExampleClient_DeactivateUser() {
client, _ := NewClient("XXXX", []byte("XXXX"))
client, _ := NewClient("XXXX", "XXXX")

_ = client.DeactivateUser("userID", nil)
}

func ExampleClient_ReactivateUser() {
client, _ := NewClient("XXXX", []byte("XXXX"))
client, _ := NewClient("XXXX", "XXXX")

_ = client.ReactivateUser("userID", nil)
}

func ExampleClient_DeleteUser() {
client, _ := NewClient("XXXX", []byte("XXXX"))
client, _ := NewClient("XXXX", "XXXX")

_ = client.DeleteUser("userID", nil)
}

func ExampleClient_DeleteUser_hard() {
client, _ := NewClient("XXXX", []byte("XXXX"))
client, _ := NewClient("XXXX", "XXXX")

options := map[string][]string{
"mark_messages_deleted": {"true"},
Expand All @@ -210,7 +210,7 @@ func ExampleClient_DeleteUser_hard() {
}

func ExampleClient_BanUser() {
client, _ := NewClient("XXXX", []byte("XXXX"))
client, _ := NewClient("XXXX", "XXXX")

// ban a user for 60 minutes from all channel
_ = client.BanUser("eviluser", "modUser",
Expand Down

0 comments on commit 5f5ce09

Please sign in to comment.