ruby-hackernews 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. data/README.rdoc +4 -0
  2. data/Rakefile +1 -1
  3. data/lib/ruby-hackernews/domain/comment/comment.rb +44 -41
  4. data/lib/ruby-hackernews/domain/entry/comments_info.rb +16 -13
  5. data/lib/ruby-hackernews/domain/entry/entry.rb +64 -60
  6. data/lib/ruby-hackernews/domain/entry/link_info.rb +12 -9
  7. data/lib/ruby-hackernews/domain/entry/time_info.rb +18 -15
  8. data/lib/ruby-hackernews/domain/entry/user_info.rb +11 -8
  9. data/lib/ruby-hackernews/domain/entry/voting_info.rb +12 -9
  10. data/lib/ruby-hackernews/domain/user.rb +31 -27
  11. data/lib/ruby-hackernews/services/comment_service.rb +54 -51
  12. data/lib/ruby-hackernews/services/configuration_service.rb +25 -22
  13. data/lib/ruby-hackernews/services/entry_service.rb +53 -51
  14. data/lib/ruby-hackernews/services/login_service.rb +23 -20
  15. data/lib/ruby-hackernews/services/mechanize_context.rb +23 -19
  16. data/lib/ruby-hackernews/services/not_authenticated_error.rb +8 -5
  17. data/lib/ruby-hackernews/services/parsers/comments_info_parser.rb +16 -11
  18. data/lib/ruby-hackernews/services/parsers/entry_page_parser.rb +20 -17
  19. data/lib/ruby-hackernews/services/parsers/entry_parser.rb +25 -22
  20. data/lib/ruby-hackernews/services/parsers/link_info_parser.rb +14 -12
  21. data/lib/ruby-hackernews/services/parsers/time_info_parser.rb +13 -11
  22. data/lib/ruby-hackernews/services/parsers/user_info_parser.rb +15 -11
  23. data/lib/ruby-hackernews/services/parsers/voting_info_parser.rb +16 -12
  24. data/lib/ruby-hackernews/services/signup_service.rb +15 -12
  25. data/lib/ruby-hackernews/services/user_info_service.rb +21 -18
  26. data/lib/ruby-hackernews/services/voting_service.rb +10 -7
  27. metadata +24 -24
@@ -1,28 +1,31 @@
1
+ module RubyHackernews
1
2
 
2
- class EntryParser
3
+ class EntryParser
3
4
 
4
- def initialize(first_line, second_line)
5
- @first_line = first_line
6
- @second_line = second_line
7
- end
5
+ def initialize(first_line, second_line)
6
+ @first_line = first_line
7
+ @second_line = second_line
8
+ end
8
9
 
9
- def parse
10
- first_line_title = @first_line.search("[@class='title']")
11
- number_segment = nil
12
- link_segment = nil
13
- if(first_line_title.length > 1)
14
- number_segment = first_line_title[0]
15
- link_segment = first_line_title[1]
16
- else
17
- link_segment = first_line_title[0]
10
+ def parse
11
+ first_line_title = @first_line.search("[@class='title']")
12
+ number_segment = nil
13
+ link_segment = nil
14
+ if(first_line_title.length > 1)
15
+ number_segment = first_line_title[0]
16
+ link_segment = first_line_title[1]
17
+ else
18
+ link_segment = first_line_title[0]
19
+ end
20
+ number = number_segment.inner_html.sub(".","").to_i if number_segment
21
+ link = LinkInfoParser.new(link_segment).parse
22
+ voting = VotingInfoParser.new(@first_line.search("td/center/a"), @second_line.search("[@class='subtext']")[0]).parse
23
+ user = UserInfoParser.new(@second_line.search("[@class='subtext']")[0]).parse
24
+ comments = CommentsInfoParser.new(@second_line.search("[@class='subtext']")[0]).parse
25
+ time = TimeInfoParser.new(@second_line.search("[@class='subtext']").children[3]).parse
26
+ return Entry.new(number, link, voting, user, comments, time)
18
27
  end
19
- number = number_segment.inner_html.sub(".","").to_i if number_segment
20
- link = LinkInfoParser.new(link_segment).parse
21
- voting = VotingInfoParser.new(@first_line.search("td/center/a"), @second_line.search("[@class='subtext']")[0]).parse
22
- user = UserInfoParser.new(@second_line.search("[@class='subtext']")[0]).parse
23
- comments = CommentsInfoParser.new(@second_line.search("[@class='subtext']")[0]).parse
24
- time = TimeInfoParser.new(@second_line.search("[@class='subtext']").children[3]).parse
25
- return Entry.new(number, link, voting, user, comments, time)
28
+
26
29
  end
27
-
30
+
28
31
  end
@@ -1,17 +1,19 @@
1
+ module RubyHackernews
1
2
 
2
- class LinkInfoParser
3
+ class LinkInfoParser
3
4
 
