-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Related to #17
- Loading branch information
Showing
15 changed files
with
222 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package models | ||
|
||
import "time" | ||
|
||
// Group represents a user group. | ||
type Group struct { | ||
ID string `json:"id"` | ||
CreatedAt time.Time `json:"createdAt"` | ||
Name string `json:"name"` | ||
OwnerID string `json:"ownerId"` | ||
UserIDs []string `json:"userIds"` | ||
} |
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
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,11 @@ | ||
[ | ||
{ | ||
"createdAt": "2020-02-16T18:57:39.746Z", | ||
"id": "93tyd132e7", | ||
"name": "Test", | ||
"ownerId": "83sv4lyx22", | ||
"userIds": [ | ||
"83sv4lyx22" | ||
] | ||
} | ||
] |
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,11 @@ | ||
[ | ||
{ | ||
"createdAt": "2020-02-16T18:57:39.746Z", | ||
"id": "93tyd132e7", | ||
"name": "Admin", | ||
"ownerId": "83sv4lyx22", | ||
"userIds": [ | ||
"83sv4lyx22" | ||
] | ||
} | ||
] |
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,25 @@ | ||
package groups | ||
|
||
import ( | ||
"github.com/yitsushi/go-misskey/core" | ||
"github.com/yitsushi/go-misskey/models" | ||
) | ||
|
||
// JoinedRequest represents an List request. | ||
type JoinedRequest struct{} | ||
|
||
// Validate the request. | ||
func (r JoinedRequest) Validate() error { | ||
return nil | ||
} | ||
|
||
// Joined clips. | ||
func (s *Service) Joined() ([]models.Group, error) { | ||
var response []models.Group | ||
err := s.Call( | ||
&core.JSONRequest{Request: &JoinedRequest{}, Path: "/users/groups/joined"}, | ||
&response, | ||
) | ||
|
||
return response, 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,43 @@ | ||
package groups_test | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"github.com/yitsushi/go-misskey" | ||
"github.com/yitsushi/go-misskey/services/users/groups" | ||
"github.com/yitsushi/go-misskey/test" | ||
"log" | ||
"net/http" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestService_Joined(t *testing.T) { | ||
client := test.MakeMockClient(test.SimpleMockOptions{ | ||
Endpoint: "/api/users/groups/joined", | ||
RequestData: &groups.JoinedRequest{}, | ||
ResponseFile: "joined.json", | ||
StatusCode: http.StatusOK, | ||
}) | ||
|
||
resp, err := client.Users().Groups().Joined() | ||
if !assert.NoError(t, err) { | ||
return | ||
} | ||
|
||
assert.Len(t, resp, 1) | ||
} | ||
|
||
func ExampleService_Joined() { | ||
client := misskey.NewClient("https://slippy.xyz", os.Getenv("MISSKEY_TOKEN")) | ||
|
||
resp, err := client.Users().Groups().Joined() | ||
if err != nil { | ||
log.Printf("[Users/Groups/Joined] %s", err) | ||
|
||
return | ||
} | ||
|
||
for _, group := range resp { | ||
log.Printf("[Users/Groups/Joined] %s", group.Name) | ||
} | ||
} |
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,25 @@ | ||
package groups | ||
|
||
import ( | ||
"github.com/yitsushi/go-misskey/core" | ||
"github.com/yitsushi/go-misskey/models" | ||
) | ||
|
||
// OwnedRequest represents an List request. | ||
type OwnedRequest struct{} | ||
|
||
// Validate the request. | ||
func (r OwnedRequest) Validate() error { | ||
return nil | ||
} | ||
|
||
// Owned clips. | ||
func (s *Service) Owned() ([]models.Group, error) { | ||
var response []models.Group | ||
err := s.Call( | ||
&core.JSONRequest{Request: &OwnedRequest{}, Path: "/users/groups/owned"}, | ||
&response, | ||
) | ||
|
||
return response, 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,43 @@ | ||
package groups_test | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"github.com/yitsushi/go-misskey" | ||
"github.com/yitsushi/go-misskey/services/users/groups" | ||
"github.com/yitsushi/go-misskey/test" | ||
"log" | ||
"net/http" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestService_Owned(t *testing.T) { | ||
client := test.MakeMockClient(test.SimpleMockOptions{ | ||
Endpoint: "/api/users/groups/owned", | ||
RequestData: &groups.OwnedRequest{}, | ||
ResponseFile: "owned.json", | ||
StatusCode: http.StatusOK, | ||
}) | ||
|
||
resp, err := client.Users().Groups().Owned() | ||
if !assert.NoError(t, err) { | ||
return | ||
} | ||
|
||
assert.Len(t, resp, 1) | ||
} | ||
|
||
func ExampleService_Owned() { | ||
client := misskey.NewClient("https://slippy.xyz", os.Getenv("MISSKEY_TOKEN")) | ||
|
||
resp, err := client.Users().Groups().Owned() | ||
if err != nil { | ||
log.Printf("[Users/Groups/Owned] %s", err) | ||
|
||
return | ||
} | ||
|
||
for _, group := range resp { | ||
log.Printf("[Users/Groups/Owned] %s", group.Name) | ||
} | ||
} |
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,15 @@ | ||
package groups | ||
|
||
import ( | ||
"github.com/yitsushi/go-misskey/core" | ||
) | ||
|
||
// Service is the base for all the endpoints on this service. | ||
type Service struct { | ||
Call core.RequestHandlerFunc | ||
} | ||
|
||
// NewService creates a new Service instance. | ||
func NewService(requestHandler core.RequestHandlerFunc) *Service { | ||
return &Service{Call: requestHandler} | ||
} |
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,21 @@ | ||
package users | ||
|
||
import ( | ||
"github.com/yitsushi/go-misskey/core" | ||
"github.com/yitsushi/go-misskey/services/users/groups" | ||
) | ||
|
||
// Service is the base for all the endpoints on this service. | ||
type Service struct { | ||
Call core.RequestHandlerFunc | ||
} | ||
|
||
// NewService creates a new Service instance. | ||
func NewService(requestHandler core.RequestHandlerFunc) *Service { | ||
return &Service{Call: requestHandler} | ||
} | ||
|
||
// Groups contains all endpoints under /users/groups. | ||
func (s *Service) Groups() *groups.Service { | ||
return groups.NewService(s.Call) | ||
} |