Sha256: 55fc307901b98f00035aab11b018a10df9828a935e3d42a45f859884890a1dfe

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

module RubyRedtail
  class TagGroup
    
    def initialize(tag_group = {},api_hash)
      @api_hash = api_hash
      
      raise ArgumentError unless tag_group['RecID']
      @id = tag_group['RecID']
      
      raise ArgumentError if tag_group.class != Hash
      tag_group.each do |key, value|
        key = key.underscore
        self.class.send :attr_accessor, key
        instance_variable_set "@#{key}", value
      end
    end
    
    def contacts
      build_contacts_array RubyRedtail::Query.run("taggroups/#{@id}/contacts", @api_hash, "GET")["TagMember_Result"]["TagMembers"]
    end
      
    private
    
    def build_contact contact_hash
      if contact_hash
        RubyRedtail::Contact.new(contact_hash,@api_hash)
      else
        raise RubyRedtail::AuthenticationError
      end
    end

    def build_contacts_array contact_hashes
      if contact_hashes
        contact_hashes.collect { |contact_hash| self.build_contact contact_hash }
      else
        raise RubyRedtail::AuthenticationError
      end
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby-redtail-0.3.6 lib/ruby-redtail/tag_group.rb