-
Notifications
You must be signed in to change notification settings - Fork 0
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
#6 Receive Achievements #34
base: main
Are you sure you want to change the base?
Conversation
``` | ||
**Receive Achievements** | ||
|
||
You'll need an admin token to make this example work |
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.
Use long form of will
. Simple language is important in documentation like this, because most people reading the documentation will not be natives and only have limited language proficiency.
} | ||
|
||
for _, achievement := range achievements { | ||
// Do something with the achievement |
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.
Please add an example like printing the title of the achievement.
for _, achievement := range achievements {
fmt.Println(achievement.Title)
}
Email string `json:"email"` | ||
} | ||
|
||
func (client *Client) GetAchivements() ([]Achievement, error) { |
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.
} | ||
|
||
func Test_gettingAchievements(t *testing.T) { | ||
server := httpMock("/api/v1/achievements", http.StatusOK, `{ |
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.
No need for HTTP mocking here. Use a mock of the bonusly Client.
See: https://github.com/groundfoghub/bonusly-sdk-go/blob/main/user_test.go#L170-L181
@@ -0,0 +1,70 @@ | |||
package bonusly |
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.
Try to use table tests in Go.
Email string `json:"email"` | ||
} | ||
|
||
func (client *Client) GetAchivements() ([]Achievement, error) { |
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.
Create a type GetAchievementsOutput
and return a pointer to it.
bodyMessage, readErr := readBody(resp) | ||
|
||
if readErr != nil { | ||
return make([]Achievement, 0), readErr |
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.
Return nil
instead of empty array.
resp, requestErr := client.Do(req) | ||
|
||
if requestErr != nil { | ||
return make([]Achievement, 0), requestErr |
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.
Return nil
instead of empty array.
jsonParsingErr := json.Unmarshal([]byte(bodyMessage), &archivements) | ||
|
||
if jsonParsingErr != nil { | ||
return make([]Achievement, 0), jsonParsingErr |
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.
Return nil
instead of empty array.
Email string `json:"email"` | ||
} | ||
|
||
func (client *Client) GetAchivements() ([]Achievement, error) { |
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.
use c
as receiver name instead of client
for consistency.
Changes
#6 Listing Recent Achievements