Sha256: 775fecfbd0622cd0978b4d0b58f8853ab867513e7c2d76c36794e3445b2bda9c

Contents?: true

Size: 1.81 KB

Versions: 2

Compression:

Stored size: 1.81 KB

Contents

require 'postini/api/automatedbatch/AutomatedBatchDriver'

module Postini
  
  # Represents the functions to perform on a domain
  #
  # TODO: Definitely improve this documentation
  class Domain
    
    attr_accessor :id, :name, :org, :substrip
    
    class << self
      
      # Return an instance of #Domain with all the attributes populated
      def find( domain )
        remote = Postini::API::AutomatedBatch::AutomatedBatchPort.new( Postini.endpoint_uri )
        request = Postini::API::AutomatedBatch::Displaydomain.new( Postini.auth, domain )
        response = remote.displaydomain( request )
        domain_record = response.domainRecord
        
        # Don't give back false positives
        if domain_record.domainid == ""
          return nil
        end
        
        new(
          :name => domain_record.domainname,
          :id => domain_record.domainid,
          :org => domain_record.org,
          :substrip => domain_record.substrip
        )
      end
      
    end
    
    # Setup a new instance with the combination of attributes set
    def initialize( attributes = {} )
      attributes.each_pair do |k,v|
        instance_variable_set "@#{k.to_s}", v
      end
    end
    
    def new?
      @id.nil?
    end
    
    # Create a new domain in the system. Requires +name+ and +org+ to be set.
    # This method will through a SOAP exception if the domain could not be
    # added.
    def create
      return false unless new?
      
      # TODO: Add missing validations here
      
      remote = Postini::API::AutomatedBatch::AutomatedBatchPort.new( Postini.endpoint_uri )
      args = Postini::API::AutomatedBatch::Adddomainargs.new( @name )
      request = Postini::API::AutomatedBatch::Adddomain.new(
        Postini.auth, @org, args
      )
      remote.adddomain( request )
    end
    
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
postini-0.0.1 lib/postini/domain.rb
postini-0.0.2 lib/postini/domain.rb