Sha256: 2da5cfe173885a57cf613098450e551fafb47a0c23e54b923a609b68fb491c6a
Contents?: true
Size: 1.32 KB
Versions: 1
Compression:
Stored size: 1.32 KB
Contents
class EntryService include MechanizeContext def get_entries(pages = 1, url = ConfigurationService.base_url) parser = EntryPageParser.new(agent.get(url)) entry_infos = [] pages.times do lines = parser.get_lines (lines.length / 2).times do entry_infos << EntryParser.new(lines.shift, lines.shift).parse end next_url = parser.get_next_url || break parser = EntryPageParser.new(agent.get(next_url)) end return entry_infos end def get_new_entries(pages = 1) return get_entries(pages, ConfigurationService.new_url) end def get_questions(pages = 1) return get_entries(pages, ConfigurationService.ask_url) end def get_jobs(pages = 1) return get_entries(pages, ConfigurationService.jobs_url) end def submit(title, url) require_authentication form = agent.get(ConfigurationService.submit_url).forms.first submit_link(form, title, url) return true end def ask(title, text) require_authentication form = agent.get(ConfigurationService.submit_url).forms.first submit_question(form, title, text) return true end private def submit_link(form, title, url) form.t = title form.u = url form.submit end def submit_question(form, title, text) form.t = title form.x = text form.submit end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ruby-hackernews-1.2.0 | lib/ruby-hackernews/services/entry_service.rb |