Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Channels.archive #12

Open
wants to merge 54 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
045b086
Fixed Login
Aug 25, 2018
9cbace6
Added limited doc to code
Aug 25, 2018
5bcdef3
Merge branch 'master' of https://github.com/RocketChat/Rocket.Chat.Go…
Aug 25, 2018
fe8e993
Refactor to make development and testing easier
chrisjoyce911 Aug 26, 2018
f29b08c
Creaged an example client
chrisjoyce911 Aug 26, 2018
9141516
Improved information tests
chrisjoyce911 Aug 26, 2018
e281b67
Improved messages tests
chrisjoyce911 Aug 26, 2018
ec503df
Fixed naming of tests
chrisjoyce911 Aug 27, 2018
2f14444
Added Post example
chrisjoyce911 Aug 27, 2018
ff5969b
Added client tests
chrisjoyce911 Aug 27, 2018
45c5b66
user tests added
chrisjoyce911 Aug 27, 2018
612ea45
Fix Lint errors
chrisjoyce911 Aug 27, 2018
bebf8c4
wss
chrisjoyce911 Aug 27, 2018
7465a31
Merge pull request #1 from chrisjoyce911/make_testable
chrisjoyce911 Aug 27, 2018
444cd53
Restore mobels subpackage
chrisjoyce911 Aug 28, 2018
7eb1576
Restored use of models subpackage
chrisjoyce911 Aug 28, 2018
ec5c9b8
restored realtime and common_testing
chrisjoyce911 Aug 28, 2018
8004384
restored realtime and common_testing
chrisjoyce911 Aug 28, 2018
5917e8a
Merge branch 'subpackage' of github.com:chrisjoyce911/Rocket.Chat.Go.…
chrisjoyce911 Aug 28, 2018
878afdb
restored rest sub package
chrisjoyce911 Aug 28, 2018
5aed498
Move rest client as its own example
chrisjoyce911 Aug 28, 2018
6be7a86
Added more docs
chrisjoyce911 Aug 28, 2018
bb701c1
Added channels.kick
chrisjoyce911 Aug 28, 2018
61b7cbe
Added GetMembersList
chrisjoyce911 Aug 28, 2018
12dab2e
Uncomment post example
chrisjoyce911 Aug 28, 2018
467ba63
Added ChannelsCreate
chrisjoyce911 Aug 28, 2018
7cc506e
ChannelClose added
chrisjoyce911 Aug 28, 2018
238e3f7
Added Creat and Close to example
chrisjoyce911 Aug 28, 2018
607a652
ChannelArchive added
chrisjoyce911 Aug 28, 2018
fd53cb9
Fixed error in comments
chrisjoyce911 Aug 28, 2018
4b2ab76
ChannelUnarchive
chrisjoyce911 Aug 28, 2018
be96e72
Added a http in terfacr to client
chrisjoyce911 Aug 28, 2018
7c189cb
Added channels.kick
chrisjoyce911 Aug 28, 2018
43e2dc5
Added GetMembersList
chrisjoyce911 Aug 28, 2018
38189fa
Merge branch 'subpackage' of github.com:chrisjoyce911/Rocket.Chat.Go.…
chrisjoyce911 Aug 29, 2018
720e686
Merge branch 'channels.kick' of github.com:chrisjoyce911/Rocket.Chat.…
chrisjoyce911 Aug 29, 2018
9b61947
Merge pull request #2 from chrisjoyce911/channels.kick
chrisjoyce911 Aug 29, 2018
922ae9e
Move rest client as its own example
chrisjoyce911 Aug 28, 2018
cce0442
Added more docs
chrisjoyce911 Aug 28, 2018
133137c
Added ChannelsCreate
chrisjoyce911 Aug 28, 2018
88447bd
ChannelClose added
chrisjoyce911 Aug 28, 2018
9719525
Added Creat and Close to example
chrisjoyce911 Aug 28, 2018
15419cd
Merge branch 'subpackage' of github.com:chrisjoyce911/Rocket.Chat.Go.…
chrisjoyce911 Aug 29, 2018
21f019b
Fixed conflicts
chrisjoyce911 Aug 29, 2018
e786a4e
Merge branch 'channels.create' of github.com:chrisjoyce911/Rocket.Cha…
chrisjoyce911 Aug 29, 2018
25d31e1
Merge pull request #3 from chrisjoyce911/channels.create
chrisjoyce911 Aug 29, 2018
c534f5e
ChannelArchive added
chrisjoyce911 Aug 28, 2018
29f369f
ChannelUnarchive
chrisjoyce911 Aug 28, 2018
07b0535
Merge branch 'subpackage' of github.com:chrisjoyce911/Rocket.Chat.Go.…
chrisjoyce911 Aug 29, 2018
d33683f
Merge branch 'channels.archive' of github.com:chrisjoyce911/Rocket.Ch…
chrisjoyce911 Aug 29, 2018
b12bfae
ChannelArchive added
chrisjoyce911 Aug 28, 2018
07f74f5
ChannelUnarchive
chrisjoyce911 Aug 28, 2018
38da81d
ChannelArchive added
chrisjoyce911 Aug 28, 2018
928931f
Merge branch 'channels.archive' of github.com:chrisjoyce911/Rocket.Ch…
chrisjoyce911 Aug 29, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions example/rest/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package main

