ficonabses 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/ruby
2
+ usage=<<EOF_USAGE
3
+
4
+ # == Synopsis
5
+ # read a csv file and blacklist it
6
+ # == Usage
7
+ # ficonabses_blacklist.rb -u username -p password -f csvfile.name -D
8
+ # csv file needs to be in the format (including headers) with destination,
9
+ # -D debug
10
+ # == Author
11
+ # Scott Sproule --- Ficonab.com (scott.sproule@ficonab.com)
12
+ # == Example
13
+ # ficonabses_blacklist.rb -u xxxx -p yyyy -f yyy.csv
14
+ # == Copyright
15
+ # Copyright (c) 2011 Ficonab Pte. Ltd.
16
+ # See license for license details
17
+ EOF_USAGE
18
+ require 'yaml'
19
+ require 'rubygems'
20
+ require 'uri'
21
+ gem 'ficonabses'
22
+ gem 'fastercsv'
23
+ require 'fastercsv'
24
+ require 'ficonabses'
25
+ require 'optparse'
26
+ #require 'java' if RUBY_PLATFORM =~ /java/
27
+ # start the processing
28
+ def send_row(ficonab,row,username)
29
+ #puts "row destination: #{row['destination']} template: #{row['template']} campaign: #{row['campaign']} campaign flag: #{flag}"
30
+ row['destination'].strip!
31
+ sleep(1)
32
+ if row!=nil then
33
+
34
+ res =ficonab.global_blacklist(row['destination'],username)
35
+
36
+ end
37
+ res
38
+ end
39
+
40
+
41
+ arg_hash=FiconabSES::Options.parse_options(ARGV)
42
+ FiconabSES::Options.show_usage_exit(usage) if arg_hash[:help]==true
43
+
44
+ require 'pp'
45
+ options=arg_hash
46
+ puts "[#{Time.now}] START"
47
+ @f=FiconabSES::Base.new
48
+ @f.set_credentials(options[:username],options[:password])
49
+ @f.set_debug if options[:debug] # if debug sends to localhost
50
+ count=0
51
+ flag=false
52
+ #send_template(options[:template],'7923044488','scott.sproule@gmail.com',count+=1)
53
+ rows=FiconabSES::Addons.readfile(options[:filename])
54
+ rows.each {|row|
55
+ #puts "row is: #{row}"
56
+ begin
57
+ hash={}
58
+ hash=hash.merge row
59
+ res=send_row(@f,hash.clone,options[:username])
60
+ puts "COUNT: #{count} result: #{res} row: #{hash} "
61
+ count+=1
62
+
63
+ rescue Exception => e
64
+ puts "Found count: #{count} error #{e.inspect}"
65
+ end
66
+ }
67
+
68
+
69
+ # puts "response is list is #{list.to_yaml} #{finallist.to_yaml}"
70
+ puts "[#{Time.now}] FINISHED: sending: #{count}"
@@ -40,11 +40,7 @@ def send_row(ficonab,row,flag)
40
40
  res
41
41
  end
42
42
 
43
- def readfile(filename)
44
- csvfile=File.open(filename,'r')
45
- rawfile= FasterCSV.parse(csvfile.read, { :headers => true})
46
- rawfile
47
- end
43
+
48
44
  arg_hash=FiconabSES::Options.parse_options(ARGV)
49
45
  FiconabSES::Options.show_usage_exit(usage) if arg_hash[:help]==true
50
46
 
@@ -58,7 +54,7 @@ require 'pp'
58
54
  flag=false
59
55
  flag=options[:campaign] if options[:campaign]
60
56
  #send_template(options[:template],'7923044488','scott.sproule@gmail.com',count+=1)