4
- def initialize(link_element)
5
- @element = link_element
6
- end
5
+ def initialize(link_element)
6
+ @element = link_element
7
+ end
8
+
9
+ def parse
10
+ link = @element.search("a")[0]['href']
11
+ title = @element.search("a")[0].inner_html
12
+ site_element = @element.search("span")
13
+ site = site_element.inner_html.sub("(","").sub(")","").strip if site_element.any?
14
+ return LinkInfo.new(title, link, site)
15
+ end
7
16
 
8
- def parse
9
- link = @element.search("a")[0]['href']
10
- title = @element.search("a")[0].inner_html
11
- site_element = @element.search("span")
12
- site = site_element.inner_html.sub("(","").sub(")","").strip if site_element.any?
13
- return LinkInfo.new(title, link, site)
14
17
  end
15
-
16
18
 
17
- end
19
+ end
@@ -1,17 +1,19 @@
1
+ module RubyHackernews
1
2
 
2
- class TimeInfoParser
3
+ class TimeInfoParser
3
4
 
4
- def initialize(time_element)
5
- @element = time_element
6
- end
5
+ def initialize(time_element)
6
+ @element = time_element
7
+ end
7
8
 
8
- def parse
9
- if @element
10
- value = @element.text.strip.split[0].to_i
11
- unit_of_measure = @element.text.strip.split[1]
9
+ def parse
10
+ if @element
11
+ value = @element.text.strip.split[0].to_i
12
+ unit_of_measure = @element.text.strip.split[1]
13
+ end
14
+ return TimeInfo.new(value, unit_of_measure)
12
15
  end
13
- return TimeInfo.new(value, unit_of_measure)
14
- end
15
- end
16
16
 
17
+ end
17
18
 
19
+ end
@@ -1,16 +1,20 @@
1
+ module RubyHackernews
1
2
 
2
- class UserInfoParser
3
+ class UserInfoParser
3
4
 
4
- def initialize(user_element)
5
- @element = user_element
6
- end
5
+ def initialize(user_element)
6
+ @element = user_element
7
+ end
7
8
 
8
- def parse
9
- user_element = @element.search("a")[0]
10
- if user_element
11
- user_name = user_element.inner_html
12
- user_page = user_element['href']
9
+ def parse
10
+ user_element = @element.search("a")[0]
11
+ if user_element
12
+ user_name = user_element.inner_html
13
+ user_page = user_element['href']
14
+ end
15
+ return UserInfo.new(user_name, user_page)
13
16
  end
14
- return UserInfo.new(user_name, user_page)
17
+
15
18
  end
16
- end
19
+
20
+ end
@@ -1,16 +1,20 @@
1
+ module RubyHackernews
1
2
 
2
- class VotingInfoParser
3
+ class VotingInfoParser
3
4
 
4
- def initialize(voting_element, score_element)
5
- @voting_element = voting_element
6
- @score_element = score_element
7
- end
5
+ def initialize(voting_element, score_element)
6
+ @voting_element = voting_element
7
+ @score_element = score_element
8
+ end
9
+
10
+ def parse
11
+ upvote = @voting_element[0]['href'] if @voting_element[0]
12
+ downvote = @voting_element[1]['href'] if @voting_element[1]
13
+ points_element = @score_element.search("span")[0]
14
+ score = points_element.inner_html.split[0].to_i if points_element
15
+ return VotingInfo.new(score, upvote, downvote)
16
+ end
8
17
 
9
- def parse
10
- upvote = @voting_element[0]['href'] if @voting_element[0]
11
- downvote = @voting_element[1]['href'] if @voting_element[1]
12
- points_element = @score_element.search("span")[0]
13
- score = points_element.inner_html.split[0].to_i if points_element
14
- return VotingInfo.new(score, upvote, downvote)
15
18
  end
16
- end
19
+
20
+ end
@@ -1,17 +1,20 @@
1
+ module RubyHackernews
1
2
 
2
- class SignupService
3
- include MechanizeContext
3
+ class SignupService
4
+ include MechanizeContext
5
+
6
+ def signup(username, password)
7
+ raise "You are logged in already - logout first." if authenticated?
8
+ page = agent.get(ConfigurationService.base_url)
9
+ login_url = page.search(".pagetop/a").last['href'].sub("/","")
10
+ login_page = agent.get(ConfigurationService.base_url + login_url)
11
+ form = login_page.forms[1]
12
+ form.u = username
13
+ form.p = password
14
+ page = form.submit
15
+ return page.title != nil
16
+ end
4
17
 
5
- def signup(username, password)
6
- raise "You are logged in already - logout first." if authenticated?
7
- page = agent.get(ConfigurationService.base_url)
8
- login_url = page.search(".pagetop/a").last['href'].sub("/","")
9
- login_page = agent.get(ConfigurationService.base_url + login_url)
10
- form = login_page.forms[1]
11
- form.u = username
12
- form.p = password
13
- page = form.submit
14
- return page.title != nil
15
18
  end
16
19
 
17
20
  end
@@ -1,22 +1,25 @@
1
+ module RubyHackernews
1
2
 
