Sha256: 1918c1470c41f50e66365e2eaa2d5d619385e33e87a9db9a07e95a930e167364

Contents?: true

Size: 1.56 KB

Versions: 1

Compression:

Stored size: 1.56 KB

Contents

module Ubiquitously
  module Newsvine
    class User < Ubiquitously::Base::User
      def login
        return true if logged_in?
        
        page = agent.get("https://www.newsvine.com/_nv/accounts/login")
        form = page.form_with(:action => "https://www.newsvine.com/_nv/api/accounts/login")
        form["email"] = username
        form["password"] = password
        page = form.submit
        
        # No match. Please try again        
        @logged_in = (page.title =~ /Log in/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.newsvine.com/_tools/seed")
        form = page.form_with(:action => "http://www.newsvine.com/_action/tools/saveLink")
        
        form["url"] = url
        form["headline"] = title
        form.radiobuttons_with(:name => "newsType").each do |button|
          button.check if button.value == "x"
        end
        form.field_with(:name => "categoryTag").options.each do |option|
          option.select if option.value == "technology"
        end
        form["blurb"] = description
        form["tags"] = tags.join(", ")
        
        unless options[:debug] == true
          page = form.submit
        end
        
        true
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ubiquitously-0.0.1.6 lib/ubiquitously/newsvine.rb