-
Notifications
You must be signed in to change notification settings - Fork 2.1k
#569:Partial Fix: Fix for Users Blocking #600
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
74b3db5
#514: added inviter to Invitation for orgs and teams invite
varadarajana 4a4a270
#514: go fmt
varadarajana 3f2f969
#514: removed prints
varadarajana 1d7107a
#514: changed time data types and included them in test
varadarajana f5b2eeb
#514 Added Org List Pending Invitations
varadarajana 112d718
#514 removed typos in error handling
varadarajana 2a95ca6
#514: Modified to pointer time.Time in Invitation
varadarajana 6305685
#514: Set up Naming conventions for multi words, pointer to bool
varadarajana 1840a00
#514: multi word variable format
varadarajana 5c4cab8
#514 : used User instead of new struct
varadarajana e732a04
#514 : removed Inviter struct
varadarajana 7e8a9ee
Merge remote-tracking branch 'upstream/master'
varadarajana 1bd4328
#514: Added quotes to list values in comment
varadarajana 7883eb5
#569:user block: first cut
varadarajana 8206fe8
Merge branch 'master' of https://github.com/varadarajana/go-github
varadarajana 546b2aa
#569: merge issue
varadarajana 11768d6
#569 : Changes to media type for user blocking APIs
varadarajana b5b6801
Merge remote-tracking branch 'upstream/master'
varadarajana 6868470
#569 : changed method name to IsBlocking
varadarajana 5cd446d
#567 : Code review comments for GIT API URL
varadarajana f2a91e1
Rephrase documentation to be more direct.
dmitshur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,91 @@ | ||
// Copyright 2017 The go-github 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 github | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
) | ||
|
||
// ListBlockedUsers lists all the blocked users by the authenticated user. | ||
// | ||
// GitHub API docs: https://developer.github.com/v3/users/blocking/#list-blocked-users | ||
func (s *UsersService) ListBlockedUsers(ctx context.Context, opt *ListOptions) ([]*User, *Response, error) { | ||
u := "user/blocks" | ||
u, err := addOptions(u, opt) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
req, err := s.client.NewRequest("GET", u, nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
// TODO: remove custom Accept header when this API fully launches. | ||
req.Header.Set("Accept", mediaTypeBlockUsersPreview) | ||
|
||
var blockedUsers []*User | ||
resp, err := s.client.Do(ctx, req, &blockedUsers) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
|
||
return blockedUsers, resp, nil | ||
} | ||
|
||
// IsBlocked reports whether specified user is blocked by the authenticated user. | ||
// | ||
// GitHub API docs: https://developer.github.com/v3/users/blocking/#check-whether-youve-blocked-a-user | ||
func (s *UsersService) IsBlocked(ctx context.Context, user string) (bool, *Response, error) { | ||
u := fmt.Sprintf("user/blocks/%v", user) | ||
|
||
req, err := s.client.NewRequest("GET", u, nil) | ||
if err != nil { | ||
return false, nil, err | ||
} | ||
|
||
// TODO: remove custom Accept header when this API fully launches. | ||
req.Header.Set("Accept", mediaTypeBlockUsersPreview) | ||
|
||
resp, err := s.client.Do(ctx, req, nil) | ||
isBlocked, err := parseBoolResponse(err) | ||
return isBlocked, resp, err | ||
} | ||
|
||
// BlockUser blocks specified user for the authenticated user. | ||
// | ||
// GitHub API docs: https://developer.github.com/v3/users/blocking/#block-a-user | ||
func (s *UsersService) BlockUser(ctx context.Context, user string) (*Response, error) { | ||
u := fmt.Sprintf("user/blocks/%v", user) | ||
|
||
req, err := s.client.NewRequest("PUT", u, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// TODO: remove custom Accept header when this API fully launches. | ||
req.Header.Set("Accept", mediaTypeBlockUsersPreview) | ||
|
||
return s.client.Do(ctx, req, nil) | ||
} | ||
|
||
// UnblockUser unblocks specified user for the authenticated user. | ||
// | ||
// GitHub API docs: https://developer.github.com/v3/users/blocking/#unblock-a-user | ||
func (s *UsersService) UnblockUser(ctx context.Context, user string) (*Response, error) { | ||
u := fmt.Sprintf("user/blocks/%v", user) | ||
|
||
req, err := s.client.NewRequest("DELETE", u, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// TODO: remove custom Accept header when this API fully launches. | ||
req.Header.Set("Accept", mediaTypeBlockUsersPreview) | ||
|
||
return s.client.Do(ctx, req, nil) | ||
} |
This file contains hidden or 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,90 @@ | ||
// Copyright 2017 The go-github 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 github | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestUsersService_ListBlockedUsers(t *testing.T) { | ||
setup() | ||
defer teardown() | ||
|
||
mux.HandleFunc("/user/blocks", func(w http.ResponseWriter, r *http.Request) { | ||
testMethod(t, r, "GET") | ||
testHeader(t, r, "Accept", mediaTypeBlockUsersPreview) | ||
testFormValues(t, r, values{"page": "2"}) | ||
fmt.Fprint(w, `[{ | ||
"login": "octocat" | ||
}]`) | ||
}) | ||
|
||
opt := &ListOptions{Page: 2} | ||
blockedUsers, _, err := client.Users.ListBlockedUsers(context.Background(), opt) | ||
if err != nil { | ||
t.Errorf("Users.ListBlockedUsers returned error: %v", err) | ||
} | ||
|
||
want := []*User{{Login: String("octocat")}} | ||
if !reflect.DeepEqual(blockedUsers, want) { | ||
t.Errorf("Users.ListBlockedUsers returned %+v, want %+v", blockedUsers, want) | ||
} | ||
} | ||
|
||
func TestUsersService_IsBlocked(t *testing.T) { | ||
setup() | ||
defer teardown() | ||
|
||
mux.HandleFunc("/user/blocks/u", func(w http.ResponseWriter, r *http.Request) { | ||
testMethod(t, r, "GET") | ||
testHeader(t, r, "Accept", mediaTypeBlockUsersPreview) | ||
w.WriteHeader(http.StatusNoContent) | ||
}) | ||
|
||
isBlocked, _, err := client.Users.IsBlocked(context.Background(), "u") | ||
if err != nil { | ||
t.Errorf("Users.IsBlocked returned error: %v", err) | ||
} | ||
if want := true; isBlocked != want { | ||
t.Errorf("Users.IsBlocked returned %+v, want %+v", isBlocked, want) | ||
} | ||
} | ||
|
||
func TestUsersService_BlockUser(t *testing.T) { | ||
setup() | ||
defer teardown() | ||
|
||
mux.HandleFunc("/user/blocks/u", func(w http.ResponseWriter, r *http.Request) { | ||
testMethod(t, r, "PUT") | ||
testHeader(t, r, "Accept", mediaTypeBlockUsersPreview) | ||
w.WriteHeader(http.StatusNoContent) | ||
}) | ||
|
||
_, err := client.Users.BlockUser(context.Background(), "u") | ||
if err != nil { | ||
t.Errorf("Users.BlockUser returned error: %v", err) | ||
} | ||
} | ||
|
||
func TestUsersService_UnblockUser(t *testing.T) { | ||
setup() | ||
defer teardown() | ||
|
||
mux.HandleFunc("/user/blocks/u", func(w http.ResponseWriter, r *http.Request) { | ||
testMethod(t, r, "DELETE") | ||
testHeader(t, r, "Accept", mediaTypeBlockUsersPreview) | ||
w.WriteHeader(http.StatusNoContent) | ||
}) | ||
|
||
_, err := client.Users.UnblockUser(context.Background(), "u") | ||
if err != nil { | ||
t.Errorf("Users.UnblockUser returned error: %v", err) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the the GitHub API docs:
I think you're missing that preview header.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shurcooL Thank you, I missed the preview header, now it is added. Can you please review?