Add user info endpoint
Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
+19
@@ -8,6 +8,7 @@ import (
|
||||
// AccountService handles communication with the account
|
||||
// related methods of the Reddit API.
|
||||
type AccountService interface {
|
||||
Info(ctx context.Context) (*User, *Response, error)
|
||||
Karma(ctx context.Context) ([]SubredditKarma, *Response, error)
|
||||
Settings(ctx context.Context) (*Settings, *Response, error)
|
||||
UpdateSettings(ctx context.Context, settings *Settings) (*Settings, *Response, error)
|
||||
@@ -216,6 +217,24 @@ type Settings struct {
|
||||
EnableVideoAutoplay *bool `json:"video_autoplay,omitempty"`
|
||||
}
|
||||
|
||||
// Info returns some general information about your account.
|
||||
func (s *AccountServiceOp) Info(ctx context.Context) (*User, *Response, error) {
|
||||
path := "api/v1/me"
|
||||
|
||||
req, err := s.client.NewRequest(http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
root := new(User)
|
||||
resp, err := s.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
|
||||
return root, resp, nil
|
||||
}
|
||||
|
||||
// Karma returns a breakdown of your karma per subreddit.
|
||||
func (s *AccountServiceOp) Karma(ctx context.Context) ([]SubredditKarma, *Response, error) {
|
||||
path := "api/v1/me/karma"
|
||||
|
||||
@@ -5,10 +5,21 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var expectedInfo = &User{
|
||||
ID: "164ab8",
|
||||
Name: "v_95",
|
||||
Created: &Timestamp{time.Date(2017, 3, 12, 4, 56, 47, 0, time.UTC)},
|
||||
PostKarma: 488,
|
||||
CommentKarma: 22223,
|
||||
HasVerifiedEmail: true,
|
||||
NSFW: true,
|
||||
}
|
||||
|
||||
var expectedKarma = []SubredditKarma{
|
||||
{Subreddit: "nba", PostKarma: 144, CommentKarma: 21999},
|
||||
{Subreddit: "redditdev", PostKarma: 19, CommentKarma: 4},
|
||||
@@ -86,6 +97,22 @@ var expectedSettings = &Settings{
|
||||
EnableVideoAutoplay: Bool(true),
|
||||
}
|
||||
|
||||
func TestAccountServiceOp_Info(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
|
||||
blob := readFileContents(t, "testdata/account/info.json")
|
||||
|
||||
mux.HandleFunc("/api/v1/me", func(w http.ResponseWriter, r *http.Request) {
|
||||
assert.Equal(t, http.MethodGet, r.Method)
|
||||
fmt.Fprint(w, blob)
|
||||
})
|
||||
|
||||
info, _, err := client.Account.Info(ctx)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, expectedInfo, info)
|
||||
}
|
||||
|
||||
func TestAccountServiceOp_Karma(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
|
||||
Vendored
+158
@@ -0,0 +1,158 @@
|
||||
{
|
||||
"is_employee": false,
|
||||
"seen_layout_switch": false,
|
||||
"has_visited_new_profile": false,
|
||||
"pref_no_profanity": false,
|
||||
"has_external_account": false,
|
||||
"pref_geopopular": "GLOBAL",
|
||||
"seen_redesign_modal": true,
|
||||
"pref_show_trending": true,
|
||||
"subreddit": {
|
||||
"default_set": true,
|
||||
"user_is_contributor": false,
|
||||
"banner_img": "",
|
||||
"restrict_posting": true,
|
||||
"user_is_banned": false,
|
||||
"free_form_reports": true,
|
||||
"community_icon": null,
|
||||
"show_media": true,
|
||||
"icon_color": "#94E044",
|
||||
"user_is_muted": false,
|
||||
"display_name": "u_v_95",
|
||||
"header_img": null,
|
||||
"title": "",
|
||||
"coins": 0,
|
||||
"previous_names": [],
|
||||
"over_18": false,
|
||||
"icon_size": [256, 256],
|
||||
"primary_color": "",
|
||||
"icon_img": "https://www.redditstatic.com/avatars/avatar_default_01_94E044.png",
|
||||
"description": "",
|
||||
"submit_link_label": "",
|
||||
"header_size": null,
|
||||
"restrict_commenting": false,
|
||||
"subscribers": 0,
|
||||
"submit_text_label": "",
|
||||
"is_default_icon": true,
|
||||
"link_flair_position": "",
|
||||
"display_name_prefixed": "u/v_95",
|
||||
"key_color": "",
|
||||
"name": "t5_17a8op",
|
||||
"is_default_banner": true,
|
||||
"url": "/user/v_95/",
|
||||
"banner_size": null,
|
||||
"user_is_moderator": true,
|
||||
"public_description": "",
|
||||
"link_flair_enabled": false,
|
||||
"disable_contributor_requests": false,
|
||||
"subreddit_type": "user",
|
||||
"user_is_subscriber": false
|
||||
},
|
||||
"is_sponsor": false,
|
||||
"gold_expiration": null,
|
||||
"has_gold_subscription": false,
|
||||
"num_friends": 0,
|
||||
"features": {
|
||||
"promoted_trend_blanks": true,
|
||||
"show_amp_link": true,
|
||||
"mweb_link_tab": {
|
||||
"owner": "growth",
|
||||
"variant": "treatment_1",
|
||||
"experiment_id": 404
|
||||
},
|
||||
"reports_double_write_to_report_service_for_spam": true,
|
||||
"twitter_embed": true,
|
||||
"is_email_permission_required": true,
|
||||
"mod_awards": true,
|
||||
"mweb_xpromo_revamp_v3": {
|
||||
"owner": "growth",
|
||||
"variant": "treatment_2",
|
||||
"experiment_id": 480
|
||||
},
|
||||
"mweb_xpromo_revamp_v2": {
|
||||
"owner": "growth",
|
||||
"variant": "treatment_6",
|
||||
"experiment_id": 457
|
||||
},
|
||||
"awards_on_streams": true,
|
||||
"mweb_xpromo_modal_listing_click_daily_dismissible_ios": true,
|
||||
"reports_double_write_to_report_service_for_som": true,
|
||||
"chat_subreddit": true,
|
||||
"modlog_copyright_removal": true,
|
||||
"do_not_track": true,
|
||||
"chat_user_settings": true,
|
||||
"resized_styles_images": true,
|
||||
"mweb_xpromo_interstitial_comments_ios": true,
|
||||
"mweb_sharing_clipboard": {
|
||||
"owner": "growth",
|
||||
"variant": "control_2",
|
||||
"experiment_id": 315
|
||||
},
|
||||
"premium_subscriptions_table": true,
|
||||
"mweb_xpromo_interstitial_comments_android": true,
|
||||
"mweb_nsfw_xpromo": {
|
||||
"owner": "growth",
|
||||
"variant": "control_2",
|
||||
"experiment_id": 361
|
||||
},
|
||||
"mweb_xpromo_modal_listing_click_daily_dismissible_android": true,
|
||||
"stream_as_a_post_type": true,
|
||||
"mweb_sharing_web_share_api": {
|
||||
"owner": "growth",
|
||||
"variant": "control_1",
|
||||
"experiment_id": 314
|
||||
},
|
||||
"chat_group_rollout": true,
|
||||
"custom_feeds": true,
|
||||
"spez_modal": true,
|
||||
"noreferrer_to_noopener": true,
|
||||
"expensive_coins_package": true
|
||||
},
|
||||
"has_android_subscription": false,
|
||||
"verified": true,
|
||||
"new_modmail_exists": null,
|
||||
"pref_autoplay": true,
|
||||
"coins": 0,
|
||||
"has_paypal_subscription": false,
|
||||
"has_subscribed_to_premium": false,
|
||||
"id": "164ab8",
|
||||
"has_stripe_subscription": false,
|
||||
"seen_premium_adblock_modal": false,
|
||||
"can_create_subreddit": true,
|
||||
"over_18": true,
|
||||
"is_gold": false,
|
||||
"is_mod": false,
|
||||
"suspension_expiration_utc": null,
|
||||
"has_verified_email": true,
|
||||
"is_suspended": false,
|
||||
"pref_video_autoplay": true,
|
||||
"can_edit_name": false,
|
||||
"in_redesign_beta": false,
|
||||
"icon_img": "https://www.redditstatic.com/avatars/avatar_default_01_94E044.png",
|
||||
"has_mod_mail": false,
|
||||
"pref_nightmode": true,
|
||||
"oauth_client_id": "niGQOYEVagdRZQ",
|
||||
"hide_from_robots": false,
|
||||
"password_set": true,
|
||||
"link_karma": 488,
|
||||
"accept_chats": false,
|
||||
"force_password_reset": false,
|
||||
"seen_give_award_tooltip": false,
|
||||
"inbox_count": 0,
|
||||
"pref_top_karma_subreddits": false,
|
||||
"has_mail": false,
|
||||
"pref_show_snoovatar": false,
|
||||
"name": "v_95",
|
||||
"pref_clickgadget": 5,
|
||||
"created": 1489323407.0,
|
||||
"gold_creddits": 0,
|
||||
"created_utc": 1489294607.0,
|
||||
"has_ios_subscription": false,
|
||||
"pref_show_twitter": false,
|
||||
"in_beta": false,
|
||||
"comment_karma": 22223,
|
||||
"has_subscribed": true,
|
||||
"seen_subreddit_chat_ftux": false,
|
||||
"linked_identities": [],
|
||||
"accept_pms": true
|
||||
}
|
||||
Reference in New Issue
Block a user