redd 0.6.1 → 0.6.2

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: 6760b565561bde890fe1595ebda87ada31bae326
4
- data.tar.gz: 7bccd9ea39fb2fa9d8201648d2c6164cab2791f6
3
+ metadata.gz: f1c9095dc0fc6208e07728e40a724e40a0c0a24d
4
+ data.tar.gz: 7a752d0341708cbd837e1ae23e486aaa6c29f468
5
5
  SHA512:
6
- metadata.gz: 24762a4de14370f0d6cb4b9a79150c8d8db6f86a290d06edb82034e664f2b878cb48c37bf4a046fe5f03b23623bd8c6af2008ca9687154596da56bf34d522072
7
- data.tar.gz: ba5116ceaa492bdefb12dcd626597fdf9989b301dcc66154240f844b38163cc944eb682290f0282bd9118785dd7919a1d87c1b343ab5071a3f4edf4e7847cc88
6
+ metadata.gz: 56bc149cb63a27a6bd6531f85a4ad56491dd888270cc70963d82cfd748445641e9d404bbea4cc0100dd673800d14fec1b5edcd5311e456ddf77854a271436574
7
+ data.tar.gz: 490cc65032031f6d0ed56b69eeef554773865b5503a47bae20ffea12bd8314b083ffbb43b537e8650a749b241e6f6b58721cb38968dc9b01c6cd3f07dbccbbd3
data/README.md CHANGED
@@ -15,6 +15,7 @@
15
15
  <a href="#getting-started">Getting Started</a> |
16
16
  <a href="#oauth2">OAuth2</a> |
17
17
  <a href="#extending-redd">Extending Redd</a> |
18
+ <a href="#contributing">Contributing</a> |
18
19
  <a href="#supported-rubies">Supported Rubies</a> |
19
20
  <a href="#copyright">Copyright</a>
20
21
  </p>
@@ -217,8 +218,8 @@ Extending any ruby library, including redd is incredibly easy. Let's try this ou
217
218
  Redd::Object::Comment.include(Gildable)
