Sha256: 18f61af30815acc0938d2dd3de6cc0fde3deafe0e8adf846d4b0901e3cd92954
Contents?: true
Size: 1.27 KB
Versions: 1
Compression:
Stored size: 1.27 KB
Contents
module Ubiquitously module Reddit class User < Ubiquitously::Base::User def login return true if logged_in? page = agent.get("http://www.reddit.com/") form = page.form_with(:action => "http://www.reddit.com/post/login") form["user"] = username form["passwd"] = password page = form.submit @logged_in = (page.title =~ /login or register/i).nil? unless @logged_in raise AuthenticationError.new("Invalid username or password for #{service_name.titleize}") end @logged_in end end class Post < Ubiquitously::Base::Post validates_presence_of :url, :title def save(options = {}) return false unless valid? user.login page = agent.get("http://www.reddit.com/submit") form = page.forms.detect {|form| form.form_node["id"] == "newlink"} form["title"] = title form["url"] = url form["id"] = "#newlink" form.action = "http://www.reddit.com/api/submit" headers = { "Content-Type" => "application/json" } unless options[:debug] == true page = form.submit(nil, headers) end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ubiquitously-0.0.1.6 | lib/ubiquitously/reddit.rb |