-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to get a specific member by id (#17)
* Fix a typo MembersRepsonse -> MembersResponse. * Add members.Get method.
- Loading branch information
1 parent
fbc4bd7
commit b80e317
Showing
3 changed files
with
48 additions
and
4 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,39 @@ | ||
package members | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
func (c *MembersClient) Get(MemberId int) (*MemberGetResult, error) { | ||
req, err := c.client.NewRequest("GET", fmt.Sprintf("/v1/members/%d", MemberId), nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
r, err := c.client.Client.Do(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer r.Body.Close() | ||
|
||
if r.StatusCode != http.StatusOK { | ||
var target Error | ||
decode := json.NewDecoder(r.Body) | ||
err = decode.Decode(&target) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &MemberGetResult{Error: &target}, fmt.Errorf("%s", target.Detail) | ||
} | ||
|
||
var target MembersResponse | ||
decode := json.NewDecoder(r.Body) | ||
err = decode.Decode(&target) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &MemberGetResult{Result: target}, nil | ||
} |
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