218
219
  ```
219
220
 
220
- #### Contributing
221
- Please do. If you would like to become a contributor, do ask.
221
+ ## Contributing
222
+ [Fork the repository](https://github.com/avidw/redd/fork), [create a pull request](https://github.com/avidw/redd/compare) and [go nuts](https://i.imgur.com/lz7hOlC.jpg).
222
223
 
223
224
  ## Supported Rubies
224
225
  This gem aims to work on the following rubies:
@@ -6,13 +6,12 @@ module Redd
6
6
  # @option params [String] :id The fullname of a thing.
7
7
  # @option params [String] :url The url of a thing. If an id is also
8
8
  # provided, the id will take precedence.
9
- # @return [Redd::Object::Submission, Redd::Object::Comment] The object.
9
+ # @return [Redd::Object::Listing] Listing of the object or objects.
10
10
  #
11
11
  # @note Reddit does accept a subreddit, but with fullnames and urls, I
12
12
  # assumed that was unnecessary.
13
13
  def get_info(params = {})
14
- object = object_from_response :get, "/api/info.json", params
15
- object.first
14
+ object_from_response :get, "/api/info.json", params
16
15
  end
17
16
 
18
17
  # Get the comments for a submission.
@@ -36,38 +35,24 @@ module Redd
36
35
  object_from_body(replies)
37
36
  end
38
37
 
39
- def replace_morecomments(morecomments, submission = nil)
38
+ def expand_morecomments(morecomments, submission = nil)
40
39
  parent_id = morecomments.parent_id
41
40
  link_id =
42
41
  if submission
43
- submission
42
+ extract_fullname(submission)
44
43
  elsif parent_id.start_with?("t3_")
45
44
  parent_id
46
45
  elsif parent_id.start_with?("t1_")
47
46
  get_info(id: parent_id).first.link_id
48
47
  end
49
48
 
50
- response = post "/api/morechildren",
49
+ response = post "/api/morechildren.json",
51
50
  api_type: "json",
52
51
  link_id: link_id,
53
52
  children: morecomments.children.join(",")
54
53
  comments = response[:json][:data][:things]
55
54
 
56
- # No idea how to increase the depth of the comments.
57
- comments.select! { |comment| comment[:kind] == "t1" }
58
-
59
- comments.map do |comment|
60
- object_from_body(
61
- kind: comment[:kind],
62
- data: {
63
- parent_id: comment[:data][:parent],
64
- body: comment[:data][:contentText],
65
- body_html: comment[:data][:contentHTML],
66
- link_id: comment[:data][:link],
67
- name: comment[:data][:id]
68
- }
69
- )
70
- end
55
+ object_from_body(kind: "Listing", data: {children: comments})
71
56
  end
72
57
  end
73
58
  end
@@ -4,12 +4,14 @@ module Redd
4
4
  module Object
5
5
  # A comment made on links.
6
6
  class Comment < Redd::Thing
7
+ require "redd/thing/commentable"
7
8
  require "redd/thing/editable"
8
9
  require "redd/thing/inboxable"
9
10
  require "redd/thing/moderatable"
10
11
  require "redd/thing/reportable"
11
12
  require "redd/thing/voteable"
12
13
 
14
+ include Redd::Thing::Commentable
13
15
  include Redd::Thing::Editable
14
16
  include Redd::Thing::Inboxable
15
17
  include Redd::Thing::Moderatable
@@ -43,14 +45,19 @@ module Redd
43
45
 
44
46
  alias_method :reports_count, :num_reports
45
47
 
46
- def replies
47
- @replies ||= client.get_replies(self)
48
+ def comments
49
+ @comments ||= client.get_replies(self)
48
50
  end
51
+ alias_method :replies, :comments
49
52
 
50
53
  def subreddit
51
54
  @subreddit ||= client.subreddit(@attributes[:subreddit])
52
55
  end
53
56
 
57
+ def submission
58
+ @submission ||= client.get_info(id: link_id).first
59
+ end
60
+
54
61
  def created
55
62
  @created ||= Time.at(@attributes[:created_utc])
56
63
  end
@@ -5,6 +5,10 @@ module Redd
5
5
  attr_reader :count
6
6
  attr_reader :parent_id
7
7
  attr_reader :children
8
+
9
+ def expand(submission = nil)
10
+ client.expand_morecomments(self, submission)
11
+ end
8
12
  end
9
13
  end
10
14
  end
@@ -4,6 +4,7 @@ module Redd
4
4
  module Object
5
5
  # A submission made in a subreddit.
6
6
  class Submission < Redd::Thing
7
+ require "redd/thing/commentable"
7
8
  require "redd/thing/editable"
8
9
  require "redd/thing/hideable"
9
10
  require "redd/thing/moderatable"
@@ -11,6 +12,7 @@ module Redd
11
12
  require "redd/thing/saveable"
12
13
  require "redd/thing/voteable"
13
14
 
15
+ include Redd::Thing::Commentable
14
16
  include Redd::Thing::Editable
15
17
  include Redd::Thing::Hideable
16
18
  include Redd::Thing::Moderatable
data/lib/redd/thing.rb CHANGED
@@ -21,7 +21,7 @@ module Redd
21
21
 
22
22
  # @return [String] The fullname of the thing.
23
23
  def fullname
24
- @fullname ||= (attributes[:name] || "#{kind}_#{id}")
24
+ @fullname ||= "#{kind}_#{id}"
25
25
  end
26
26
  end
27
27
  end
@@ -0,0 +1,27 @@
1
+ require "redd/thing"
2
+
3
+ module Redd
4
+ class Thing
5
+ # A Redd::Object that can be commented on.
6
+ # This means that the comments could contain a MoreComments object.
7
+ module Commentable
8
+ def expand_morecomments
9
+ comments.things.map! do |comment|
10
+ if comment.is_a?(Redd::Object::MoreComments)
11
+ comment.expand.things
12
+ else
13
+ comment
14
+ end
15
+ end
16
+
17
+ comments.things.flatten!
18
+ end
19
+
20
+ def remove_morecomments
21
+ while comments.map { |c| c.class }.include? Redd::Object::MoreComments
22
+ expand_morecomments
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
data/lib/redd/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # The main Redd module.
2
2
  module Redd
3
3
  # The semantic version number for Redd.
4
- VERSION = "0.6.1"
4
+ VERSION = "0.6.2"
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.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Avinash Dwarapu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-11 00:00:00.000000000 Z
11
+ date: 2014-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -223,6 +223,7 @@ files:
223
223
  - lib/redd/response/parse_json.rb
224
224
  - lib/redd/response/raise_error.rb
225
225
  - lib/redd/thing.rb
226
+ - lib/redd/thing/commentable.rb
226
227
  - lib/redd/thing/editable.rb
227
228
  - lib/redd/thing/hideable.rb
228
229
  - lib/redd/thing/inboxable.rb