import (
"flag"
"fmt"
"log"
"net/url"
"os"

"github.com/RocketChat/Rocket.Chat.Go.SDK/models"
"github.com/RocketChat/Rocket.Chat.Go.SDK/rest"
)

func main() {

hostPtr := flag.String("host", "", "Rocket.chat server host")
schemePtr := flag.String("scheme", "https", "http/https")
userPtr := flag.String("user", "", "Rocket.chat user")
passPtr := flag.String("pass", "", "Rocket.chat password")

required := []string{"host", "user", "pass"}
flag.Parse()

seen := make(map[string]bool)
flag.Visit(func(f *flag.Flag) { seen[f.Name] = true })
for _, req := range required {
if !seen[req] {
fmt.Fprintf(os.Stderr, "Missing required argument -%s\n", req)
os.Exit(2)
}
}

rockerServer := &url.URL{Host: *hostPtr, Scheme: *schemePtr}
debug := false

credentials := &models.UserCredentials{Email: *userPtr, Password: *passPtr}
rc, err := rest.NewRestClient(rockerServer, debug)
if err != nil {
log.Fatal(err)
}
err = rc.Rest.Login(credentials)
if err != nil {
log.Fatal(err)
}

myroom := &models.Channel{Name: "myroom"}

err = rc.Rest.ChannelsCreate(myroom)
if err != nil {
log.Println(err)
}

rcChannels, err := rc.Rest.GetPublicChannels()
if err != nil {
log.Println(err)
}

for _, channel := range rcChannels.Channels {
fmt.Printf("channel\n\tName:\t%s\n\tID:\t%s\n", channel.Name, channel.ID)

if channel.Name == "myroom" {
closeThisRoom := &models.Channel{ID: channel.ID}
err = rc.Rest.ChannelClose(closeThisRoom)
if err != nil {
log.Println(err)
}
}
}

general := &models.Channel{ID: "GENERAL", Name: "general"}

members, _ := rc.Rest.GetMembersList("GENERAL")
fmt.Println(members)

messages, err := rc.Rest.GetMessages(general, &models.Pagination{Count: 5})
if err != nil {
log.Println(err)
}

for _, message := range messages {
fmt.Printf("%s %s\n", message.Timestamp, message.User.UserName)
fmt.Printf("%s\n", message.Msg)
fmt.Println("")
}

msgOBJ := models.Attachment{
Color: "#00ff00",
Text: "Yay for the gopher!",
ImageURL: "https://ih1.redbubble.net/image.377846240.0222/ap,550x550,12x16,1,transparent,t.png",
Title: "PostMessage Example for Go",
Fields: []models.AttachmentField{
models.AttachmentField{Short: true, Title: "Get the package", Value: "[Link](https://github.com/RocketChat/Rocket.Chat.Go.SDK) Rocket.Chat.Go.SDK"},
},
}

msgPOST := models.PostMessage{
RoomID: "GENERAL",
Channel: "general",
Emoji: ":smirk:",
Text: "PostMessage API using GoLang works ok",
Attachments: []models.Attachment{
msgOBJ,
},
}

message, err := rc.Rest.PostMessage(&msgPOST)
log.Println(message)

if err != nil {
log.Println(err)
}
}

21 changes: 20 additions & 1 deletion models/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package models

import "time"