61
- rows=readfile(options[:filename])
57
+ rows=FiconabSES::Addons.readfile(options[:filename])
62
58
  rows.each {|row|
63
59
  #puts "row is: #{row}"
64
60
  begin
@@ -5,6 +5,11 @@ module FiconabSES
5
5
  f.set_credentials(account,password)
6
6
  FiconabSES::Addons.send_ruby_exception(f,exception,destination,nil)
7
7
  end
8
+ def self.readfile(filename)
9
+ csvfile=File.open(filename,'r')
10
+ rawfile= FasterCSV.parse(csvfile.read, { :headers => true})
11
+ rawfile
12
+ end
8
13
  def self.send_ruby_exception(ficonab_obj,exception,tolist, other, cclist=[],prefix2='[Exception]')
9
14
  begin
10
15
  backtrace=exception.backtrace|| 'No backtrace available'
@@ -53,6 +53,11 @@ module FiconabSES
53
53
  f.set_credentials(account,password)
54
54
  f.send_template_params(destination,templatename,options)
55
55
  end
56
+ def self.global_blacklist_direct(account,password,destination)
57
+ f=FiconabSES::Base.new
58
+ f.set_credentials(account,password)
59
+ f.global_blacklist(destination,account)
60
+ end
56
61
  def self.send_campaign_flow_direct(account,password,destination,templatename,options={})
57
62
  f=FiconabSES::Base.new
58
63
  f.set_credentials(account,password)
@@ -86,6 +91,10 @@ module FiconabSES
86
91
  url="#{self.action_url('ficonabsendemail',destination)}&subject=#{URI.encode(subject)}&text=#{URI.encode(contents)}"
87
92
  url
88
93
  end
94
+ def global_blacklist_url(destination,username)
95
+ url="#{self.action_url('ficonabaction',destination)}&type=globalunsubscribe&user=#{URI.encode(username)}"
96
+ url
97
+ end
89
98
  def template_url(destination,templatename)
90
99
  url="#{self.action_url('ficonabsimpletemplate',destination)}&template=#{URI.encode(templatename)}"
91
100
  url
@@ -120,6 +129,12 @@ module FiconabSES
120
129
  perform(url)
121
130
  # res
122
131
  end
132
+ def global_blacklist(destination,username)
133
+ url=self.global_blacklist_url(destination,username)
134
+ puts "url is: #{url}"
135
+ perform(url)
136
+ # res
137
+ end
123
138
  def send_campaign_flow(destination,campaign_name,options={})
124
139
  url=self.campaign_flow_params(destination,campaign_name,options)
125
140
  puts "url is: #{url}"
@@ -19,7 +19,16 @@ class TestFiconabses < Test::Unit::TestCase
19
19
  assert false==(res.include? 'Error')
20
20
 
21
21
  end
22
- def test_local_blacklisturl
22
+ def test_global_blacklist_adding
23
+ options={}
24
+ options['hello']='TESTING'
25
+ res =@f.global_blacklist(@destination,'scott') #no text portion
26
+ puts "RES is: #{res}"
27
+ assert res.include? 'successfully'
28
+ assert false==(res.include? 'Error')
29
+
30
+ end
31
+ def test_local_blacklist
23
32
  options={}
24
33
  options['hello']='TESTING'
25
34
  res =@f.send_template_params(@destination,'testblacklist',options) #no text portion
@@ -28,7 +37,7 @@ class TestFiconabses < Test::Unit::TestCase
28
37
  assert false==(res.include? 'Error')
29
38
 
30
39
  end
31
- def test_global_blacklisturl
40
+ def test_global_blacklist
32
41
  options={}
33
42
  options['hello']='TESTING'
34
43
  res =@f.send_template_params('blacklist','testblacklist',options) #no text portion
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 5
9
- version: 0.2.5
8
+ - 6
9
+ version: 0.2.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Scott Sproule
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2012-03-01 00:00:00 +08:00
17
+ date: 2012-03-11 00:00:00 +08:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -23,6 +23,7 @@ email: scott.sproule@estormtech.com
23
23
  executables:
24
24
  - ficonabses_template_test.rb
25
25
  - ficonabses_csv.rb
26
+ - ficonabses_blacklist.rb
26
27
  extensions: []
27
28
 
28
29
  extra_rdoc_files: []
@@ -41,6 +42,7 @@ files:
41
42
  - test/test_smartroam.rb
42
43
  - test/test_smartroam2.rb
43
44
  - test/test_templates.rb
45
+ - bin/ficonabses_blacklist.rb
44
46
  - bin/ficonabses_csv.rb
45
47
  - bin/ficonabses_template_test.rb
46
48
  - History.txt