redd 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ca106c8ea55f1c1278f643802a357163ebca48cc
4
- data.tar.gz: 38302c79dbc6c94813c182b5b0ec2b0cae02c124
3
+ metadata.gz: a0f001106f53af036bc79b0d02fb744f9f8807ac
4
+ data.tar.gz: dea813c1bc65c8a42e7b533da29787e2f25d5786
5
5
  SHA512:
6
- metadata.gz: c379f17013fbd83957752e7e745b8f55bc37b96f7cb96ad4d08252f1857b57258cf2fe5fcb8a711f65217908ad703b2e4a506720833226fcc89d36fefe2e9f62
7
- data.tar.gz: a95cee5b5b15124d6867f1a998c9abb21b7aace479d23ff32e85e86b06c6dac129ffa9dedfc169ce6612a1bfe07614b5a79d8b4d1e5fd506b938bc0bd8b4cdfb
6
+ metadata.gz: 67c4940373ced4e6513a03168e3e61e56353b5db665e53a5313987f7fd07d86b33f0e93d546428691ee077e9c7731da66a4f9d179858ddaca61b61bfbe6671f5
7
+ data.tar.gz: 700cbec73a627b874ee3fd254c7cc2d78f8c0455f6c6c17574fa0a5518dd11b2438ff7e36be9e15aa01d2944c4d88bf63bc5a0b9cd811dcc2da775e1d7c00c70
data/README.md CHANGED
@@ -1,12 +1,27 @@
1
1
  <div align="center">
2
- <!-- Redd -->
3
- <img src="logo.png" width="500"><br>
2
+ <p>
3
+ <!-- Redd -->
4
+ <img src="logo.png" width="500"><br>
5
+
6
+ <!-- Badges -->
7
+ <a href="https://rubygems.org/gems/redd">
8
+ <img src="http://img.shields.io/gem/v/redd.svg?style=flat-square" alt="Gem Version">
9
+ </a>
10
+ <a href="https://travis-ci.org/avinashbot/redd">
11
+ <img src="http://img.shields.io/travis/avinashbot/redd.svg?style=flat-square" alt="Build Status">
12
+ </a>
13
+ <a href="https://rubygems.org/gems/redd">
14
+ <img src="http://img.shields.io/gem/dt/redd.svg?style=flat-square" alt="Gem Downloads">
15
+ </a>
16
+ </p>
4
17
 
5
18
  <!-- Intro Text -->
6
- <strong>Redd</strong> is an API wrapper
7
- for <a href="https://www.reddit.com/dev/api">reddit</a>
8
- that is all about being <strong>simple</strong>
9
- and <strong>intuitive</strong>.
19
+ <p>
20
+ <strong>Redd</strong> is an API wrapper
21
+ for <a href="https://www.reddit.com/dev/api">reddit</a>
22
+ that is all about being <strong>simple</strong>
23
+ and <strong>intuitive</strong>.
24
+ </p>
10
25
  </div>
11
26
 
12
27
  ---
