Class: Redd::Models::ModMail
- Inherits:
-
BasicModel
- Object
- BasicModel
- Redd::Models::ModMail
- Defined in:
- lib/redd/models/mod_mail.rb
Overview
A container for the new modmail. XXX: Instead of making ModMail a dumb container, could it be a lazy wrapper for #unread_count?
Defined Under Namespace
Classes: Conversation, Message
Instance Attribute Summary
Attributes inherited from BasicModel
Instance Method Summary collapse
-
#conversations(subreddits: nil, **params) ⇒ Object
Get the conversations.
-
#create(from:, to:, subject:, body:, hidden: false) ⇒ Conversation
Create a new conversation.
-
#enrolled ⇒ Array<Subreddit>
Moderated subreddits that are enrolled in the new modmail.
-
#get(id) ⇒ Conversation
Get a conversation from its base36 id.
-
#unread_count ⇒ #highlighted, ...
The number of unread messages in each category.
Methods inherited from BasicModel
from_id, #initialize, #inspect, #method_missing, #respond_to_missing?, #to_ary, #to_h
Constructor Details
This class inherits a constructor from Redd::Models::BasicModel
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Redd::Models::BasicModel
Instance Method Details
#conversations(subreddits: nil, **params) ⇒ Object
Get the conversations
113 114 115 116 117 118 |
# File 'lib/redd/models/mod_mail.rb', line 113 def conversations(subreddits: nil, **params) params[:entity] = Array(subreddits).map(&:display_name).join(',') if subreddits @client.get('/api/mod/conversations', **params).body[:conversations].map do |_, conv| Conversation.new(@client, conv) end end |
#create(from:, to:, subject:, body:, hidden: false) ⇒ Conversation
Create a new conversation.
126 127 128 129 130 131 132 |
# File 'lib/redd/models/mod_mail.rb', line 126 def create(from:, to:, subject:, body:, hidden: false) Conversation.new(@client, @client.post( '/api/mod/conversations', srName: from.display_name, to: to.name, subject: subject, body: body, isAuthorHidden: hidden ).body[:conversation]) end |
#enrolled ⇒ Array<Subreddit>
Returns moderated subreddits that are enrolled in the new modmail.
99 100 101 102 103 |
# File 'lib/redd/models/mod_mail.rb', line 99 def enrolled @client.get('/api/mod/conversations/subreddits').body[:subreddits].map do |_, s| Subreddit.new(@client, s.merge(last_updated: s.delete(:lastUpdated))) end end |
#get(id) ⇒ Conversation
Get a conversation from its base36 id.
137 138 139 |
# File 'lib/redd/models/mod_mail.rb', line 137 def get(id) Conversation.from_id(@client, id) end |
#unread_count ⇒ #highlighted, ...
Returns the number of unread messages in each category.
94 95 96 |
# File 'lib/redd/models/mod_mail.rb', line 94 def unread_count BasicModel.new(nil, @client.get('/api/mod/conversations/unread/count').body) end |