Sha256: fb1fe9bf770adbcae2517f0832e75db96779ca625c7cf253dd48a5ca120575b4

Contents?: true

Size: 1.47 KB

Versions: 1

Compression:

Stored size: 1.47 KB

Contents

module Ubiquitously
  module Base
    class User
      include ActiveModel::Validations
      include ActiveModel::Serialization
      include Ubiquitously::Resourceful
      
      attr_accessor :agent, :username, :password
      
      validates_presence_of :username, :password
      
      def initialize(attributes = {})
        attributes = attributes.symbolize_keys
        
        attributes[:username] ||= Ubiquitously.key("#{service_name}.key")
        attributes[:password] ||= Ubiquitously.key("#{service_name}.secret")
        
        @logged_in = false
        
        super(attributes)
        
        self.agent = Mechanize.new
        # self.agent.log = Logger.new(STDOUT)
        self.agent.user_agent = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; ru-ru) AppleWebKit/533.2+ (KHTML, like Gecko) Version/4.0.4 Safari/531.21.10"
      end
      
      def logged_in?
        @logged_in == true
      end
    end
    
    class Post
      include ActiveModel::Validations
      include ActiveModel::Serialization
      include Ubiquitously::Resourceful
      
      attr_accessor :title, :url, :description, :tags, :categories, :service_url, :user
      
      def user
        @user ||= "Ubiquitously::#{service_name.titleize}::User".constantize.new
      end
      
      def agent
        user.agent
      end
      
      class << self
        def create(options = {})
          record = new(options)
          record.save
          record
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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