Class: InfunnelCli::CLI::Email

Inherits:
Base
  • Object
show all
Defined in:
lib/infunnel_cli/cli/email.rb

Instance Method Summary collapse

Instance Method Details

#campaign(campaign_id) ⇒ Object



65
66
67
68
# File 'lib/infunnel_cli/cli/email.rb', line 65

def campaign(campaign_id)
  elements = EloquaApiService::Email.new(account: options[:account]).campaign(campaign_id: campaign_id)
  puts elements.select { |e| e[:type] == 'CampaignEmail' }.map{ |e| find(e[:id]) }
end

#find(id) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/infunnel_cli/cli/email.rb', line 12

def find( id )

  email = EloquaApiService::Email.new(account: options[:account])
  body = email.find(id: id)
  puts body

  if body.nil?
    puts "\e[31m" + "#{id} not found"
    return
  end

  puts '#' * 90
  puts "\e[36m" + " Email name: #{body[:name]} (id: #{id})" + "\e[0m"
  puts body[:hyperlinks].map.count

  html = body[:htmlContent][:html]
  puts "Rows: " + html.count("\n").to_s
  n = Nokogiri::HTML.parse(html)
  puts '-' * 90

  n.css('a').each_with_index  do |link, index|

    puts "Link #{index + 1}:"
    puts link[:href] =~ /\A#{URI::regexp()}\z/ ? 'Valid link' : 'invalid link'

    puts link[:href]
    puts link.to_s if options[:full]
    puts ''
    puts 'Params: '

    unless link[:href] == ""
      uri    = URI.parse(link[:href])
      params = CGI.parse(uri.query)
      params.each do |param|
        puts "#{param[0]}:"
        puts "#{param[1].join(', ')}"
        puts
      end
    end
    #CGI::parse(link['href']).map {|k, v| puts "#{k} = #{v.join(',')}"}
    puts '-' * 90
  end
  # Look for stray anchor tags
  puts html.gsub(/<a /).count

end

#preview(email_id, contact_id) ⇒ Object



60
61
62
# File 'lib/infunnel_cli/cli/email.rb', line 60

def preview(email_id, contact_id)
  puts body = EloquaApiService::Email.new(account: options[:account]).preview(contact_id: contact_id, id: email_id)
end