@@ -25,9 +40,8 @@ session = Redd.it(
25
40
  session.subreddit('all').comment_stream do |comment|
26
41
  if comment.body.include?('roll a dice')
27
42
  comment.reply("I just rolled a dice! It's a #{rand(1..6)}!")
28
- elsif comment.body.include?('flip a coin') || comment.body.include?('coin flip')
29
- coin_face = (rand(0..1) == 1 ? 'heads' : 'tails')
30
- comment.reply("I just flipped a coin! It's #{coin_face}!")
43
+ elsif comment.body.include?('flip a coin')
44
+ comment.reply("I just flipped a coin! It's a #{%w(heads tails).sample}!")
31
45
  end
32
46
  end
33
47
  ```
@@ -42,7 +56,7 @@ or protect against issues on reddit's end (like 5xx errors).
42
56
 
43
57
  #### Where can I find the documentation?
44
58
 
45
- [**Latest**](www.rubydoc.info/gems/redd) / [**GitHub**](http://www.rubydoc.info/github/avinashbot/redd/master/Redd/Models/Session)
59
+ [**Gem**](http://www.rubydoc.info/gems/redd/Redd/Models/Session) / [**GitHub**](http://www.rubydoc.info/github/avinashbot/redd/master/Redd/Models/Session)
46
60
 
47
61
  #### How can I contact you?
48
62
  [Reddit](https://www.reddit.com/message/compose/?to=Mustermind) /
data/TODO.md CHANGED
@@ -3,5 +3,6 @@
3
3
  - [ ] make rubocop fail on error
4
4
  - [ ] unduplicate duplicated code
5
5
  - [ ] Write tests (oh boy)
6
+ - [ ] change after_initialize to include force_load
6
7
  - [ ] abstract out listing methods?
7
8
  - [ ] Add `#==` and `#to_s` methods to models
data/bin/console CHANGED
@@ -22,7 +22,7 @@ server.mount_proc '/' do |_, res|
22
22
  </style>
23
23
  <div class="wrapper">
24
24
  <h1>redd // quickstart</h1>
25
- <a onclick="window.open('/authenticate', '', 'width=960,height=640')" href="#" id="btn">Start</a>
25
+ <a href="#" target="_blank" id="btn">Start</a>
26
26
  <span>a new session in your terminal?</span>
27
27
  </div>
28
28
  EOS
@@ -36,8 +36,9 @@ server.mount_proc '/authenticate' do |_, res|
36
36
  response_type: 'code',
37
37
  state: '0',
38
38
  redirect_uri: 'http://localhost:8000/redirect',
39
- 'scope': %w(identity read subscribe privatemessages wikiread submit vote edit modposts history
40
- modflair modconfig modmail livemanage)
39
+ 'scope': %w(account creddits edit flair history identity livemanage modconfig modcontributors
40
+ modflair modlog modmail modothers modposts modself modwiki mysubreddits
41
+ privatemessages read report save submit subscribe vote wikiedit wikiread)
41
42
  )
42
43
  )
43
44
  end
@@ -19,7 +19,6 @@ module Redd
19
19
  include Postable
20
20
  include Replyable
21
21
 
22
- coerce_attribute :replies
23
22
  coerce_attribute :author, User
24
23
  coerce_attribute :subreddit, Subreddit
25
24
 
@@ -31,11 +30,11 @@ module Redd
31
30
  # FIXME: listings can be empty... (for some reason)
32
31
 
33
32
  # Ensure we have the comment's id.
34
- id = hash.fetch(:id) { hash.fetch(:name).tr('t1_', '') }
33
+ id = hash.fetch(:id) { hash.fetch(:name).sub('t1_', '') }
35
34
 
36
35
  # If we have the link_id, we can load the listing with replies.
37
36
  if hash.key?(:link_id)
38
- link_id = hash[:link_id].tr('t3_', '')
37
+ link_id = hash[:link_id].sub('t3_', '')
39
38
  return new(client, hash) do |c|
40
39
  # The second half contains a single-item listing containing the comment
41
40
  c.get("/comments/#{link_id}/_/#{id}").body[1][:data][:children][0][:data]
@@ -52,7 +51,12 @@ module Redd
52
51
  private
53
52
 
54
53
  def after_initialize
55
- @attributes[:replies] = [] if !@attributes.key?(:replies) || @attributes[:replies] == ''
54
+ @attributes[:replies] =
55
+ if !@attributes.key?(:replies) || @attributes[:replies] == ''
56
+ Listing.new(@client, children: [])
57
+ else
58
+ @client.unmarshal(@attributes[:replies])
59
+ end
56
60
  end
57
61
  end
58
62
  end
@@ -21,7 +21,8 @@ module Redd
21
21
  end
22
22
 
23
23
  # Get the appropriate listing.
24
- # @param sort [:hot, :new, :top, :controversial, :comments, :rising] the type of listing
24
+ # @param sort [:hot, :new, :top, :controversial, :comments, :rising, :gilded] the type of
25
+ # listing
25
26
  # @param params [Hash] a list of params to send with the request
26
27
  # @option params [String] :after return results after the given fullname
27
28
  # @option params [String] :before return results before the given fullname
@@ -34,7 +35,7 @@ module Redd
34
35
  # @return [Listing<Submission>]
