redd 0.7.4 → 0.7.5

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: 36eb57cd9b39fd9bc40fa5fb242f0ce23808c623
4
- data.tar.gz: 167e62283d79e46b12e3bdc55f44acbf8f87703e
3
+ metadata.gz: c90f67d9e2534cad626e22954ec8d4b901219fde
4
+ data.tar.gz: 3a100caa0269c8fdbd4b14dfc1a6c8a1664b707a
5
5
  SHA512:
6
- metadata.gz: f94502a932a54d1f6c63bb14ae42f08897ba3e5a4958f211119ce71ad3bdb72a96f2b2699ae31856a66c6c5baf8ac5f5be90050f18b5cbb63f9457afe33db0a3
7
- data.tar.gz: b17c0e4d62fc82f8dd31c62d25ecf4e38e87f59071b54229e96f4ec3a68954d143ec2b7d76b2fe251375dbc38030750df6e8cf0065cf854caad2adf4053b7bde
6
+ metadata.gz: 03f52c6f88fefb1f14e6ae690d98bf53240dc9f7bf76039ff2b236e6e98c41f774f327c8a9fab85780ace0cf3c623188d13b971a5878369f0ed9f870463cf5d9
7
+ data.tar.gz: 33fb6ee0ce7d72dca59af56a93b43284f0417f624945329466970c91a2dee84dbd51d9845dbaf63d40dd8c9d2ad26a86793ff514e5aa67fce403f3c69591a069
@@ -22,6 +22,11 @@ module Redd
22
22
  params[:mark] = mark
23
23
  request_object(:get, "/message/#{category}.json", params)
24
24
  end
25
+
26
+ # Mark all messages as read.
27
+ def read_all_messages
28
+ post("/api/read_all_messages")
29
+ end
25
30
  end
26
31
  end
27
32
  end
@@ -29,6 +29,20 @@ module Redd
29
29
  request_object(:get, "/r/#{name}/about.json")
30
30
  end
31
31
 
