ruby_reddit_api 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,4 +1,4 @@
1
- Ruby Reddit Client v0.2.0
1
+ Ruby Reddit Client v0.2.1
2
2
  ==================
3
3
  Tested with ruby 1.9.2
4
4
 
@@ -53,11 +53,6 @@ Then /^I should be able to downvote it$/ do
53
53
  @submission.downvote.should be true
54
54
  end
55
55
 
56
- Then /^I should be able to see the comments$/ do
57
- comments = @submission.comments
58
- comments.size.should > 0
59
- end
60
-
61
56
  Then /^I should not be able to save the submission$/ do
62
57
  @submission.save.should be false
63
58
  end
@@ -115,3 +110,8 @@ end
115
110
  Then /^I should be able to indistinguish the submission$/ do
116
111
  @submission.indistinguish
117
112
  end
113
+
114
+ Then /^I should be able to see the comments$/ do
115
+ comments = @submission.comments
116
+ comments.size.should > 0
117
+ end
@@ -1,6 +1,8 @@
1
1
  Before do
2
2
  load_server_config
3
+ Reddit::Base.base_uri @address
3
4
  Reddit::Api.base_uri @address
5
+ Reddit::Thing.base_uri @address
4
6
  Reddit::Submission.base_uri @address
5
7
  Reddit::Comment.base_uri @address
6
8
  Reddit::User.base_uri @address
@@ -5,13 +5,14 @@ end
5
5
 
6
6
  require "httparty"
7
7
  require "json"
8
- require "reddit/version"
9
- require "reddit/base"
10
- require "reddit/json_listing"
11
- require "reddit/api"
12
- require "reddit/user"
13
- require "reddit/vote"
14
- require "reddit/submission"
15
- require "reddit/comment"
16
- require "reddit/message"
8
+ require "ruby_reddit_api/version"
9
+ require "ruby_reddit_api/json_listing"
10
+ require "ruby_reddit_api/base"
11
+ require "ruby_reddit_api/thing"
12
+ require "ruby_reddit_api/api"
13
+ require "ruby_reddit_api/user"
14
+ require "ruby_reddit_api/vote"
15
+ require "ruby_reddit_api/submission"
16
+ require "ruby_reddit_api/comment"
17
+ require "ruby_reddit_api/message"
17
18
 
@@ -103,7 +103,7 @@ module Reddit
103
103
 
104
104
  def capture_user_id
105
105
  return true if user_id
106
- this_user = read("/user/#{user}/about.json", :handler => "User")
106
+ this_user = read("/user/#{user}/about.json", :handler => "User")[0]
107
107
  Reddit::Base.instance_variable_set("@user_id", this_user.id)
108
108
  end
109
109
 
@@ -3,7 +3,7 @@ module Reddit
3
3
  class Comment < Thing
4
4
 
5
5
  include JsonListing
6
- attr_reader :body, :subreddit_id, :name, :created, :downs, :author, :created_utc, :body_html, :link_id, :parent_id, :likes, :replies, :subreddit, :ups, :debug, :kind
6
+ attr_reader :body, :subreddit_id, :name, :created, :downs, :author, :created_utc, :body_html, :link_id, :parent_id, :likes, :num_comments, :subreddit, :ups, :debug, :kind
7
7
  def initialize(json)
8
8
  parse(json)
9
9
  @debug = StringIO.new
@@ -18,6 +18,17 @@ module Reddit
18
18
  body
19
19
  end
20
20
 
21
+ # Fetch comments
22
+ # @return [Array<Reddit::Comment>]
23
+ def comments
24
+ opts = {:handler => "Comment",
25
+ :verb => "post",
26
+ :body =>
27
+ {:link_id => id, :depth => 10, :r => subreddit, :uh => modhash, :renderstyle => "json", :pv_hex => "", :id => id}
28
+ }
29
+ return read("/api/morechildren", opts )
30
+ end
31
+
21
32
  # Modify a comment
22
33
  # @return [true,false]
23
34
  def edit(newtext)
@@ -20,7 +20,7 @@ module Reddit
20
20
  data = json["data"]
21
21
  Reddit::Base.instance_variable_set("@modhash", data["modhash"]) # Needed for api calls
22
22
 
23
- children = data["children"]
23
+ children = data["children"] || [{"data" => data, "kind" => json["kind"] }]
24
24
  children.each do |message|
25
25
  kind = message["kind"]
26
26
  message["data"]["kind"] = kind
@@ -55,21 +55,10 @@ module Reddit
55
55
  # Fetch submission comments
56
56
  # @todo Move to 'Thing' class
57
57
  # @return [Array<Reddit::Comment>]
58
- def comments(more=false)
59
- #TODO Get morechildren to work correctly
60
- if more && last_comment_id
61
- opts = {:handler => "Comment",
62
- :verb => "post",
63
- :body =>
64
- {:link_id => last_comment_id, :depth => 0, :r => subreddit, :uh => modhash, :renderstyle => "json", :pv_hex => "", :id => id}
65
- }
66
- return read("/api/morechildren", opts )
67
-
68
- else
69
- _comments = read( permalink + ".json", {:handler => "Comment", :query => {:limit => 50}} )
70
- @last_comment_id = _comments.last.id if _comments && _comments.any?
71
- return _comments
72
- end
58
+ def comments
59
+ _comments = read( permalink + ".json", {:handler => "Comment", :query => {:limit => 250}} )
60
+ @last_comment_id = _comments.last.id if _comments && _comments.any?
61
+ return _comments
73
62
  end
74
63
 
75
64
  protected
@@ -17,7 +17,7 @@ module Reddit
17
17
  # The author of the entity. The data is lazy-loaded and cached on the object
18
18
  # @return [Reddit::User]
19
19
  def author
20
- @author_data ||= read("/user/#{@author}/about.json", :handler => "User")
20
+ @author_data ||= read("/user/#{@author}/about.json", :handler => "User")[0]
21
21
  end
22
22
 
23
23
  # Upvote thing
@@ -1,7 +1,7 @@
1
1
  module Reddit
2
2
  # @author James Cook
3
3
  class User < Api
4
- include JSONListing
4
+ include JsonListing
5
5
  attr_reader :name, :debug, :created, :created_utc, :link_karma, :comment_karma, :is_mod, :has_mod_mail, :kind
6
6
  def initialize(json)
7
7
  @debug = StringIO.new
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - James Cook