35
36
  def listing(sort, **params)
36
37
  params[:t] = params.delete(:time) if params.key?(:time)
37
- @client.model(:get, "/#{sort}.json", params)
38
+ @client.model(:get, "/#{sort}", params)
38
39
  end
39
40
 
40
41
  # @!method hot(**params)
@@ -43,9 +44,10 @@ module Redd
43
44
  # @!method controversial(**params)
44
45
  # @!method comments(**params)
45
46
  # @!method rising(**params)
47
+ # @!method gilded(**params)
46
48
  #
47
49
  # @see #listing
48
- %i(hot new top controversial comments rising).each do |sort|
50
+ %i(hot new top controversial comments rising gilded).each do |sort|
49
51
  define_method(sort) { |**params| listing(sort, **params) }
50
52
  end
51
53
 
@@ -29,6 +29,7 @@ module Redd
29
29
  return unless lazy?
30
30
  @attributes.merge!(@lazy_loader.call(@client))
31
31
  @definitely_fully_loaded = true
32
+ after_initialize
32
33
  self
33
34
  end
34
35
  alias reload force_load
@@ -1,11 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'basic_model'
3
4
  require_relative 'lazy_model'
4
5
 
5
6
  module Redd
6
7
  module Models
7
8
  # Represents a live thread.
8
9
  class LiveThread < LazyModel
10
+ # An update in a live thread.
11
+ class LiveUpdate < BasicModel; end
12
+
9
13
  # Get a Conversation from its id.
10
14
  # @option hash [String] :id the base36 id (e.g. abc123)
11
15
  # @return [Conversation]
@@ -21,6 +25,17 @@ module Redd
21
25
  from_response(client, id: id)
22
26
  end
23
27
 
28
+ # Get the updates from the thread.
29
+ # @param params [Hash] a list of params to send with the request
30
+ # @option params [String] :after return results after the given fullname
31
+ # @option params [String] :before return results before the given fullname
32
+ # @option params [Integer] :count the number of items already seen in the listing
33
+ # @option params [1..100] :limit the maximum number of things to return
34
+ # @return [Listing]
35
+ def updates(**params)
36
+ @client.model(:get, "/live/#{get_attribute(:id)}", params)
37
+ end
38
+
24
39
  # Configure the settings of this live thread
25
40
  # @param params [Hash] a list of params to send with the request
26
41
  # @option params [String] :description the new description
@@ -2,13 +2,99 @@
2
2
 
3
3
  require_relative 'basic_model'
4
4
  require_relative 'subreddit'
5
- require_relative 'conversation'
6
5
 
7
6
  module Redd
8
7
  module Models
9
8
  # A container for the new modmail.
10
9
  # XXX: Instead of making ModMail a dumb container, could it be a lazy wrapper for #unread_count?
11
10
  class ModMail < BasicModel
