ruby-hackernews 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -59,6 +59,9 @@ Each Entry instance has the following data:
59
59
 
60
60
  entry.time # the elapsed time from submission
61
61
 
62
+ entry.text # the text of the submission (ask/jobs only)
63
+ # NOTE: it will fetch the inner page
64
+
62
65
  After you've logged in (see below) you can do the following
63
66
 
64
67
  entry.upvote # votes the entry
@@ -74,6 +77,11 @@ You get an entry's comments with:
74
77
 
75
78
  entry.comments
76
79
 
80
+ You can also get a specific comment by id with:
81
+
82
+ Comment.find("1234") # returns the comments with id 1234,
83
+ # and its subcomments.
84
+
77
85
  Note that the method above will send a request to HN. If you just need the comments' count or url, you can instead use:
78
86
 
79
87
  entry.comments_count
@@ -93,6 +101,7 @@ Each Comment instance has the following data:
93
101
 
94
102
  comment = Entry.all.first.comments.first # gets the first comment of the first entry on HN's main page
95
103
 
104
+ comment.id # comment's unique identifier
96
105
  comment.text # comment's body
97
106
  comment.user.name # poster's user name on HN
98
107
  comment.voting.score # comment's score
@@ -158,3 +167,4 @@ Will return the HN comment url of the last submitted story of that user
158
167
  - Josh Ellington ( http://github.com/joshellington ) for reporting a bug about job entries
159
168
  - Wayne ( http://github.com/BlissOfBeing ) for adding User.submissions, Entry.comments_url and cleaning up the Rakefile
160
169
  - Daniel Da Cunha ( http://github.com/ddacunha ) for a fix on Entry#comments_count
170
+ - Nathan Campos ( http://github.com/nathanpc) for adding #text to Entry
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ require 'rake/testtask'
8
8
 
9
9
  spec = Gem::Specification.new do |s|
10
10
  s.name = 'ruby-hackernews'
11
- s.version = '1.3.1'
11
+ s.version = '1.3.2'
12
12
  s.add_dependency('require_all', '>= 1.1.0')
13
13
  s.add_dependency('mechanize', '>= 1.0.0')
14
14
  s.has_rdoc = false
@@ -9,14 +9,19 @@ module RubyHackernews
9
9
 
10
10
  attr_accessor :parent
11
11
 
12
- def initialize(text, voting, user_info, reply_link)
12
+ def initialize(text, voting, user_info, reply_link, absolute_link)
13
13
  @text = text
14
14
  @voting = voting
15
15
  @user = user_info
16
16
  @reply_link = reply_link
17
+ @absolute_link = absolute_link
17
18
  @children = []
18
19
  end
19
20
 
21
+ def id
22
+ return @absolute_link.split("=")[1].to_i
23
+ end
24
+
20
25
  def <<(comment)
21
26
  comment.parent = self
22
27
  @children << comment
@@ -38,6 +43,10 @@ module RubyHackernews
38
43
  return CommentService.new.get_new_comments(pages)
39
44
  end
40
45
 
46
+ def self.find(id)
47
+ return CommentService.new.find_by_id(id)
48
+ end
49
+
41
50
  def reply(text)
42
51
  return false unless @reply_link
43
52
  CommentService.new.write_comment(@reply_link, text)
@@ -14,6 +14,15 @@ module RubyHackernews
14
14
  return get_comments_entities(table)
15
15
  end
16
16
 
17
+ def find_by_id(id)
18
+ page = agent.get(ConfigurationService.base_url + "item?id=#{id}")
19
+ comment = parse_comment(page.search("table")[2].search("tr").first)
20
+ get_comments_entities(page.search("table")[3]).each do |c|
21
+ comment << c
22
+ end
23
+ return comment
24
+ end
25
+
17
26
  def get_comments_entities(table)
18
27
  comments = []
19
28
  target = comments
@@ -58,7 +67,9 @@ module RubyHackernews
58
67
  user_info = UserInfoParser.new(header).parse
59
68
  reply_link = element.search("td[@class='default']/p//u//a").first
60
69
  reply_url = reply_link['href'] if reply_link
61
- return Comment.new(text, voting, user_info, reply_url)
70
+ absolute_link_group = header.search("a")
71
+ absolute_url = absolute_link_group.count == 2 ? absolute_link_group[1]['href'] : nil
72
+ return Comment.new(text, voting, user_info, reply_url, absolute_url)
62
73
  end
63
74
 
64
75
  def write_comment(page_url, comment)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-hackernews
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-09 00:00:00.000000000 Z
12
+ date: 2012-12-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: require_all
@@ -51,34 +51,34 @@ extra_rdoc_files: []
51
51
  files:
52
52
  - README.rdoc
53
53
  - Rakefile
54
- - lib/ruby-hackernews.rb
54
+ - lib/ruby-hackernews/domain/comment/comment.rb
55
+ - lib/ruby-hackernews/domain/entry/user_info.rb
56
+ - lib/ruby-hackernews/domain/entry/time_info.rb
57
+ - lib/ruby-hackernews/domain/entry/entry.rb
58
+ - lib/ruby-hackernews/domain/entry/link_info.rb
59
+ - lib/ruby-hackernews/domain/entry/voting_info.rb
60
+ - lib/ruby-hackernews/domain/entry/comments_info.rb
61
+ - lib/ruby-hackernews/domain/user.rb
55
62
  - lib/ruby-hackernews/services/comment_service.rb
56
- - lib/ruby-hackernews/services/entry_service.rb
57
- - lib/ruby-hackernews/services/voting_service.rb
58
63
  - lib/ruby-hackernews/services/text_service.rb
59
- - lib/ruby-hackernews/services/parsers/entry_page_parser.rb
60
- - lib/ruby-hackernews/services/parsers/comments_info_parser.rb
61
- - lib/ruby-hackernews/services/parsers/voting_info_parser.rb
62
- - lib/ruby-hackernews/services/parsers/entry_parser.rb
63
- - lib/ruby-hackernews/services/parsers/user_info_parser.rb
64
- - lib/ruby-hackernews/services/parsers/link_info_parser.rb
65
- - lib/ruby-hackernews/services/parsers/text_parser.rb
66
- - lib/ruby-hackernews/services/parsers/time_info_parser.rb
67
- - lib/ruby-hackernews/services/login_service.rb
68
- - lib/ruby-hackernews/services/signup_service.rb
69
- - lib/ruby-hackernews/services/not_authenticated_error.rb
70
64
  - lib/ruby-hackernews/services/user_info_service.rb
71
65
  - lib/ruby-hackernews/services/mechanize_context.rb
66
+ - lib/ruby-hackernews/services/entry_service.rb
67
+ - lib/ruby-hackernews/services/not_authenticated_error.rb
68
+ - lib/ruby-hackernews/services/login_service.rb
72
69
  - lib/ruby-hackernews/services/page_fetcher.rb
70
+ - lib/ruby-hackernews/services/parsers/user_info_parser.rb
71
+ - lib/ruby-hackernews/services/parsers/link_info_parser.rb
72
+ - lib/ruby-hackernews/services/parsers/entry_parser.rb
73
+ - lib/ruby-hackernews/services/parsers/time_info_parser.rb
74
+ - lib/ruby-hackernews/services/parsers/text_parser.rb
75
+ - lib/ruby-hackernews/services/parsers/entry_page_parser.rb
76
+ - lib/ruby-hackernews/services/parsers/comments_info_parser.rb
77
+ - lib/ruby-hackernews/services/parsers/voting_info_parser.rb
73
78
  - lib/ruby-hackernews/services/configuration_service.rb
74
- - lib/ruby-hackernews/domain/user.rb
75
- - lib/ruby-hackernews/domain/entry/time_info.rb
76
- - lib/ruby-hackernews/domain/entry/link_info.rb
77
- - lib/ruby-hackernews/domain/entry/user_info.rb
78
- - lib/ruby-hackernews/domain/entry/voting_info.rb
79
- - lib/ruby-hackernews/domain/entry/comments_info.rb
80
- - lib/ruby-hackernews/domain/entry/entry.rb
81
- - lib/ruby-hackernews/domain/comment/comment.rb
79
+ - lib/ruby-hackernews/services/voting_service.rb
80
+ - lib/ruby-hackernews/services/signup_service.rb
81
+ - lib/ruby-hackernews.rb
82
82
  homepage: http://github.com/bolthar/ruby-hackernews
83
83
  licenses: []
84
84
  post_install_message: