Sha256: 21c7c428dced50af2047c7b2ff402d9aa2a0e76d196555d3450a1c81a1964e3a

Contents?: true

Size: 1.68 KB

Versions: 5

Compression:

Stored size: 1.68 KB

Contents

module Dreamy::Command
  class Announce < Base

    def list
      if args.length >= 1
        listname, domain = extract_values(args.shift)
        subscribers = @account.announce_list(listname,domain)
        if subscribers.empty?
          display "No subscribers to this list"
        else
          subscriber_table = table do |t|
            t.headings = 'email', 'name', 'subscribe_date', 'bounces'
            subscribers.each { |s| t << [s.email, s.name, s.subscribe_date, s.num_bounces] }
          end
          display subscriber_table
          display "#{subscribers.size} total subscribers"
        end
      else
        display "Usage: dh announce:list my_list@example.com"
      end
    end
    
    def add
      if args.length >= 2
        listname, domain = extract_values(args.shift)
        email = args.shift
        if @account.announce_add(listname,domain,email)
          display "Successfully added #{email} to #{listname} list"
        else
          display "Failed to add #{email} to #{listname} list"
        end
      else
        display "Usage: dh announce:add my_list@example.com new_guy@gmail.com"
      end
    end
    
    def remove
      if args.length >= 2
        listname, domain = extract_values(args.shift)
        email = args.shift
        if @account.announce_remove(listname,domain,email)
          display "Successfully removed #{email} from #{listname} list"
        else
          display "Failed to remove #{email} from #{listname} list"
        end
      else
        display "Usage: dh announce:remove my_list@example.com new_guy@gmail.com"
      end
    end

    private

    def extract_values(arg)
      arg =~ /^(.*)@(.*)$/
      return $1, $2
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sant0sk1-dreamy-0.2.0 lib/dreamy/commands/announce.rb
sant0sk1-dreamy-0.2.1 lib/dreamy/commands/announce.rb
sant0sk1-dreamy-0.2.2 lib/dreamy/commands/announce.rb
sant0sk1-dreamy-0.2.3 lib/dreamy/commands/announce.rb
sant0sk1-dreamy-0.2.4 lib/dreamy/commands/announce.rb