11
+ # Represents a conversation in the new modmail.
12
+ # TODO: add modmail-specific user type
13
+ class Conversation < LazyModel
14
+ # Get a Conversation from its id.
15
+ # @option hash [String] :id the base36 id (e.g. abc123)
16
+ # @return [Conversation]
17
+ def self.from_response(client, hash)
18
+ id = hash.fetch(:id)
19
+ new(client, hash) do |c|
20
+ response = c.get("/api/mod/conversations/#{id}").body
21
+ response[:conversation].merge(
22
+ messages: response[:messages].values.map { |m| Message.from_response(c, m) },
23
+ user: response[:user],
24
+ mod_actions: response[:modActions]
25
+ )
26
+ end
27
+ end
28
+
29
+ # Get a Conversation from its id.
30
+ # @param id [String] the base36 id (e.g. abc123)
31
+ # @return [Conversation]
32
+ def self.from_id(client, id)
33
+ from_response(client, id: id)
34
+ end
35
+
36
+ # Add a reply to the ongoing conversation.
37
+ def reply(body, hidden: false, internal: false)
38
+ # TODO: merge response into the conversation
39
+ @client.post(
40
+ "/api/mod/conversations/#{get_attribute(:id)}",
41
+ body: body, isAuthorHidden: hidden, isInternal: internal
42
+ ).body
43
+ end
44
+
45
+ # Mark this conversation as read.
46
+ def mark_as_read
47
+ @client.post('/api/mod/conversations/read', conversationIds: [get_attribute(:id)])
48
+ end
49
+
50
+ # Mark this conversation as unread.
51
+ def mark_as_unread
52
+ @client.post('/api/mod/conversations/unread', conversationIds: [get_attribute(:id)])
53
+ end
54
+
55
+ # Mark this conversation as archived.
56
+ def archive
57
+ perform_action(:post, 'archive')
58
+ end
59
+
60
+ # Removed this conversation from archived.
61
+ def unarchive
62
+ perform_action(:post, 'unarchive')
63
+ end
64
+
65
+ # Highlight this conversation.
66
+ def highlight
67
+ perform_action(:post, 'highlight')
68
+ end
69
+
70
+ # Remove the highlight on this conversation.
71
+ def unhighlight
72
+ perform_action(:delete, 'highlight')
73
+ end
74
+
75
+ # Mute this conversation.
76
+ def mute
77
+ perform_action(:post, 'mute')
78
+ end
79
+
80
+ # Unmute this conversation.
81
+ def unmute
82
+ perform_action(:post, 'unmute')
83
+ end
84
+
85
+ private
86
+
87
+ # Perform an action on a conversation.
88
+ # @param method [:post, :delete] the method to use
89
+ # @param action [String] the name of the action
90
+ def perform_action(method, action)
91
+ @client.send(method, "/api/mod/conversations/#{id}/#{action}")
92
+ end
93
+ end
94
+
95
+ # A conversation message.
96
+ class Message < BasicModel; end
97
+
12
98
  # @return [#highlighted, #notifications, #archived, #new, #inprogress, #mod] the number of
13
99
  # unread messages in each category
14
100
  def unread_count
@@ -31,7 +117,23 @@ module Redd
31
117
  # state to limit the conversations by
32
118
  def conversations(subreddits: nil, **params)
33
119
  params[:entity] = Array(subreddits).map(&:display_name).join(',') if subreddits
34
- @client.get('/api/mod/conversations', **params).body
120
+ @client.get('/api/mod/conversations', **params).body[:conversations].map do |_, conv|
121
+ Conversation.from_response(@client, conv)
122
+ end
123
+ end
124
+
125
+ # Create a new conversation.
126
+ # @param from [Subreddit] the subreddit to send the conversation from
127
+ # @param to [User] the person to send the message to
128
+ # @param subject [String] the message subject
129
+ # @param body [String] the message body
130
+ # @return [Conversation] the created conversation
131
+ def create(from:, to:, subject:, body:, hidden: false)
132
+ Conversation.from_response(@client, @client.post(
133
+ '/api/mod/conversations',
134
+ srName: from.display_name, to: to.name,
135
+ subject: subject, body: body, isAuthorHidden: hidden
136
+ ).body[:conversation])
35
137
  end
36
138
 
37
139
  # Get a conversation from its base36 id.
@@ -7,30 +7,51 @@ module Redd
7
7
  # An object that represents a bunch of comments that need to be expanded.
8
8
  class MoreComments < BasicModel
9
9
  # Expand the object's children into a listing of Comments and MoreComments.
10
- # @param link [String] the fullname of the submission the object belongs to
10
+ # @param link [Submission] the submission the object belongs to
11
11
  # @param sort [String] the sort order of the submission
12
12
  # @return [Listing<Comment, MoreComments>] the expanded children
13
13
  def expand(link:, sort: 'best')
14
14
  @client.model(
15
15
  :get, '/api/morechildren',
16
- link_id: link,
16
+ link_id: link.name,
17
17
  children: get_attribute(:children).join(','),
18
18
  sort: sort
19
19
  )
20
20
  end
21
21
 
