-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) 2019, NewReleases Go client AUTHORS. | ||
// All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package newreleases | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
) | ||
|
||
// TelegramChatsService provides information about Telegram notifications. | ||
type TelegramChatsService service | ||
|
||
// TelegramChat holds information about a Telegram Chat which receives | ||
// notifications. | ||
type TelegramChat struct { | ||
ID string `json:"id"` | ||
Type string `json:"type"` | ||
Name string `json:"name"` | ||
} | ||
|
||
// List returns all connected Slack Channels. | ||
func (s *TelegramChatsService) List(ctx context.Context) (channels []TelegramChat, err error) { | ||
|
||
type TelegramChatsResponse struct { | ||
Chats []TelegramChat `json:"chats"` | ||
} | ||
|
||
var r TelegramChatsResponse | ||
err = s.client.request(ctx, http.MethodGet, "v1/telegram-chats", nil, &r) | ||
return r.Chats, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) 2019, NewReleases Go client AUTHORS. | ||
// All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package newreleases_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
|
||
"newreleases.io/newreleases" | ||
) | ||
|
||
func TestTelegramChatsService_List(t *testing.T) { | ||
client, mux, _, teardown := newClient(t, "") | ||
defer teardown() | ||
|
||
mux.HandleFunc("/v1/telegram-chats", requireMethod("GET", func(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("Content-Type", jsonContentType) | ||
fmt.Fprintln(w, telegramChatsServiceList) | ||
})) | ||
|
||
got, err := client.TelegramChats.List(context.Background()) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
assertEqual(t, "", got, telegramChatsServiceListWant) | ||
} | ||
|
||
var ( | ||
telegramChatsServiceList = ` | ||
{ | ||
"chats": [ | ||
{ | ||
"id": "00q3pe8gf7322d8n52bgrl551", | ||
"type": "group", | ||
"name": "My Telegram Chat" | ||
} | ||
] | ||
} | ||
` | ||
telegramChatsServiceListWant = []newreleases.TelegramChat{ | ||
{ | ||
ID: "00q3pe8gf7322d8n52bgrl551", | ||
Type: "group", | ||
Name: "My Telegram Chat", | ||
}, | ||
} | ||
) |