Sha256: 9d18e66a2f888b389bb2392e066f6a6e6b6351797ab19027b4234282d560f8d5

Contents?: true

Size: 899 Bytes

Versions: 2

Compression:

Stored size: 899 Bytes

Contents

module Gattica
  
  # Represents a user to be authenticated by GA
  
  class User
  
    include Convertible
  
    SERVICE = 'analytics'
    attr_accessor :email, :password
  
    def initialize(email,password,source='')
      @email = email
      @password = password
      validate
    end
    
    # User gets a special +to_h+ because Google expects +Email+ and +Passwd+ instead of our nicer internal names
    def to_h
      { :Email => @email,
        :Passwd => @password }
    end
    
    private
    # Determine whether or not this is a valid user
    def validate
      raise GatticaError::InvalidEmail, "The email address '#{@email}' is not valid" if not @email.match(/^(?:[_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-zA-Z0-9\-\.]+)*(\.[a-z]{2,4})$/i)
      raise GatticaError::InvalidPassword, "The password cannot be blank" if @password.empty? || @password.nil?
    end
  
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cannikin-gattica-0.1.4 lib/gattica/user.rb
cannikin-gattica-0.2.0 lib/gattica/user.rb