22
+ # Keep expanding until all top-level MoreComments are converted to comments.
23
+ # @param link [Submission] the object's submission
24
+ # @param sort [String] the sort order of the returned comments
25
+ # @param lookup [Hash] a hash of comments to add future replies to
26
+ # @param depth [Number] the maximum recursion depth
27
+ # @return [Array<Comment, MoreComments>] the expanded comments or {self} if past depth
28
+ def recursive_expand(link:, sort: 'best', lookup: {}, depth: 10)
29
+ return [self] if depth == 0
30
+
31
+ expand(link: link, sort: sort).flat_map do |thing|
32
+ if thing.is_a?(MoreComments) && thing.count > 0
33
+ # Get an array of expanded comments from the thing.
34
+ ary = thing.recursive_expand(link: link, sort: sort, lookup: lookup, depth: depth - 1)
35
+ # If we can't find its parent (or if the parent is the submission), add it to the root.
36
+ next ary unless lookup.key?(thing.parent_id)
37
+ # Since the thing has a parent that we're tracking, attach it to the parent.
38
+ lookup[thing.parent_id].replies.children.concat(ary)
39
+ elsif thing.is_a?(Comment)
40
+ # Add the comment to a lookup hash.
41
+ lookup[thing.name] = thing
42
+ # If the parent is not in the lookup hash, add it to the root listing.
43
+ next thing unless lookup.key?(thing.parent_id)
44
+ # If the parent was found, add the child to the parent's replies instead.
45
+ lookup[thing.parent_id].replies.children << thing
46
+ end
47
+ []
48
+ end
49
+ end
50
+
22
51
  # @return [Array<String>] an array representation of self
23
52
  def to_ary
24
53
  get_attribute(:children)
25
54
  end
26
-
27
- # Keep expanding until all top-level MoreComments are converted to comments
28
- def recursive_expand(link:, sort: 'best')
29
- # FIXME: this returns a flattened listing of comments and doesn't preserve the structure
30
- expand(link: link, sort: sort).flat_map do |o|
31
- o.is_a?(MoreComments) && o.count > 0 ? o.recursive_expand(link: link, sort: sort) : [o]
32
- end
33
- end
34
55
  end
35
56
  end
36
57
  end
@@ -22,10 +22,43 @@ module Redd
22
22
  from_response(client, path: id)
23
23
  end
24
24
 
25
+ # Get the appropriate listing.
26
+ # @param sort [:hot, :new, :top, :controversial, :comments, :rising, :gilded] the type of
27
+ # listing
28
+ # @param params [Hash] a list of params to send with the request
29
+ # @option params [String] :after return results after the given fullname
30
+ # @option params [String] :before return results before the given fullname
31
+ # @option params [Integer] :count the number of items already seen in the listing
32
+ # @option params [1..100] :limit the maximum number of things to return
33
+ # @option params [:hour, :day, :week, :month, :year, :all] :time the time period to consider
34
+ # when sorting.
35
+ #
36
+ # @note The option :time only applies to the top and controversial sorts.
37
+ # @return [Listing<Submission>]
38
+ def listing(sort, **params)
39
+ params[:t] = params.delete(:time) if params.key?(:time)
40
+ @client.model(:get, "#{get_attribute(:path)}#{sort}", params)
41
+ end
42
+
43
+ # @!method hot(**params)
44
+ # @!method new(**params)
45
+ # @!method top(**params)
46
+ # @!method controversial(**params)
47
+ # @!method comments(**params)
48
+ # @!method rising(**params)
49
+ # @!method gilded(**params)
50
+ #
51
+ # @see #listing
52
+ %i(hot new top controversial comments rising gilded).each do |sort|
53
+ define_method(sort) { |**params| listing(sort, **params) }
54
+ end
55
+
56
+ private
57
+
25
58
  def after_initialize
26
- @attributes[:subreddits].map! do |subreddit|
27
- Subreddit.from_response(client, display_name: subreddit[:name])
28
- end
59
+ # @attributes[:subreddits].map! do |subreddit|
60
+ # Subreddit.from_response(client, display_name: subreddit[:name])
61
+ # end
29
62
  end
30
63
  end
31
64
  end
@@ -10,7 +10,7 @@ module Redd
10
10
  include Searchable
11
11
 
12
12
  # @return [ModMail] the new modmail
13
- def modmail
13
+ def mod_mail
14
14
  ModMail.new(@client)