// Channel ...
type Channel struct {
ID string `json:"_id"`
Name string `json:"name"`
Expand All @@ -25,15 +26,33 @@ type Channel struct {
// } `json:"customFields,omitempty"`
}

// ChannelSubscription ...
type ChannelSubscription struct {
ID string `json:"_id"`
Alert bool `json:"alert"`
Name string `json:"name"`
DisplayName string `json:"fname"`
Open bool `json:"open"`
RoomId string `json:"rid"`
RoomID string `json:"rid"`
Type string `json:"c"`
User User `json:"u"`
Roles []string `json:"roles"`
Unread float64 `json:"unread"`
}

//MembersList members in a channel
type MembersList struct {
Members []Member `json:"members"`
Count int `json:"count"`
Offset int `json:"offset"`
Total int `json:"total"`
Success bool `json:"success"`
}

// Member ...
type Member struct {
ID string `json:"_id"`
Username string `json:"username"`
Name string `json:"name"`
Status string `json:"status"`
}
7 changes: 7 additions & 0 deletions models/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package models

import "time"

// Info ...
type Info struct {
Version string `json:"version"`

Expand All @@ -22,12 +23,14 @@ type Info struct {
} `json:"commit"`
}

// Pagination ...
type Pagination struct {
Count int `json:"count"`
Offset int `json:"offset"`
Total int `json:"total"`
}

// Directory ...
type Directory struct {
Result []struct {
ID string `json:"_id"`
Expand All @@ -43,11 +46,13 @@ type Directory struct {
Pagination
}

// Spotlight ...
type Spotlight struct {
Users []User `json:"users"`
Rooms []Channel `json:"rooms"`
}

// Statistics ...
type Statistics struct {
ID string `json:"_id"`
UniqueID string `json:"uniqueId"`
Expand Down Expand Up @@ -122,10 +127,12 @@ type Statistics struct {
UpdatedAt time.Time `json:"_updatedAt"`
}

// StatisticsInfo ...
type StatisticsInfo struct {
Statistics Statistics `json:"statistics"`
}

// StatisticsList ...
type StatisticsList struct {
Statistics []Statistics `json:"statistics"`

Expand Down
1 change: 1 addition & 0 deletions models/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package models

import "time"

// Message ...
type Message struct {
ID string `json:"_id"`
RoomID string `json:"rid"`
Expand Down
1 change: 1 addition & 0 deletions models/permission.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package models

// Permission ...
type Permission struct {
ID string `json:"_id"`
UpdatedAt string `json:"_updatedAt.$date"`
Expand Down
4 changes: 3 additions & 1 deletion models/setting.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package models

// Setting ...
type Setting struct {
ID string `json:"_id"`
Blocked bool `json:"blocked"`
Expand All @@ -16,6 +17,7 @@ type Setting struct {
ValueAsset Asset `json:"asset"`
}

// Asset ...
type Asset struct {
DefaultUrl string `json:"defaultUrl"`
DefaultURL string `json:"defaultUrl"`
}
1 change: 1 addition & 0 deletions models/user.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package models

// User ...
type User struct {
ID string `json:"_id"`
Name string `json:"name"`
Expand Down
1 change: 1 addition & 0 deletions models/userCredentials.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package models

// UserCredentials model
type UserCredentials struct {
ID string `json:"id"`
Token string `json:"token"`
Expand Down
49 changes: 25 additions & 24 deletions realtime/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
"github.com/RocketChat/Rocket.Chat.Go.SDK/models"
)

func (c *Client) GetChannelId(name string) (string, error) {
// GetChannelID ...
func (c *Client) GetChannelID(name string) (string, error) {
rawResponse, err := c.ddp.Call("getRoomIdByNameOrId", name)
if err != nil {
return "", err
Expand Down Expand Up @@ -99,8 +100,8 @@ func (c *Client) GetChannelSubscriptions() ([]models.ChannelSubscription, error)
// GetChannelRoles returns room roles
//
// https://rocket.chat/docs/developer-guides/realtime-api/method-calls/get-room-roles
func (c *Client) GetChannelRoles(roomId string) error {
_, err := c.ddp.Call("getRoomRoles", roomId)
func (c *Client) GetChannelRoles(roomID string) error {
_, err := c.ddp.Call("getRoomRoles", roomID)
if err != nil {
return err
}
Expand Down Expand Up @@ -138,8 +139,8 @@ func (c *Client) CreateGroup(name string, users []string) error {
// Takes roomId
//
// https://rocket.chat/docs/developer-guides/realtime-api/method-calls/joining-channels
func (c *Client) JoinChannel(roomId string) error {
_, err := c.ddp.Call("joinRoom", roomId)
func (c *Client) JoinChannel(roomID string) error {
_, err := c.ddp.Call("joinRoom", roomID)
if err != nil {
return err
}
Expand All @@ -151,8 +152,8 @@ func (c *Client) JoinChannel(roomId string) error {
// Takes roomId
//
// https://rocket.chat/docs/developer-guides/realtime-api/method-calls/leaving-rooms
func (c *Client) LeaveChannel(roomId string) error {
_, err := c.ddp.Call("leaveRoom", roomId)
func (c *Client) LeaveChannel(roomID string) error {
_, err := c.ddp.Call("leaveRoom", roomID)
if err != nil {
return err
}
Expand All @@ -164,8 +165,8 @@ func (c *Client) LeaveChannel(roomId string) error {
// Takes roomId
//
// https://rocket.chat/docs/developer-guides/realtime-api/method-calls/archive-rooms
func (c *Client) ArchiveChannel(roomId string) error {
_, err := c.ddp.Call("archiveRoom", roomId)
func (c *Client) ArchiveChannel(roomID string) error {
_, err := c.ddp.Call("archiveRoom", roomID)
if err != nil {
return err
}
Expand All @@ -177,8 +178,8 @@ func (c *Client) ArchiveChannel(roomId string) error {
// Takes roomId
//
// https://rocket.chat/docs/developer-guides/realtime-api/method-calls/unarchive-rooms
func (c *Client) UnArchiveChannel(roomId string) error {
_, err := c.ddp.Call("unarchiveRoom", roomId)
func (c *Client) UnArchiveChannel(roomID string) error {
_, err := c.ddp.Call("unarchiveRoom", roomID)
if err != nil {
return err
}
Expand All @@ -190,8 +191,8 @@ func (c *Client) UnArchiveChannel(roomId string) error {
// Takes roomId
//
// https://rocket.chat/docs/developer-guides/realtime-api/method-calls/delete-rooms
func (c *Client) DeleteChannel(roomId string) error {
_, err := c.ddp.Call("eraseRoom", roomId)
func (c *Client) DeleteChannel(roomID string) error {
_, err := c.ddp.Call("eraseRoom", roomID)
if err != nil {
return err
}
Expand All @@ -203,8 +204,8 @@ func (c *Client) DeleteChannel(roomId string) error {
// takes roomId and topic
//
// https://rocket.chat/docs/developer-guides/realtime-api/method-calls/save-room-settings
func (c *Client) SetChannelTopic(roomId string, topic string) error {
_, err := c.ddp.Call("saveRoomSettings", roomId, "roomTopic", topic)
func (c *Client) SetChannelTopic(roomID string, topic string) error {
_, err := c.ddp.Call("saveRoomSettings", roomID, "roomTopic", topic)
if err != nil {
return err
}
Expand All @@ -216,8 +217,8 @@ func (c *Client) SetChannelTopic(roomId string, topic string) error {
// takes roomId and roomType
//
// https://rocket.chat/docs/developer-guides/realtime-api/method-calls/save-room-settings
func (c *Client) SetChannelType(roomId string, roomType string) error {
_, err := c.ddp.Call("saveRoomSettings", roomId, "roomType", roomType)
func (c *Client) SetChannelType(roomID string, roomType string) error {
_, err := c.ddp.Call("saveRoomSettings", roomID, "roomType", roomType)
if err != nil {
return err
}
Expand All @@ -226,11 +227,11 @@ func (c *Client) SetChannelType(roomId string, roomType string) error {
}

// SetChannelJoinCode sets channel join code
// takes roomId and joinCode
// takes roomID and joinCode
//
// https://rocket.chat/docs/developer-guides/realtime-api/method-calls/save-room-settings
func (c *Client) SetChannelJoinCode(roomId string, joinCode string) error {
_, err := c.ddp.Call("saveRoomSettings", roomId, "joinCode", joinCode)
func (c *Client) SetChannelJoinCode(roomID string, joinCode string) error {
_, err := c.ddp.Call("saveRoomSettings", roomID, "joinCode", joinCode)
if err != nil {
return err
}
Expand All @@ -242,8 +243,8 @@ func (c *Client) SetChannelJoinCode(roomId string, joinCode string) error {
// takes roomId and boolean
//
// https://rocket.chat/docs/developer-guides/realtime-api/method-calls/save-room-settings
func (c *Client) SetChannelReadOnly(roomId string, readOnly bool) error {
_, err := c.ddp.Call("saveRoomSettings", roomId, "readOnly", readOnly)
func (c *Client) SetChannelReadOnly(roomID string, readOnly bool) error {
_, err := c.ddp.Call("saveRoomSettings", roomID, "readOnly", readOnly)
if err != nil {
return err
}
Expand All @@ -255,8 +256,8 @@ func (c *Client) SetChannelReadOnly(roomId string, readOnly bool) error {
// takes roomId and description
//
// https://rocket.chat/docs/developer-guides/realtime-api/method-calls/save-room-settings
func (c *Client) SetChannelDescription(roomId string, description string) error {
_, err := c.ddp.Call("saveRoomSettings", roomId, "roomDescription", description)
func (c *Client) SetChannelDescription(roomID string, description string) error {
_, err := c.ddp.Call("saveRoomSettings", roomID, "roomDescription", description)
if err != nil {
return err
}
Expand Down
Loading