32
+ # Fetch a list of multis belonging to the user.
33
+ def my_multis
34
+ multis = get("/api/multi/mine").body
35
+ multis.map { |thing| object_from_body(thing) }
36
+ end
37
+
38
+ # Fetch an individual multi from its path.
39
+ # @param [String] path The multi's path.
40
+ # @return [Objects::LabeledMulti]
41
+ def multi_from_path(path)
42
+ without_slash = path.gsub(/^\//, "")
43
+ request_object(:get, "/api/multi/" + without_slash)
44
+ end
45
+
32
46
  # @!method get_hot(subreddit = nil, **params)
33
47
  # @!method get_new(subreddit = nil, **params)
34
48
  # @!method get_top(subreddit = nil, **params)
@@ -2,6 +2,7 @@ require_relative "../../objects/base"
2
2
  require_relative "../../objects/thing"
3
3
  require_relative "../../objects/listing"
4
4
  require_relative "../../objects/wiki_page"
5
+ require_relative "../../objects/labeled_multi"
5
6
  require_relative "../../objects/more_comments"
6
7
  require_relative "../../objects/comment"
7
8
  require_relative "../../objects/user"
@@ -17,14 +18,15 @@ module Redd
17
18
  module Utilities
18
19
  # The kind strings and the objects that should be used for them.
19
20
  OBJECT_KINDS = {
20
- "Listing" => Objects::Listing,
21
- "wikipage" => Objects::WikiPage,
22
- "more" => Objects::MoreComments,
23
- "t1" => Objects::Comment,
24
- "t2" => Objects::User,
25
- "t3" => Objects::Submission,
26
- "t4" => Objects::PrivateMessage,
27
- "t5" => Objects::Subreddit
21
+ "Listing" => Objects::Listing,
22
+ "wikipage" => Objects::WikiPage,
23
+ "LabeledMulti" => Objects::LabeledMulti,
24
+ "more" => Objects::MoreComments,
25
+ "t1" => Objects::Comment,
26
+ "t2" => Objects::User,
27
+ "t3" => Objects::Submission,
28
+ "t4" => Objects::PrivateMessage,
29
+ "t5" => Objects::Subreddit
28
30
  }
29
31
 
30
32
  # Request and create an object from the response.
@@ -89,12 +89,14 @@ module Redd
89
89
  end
90
90
  end
91
91
 
92
- # @param [Access] access The access to use.
92
+ # @param [Access] new_access The access to use.
93
93
  # @yield The client with the given access.
94
- def with(access)
95
- new_instance = dup
96
- new_instance.access = access
97
- yield new_instance
94
+ def with(new_access)
95
+ old_access = @access
96
+ @access = new_access
97
+ response = yield(self)
98
+ @access = old_access
99
+ response
98
100
  end
99
101
 
100
102
  # Obtain a new access token using a refresh token.
@@ -32,6 +32,7 @@ module Redd
32
32
  # @param [Symbol] old_name The existing property.
33
33
  def self.alias_property(new_name, old_name)
34
34
  define_method(new_name) { send(old_name) }
35
+ define_method(:"#{new_name}?") { send(old_name) }
35
36
  end
36
37
  end
37
38
  end
@@ -0,0 +1,13 @@
1
+ module Redd
2
+ module Objects
3
+ # A comment that can be made on a link.
4
+ class LabeledMulti < Base
5
+ # @see Objects::Base
6
+ def initialize(client, attributes = {})
7
+ attr_dup = attributes.dup
8
+ attr_dup[:subreddits].map! { |sub| sub[:name] }
9
+ super(client, attr_dup)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -13,6 +13,16 @@ module Redd
13
13
  def block_sender!
14
14
  post("/api/block", id: fullname)
15
15
  end
16
+
17
+ # Mark the message as read.
18
+ def mark_as_read
19
+ post("/api/read_message", id: fullname)
20
+ end
21
+
22
+ # Mark the message as unread and add orangered to account.
23
+ def mark_as_unread
24
+ post("/api/unread_message", id: fullname)
25
+ end
16
26
  end
17
27
  end
18
28
  end
@@ -25,6 +25,19 @@ module Redd
25
25
  self[:gilded] > 0
26
26
  end
27
27
 
28
+ # Mark the thing as Not Suitable For Work.
29
+ def mark_as_nsfw
30
+ get("/api/marknsfw", id: fullname)
31
+ self[:over_18] = true
32
+ end
33
+
34
+ # No longer mark the thing as Not Suitable For Work.
35
+ def unmark_as_nsfw
36
+ get("/api/unmarknsfw", id: fullname)
37
+ self[:over_18] = false
38
+ end
39
+ alias_method :mark_as_safe, :unmark_as_nsfw
40
+
28
41
  # Reply to the thing.
29
42
  # @param text [String] The text to comment.
30
43
  # @return [Objects::Comment] The reply.
@@ -32,6 +45,28 @@ module Redd
32
45
  client.add_comment(self, text)
33
46
  end
34
47
 
48
+ # Set the submission to "contest mode" (comments are randomly sorted)
49
+ def set_contest_mode
50
+ post("/api/set_contest_mode", id: fullname, state: true)
51
+ end
52
+
53
+ # Unset the "contest mode".
54
+ def unset_contest_mode
55
+ post("/api/set_contest_mode", id: fullname, state: false)
56
+ end
57
+
58
+ # Set the submission as the sticky post of the subreddit
59
+ def set_sticky
60
+ post("/api/set_subreddit_sticky", id: fullname, state: true)
61
+ self[:stickied] = true
62
+ end
63
+
64
+ # Unsticky the post from the subreddit
65
+ def unset_sticky
66
+ post("/api/set_subreddit_sticky", id: fullname, state: false)
67
+ self[:stickied] = false
68
+ end
69
+
35
70
  # @return [Listing] The submission's comments.
36
71
  # @todo Allow for various depths and contexts and what not. Maybe a
37
72
  # get_comment method?
data/lib/redd/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Redd # rubocop:disable Style/Documentation
2
2
  # The semantic version number.
3
- VERSION = "0.7.4"
3
+ VERSION = "0.7.5"
4
4
  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.7.4
4
+ version: 0.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Avinash Dwarapu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-18 00:00:00.000000000 Z
11
+ date: 2015-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -171,6 +171,7 @@ files:
171
171
  - lib/redd/error.rb
172
172
  - lib/redd/objects/base.rb
173
173
  - lib/redd/objects/comment.rb
174
+ - lib/redd/objects/labeled_multi.rb
174
175
  - lib/redd/objects/listing.rb
175
176
  - lib/redd/objects/more_comments.rb
176
177
  - lib/redd/objects/private_message.rb