15
15
  end
16
16
 
@@ -24,6 +24,11 @@ module Redd
24
24
  FrontPage.new(@client)
25
25
  end
26
26
 
27
+ # @return [Hash] a breakdown of karma over subreddits
28
+ def karma_breakdown
29
+ @client.get('/api/v1/me/karma').body[:data]
30
+ end
31
+
27
32
  # @return [User] the logged-in user
28
33
  def me
29
34
  User.new(@client) { |client| client.get('/api/v1/me').body }
@@ -49,7 +54,7 @@ module Redd
49
54
  end
50
55
 
51
56
  # Get a (lazily loaded) multi by its path.
52
- # @param path [String] the multi's path, prepended by a /
57
+ # @param path [String] the multi's path, surrounded by a leading and trailing /
53
58
  # @return [Multireddit]
54
59
  def multi(path)
55
60
  Multireddit.from_id(@client, path)
@@ -92,16 +97,29 @@ module Redd
92
97
  # @return [Array<User>] the logged-in user's friends
93
98
  def friends
94
99
  @client.get('/api/v1/me/friends').body[:data][:children].map do |h|
95
- User.from_response(@client, name: h[:name], id: h[:id].tr('t2_', ''), since: h[:date])
100
+ User.from_response(@client, name: h[:name], id: h[:id].sub('t2_', ''), since: h[:date])
96
101
  end
97
102
  end
98
103
 
99
104
  # @return [Array<User>] users blocked by the logged-in user
100
105
  def blocked
101
106
  @client.get('/prefs/blocked').body[:data][:children].map do |h|
102
- User.from_response(@client, name: h[:name], id: h[:id].tr('t2_', ''), since: h[:date])
107
+ User.from_response(@client, name: h[:name], id: h[:id].sub('t2_', ''), since: h[:date])
103
108
  end
104
109
  end
110
+
111
+ # Return a listing of the user's subreddits.
112
+ #
113
+ # @param type ['subscriber', 'contributor', 'moderator'] the type of subreddits
114
+ # @param params [Hash] a list of optional params to send with the request
115
+ # @option params [String] :after return results after the given fullname
116
+ # @option params [String] :before return results before the given fullname
117
+ # @option params [Integer] :count (0) the number of items already seen in the listing
118
+ # @option params [1..100] :limit (25) the maximum number of things to return
119
+ # @return [Listing<Subreddit>]
120
+ def my_subreddits(type, **params)
121
+ @client.model(:get, "/subreddits/mine/#{type}", params)
122
+ end
105
123
  end
106
124
  end
107
125
  end
@@ -69,7 +69,8 @@ module Redd
69
69
  # @!group Listings
70
70
 
71
71
  # Get the appropriate listing.
72
- # @param sort [:hot, :new, :top, :controversial, :comments, :rising] the type of listing
72
+ # @param sort [:hot, :new, :top, :controversial, :comments, :rising, :gilded] the type of
73
+ # listing
73
74
  # @param params [Hash] a list of params to send with the request
74
75
  # @option params [String] :after return results after the given fullname
75
76
  # @option params [String] :before return results before the given fullname
@@ -91,9 +92,10 @@ module Redd
91
92
  # @!method controversial(**params)
92
93
  # @!method comments(**params)
93
94
  # @!method rising(**params)
95
+ # @!method gilded(**params)
94
96
  #
95
97
  # @see #listing
96
- %i(hot new top controversial comments rising).each do |sort|
98
+ %i(hot new top controversial comments rising gilded).each do |sort|
97
99
  define_method(sort) { |**params| listing(sort, **params) }
98
100
  end
99
101
 
@@ -34,6 +34,7 @@ module Redd
34
34
  auth_header = response.headers['www-authenticate']
35
35
  return klass.new(response) if auth_header && auth_header.include?(key)
36
36
  end
37
+ nil
37
38
  end
38
39
  end
39
40
  end
@@ -7,16 +7,16 @@ module Redd
7
7
  # Contains the mapping from 'kind' strings to classes.
8
8
  # TODO: UserList type!