2
- class UserInfoService
3
- include MechanizeContext
3
+ class UserInfoService
4
+ include MechanizeContext
4
5
 
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
6
+ def submissions(username, pages = 1)
7
+ page_url = ConfigurationService.base_url + 'submitted?id=' + username
8
+ return EntryService.new.get_entries(pages, page_url)
9
+ end
9
10
 
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
11
+ def saved(username, pages = 1)
12
+ require_authentication
13
+ page_url = ConfigurationService.base_url + 'saved?id=' + username
14
+ return EntryService.new.get_entries(pages, page_url)
15
+ end
21
16
 
22
- end
17
+ ##This doesn't work, need a new commentService to handle the user comment page
18
+ def comments(username, pages = 1)
19
+ page_url = ConfigurationService.base_url + 'threads?id=' + username
20
+ return CommentService.new.get_new_comments(pages,page_url)
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -1,11 +1,14 @@
1
+ module RubyHackernews
1
2
 
2
- class VotingService
3
- include MechanizeContext
3
+ class VotingService
4
+ include MechanizeContext
5
+
6
+ def vote(url)
7
+ require_authentication
8
+ agent.get(url)
9
+ return true
10
+ end
4
11
 
5
- def vote(url)
6
- require_authentication
7
- agent.get(url)
8
- return true
9
12
  end
10
13
 
11
- end
14
+ end
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.2.1
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-03 00:00:00.000000000 Z
12
+ date: 2012-05-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: require_all
16
- requirement: &18134820 !ruby/object:Gem::Requirement
16
+ requirement: &16407680 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *18134820
24
+ version_requirements: *16407680
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mechanize
27
- requirement: &18134360 !ruby/object:Gem::Requirement
27
+ requirement: &16407120 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 1.0.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *18134360
35
+ version_requirements: *16407120
36
36
  description: An interface to Hacker News
37
37
  email: andrea@andreadallera.com
38
38
  executables: []
@@ -41,31 +41,31 @@ extra_rdoc_files: []
41
41
  files:
42
42
  - README.rdoc
43
43
  - Rakefile
44
- - lib/ruby-hackernews.rb
45
- - lib/ruby-hackernews/services/voting_service.rb
46
- - lib/ruby-hackernews/services/parsers/time_info_parser.rb
47
- - lib/ruby-hackernews/services/parsers/link_info_parser.rb
48
- - lib/ruby-hackernews/services/parsers/entry_parser.rb
49
- - lib/ruby-hackernews/services/parsers/voting_info_parser.rb
44
+ - lib/ruby-hackernews/services/not_authenticated_error.rb
50
45
  - lib/ruby-hackernews/services/parsers/comments_info_parser.rb
51
- - lib/ruby-hackernews/services/parsers/user_info_parser.rb
46
+ - lib/ruby-hackernews/services/parsers/link_info_parser.rb
52
47
  - lib/ruby-hackernews/services/parsers/entry_page_parser.rb
53
- - lib/ruby-hackernews/services/not_authenticated_error.rb
48
+ - lib/ruby-hackernews/services/parsers/user_info_parser.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
53
+ - lib/ruby-hackernews/services/signup_service.rb
54
54
  - lib/ruby-hackernews/services/entry_service.rb
55
- - lib/ruby-hackernews/services/comment_service.rb
55
+ - lib/ruby-hackernews/services/login_service.rb
56
56
  - lib/ruby-hackernews/services/configuration_service.rb
57
- - lib/ruby-hackernews/services/signup_service.rb
58
- - lib/ruby-hackernews/services/user_info_service.rb
59
57
  - lib/ruby-hackernews/services/mechanize_context.rb
60
- - lib/ruby-hackernews/services/login_service.rb
61
- - lib/ruby-hackernews/domain/comment/comment.rb
62
- - lib/ruby-hackernews/domain/user.rb
58
+ - lib/ruby-hackernews/services/comment_service.rb
59
+ - lib/ruby-hackernews/services/voting_service.rb
60
+ - lib/ruby-hackernews/domain/entry/link_info.rb
61
+ - lib/ruby-hackernews/domain/entry/time_info.rb
63
62
  - lib/ruby-hackernews/domain/entry/entry.rb
63
+ - lib/ruby-hackernews/domain/entry/user_info.rb
64
64
  - lib/ruby-hackernews/domain/entry/comments_info.rb
65
65
  - lib/ruby-hackernews/domain/entry/voting_info.rb
66
- - lib/ruby-hackernews/domain/entry/time_info.rb
67
- - lib/ruby-hackernews/domain/entry/link_info.rb
68
- - lib/ruby-hackernews/domain/entry/user_info.rb
66
+ - lib/ruby-hackernews/domain/user.rb
67
+ - lib/ruby-hackernews/domain/comment/comment.rb
68
+ - lib/ruby-hackernews.rb
69
69
  homepage: http://github.com/bolthar/ruby-hackernews
70
70
  licenses: []
71
71
  post_install_message:
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  version: '0'
87
87
  requirements: []
88
88
  rubyforge_project:
89
- rubygems_version: 1.8.10
89
+ rubygems_version: 1.8.17
90
90
  signing_key:
91
91
  specification_version: 3
92
92
  summary: An interface to Hacker News