<commit_before>module ConstantContact 
  class ContactList < BaseResource

    attr_reader :uid, :original_xml

    def initialize( params={}, orig_xml='' ) #:nodoc:
      return false if params.empty?

      @uid = params['id'].split('/').last
      @original_xml = orig_xml

      params['content']['ContactList'].each do |k,v|
        underscore_key = underscore( k )

        instance_eval %{
          @#{underscore_key} = "#{v}"

          def #{underscore_key}
            @#{underscore_key}
          end
        }
      end
    end

    # Update a contacts attributes
    def update_attributes!( params={} )
      return false unless full_record?

      params.each do |key,val|
        self.instance_variable_set("@#{key.to_s}", val)
      end

      data = ConstantContact.put( "/lists/#{self.uid}", :body => self.send(:to_xml) )

      if data.code == 204
        return true
      else
        return data # probably should raise an error here instead
      end
    end

    # Remove all contacts from the contact list
    def clear_contacts!
      Activity.remove_all_contacts_from_lists( self.uid )
    end

    # Get all contact lists
    def self.all( options={} )
      lists = []

      data = ConstantContact.get( '/lists', options )
      return lists if ( data.nil? or data.empty? )

      data['feed']['entry'].each do |entry|
        lists << new( entry )
      end

      lists
    end

    # Add a new contact list
    def self.add( name, opt_in=false, sort_order=99, options={} )
      return nil if( name.nil? || name.empty? )

      xml = build_contact_list_xml_packet( name, opt_in, sort_order )

      options.merge!({ :body => xml })
      data = ConstantContact.post( "/lists", options )

      if data.code == 201
        return new( data['entry'] )
      else
        puts "HTTP Status Code: #{data.code}, message: #{data.message}"
        return nil
      end
    end

    # Delete a contact list
    def self.delete( id, options={} )
      data = ConstantContact.delete( "/lists/#{id.to_s}", options )
      return ( data.code == 204 ) ? true : false
    end

    # Get a single contact list
    def self.get( id, options={} )
      list = ConstantContact.get( "/lists/#{id.to_s}", options )
      return nil if ( list.nil? or list.empty? )
      new( list['entry'], list.body )
    end

    # Get a lists members
    def self.members( id, options={} )
      members = ConstantContact.get( "/lists/#{id.to_s}/members", options )
      return nil if ( members.nil? or members.empty? )
      
      if( members['feed']['entry'].is_a?(Array) )
        members['feed']['entry'].collect { |entry| Contact.new( entry, '', true ) }
      else
        Contact.new( members['feed']['entry'], '', true )
      end
    end
<commit_msg>always return an array from ContactList.members<commit_after>module ConstantContact 
  class ContactList < BaseResource

    attr_reader :uid, :original_xml

    def initialize( params={}, orig_xml='' ) #:nodoc:
      return false if params.empty?

      @uid = params['id'].split('/').last
      @original_xml = orig_xml

      params['content']['ContactList'].each do |k,v|
        underscore_key = underscore( k )

        instance_eval %{
          @#{underscore_key} = "#{v}"

          def #{underscore_key}
            @#{underscore_key}
          end
        }
      end
    end

    # Update a contacts attributes
    def update_attributes!( params={} )
      return false unless full_record?

      params.each do |key,val|
        self.instance_variable_set("@#{key.to_s}", val)
      end

      data = ConstantContact.put( "/lists/#{self.uid}", :body => self.send(:to_xml) )

      if data.code == 204
        return true
      else
        return data # probably should raise an error here instead
      end
    end

    # Remove all contacts from the contact list
    def clear_contacts!
      Activity.remove_all_contacts_from_lists( self.uid )
    end

    # Get all contact lists
    def self.all( options={} )
      lists = []

      data = ConstantContact.get( '/lists', options )
      return lists if ( data.nil? or data.empty? )

      data['feed']['entry'].each do |entry|
        lists << new( entry )
      end

      lists
    end

    # Add a new contact list
    def self.add( name, opt_in=false, sort_order=99, options={} )
      return nil if( name.nil? || name.empty? )

      xml = build_contact_list_xml_packet( name, opt_in, sort_order )

      options.merge!({ :body => xml })
      data = ConstantContact.post( "/lists", options )

      if data.code == 201
        return new( data['entry'] )
      else
        puts "HTTP Status Code: #{data.code}, message: #{data.message}"
        return nil
      end
    end

    # Delete a contact list
    def self.delete( id, options={} )
      data = ConstantContact.delete( "/lists/#{id.to_s}", options )
      return ( data.code == 204 ) ? true : false
    end

    # Get a single contact list
    def self.get( id, options={} )
      list = ConstantContact.get( "/lists/#{id.to_s}", options )
      return nil if ( list.nil? or list.empty? )
      new( list['entry'], list.body )
    end

    # Get a lists members
    def self.members( id, options={} )
      members = ConstantContact.get( "/lists/#{id.to_s}/members", options )
      return nil if ( members.nil? or members.empty? )
      
      if( members['feed']['entry'].is_a?(Array) )
        members['feed']['entry'].collect { |entry| Contact.new( entry, '', true ) }
      else
        [Contact.new( members['feed']['entry'], '', true )]
      end
    end

{'fraction_non_alphanumeric': 0.13260165527168047, 'fraction_numerical': 0.00395825836631882, 'mean_word_length': 2.2951985773562535, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 16}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '653876', 'n_tokens_mistral': 1711, 'n_tokens_neox': 1646, 'n_words': 469}