9
9
  MAPPING = {
10
- 't1' => Models::Comment,
11
- 't2' => Models::User,
12
- 't3' => Models::Submission,
13
- 't4' => Models::PrivateMessage,
14
- 't5' => Models::Subreddit,
15
- 'more' => Models::MoreComments,
16
- 'wikipage' => Models::WikiPage,
17
- 'Listing' => Models::Listing,
18
- 'LabeledMulti' => Models::Multireddit,
19
- 'LiveUpdateEvent' => Models::LiveThread
10
+ 't1' => Models::Comment,
11
+ 't2' => Models::User,
12
+ 't3' => Models::Submission,
13
+ 't4' => Models::PrivateMessage,
14
+ 't5' => Models::Subreddit,
15
+ 'more' => Models::MoreComments,
16
+ 'wikipage' => Models::WikiPage,
17
+ 'Listing' => Models::Listing,
18
+ 'LabeledMulti' => Models::Multireddit,
19
+ 'LiveUpdate' => Models::LiveThread::LiveUpdate
20
20
  }.freeze
21
21
 
22
22
  def initialize(client)
data/lib/redd/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Redd
4
- VERSION = '0.8.0'
4
+ VERSION = '0.8.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Avinash Dwarapu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-26 00:00:00.000000000 Z
11
+ date: 2017-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -152,7 +152,6 @@ files:
152
152
  - lib/redd/models/access.rb
153
153
  - lib/redd/models/basic_model.rb
154
154
  - lib/redd/models/comment.rb
155
- - lib/redd/models/conversation.rb
156
155
  - lib/redd/models/front_page.rb
157
156
  - lib/redd/models/inboxable.rb
158
157
  - lib/redd/models/lazy_model.rb
@@ -1,82 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'lazy_model'
4
-
5
- module Redd
6
- module Models
7
- # Represents a conversation in the new modmail.
8
- # TODO: add message and modmail-specific user type
9
- class Conversation < LazyModel
10
- # Get a Conversation from its id.
11
- # @option hash [String] :id the base36 id (e.g. abc123)
12
- # @return [Conversation]
13
- def self.from_response(client, hash)
14
- id = hash.fetch(:id)
15
- new(client) do |c|
16
- response = c.get("/api/mod/conversations/#{id}").body
17
- response[:conversation].merge(
18
- messages: response[:messages],
19
- user: response[:user],
20
- mod_actions: response[:modActions]
21
- )
22
- end
23
- end
24
-
25
- # Get a Conversation from its id.
26
- # @param id [String] the base36 id (e.g. abc123)
27
- # @return [Conversation]
28
- def self.from_id(client, id)
29
- from_response(client, id: id)
30
- end
31
-
32
- # Mark this conversation as read.
33
- def mark_as_read
34
- @client.post('/api/mod/conversations/read', conversationIds: [get_attribute(:id)])
35
- end
36
-
37
- # Mark this conversation as unread.
38
- def mark_as_unread
39
- @client.post('/api/mod/conversations/unread', conversationIds: [get_attribute(:id)])
40
- end
41
-
42
- # Mark this conversation as archived.
43
- def archive
44
- perform_action(:post, 'archive')
45
- end
46
-
47
- # Removed this conversation from archived.
48
- def unarchive
49
- perform_action(:post, 'unarchive')
50
- end
51
-
52
- # Highlight this conversation.
53
- def highlight
54
- perform_action(:post, 'highlight')
55
- end
56
-
57
- # Remove the highlight on this conversation.
58
- def unhighlight
59
- perform_action(:delete, 'highlight')
60
- end
61
-
62
- # Mute this conversation.
63
- def mute
64
- perform_action(:post, 'mute')
65
- end
66
-
67
- # Unmute this conversation.
68
- def unmute
69
- perform_action(:post, 'unmute')
70
- end
71
-
72
- private
73
-
74
- # Perform an action on a conversation.
75
- # @param method [:post, :delete] the method to use
76
- # @param action [String] the name of the action
77
- def perform_action(method, action)
78
- @client.send(method, "/api/mod/conversations/#{id}/#{action}")
79
- end
80
- end
81
- end
82
- end