ruby-hackernews 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,8 +1,13 @@
1
+ = NOTICE
1
2
 
3
+ My account on HN (http://news.ycombinator.com/threads?id=andreadallera) has been banned. Here's a discussion about why (http://news.ycombinator.com/item?id=3642719). Take your own conclusions. Personally, I won't be visiting HN anymore. I just wanted to give you all a heads-up about how things are run over there.
4
+ Anyway, these APIs will still be maintained - *I* am certainly not the one that wants to decide what's good or what's not in your place.
2
5
  = ruby-hackernews
3
6
 
4
7
  An API over Hacker News
5
8
 
9
+ http://stillmaintained.com/bolthar/ruby-hackernews.png
10
+
6
11
  == Requirements
7
12
 
8
13
  mechanize (>= 1.0.0)
@@ -57,12 +62,24 @@ After you've logged in (see below) you can do the following
57
62
  Entry.submit("mytitle", "myurl") # submit a new link
58
63
  Entry.submit("myquestion") # submit a new question (ask HN)
59
64
 
65
+ user.submissions.first.comments_url
66
+
60
67
  == Comments
61
68
 
62
69
  You get an entry's comments with:
63
70
 
64
71
  entry.comments
65
72
 
73
+ Note that the method above will send a request to HN. If you just need the comments' count or url, you can instead use:
74
+
75
+ entry.comments_count
76
+
77
+ and
78
+
79
+ entry.comment_url
80
+
81
+ Either of which will not issue a request to HN's site.
82
+
66
83
  You can also get the newest comments on HN with:
67
84
 
68
85
  Comments.newest
@@ -107,9 +124,19 @@ You can log out with:
107
124
 
108
125
  You have to log out before logging in with a different user.
109
126
 
127
+ You can also get the current users submission list by doing this:
128
+
129
+ user.submissions
130
+
131
+ This will return a new Entry instance. For example:
132
+
133
+ user.submissions.first.comment_url
134
+
135
+ Will return the HN comment url of the last submitted story of that user
136
+
110
137
  == TO DO
111
138
 
112
- Get user info (submission, comments...)
139
+ Get user info (comments, saved)
113
140
  Create account
114
141
  Change user info/settings
115
142
 
@@ -118,4 +145,7 @@ You have to log out before logging in with a different user.
118
145
  - Mike Kelly ( https://github.com/mikekelly ) for fixing a bug in TimeInfo.time
119
146
  - Marc Köhlbrugge ( http://github.com/marckohlbrugge ) fox fixing and formatting the documentation
120
147
  - Peter Cooper ( http://github.com/peterc ) for bug reports
121
- - Peter Boctor ( http://github.com/boctor ) for fixing a bug about authentication
148
+ - Peter Boctor ( http://github.com/boctor ) for fixing a bug about authentication
149
+ - Josh Ellington ( http://github.com/joshellington ) for reporting a bug about job entries
150
+ - Wayne ( http://github.com/BlissOfBeing ) for adding User.submissions, Entry.comments_url and cleaning up the Rakefile
151
+ - Daniel Da Cunha ( http://github.com/ddacunha ) for a fix on Entry#comments_count
data/Rakefile CHANGED
@@ -2,13 +2,13 @@
2
2
  require 'rubygems'
3
3
  require 'rake'
4
4
  require 'rake/clean'
5
- require 'rake/gempackagetask'
6
- require 'rake/rdoctask'
5
+ require 'rubygems/package_task'
6
+ require 'rdoc/task'
7
7
  require 'rake/testtask'
8
8
 
9
9
  spec = Gem::Specification.new do |s|
10
10
  s.name = 'ruby-hackernews'
11
- s.version = '1.1.2'
11
+ s.version = '1.1.3'
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
@@ -21,7 +21,7 @@ spec = Gem::Specification.new do |s|
21
21
  s.require_path = "lib"
22
22
  end
23
23
 
24
- Rake::GemPackageTask.new(spec) do |p|
24
+ Gem::PackageTask.new(spec) do |p|
25
25
  p.gem_spec = spec
26
26
  p.need_tar = true
27
27
  p.need_zip = true
@@ -12,5 +12,9 @@ class CommentsInfo
12
12
  def id
13
13
  return page[/\d+/]
14
14
  end
15
+
16
+ def url
17
+ return page
18
+ end
15
19
 
16
20
  end
@@ -1,4 +1,3 @@
1
-
2
1
  class Entry
3
2
 
4
3
  attr_reader :number
@@ -45,9 +44,13 @@ class Entry
45
44
  def id
46
45
  return @comments_info ? @comments_info.id : nil
47
46
  end
47
+
48
+ def comments_url
49
+ return @comments_info ? ConfigurationService.base_url + @comments_info.url : nil
50
+ end
48
51
 
49
52
  def comments_count
50
- return @comments_info.count
53
+ return @comments_info.count unless @comments_info.nil?
51
54
  end
52
55
 
53
56
  def write_comment(text)
@@ -15,4 +15,16 @@ class User
15
15
  return LoginService.new.logout
16
16
  end
17
17
 
18
+ def submissions(pages = 1)
19
+ return UserInfoService.new.submissions(@name, pages)
20
+ end
21
+
22
+ def saved(pages = 1)
23
+ return UserInfoService.new.saved(@name, pages)
24
+ end
25
+
26
+ def comments(pages = 1)
27
+ return UserInfoService.new.comments(@name, pages)
28
+ end
29
+
18
30
  end
@@ -24,8 +24,8 @@ class CommentService
24
24
  return comments
25
25
  end
26
26
 
27
- def get_new_comments(pages = 1)
28
- parser = EntryPageParser.new(agent.get(ConfigurationService.comments_url))
27
+ def get_new_comments(pages = 1, url = ConfigurationService.comments_url)
28
+ parser = EntryPageParser.new(agent.get(url))
29
29
  comments = []
30
30
  pages.times do
31
31
  lines = parser.get_lines
@@ -47,7 +47,7 @@ class CommentService
47
47
  voting = VotingInfoParser.new(element.search("td/center/a"), header).parse
48
48
  user_info = UserInfoParser.new(header).parse
49
49
  reply_link = element.search("td[@class='default']/p//u//a").first
50
- reply_url = reply_link['href'] if reply_link
50
+ reply_url = reply_link['href'] if reply_link
51
51
  return Comment.new(text, voting, user_info, reply_url)
52
52
  end
53
53
 
@@ -27,7 +27,7 @@ class EntryService
27
27
  def get_jobs(pages = 1)
28
28
  return get_entries(pages, ConfigurationService.jobs_url)
29
29
  end
30
-
30
+
31
31
  def submit(*args)
32
32
  require_authentication
33
33
  form = agent.get(ConfigurationService.submit_url).forms.first
@@ -0,0 +1,22 @@
1
+
2
+ class UserInfoService
3
+ include MechanizeContext
4
+
5
+ def submissions(username, pages = 1)
6
+ page_url = ConfigurationService.base_url + 'submitted?id=' + username
7
+ return EntryService.new.get_entries(pages, page_url)
8
+ end
9
+
10
+ def saved(username, pages = 1)
11
+ require_authentication
12
+ page_url = ConfigurationService.base_url + 'saved?id=' + username
13
+ return EntryService.new.get_entries(pages, page_url)
14
+ end
15
+
16
+ ##This doesn't work, need a new commentService to handle the user comment page
17
+ def comments(username, pages = 1)
18
+ page_url = ConfigurationService.base_url + 'threads?id=' + username
19
+ return CommentService.new.get_new_comments(pages,page_url)
20
+ end
21
+
22
+ end
@@ -6,9 +6,3 @@ require 'require_all'
6
6
 
7
7
  require_all File.join(File.dirname(__FILE__), 'ruby-hackernews', 'domain')
8
8
  require_all File.join(File.dirname(__FILE__), 'ruby-hackernews', 'services')
9
-
10
- entries = Entry.all(2)
11
-
12
- entries.each do |entry|
13
- p entry.id, entries.index(entry)
14
- end
metadata CHANGED
@@ -1,122 +1,92 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ruby-hackernews
3
- version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease: false
6
- segments:
7
- - 1
8
- - 1
9
- - 2
10
- version: 1.1.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.3
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Andrea Dallera
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-09-09 00:00:00 +02:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-03-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: require_all
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &21449480 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 19
30
- segments:
31
- - 1
32
- - 1
33
- - 0
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
34
21
  version: 1.1.0
35
22
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: mechanize
39
23
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *21449480
25
+ - !ruby/object:Gem::Dependency
26
+ name: mechanize
27
+ requirement: &21449020 !ruby/object:Gem::Requirement
41
28
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 23
46
- segments:
47
- - 1
48
- - 0
49
- - 0
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
50
32
  version: 1.0.0
51
33
  type: :runtime
52
- version_requirements: *id002
34
+ prerelease: false
35
+ version_requirements: *21449020
53
36
  description: An interface to Hacker News
54
37
  email: andrea@andreadallera.com
55
38
  executables: []
56
-
57
39
  extensions: []
58
-
59
40
  extra_rdoc_files: []
60
-
61
- files:
41
+ files:
62
42
  - README.rdoc
63
43
  - Rakefile
64
- - lib/ruby-hackernews.rb
65
- - lib/ruby-hackernews/services/parsers/voting_info_parser.rb
66
- - lib/ruby-hackernews/services/parsers/time_info_parser.rb
67
- - lib/ruby-hackernews/services/parsers/entry_page_parser.rb
68
- - lib/ruby-hackernews/services/parsers/link_info_parser.rb
44
+ - lib/ruby-hackernews/services/not_authenticated_error.rb
69
45
  - lib/ruby-hackernews/services/parsers/comments_info_parser.rb
70
- - lib/ruby-hackernews/services/parsers/entry_parser.rb
46
+ - lib/ruby-hackernews/services/parsers/link_info_parser.rb
47
+ - lib/ruby-hackernews/services/parsers/entry_page_parser.rb
71
48
  - lib/ruby-hackernews/services/parsers/user_info_parser.rb
72
- - lib/ruby-hackernews/services/voting_service.rb
73
- - lib/ruby-hackernews/services/mechanize_context.rb
74
- - lib/ruby-hackernews/services/login_service.rb
75
- - lib/ruby-hackernews/services/comment_service.rb
49
+ - lib/ruby-hackernews/services/parsers/time_info_parser.rb
50
+ - lib/ruby-hackernews/services/parsers/voting_info_parser.rb
51
+ - lib/ruby-hackernews/services/parsers/entry_parser.rb
52
+ - lib/ruby-hackernews/services/user_info_service.rb
76
53
  - lib/ruby-hackernews/services/entry_service.rb
77
- - lib/ruby-hackernews/services/not_authenticated_error.rb
54
+ - lib/ruby-hackernews/services/login_service.rb
78
55
  - lib/ruby-hackernews/services/configuration_service.rb
79
- - lib/ruby-hackernews/domain/entry/comments_info.rb
80
- - lib/ruby-hackernews/domain/entry/voting_info.rb
56
+ - lib/ruby-hackernews/services/mechanize_context.rb
57
+ - lib/ruby-hackernews/services/comment_service.rb
58
+ - lib/ruby-hackernews/services/voting_service.rb
59
+ - lib/ruby-hackernews/domain/entry/link_info.rb
60
+ - lib/ruby-hackernews/domain/entry/time_info.rb
81
61
  - lib/ruby-hackernews/domain/entry/entry.rb
82
62
  - lib/ruby-hackernews/domain/entry/user_info.rb
83
- - lib/ruby-hackernews/domain/entry/time_info.rb
84
- - lib/ruby-hackernews/domain/entry/link_info.rb
85
- - lib/ruby-hackernews/domain/comment/comment.rb
63
+ - lib/ruby-hackernews/domain/entry/comments_info.rb
64
+ - lib/ruby-hackernews/domain/entry/voting_info.rb
86
65
  - lib/ruby-hackernews/domain/user.rb
87
- has_rdoc: true
66
+ - lib/ruby-hackernews/domain/comment/comment.rb
67
+ - lib/ruby-hackernews.rb
88
68
  homepage: http://github.com/bolthar/ruby-hackernews
89
69
  licenses: []
90
-
91
70
  post_install_message:
92
71
  rdoc_options: []
93
-
94
- require_paths:
72
+ require_paths:
95
73
  - lib
96
- required_ruby_version: !ruby/object:Gem::Requirement
74
+ required_ruby_version: !ruby/object:Gem::Requirement
97
75
  none: false
98
- requirements:
99
- - - ">="
100
- - !ruby/object:Gem::Version
101
- hash: 3
102
- segments:
103
- - 0
104
- version: "0"
105
- required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
81
  none: false
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- hash: 3
111
- segments:
112
- - 0
113
- version: "0"
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
114
86
  requirements: []
115
-
116
87
  rubyforge_project:
117
- rubygems_version: 1.3.7
88
+ rubygems_version: 1.8.17
118
89
  signing_key:
119
90
  specification_version: 3
120
91
  summary: An interface to Hacker News
121
92
  test_files: []
122
-