mad_mimi_two 0.5.9 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -108,6 +108,11 @@ warning: peer certificate won't be verified in this SSL session
108
108
 
109
109
  returns a hash of promotions on your account
110
110
 
111
+ == Add email address to list (eg for drip lists)
112
+
113
+ t=MadMimiTwo::MadMimiMessage.new
114
+ r=t.add_email('driplisttest',"ttt@email2.com")
115
+
111
116
  == LICENSE:
112
117
 
113
118
  (The MIT License)
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/ruby
2
+ # == Synopsis
3
+ # send mad mimi email
4
+ # == Usage
5
+ # send_mimi.rb -e email -p promotion -k key -u mimiusername -h hashvalues -s subject
6
+ # == Author
7
+ # Scott Sproule --- Ficonab.com (scott.sproule@ficonab.com)
8
+ # == Example
9
+ # send_mimi.rb -k xxxx -u xxxx@estormtech.com -s ID
10
+ # == Copyright
11
+ # Copyright (c) 2010 Ficonab Pte. Ltd.
12
+ # See license for license details
13
+ require 'yaml'
14
+ require 'rubygems'
15
+ gem 'mad_mimi_two'
16
+ require 'mad_mimi_two'
17
+ require 'optparse'
18
+ require 'rdoc/usage'
19
+ #require 'java' if RUBY_PLATFORM =~ /java/
20
+ # start the processing
21
+ arg_hash=MadMimiTwo::Options.parse_options(ARGV)
22
+ RDoc::usage if arg_hash[:help]==true
23
+ require 'pp'
24
+
25
+ options = arg_hash
26
+ # set up variables using hash
27
+ # note the strange spacing needed to put the ' in the string
28
+ MadMimiTwo::MadMimiMessage.api_settings = {
29
+ :username => options[:username].to_s,
30
+ :api_key => options[:key].to_s
31
+ }
32
+
33
+ t=MadMimiTwo::MadMimiMessage.new
34
+ r= t.check_status(options[:subject])
35
+ puts "Status #{r}"
36
+ # t.email_placeholders(thash)
37
+ # r=t.deliver_mimi_message
38
+ # puts r
@@ -14,6 +14,7 @@ end
14
14
  module MadMimiTwo
15
15
  module MadMimiMailer
16
16
  API_URL = 'https://api.madmimi.com/'
17
+ API_URL_HTTP = 'http://api.madmimi.com/'
17
18
  SINGLE_SEND_URL = "#{API_URL}mailer"
18
19
 
19
20
  def self.included(base)
@@ -25,14 +26,34 @@ module MadMimiTwo
25
26
  client= HTTPClient.new
26
27
  res=client.get_content(url)
27
28
  rescue HTTPClient::BadResponseError
28
- res="problem retrieving status"
29
+ res="problem retrieving status: #{res.inspect}"
29
30
  end
30
31
  res
31
32
  end
33
+ def post_cmd(url,body)
34
+ begin
35
+ client= HTTPClient.new
36
+ res=client.post_content(url,body)
37
+ rescue HTTPClient::BadResponseError
38
+ res="problem posting status: #{res.inspect}"
39
+ end
40
+ res
41
+ end
32
42
  def get_promotions_xml
33
43
  url="#{API_URL}promotions.xml?#{MadMimiTwo::MadMimiMessage.api_settings.madmimiurlencode}"
34
44
  xml_list=send_cmd(url)
35
45
  end
46
+ def get_audience_xml
47
+ url="#{API_URL_HTTP}audience_lists/lists.xml?#{MadMimiTwo::MadMimiMessage.api_settings.madmimiurlencode}"
48
+ #puts url
49
+ xml_list=send_cmd(url)
50
+ end
51
+ def add_email(list,email)
52
+ url="#{API_URL_HTTP}audience_lists/#{list}/add?email=#{email}&#{MadMimiTwo::MadMimiMessage.api_settings.madmimiurlencode}"
53
+ #puts url
54
+ xml_list=post_cmd(url,"")
55
+ end
56
+ #/audience_lists/{name_of_list}/add?email={email_to_add}
36
57
  # get a hash of promotion names on mad mimi. Not certain why mad mimi returns mailing details in this call but we throw it away.
37
58
  def get_promotions
38
59
  xml_list=get_promotions_xml
@@ -43,9 +64,19 @@ module MadMimiTwo
43
64
  end
44
65
  res
45
66
  end
67
+ def get_lists
68
+ xml_list=get_audience_xml
69
+ res={}
70
+ reader = Nokogiri::XML::Reader(xml_list)
71
+ reader.each do |node|
72
+ res=res.merge({ node.attribute('name') => node.attribute('id')}) # eventually will want hash
73
+ end
74
+ res
75
+ end
46
76
  # check the status of a sent email
47
77
  def check_status(msg_id)
48
78
  url = "#{SINGLE_SEND_URL}s/status/#{msg_id}?#{MadMimiTwo::MadMimiMessage.api_settings.madmimiurlencode}"
79
+ #puts url
49
80
  send_cmd(url)
50
81
  end
51
82
 
@@ -106,12 +106,27 @@ class TestMadMimiTwo < Test::Unit::TestCase
106
106
  assert r=='sent', "message response not correct: #{r}"
107
107
 
108
108
  end
109
+ def test_email_address
110
+ t=MadMimiTwo::MadMimiMessage.new
111
+ r=t.add_email('driplisttest',"ttt@email2.com")
112
+ puts "add email list: 'r is ' #{r}"
113
+ ## assert r.key?('testlist'), "does not include testlist #{r}"
114
+ #this MAY NOT BE IN YOUR promotions list
115
+ end
116
+ def test_get_audience_list
117
+ t=MadMimiTwo::MadMimiMessage.new
118
+ r=t.get_lists()
119
+ puts "audience list: 'r is ' #{r}"
120
+ assert r.class==Hash, "response is not Hash r is: #{r} #{r.class}"
121
+ assert r.key?('testlist'), "does not include testlist #{r}"
122
+ #this MAY NOT BE IN YOUR promotions list
123
+ end
109
124
  def test_get_promotions
110
125
  t=MadMimiTwo::MadMimiMessage.new
111
126
  r=t.get_promotions()
112
127
  puts "'r is ' #{r}"
113
128
  assert r.class==Hash, "response is not Hash r is: #{r} #{r.class}"
114
- assert r.key?('new_CRM'), "does not include new_CRM #{r}" #this MAY NOT BE IN YOUR promotions list
129
+ assert r.key?('new_CRM'), "does not include new_CRM #{r}" #this MAY NOT BE IN YOUR promotions list
115
130
 
116
131
  end
117
132
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mad_mimi_two
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 5
9
- - 9
10
- version: 0.5.9
8
+ - 6
9
+ - 1
10
+ version: 0.6.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - scott sproule
@@ -55,6 +55,7 @@ email:
55
55
  - scott.sproule@ficonab.com
56
56
  executables:
57
57
  - send_mimi.rb
58
+ - check_mimi_status.rb
58
59
  extensions: []
59
60
 
60
61
  extra_rdoc_files:
@@ -77,6 +78,7 @@ files:
77
78
  - test/test_helper.rb
78
79
  - test/test_mad_mimi_two.rb
79
80
  - bin/send_mimi.rb
81
+ - bin/check_mimi_status.rb
80
82
  has_rdoc: true
81
83
  homepage: http://github.com/semdinsp/mad_mimi_two
82
84
  licenses: []