ruby-hackernews 1.1.3 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,9 +1,3 @@
1
- = NOTICE
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.
5
- = ruby-hackernews
6
-
7
1
  An API over Hacker News
8
2
 
9
3
  http://stillmaintained.com/bolthar/ruby-hackernews.png
@@ -57,12 +51,12 @@ Each Entry instance has the following data:
57
51
 
58
52
  After you've logged in (see below) you can do the following
59
53
 
60
- entry.upvote # votes the entry
61
- entry.write_comment("mycomment") # adds a comment to the entry
62
- Entry.submit("mytitle", "myurl") # submit a new link
63
- Entry.submit("myquestion") # submit a new question (ask HN)
54
+ entry.upvote # votes the entry
55
+ entry.write_comment("mycomment") # adds a comment to the entry
56
+ Entry.submit("mytitle", "myurl") # submit a new link
57
+ Entry.submit("myquestion", "question text") # submit a new question
64
58
 
65
- user.submissions.first.comments_url
59
+ user.submissions.first.comments_url # returns the url to the current user's comments
66
60
 
67
61
  == Comments
68
62
 
@@ -118,6 +112,12 @@ Then, you log in with:
118
112
 
119
113
  user.login("password")
120
114
 
115
+ Or, you can create a new use with that name:
116
+
117
+ user.signup("password") # don't abuse this!
118
+
119
+ You will be also logged in with the new user. So, no need to call user#login after user#signup.
120
+
121
121
  You can log out with:
122
122
 
123
123
  user.logout
@@ -137,7 +137,6 @@ Will return the HN comment url of the last submitted story of that user
137
137
  == TO DO
138
138
 
139
139
  Get user info (comments, saved)
140
- Create account
141
140
  Change user info/settings
142
141
 
143
142
  == THANKS TO
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.1.3'
11
+ s.version = '1.2.0'
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
@@ -57,8 +57,12 @@ class Entry
57
57
  return CommentService.new.write_comment(@comments_info.page, text)
58
58
  end
59
59
 
60
- def self.submit(*args)
61
- return EntryService.new.submit(*args)
60
+ def self.submit(title, url)
61
+ return EntryService.new.submit(title, url)
62
+ end
63
+
64
+ def self.ask(title, text)
65
+ return EntryService.new.ask(title, text)
62
66
  end
63
67
 
64
68
  def upvote
@@ -14,6 +14,10 @@ class User
14
14
  def logout
15
15
  return LoginService.new.logout
16
16
  end
17
+
18
+ def signup(password)
19
+ return SignupService.new.signup(@name, password)
20
+ end
17
21
 
18
22
  def submissions(pages = 1)
19
23
  return UserInfoService.new.submissions(@name, pages)
@@ -27,4 +31,4 @@ class User
27
31
  return UserInfoService.new.comments(@name, pages)
28
32
  end
29
33
 
30
- end
34
+ end
@@ -28,11 +28,17 @@ class EntryService
28
28
  return get_entries(pages, ConfigurationService.jobs_url)
29
29
  end
30
30
 
31
- def submit(*args)
31
+ def submit(title, url)
32
32
  require_authentication
33
33
  form = agent.get(ConfigurationService.submit_url).forms.first
34
- submit_link(form, args[0], args[1]) if args.length == 2
35
- submit_question(form, args[0]) if args.length == 1
34
+ submit_link(form, title, url)
35
+ return true
36
+ end
37
+
38
+ def ask(title, text)
39
+ require_authentication
40
+ form = agent.get(ConfigurationService.submit_url).forms.first
41
+ submit_question(form, title, text)
36
42
  return true
37
43
  end
38
44
 
@@ -43,10 +49,11 @@ class EntryService
43
49
  form.submit
44
50
  end
45
51
 
46
- def submit_question(form, text)
52
+ def submit_question(form, title, text)
53
+ form.t = title
47
54
  form.x = text
48
55
  form.submit
49
56
  end
50
57
 
51
58
 
52
- end
59
+ end
@@ -3,7 +3,6 @@ class LoginService
3
3
  include MechanizeContext
4
4
 
5
5
  def login(username, password)
6
- raise "You are logged in already - logout first." if authenticated?
7
6
  page = agent.get(ConfigurationService.base_url)
8
7
  login_url = page.search(".pagetop/a").last['href'].sub("/","")
9
8
  login_page = agent.get(ConfigurationService.base_url + login_url)
@@ -23,4 +22,4 @@ class LoginService
23
22
  return logout_page.search(".pagetop/a").last.inner_html == "login"
24
23
  end
25
24
 
26
- end
25
+ end
@@ -24,4 +24,4 @@ module MechanizeContext
24
24
  return @@contexts[key] && @@contexts[key].cookie_jar.jar.any?
25
25
  end
26
26
 
27
- end
27
+ end
@@ -0,0 +1,17 @@
1
+
2
+ class SignupService
3
+ include MechanizeContext
4
+
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
+ end
16
+
17
+ 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.1.3
4
+ version: 1.2.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-03-27 00:00:00.000000000 Z
12
+ date: 2012-04-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: require_all
16
- requirement: &21449480 !ruby/object:Gem::Requirement
16
+ requirement: &9448240 !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: *21449480
24
+ version_requirements: *9448240
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mechanize
27
- requirement: &21449020 !ruby/object:Gem::Requirement
27
+ requirement: &9447760 !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: *21449020
35
+ version_requirements: *9447760
36
36
  description: An interface to Hacker News
37
37
  email: andrea@andreadallera.com
38
38
  executables: []
@@ -50,6 +50,7 @@ files:
50
50
  - lib/ruby-hackernews/services/parsers/voting_info_parser.rb
51
51
  - lib/ruby-hackernews/services/parsers/entry_parser.rb
52
52
  - lib/ruby-hackernews/services/user_info_service.rb
53
+ - lib/ruby-hackernews/services/signup_service.rb
53
54
  - lib/ruby-hackernews/services/entry_service.rb
54
55
  - lib/ruby-hackernews/services/login_service.rb
55
56
  - lib/ruby-hackernews/services/configuration_service.rb