Class: Redd::Models::User
- Includes:
- Messageable
- Defined in:
- lib/redd/models/user.rb
Overview
A reddit user.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#comment_karma ⇒ Integer
readonly
The user's comment karma.
-
#created_at ⇒ Time
readonly
The time the user signed up.
-
#employee? ⇒ Boolean
readonly
Whether the user is a reddit employee.
-
#features ⇒ Hash
readonly
A hash of features.
-
#friend? ⇒ Boolean
readonly
Whether the user is your friend.
- #geopopular ⇒ String readonly
-
#gold? ⇒ Boolean
readonly
Whether the user currently has gold.
-
#gold_creddits ⇒ Integer
readonly
The number of gold creddits the user has.
-
#gold_expiration ⇒ Time?
readonly
The time when the user's gold expires.
-
#has_mail? ⇒ Boolean
readonly
Whether the user has new messages.
-
#has_mod_mail? ⇒ Boolean
readonly
Whether the user has old-style mod mail.
- #has_subscribed? ⇒ Boolean readonly
-
#has_verified_email? ⇒ Boolean
readonly
Whether the user's email has been verified.
-
#hidden_from_robots? ⇒ Boolean
readonly
Whether the user chose to hide from Google.
-
#id ⇒ String
readonly
The user's base36 id.
-
#in_beta? ⇒ Boolean
readonly
Whether the user is in beta.
-
#inbox_count ⇒ Integer
readonly
The number of messages in the user's inbox.
-
#link_karma ⇒ Integer
readonly
The user's link karma.
-
#mod? ⇒ Boolean
readonly
Whether the user is a moderator.
-
#name ⇒ String
readonly
The user's username.
-
#new_modmail_exists? ⇒ Boolean
readonly
Whether the user has mail in the new modmail.
-
#no_profanity? ⇒ Boolean
readonly
Whether the user chooses to filter profanity.
-
#over_18? ⇒ Boolean
readonly
Whether the user has indicated they're over 18.
-
#profile_image ⇒ String
readonly
A link to the user's profile image.
-
#show_snoovatar? ⇒ Boolean
readonly
Whether the user's snoovatar is shown.
-
#show_top_karma_subreddits? ⇒ Boolean
readonly
Whether top karma subreddits are shown on the user's page.
- #sponsor? ⇒ Boolean readonly
-
#subreddit ⇒ Subreddit
readonly
The user's personal “subreddit”.
-
#suspended? ⇒ Boolean
readonly
Whether the user is suspended.
-
#suspension_expiration ⇒ Time?
readonly
The time when the user's suspension expires.
-
#verified? ⇒ Boolean
readonly
Whether the user is verified (?).
Attributes inherited from Model
Instance Method Summary collapse
-
#block ⇒ Object
Block this user.
- #comments(**params) ⇒ Object
- #disliked(**params) ⇒ Object
-
#friend(note = nil) ⇒ Object
Add the user as a friend.
-
#gift_gold(months: 1) ⇒ Object
Gift a redditor reddit gold.
- #gilded(**params) ⇒ Object
- #hidden(**params) ⇒ Object
- #liked(**params) ⇒ Object
-
#listing(type, **options) ⇒ Listing<Submission>
Get the appropriate listing.
- #overview(**params) ⇒ Object
- #saved(**params) ⇒ Object
-
#send_message(subject:, text:, from: nil) ⇒ Object
Compose a message to the moderators of a subreddit.
- #submitted(**params) ⇒ Object
-
#trophies ⇒ Array<Trophy>
This user's trophies.
-
#unblock(me: nil) ⇒ Object
Unblock a previously blocked user.
-
#unfriend ⇒ Object
Unfriend the user.
Methods inherited from Model
Constructor Details
This class inherits a constructor from Redd::Models::Model
Instance Attribute Details
#comment_karma ⇒ Integer (readonly)
Returns the user's comment karma.
220 |
# File 'lib/redd/models/user.rb', line 220 property :comment_karma |
#created_at ⇒ Time (readonly)
Returns the time the user signed up.
208 |
# File 'lib/redd/models/user.rb', line 208 property :created_at, from: :created_utc, with: ->(epoch) { Time.at(epoch) } |
#employee? ⇒ Boolean (readonly)
Returns whether the user is a reddit employee.
103 |
# File 'lib/redd/models/user.rb', line 103 property :employee?, from: :is_employee |
#features ⇒ Hash (readonly)
Returns a hash of features.
107 |
# File 'lib/redd/models/user.rb', line 107 property :features |
#friend? ⇒ Boolean (readonly)
Returns whether the user is your friend.
111 |
# File 'lib/redd/models/user.rb', line 111 property :friend?, from: :is_friend |
#geopopular ⇒ String (readonly)
123 |
# File 'lib/redd/models/user.rb', line 123 property :geopopular, from: :pref_geopopular |
#gold? ⇒ Boolean (readonly)
Returns whether the user currently has gold.
168 |
# File 'lib/redd/models/user.rb', line 168 property :gold?, from: :is_gold |
#gold_creddits ⇒ Integer (readonly)
Returns the number of gold creddits the user has.
212 |
# File 'lib/redd/models/user.rb', line 212 property :gold_creddits |
#gold_expiration ⇒ Time? (readonly)
Returns the time when the user's gold expires.
135 |
# File 'lib/redd/models/user.rb', line 135 property :gold_expiration, with: ->(epoch) { Time.at(epoch) if epoch } |
#has_mail? ⇒ Boolean (readonly)
Returns whether the user has new messages.
200 |
# File 'lib/redd/models/user.rb', line 200 property :has_mail?, from: :has_mail |
#has_mod_mail? ⇒ Boolean (readonly)
Returns whether the user has old-style mod mail.
180 |
# File 'lib/redd/models/user.rb', line 180 property :has_mod_mail?, from: :has_mod_mail |
#has_subscribed? ⇒ Boolean (readonly)
224 |
# File 'lib/redd/models/user.rb', line 224 property :has_subscribed?, from: :has_subscribed |
#has_verified_email? ⇒ Boolean (readonly)
Returns whether the user's email has been verified.
176 |
# File 'lib/redd/models/user.rb', line 176 property :has_verified_email?, from: :has_verified_email |
#hidden_from_robots? ⇒ Boolean (readonly)
Returns whether the user chose to hide from Google.
184 |
# File 'lib/redd/models/user.rb', line 184 property :hidden_from_robots?, from: :hide_from_robots |
#id ⇒ String (readonly)
Returns the user's base36 id.
139 |
# File 'lib/redd/models/user.rb', line 139 property :id |
#in_beta? ⇒ Boolean (readonly)
Returns whether the user is in beta.
216 |
# File 'lib/redd/models/user.rb', line 216 property :in_beta?, from: :in_beta |
#inbox_count ⇒ Integer (readonly)
Returns the number of messages in the user's inbox.
192 |
# File 'lib/redd/models/user.rb', line 192 property :inbox_count |
#link_karma ⇒ Integer (readonly)
Returns the user's link karma.
188 |
# File 'lib/redd/models/user.rb', line 188 property :link_karma |
#mod? ⇒ Boolean (readonly)
Returns whether the user is a moderator.
172 |
# File 'lib/redd/models/user.rb', line 172 property :mod?, from: :is_mod |
#name ⇒ String (readonly)
Returns the user's username.
99 |
# File 'lib/redd/models/user.rb', line 99 property :name |
#new_modmail_exists? ⇒ Boolean (readonly)
Returns whether the user has mail in the new modmail.
160 |
# File 'lib/redd/models/user.rb', line 160 property :new_modmail_exists?, from: :new_modmail_exists |
#no_profanity? ⇒ Boolean (readonly)
Returns whether the user chooses to filter profanity.
115 |
# File 'lib/redd/models/user.rb', line 115 property :no_profanity?, from: :pref_no_profanity |
#over_18? ⇒ Boolean (readonly)
Returns whether the user has indicated they're over 18.
147 |
# File 'lib/redd/models/user.rb', line 147 property :over_18?, from: :profile_over_18 |
#profile_image ⇒ String (readonly)
Returns a link to the user's profile image.
143 |
# File 'lib/redd/models/user.rb', line 143 property :profile_image, from: :profile_img |
#show_snoovatar? ⇒ Boolean (readonly)
Returns whether the user's snoovatar is shown.
204 |
# File 'lib/redd/models/user.rb', line 204 property :show_snoovatar?, from: :pref_show_snoovatar |
#show_top_karma_subreddits? ⇒ Boolean (readonly)
Returns whether top karma subreddits are shown on the user's page.
196 |
# File 'lib/redd/models/user.rb', line 196 property :show_top_karma_subreddits?, from: :pref_top_karma_subreddits |
#sponsor? ⇒ Boolean (readonly)
131 |
# File 'lib/redd/models/user.rb', line 131 property :sponsor?, from: :is_sponsor |
#subreddit ⇒ Subreddit (readonly)
Returns the user's personal “subreddit”.
127 |
# File 'lib/redd/models/user.rb', line 127 property :subreddit, with: ->(name) { Subreddit.new(client, display_name: name) if name } |
#suspended? ⇒ Boolean (readonly)
Returns whether the user is suspended.
119 |
# File 'lib/redd/models/user.rb', line 119 property :suspended?, from: :is_suspended |
#suspension_expiration ⇒ Time? (readonly)
Returns the time when the user's suspension expires.
151 152 |
# File 'lib/redd/models/user.rb', line 151 property :suspension_expiration, from: :suspension_expiration_utc, with: ->(epoch) { Time.at(epoch) if epoch } |
#verified? ⇒ Boolean (readonly)
Returns whether the user is verified (?).
156 |
# File 'lib/redd/models/user.rb', line 156 property :verified?, from: :verified |
Instance Method Details
#block ⇒ Object
Block this user.
58 59 60 |
# File 'lib/redd/models/user.rb', line 58 def block client.post('/api/block_user', account_id: read_attribute(:id)) end |
#comments(**params) ⇒ Object
44 45 46 |
# File 'lib/redd/models/user.rb', line 44 %i[overview submitted comments liked disliked hidden saved gilded].each do |type| define_method(type) { |**params| listing(type, **params) } end |
#disliked(**params) ⇒ Object
44 45 46 |
# File 'lib/redd/models/user.rb', line 44 %i[overview submitted comments liked disliked hidden saved gilded].each do |type| define_method(type) { |**params| listing(type, **params) } end |
#friend(note = nil) ⇒ Object
Add the user as a friend.
79 80 81 82 83 |
# File 'lib/redd/models/user.rb', line 79 def friend(note = nil) name = read_attribute(:name) body = JSON.generate(note ? { name: name, note: note } : { name: name }) client.request(:put, "/api/v1/me/friends/#{name}", body: body) end |
#gift_gold(months: 1) ⇒ Object
Gift a redditor reddit gold.
93 94 95 |
# File 'lib/redd/models/user.rb', line 93 def gift_gold(months: 1) client.post("/api/v1/gold/give/#{read_attribute(:name)}", months: months) end |
#gilded(**params) ⇒ Object
44 45 46 |
# File 'lib/redd/models/user.rb', line 44 %i[overview submitted comments liked disliked hidden saved gilded].each do |type| define_method(type) { |**params| listing(type, **params) } end |
#hidden(**params) ⇒ Object
44 45 46 |
# File 'lib/redd/models/user.rb', line 44 %i[overview submitted comments liked disliked hidden saved gilded].each do |type| define_method(type) { |**params| listing(type, **params) } end |
#liked(**params) ⇒ Object
44 45 46 |
# File 'lib/redd/models/user.rb', line 44 %i[overview submitted comments liked disliked hidden saved gilded].each do |type| define_method(type) { |**params| listing(type, **params) } end |
#listing(type, **options) ⇒ Listing<Submission>
The option :time only applies to the top and controversial sorts.
Get the appropriate listing.
27 28 29 30 31 32 |
# File 'lib/redd/models/user.rb', line 27 def listing(type, **) [:t] = .delete(:time) if .key?(:time) PaginatedListing.new(client, ) do |**req_opts| client.model(:get, "/user/#{read_attribute(:name)}/#{type}.json", .merge(req_opts)) end end |
#overview(**params) ⇒ Object
44 45 46 |
# File 'lib/redd/models/user.rb', line 44 %i[overview submitted comments liked disliked hidden saved gilded].each do |type| define_method(type) { |**params| listing(type, **params) } end |
#saved(**params) ⇒ Object
44 45 46 |
# File 'lib/redd/models/user.rb', line 44 %i[overview submitted comments liked disliked hidden saved gilded].each do |type| define_method(type) { |**params| listing(type, **params) } end |
#send_message(subject:, text:, from: nil) ⇒ Object
Compose a message to the moderators of a subreddit.
53 54 55 |
# File 'lib/redd/models/user.rb', line 53 def (subject:, text:, from: nil) super(to: read_attribute(:name), subject: subject, text: text, from: from) end |
#submitted(**params) ⇒ Object
44 45 46 |
# File 'lib/redd/models/user.rb', line 44 %i[overview submitted comments liked disliked hidden saved gilded].each do |type| define_method(type) { |**params| listing(type, **params) } end |
#trophies ⇒ Array<Trophy>
Returns this user's trophies.
63 64 65 66 67 |
# File 'lib/redd/models/user.rb', line 63 def trophies client.get("/api/v1/user/#{read_attribute(:name)}/trophies") .body[:data][:trophies] .map { |t| client.unmarshal(t) } end |
#unblock(me: nil) ⇒ Object
Unblock a previously blocked user.
71 72 73 74 75 |
# File 'lib/redd/models/user.rb', line 71 def unblock(me: nil) my_id = 't2_' + (me.is_a?(User) ? user.id : client.get('/api/v1/me').body[:id]) # Talk about an unintuitive endpoint client.post('/api/unfriend', container: my_id, name: read_attribute(:name), type: 'enemy') end |
#unfriend ⇒ Object
Unfriend the user.
86 87 88 89 |
# File 'lib/redd/models/user.rb', line 86 def unfriend name = read_attribute(:name) client.request(:delete, "/api/v1/me/friends/#{name}", raw: true, form: { id: name }) end |