Class: Dreamy::Command::Announce

Inherits:
Base
  • Object
show all
Defined in:
lib/dreamy/commands/announce.rb

Instance Attribute Summary

Attributes inherited from Base

#args

Instance Method Summary collapse

Methods inherited from Base

#ask, #display, #extract_option, #home_directory, #initialize, #running_on_windows?, #shell

Constructor Details

This class inherits a constructor from Dreamy::Command::Base

Instance Method Details

#addObject



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/dreamy/commands/announce.rb', line 37

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 [email protected] [email protected]"
  end
end

#indexObject



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/dreamy/commands/announce.rb', line 4

def index
  lists = @account.announce_lists
  
  if lists.empty?
    display "No announcement lists on this account"
  else
    list_table = table do |t|
      t.headings = 'Name', 'Short Name', 'Domain', 'Subscribers', 'Max Bounces', 'Start Date'
      lists.each { |l| t << [l.name, l.short_name, l.domain, l.subscribers, l.max_bounces, l.start_date]}
    end
    display list_table
  end
end

#listObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/dreamy/commands/announce.rb', line 18

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 [email protected]"
  end
end

#removeObject



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/dreamy/commands/announce.rb', line 51

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 [email protected] [email protected]"
  end
end