Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
d657643538 | |||
3e663f8615 | |||
eea12a3b50 | |||
e6f29c4e73 | |||
cd2551461d | |||
2ff9a03a8c | |||
f900b99dac |
41
.github/workflows/golangci-lint.yml
vendored
41
.github/workflows/golangci-lint.yml
vendored
@ -1,28 +1,15 @@
|
|||||||
name: golangci-lint
|
- name: Run golangci-lint
|
||||||
on:
|
# You may pin to the exact commit or the version.
|
||||||
push:
|
# uses: golangci/golangci-lint-action@04eca2038305127fb1e6683425b6864cd5612f2d
|
||||||
tags:
|
uses: golangci/golangci-lint-action@v1.2.1
|
||||||
- v*
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
pull_request:
|
|
||||||
jobs:
|
|
||||||
golangci:
|
|
||||||
name: lint
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- name: golangci-lint
|
|
||||||
uses: golangci/golangci-lint-action@v1
|
|
||||||
with:
|
with:
|
||||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
# version of golangci-lint to use in form of v1.2.3
|
||||||
version: v1.29
|
version:
|
||||||
|
# golangci-lint command line arguments
|
||||||
# Optional: working directory, useful for monorepos
|
args: # optional, default is
|
||||||
# working-directory: somedir
|
# golangci-lint working directory, default is project root
|
||||||
|
working-directory: # optional
|
||||||
# Optional: golangci-lint command line arguments.
|
# the token is used for fetching patch of a pull request to show only new issues
|
||||||
# args: --issues-exit-code=0
|
github-token: # default is ${{ github.token }}
|
||||||
|
# if set to true and the action runs on a pull request - the action outputs only newly found issues
|
||||||
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
only-new-issues:
|
||||||
# only-new-issues: true
|
|
||||||
|
@ -60,6 +60,10 @@ func (r response) UnmarshalJSON(bs []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) do(req *http.Request, i interface{}) error {
|
func (c Client) do(req *http.Request, i interface{}) error {
|
||||||
|
if req.Method == "POST" {
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
}
|
||||||
|
|
||||||
getResp, err := c.httpClient.Do(req)
|
getResp, err := c.httpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -30,6 +30,14 @@ func (s *ClientSuite) TestClient_Close() {
|
|||||||
s.Assert().NoError(s.client.Close())
|
s.Assert().NoError(s.client.Close())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ClientSuite) TestClient_do_PostContentType() {
|
||||||
|
req, err := http.NewRequest("POST", "", nil)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
s.Assert().Error(s.client.do(req, struct{}{}))
|
||||||
|
s.Assert().EqualValues(req.Header.Get("Content-Type"), "application/json")
|
||||||
|
}
|
||||||
|
|
||||||
func (s *ClientSuite) TestClient_do_DoError() {
|
func (s *ClientSuite) TestClient_do_DoError() {
|
||||||
req, err := http.NewRequest("", "", nil)
|
req, err := http.NewRequest("", "", nil)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
20
examples/post_bot_message/main.go
Normal file
20
examples/post_bot_message/main.go
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/densestvoid/groupme"
|
||||||
|
)
|
||||||
|
|
||||||
|
// This is not a real Bot ID. Please find yours by logging
|
||||||
|
// into the GroupMe development website: https://dev.groupme.com/bots
|
||||||
|
const botID = "0123456789ABCDEF"
|
||||||
|
|
||||||
|
// A short program that gets the gets the first 5 groups
|
||||||
|
// the user is part of, and then the first 10 messages of
|
||||||
|
// the first group in that list
|
||||||
|
func main() {
|
||||||
|
// Create a new client with your auth token
|
||||||
|
client := groupme.NewClient("")
|
||||||
|
fmt.Println(client.PostBotMessage(botID, "Your message here!", nil))
|
||||||
|
}
|
158
json.go
158
json.go
@ -8,8 +8,8 @@ import (
|
|||||||
// Meta is the error type returned in the GroupMe response.
|
// Meta is the error type returned in the GroupMe response.
|
||||||
// Meant for clients that can't read HTTP status codes
|
// Meant for clients that can't read HTTP status codes
|
||||||
type Meta struct {
|
type Meta struct {
|
||||||
Code HTTPStatusCode `json:"code"`
|
Code HTTPStatusCode `json:"code,omitempty"`
|
||||||
Errors []string `json:"errors"`
|
Errors []string `json:"errors,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error returns the code and the error list as a string.
|
// Error returns the code and the error list as a string.
|
||||||
@ -20,35 +20,35 @@ func (m Meta) Error() string {
|
|||||||
|
|
||||||
// Group is a GroupMe group, returned in JSON API responses
|
// Group is a GroupMe group, returned in JSON API responses
|
||||||
type Group struct {
|
type Group struct {
|
||||||
ID ID `json:"id"`
|
ID ID `json:"id,omitempty"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name,omitempty"`
|
||||||
// Type of group (private|public)
|
// Type of group (private|public)
|
||||||
Type string `json:"type"`
|
Type string `json:"type,omitempty"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description,omitempty"`
|
||||||
ImageURL string `json:"image_url"`
|
ImageURL string `json:"image_url,omitempty"`
|
||||||
CreatorUserID ID `json:"creator_user_id"`
|
CreatorUserID ID `json:"creator_user_id,omitempty"`
|
||||||
CreatedAt Timestamp `json:"created_at"`
|
CreatedAt Timestamp `json:"created_at,omitempty"`
|
||||||
UpdatedAt Timestamp `json:"updated_at"`
|
UpdatedAt Timestamp `json:"updated_at,omitempty"`
|
||||||
Members []*Member `json:"members"`
|
Members []*Member `json:"members,omitempty"`
|
||||||
ShareURL string `json:"share_url"`
|
ShareURL string `json:"share_url,omitempty"`
|
||||||
Messages GroupMessages `json:"messages"`
|
Messages GroupMessages `json:"messages,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GroupMessages is a Group field, only returned in Group JSON API responses
|
// GroupMessages is a Group field, only returned in Group JSON API responses
|
||||||
type GroupMessages struct {
|
type GroupMessages struct {
|
||||||
Count uint `json:"count"`
|
Count uint `json:"count,omitempty"`
|
||||||
LastMessageID ID `json:"last_message_id"`
|
LastMessageID ID `json:"last_message_id,omitempty"`
|
||||||
LastMessageCreatedAt Timestamp `json:"last_message_created_at"`
|
LastMessageCreatedAt Timestamp `json:"last_message_created_at,omitempty"`
|
||||||
Preview MessagePreview `json:"preview"`
|
Preview MessagePreview `json:"preview,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// MessagePreview is a GroupMessages field, only returned in Group JSON API responses.
|
// MessagePreview is a GroupMessages field, only returned in Group JSON API responses.
|
||||||
// Abbreviated form of Message type
|
// Abbreviated form of Message type
|
||||||
type MessagePreview struct {
|
type MessagePreview struct {
|
||||||
Nickname string `json:"nickname"`
|
Nickname string `json:"nickname,omitempty"`
|
||||||
Text string `json:"text"`
|
Text string `json:"text,omitempty"`
|
||||||
ImageURL string `json:"image_url"`
|
ImageURL string `json:"image_url,omitempty"`
|
||||||
Attachments []*Attachment `json:"attachments"`
|
Attachments []*Attachment `json:"attachments,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetMemberByUserID gets the group member by their UserID,
|
// GetMemberByUserID gets the group member by their UserID,
|
||||||
@ -81,14 +81,16 @@ func (g Group) String() string {
|
|||||||
|
|
||||||
// Member is a GroupMe group member, returned in JSON API responses
|
// Member is a GroupMe group member, returned in JSON API responses
|
||||||
type Member struct {
|
type Member struct {
|
||||||
ID ID `json:"id"`
|
ID ID `json:"id,omitempty"`
|
||||||
UserID ID `json:"user_id"`
|
UserID ID `json:"user_id,omitempty"`
|
||||||
Nickname string `json:"nickname"`
|
Nickname string `json:"nickname,omitempty"`
|
||||||
Muted bool `json:"muted"`
|
Muted bool `json:"muted,omitempty"`
|
||||||
ImageURL string `json:"image_url"`
|
ImageURL string `json:"image_url,omitempty"`
|
||||||
AutoKicked bool `json:"autokicked"`
|
AutoKicked bool `json:"autokicked,omitempty"`
|
||||||
AppInstalled bool `json:"app_installed"`
|
AppInstalled bool `json:"app_installed,omitempty"`
|
||||||
GUID string `json:"guid"`
|
GUID string `json:"guid,omitempty"`
|
||||||
|
PhoneNumber string `json:"phone_number,omitempty"` // Only used when searching for the member to add to a group.
|
||||||
|
Email string `json:"email,omitempty"` // Only used when searching for the member to add to a group.
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Member) String() string {
|
func (m Member) String() string {
|
||||||
@ -97,25 +99,25 @@ func (m Member) String() string {
|
|||||||
|
|
||||||
// Message is a GroupMe group message, returned in JSON API responses
|
// Message is a GroupMe group message, returned in JSON API responses
|
||||||
type Message struct {
|
type Message struct {
|
||||||
ID ID `json:"id"`
|
ID ID `json:"id,omitempty"`
|
||||||
SourceGUID string `json:"source_guid"`
|
SourceGUID string `json:"source_guid,omitempty"`
|
||||||
CreatedAt Timestamp `json:"created_at"`
|
CreatedAt Timestamp `json:"created_at,omitempty"`
|
||||||
GroupID ID `json:"group_id"`
|
GroupID ID `json:"group_id,omitempty"`
|
||||||
UserID ID `json:"user_id"`
|
UserID ID `json:"user_id,omitempty"`
|
||||||
BotID ID `json:"bot_id"`
|
BotID ID `json:"bot_id,omitempty"`
|
||||||
SenderID ID `json:"sender_id"`
|
SenderID ID `json:"sender_id,omitempty"`
|
||||||
SenderType SenderType `json:"sender_type"`
|
SenderType SenderType `json:"sender_type,omitempty"`
|
||||||
System bool `json:"system"`
|
System bool `json:"system,omitempty"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name,omitempty"`
|
||||||
RecipientID ID `json:"recipient_id"`
|
RecipientID ID `json:"recipient_id,omitempty"`
|
||||||
ConversationID ID `json:"conversation_id"`
|
ConversationID ID `json:"conversation_id,omitempty"`
|
||||||
AvatarURL string `json:"avatar_url"`
|
AvatarURL string `json:"avatar_url,omitempty"`
|
||||||
// Maximum length of 1000 characters
|
// Maximum length of 1000 characters
|
||||||
Text string `json:"text"`
|
Text string `json:"text,omitempty"`
|
||||||
// Must be an image service URL (i.groupme.com)
|
// Must be an image service URL (i.groupme.com)
|
||||||
ImageURL string `json:"image_url"`
|
ImageURL string `json:"image_url,omitempty"`
|
||||||
FavoritedBy []string `json:"favorited_by"`
|
FavoritedBy []string `json:"favorited_by,omitempty"`
|
||||||
Attachments []*Attachment `json:"attachments"`
|
Attachments []*Attachment `json:"attachments,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Message) String() string {
|
func (m Message) String() string {
|
||||||
@ -143,15 +145,15 @@ const (
|
|||||||
|
|
||||||
// Attachment is a GroupMe message attachment, returned in JSON API responses
|
// Attachment is a GroupMe message attachment, returned in JSON API responses
|
||||||
type Attachment struct {
|
type Attachment struct {
|
||||||
Type AttachmentType `json:"type"`
|
Type AttachmentType `json:"type,omitempty"`
|
||||||
Loci [][]int `json:"loci"`
|
Loci [][]int `json:"loci,omitempty"`
|
||||||
UserIDs []ID `json:"user_ids"`
|
UserIDs []ID `json:"user_ids,omitempty"`
|
||||||
URL string `json:"url"`
|
URL string `json:"url,omitempty"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name,omitempty"`
|
||||||
Latitude string `json:"lat"`
|
Latitude string `json:"lat,omitempty"`
|
||||||
Longitude string `json:"lng"`
|
Longitude string `json:"lng,omitempty"`
|
||||||
Placeholder string `json:"placeholder"`
|
Placeholder string `json:"placeholder,omitempty"`
|
||||||
Charmap [][]int `json:"charmap"`
|
Charmap [][]int `json:"charmap,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a Attachment) String() string {
|
func (a Attachment) String() string {
|
||||||
@ -160,15 +162,15 @@ func (a Attachment) String() string {
|
|||||||
|
|
||||||
// User is a GroupMe user, returned in JSON API responses
|
// User is a GroupMe user, returned in JSON API responses
|
||||||
type User struct {
|
type User struct {
|
||||||
ID ID `json:"id"`
|
ID ID `json:"id,omitempty"`
|
||||||
PhoneNumber PhoneNumber `json:"phone_number"`
|
PhoneNumber PhoneNumber `json:"phone_number,omitempty"`
|
||||||
ImageURL string `json:"image_url"`
|
ImageURL string `json:"image_url,omitempty"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name,omitempty"`
|
||||||
CreatedAt Timestamp `json:"created_at"`
|
CreatedAt Timestamp `json:"created_at,omitempty"`
|
||||||
UpdatedAt Timestamp `json:"updated_at"`
|
UpdatedAt Timestamp `json:"updated_at,omitempty"`
|
||||||
AvatarURL string `json:"avatar_url"`
|
AvatarURL string `json:"avatar_url,omitempty"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email,omitempty"`
|
||||||
SMS bool `json:"sms"`
|
SMS bool `json:"sms,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u User) String() string {
|
func (u User) String() string {
|
||||||
@ -178,11 +180,11 @@ func (u User) String() string {
|
|||||||
// Chat is a GroupMe direct message conversation between two users,
|
// Chat is a GroupMe direct message conversation between two users,
|
||||||
// returned in JSON API responses
|
// returned in JSON API responses
|
||||||
type Chat struct {
|
type Chat struct {
|
||||||
CreatedAt Timestamp `json:"created_at"`
|
CreatedAt Timestamp `json:"created_at,omitempty"`
|
||||||
UpdatedAt Timestamp `json:"updated_at"`
|
UpdatedAt Timestamp `json:"updated_at,omitempty"`
|
||||||
LastMessage *Message `json:"last_message"`
|
LastMessage *Message `json:"last_message,omitempty"`
|
||||||
MessagesCount int `json:"messages_count"`
|
MessagesCount int `json:"messages_count,omitempty"`
|
||||||
OtherUser User `json:"other_user"`
|
OtherUser User `json:"other_user,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Chat) String() string {
|
func (c Chat) String() string {
|
||||||
@ -190,12 +192,12 @@ func (c Chat) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Bot struct {
|
type Bot struct {
|
||||||
BotID ID `json:"bot_id"`
|
BotID ID `json:"bot_id,omitempty"`
|
||||||
GroupID ID `json:"group_id"`
|
GroupID ID `json:"group_id,omitempty"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name,omitempty"`
|
||||||
AvatarURL string `json:"avatar_url"`
|
AvatarURL string `json:"avatar_url,omitempty"`
|
||||||
CallbackURL string `json:"callback_url"`
|
CallbackURL string `json:"callback_url,omitempty"`
|
||||||
DMNotification bool `json:"dm_notification"`
|
DMNotification bool `json:"dm_notification,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b Bot) String() string {
|
func (b Bot) String() string {
|
||||||
@ -203,9 +205,9 @@ func (b Bot) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Block struct {
|
type Block struct {
|
||||||
UserID ID `json:"user_id"`
|
UserID ID `json:"user_id,omitempty"`
|
||||||
BlockedUserID ID `json:"blocked_user_id"`
|
BlockedUserID ID `json:"blocked_user_id,omitempty"`
|
||||||
CreatedAT Timestamp `json:"created_at"`
|
CreatedAT Timestamp `json:"created_at,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b Block) String() string {
|
func (b Block) String() string {
|
||||||
|
@ -66,7 +66,7 @@ func (c *Client) AddMembers(groupID ID, members ...*Member) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var resp struct {
|
var resp struct {
|
||||||
ResultsID string `json:"result_id"`
|
ResultsID string `json:"results_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.doWithAuthToken(httpReq, &resp)
|
err = c.doWithAuthToken(httpReq, &resp)
|
||||||
|
Reference in New Issue
Block a user