banana_peels 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bfec30f7711bbbe46112847f564156766b08f91e
4
- data.tar.gz: b481dd4bdaff1931a9facc1a8202bda8f6e727ce
3
+ metadata.gz: d496c00442e99cceb25125e34e1b563c8a996920
4
+ data.tar.gz: ecfb95b989127e25e0328818be5ec2715ff6acd6
5
5
  SHA512:
6
- metadata.gz: 33261e9df50f7d9b4410a096cc2a0234c18967b7e98bbad86ba57e7f27300abcc939b47ab343a8d5067481700f9c43b530efd455f882c1d56518368e7dded016
7
- data.tar.gz: 5053899176347238be777ac26c8eb9e8b3b06561f2ee996cf52a2182d19cd36f2493bc1a53b0d042baeb979dc2a8a17635cb0a175eb10472d5e3e769890625de
6
+ metadata.gz: 67f36969ca122132824e302942a95674412eea447fe6ba746f926bec755620efe53938d674b9138c95e05db988c2d6268ef44bb51f6f0cfd36a0ecb54469f017
7
+ data.tar.gz: e9f461e828f8dc6b6865b961744013efa3ffdf2f6af6c4c8535aca001d456971e010124aa1ff1e689bd00e5bac0209be20611f0c6b46ac9c9d9b453ca0b4eebc
@@ -1,9 +1,12 @@
1
1
  class BananaPeels::Campaign
2
2
 
3
+ MERGE_TAG_REGEX = /\*\|(\S+?)\|\*/.freeze
4
+
5
+
3
6
  class << self
4
7
 
5
8
  def replace_merge_tags(string, merge_tags)
6
- string.gsub(/\*\|(\w+)\|\*/) do
9
+ string.gsub(MERGE_TAG_REGEX) do
7
10
  merge_tags[$1.upcase]
8
11
  end
9
12
  end
@@ -13,10 +16,14 @@ class BananaPeels::Campaign
13
16
  # merge_tags: optional, nil for default
14
17
  def initialize(campaign_id, merge_tags, api_key)
15
18
  @campaign_id = campaign_id
16
- @merge_tags = normalize_merge_tags(merge_tags || {})
19
+ @raw_merge_tags = merge_tags
17
20
  @api = BananaPeels.api(api_key)
18
21
  end
19
22
 
23
+ def merge_tags
24
+ @normalized_merge_tags ||= normalize_merge_tags(@raw_merge_tags || {})
25
+ end
26
+
20
27
  def mailchimp_meta
21
28
  # TODO: Cache campaigns from mailchimp.
22
29
  @mailchimp_meta ||= @api.campaigns.list({ campaign_id: @campaign_id })['data'].first
@@ -57,8 +64,8 @@ class BananaPeels::Campaign
57
64
  mailchimp_meta['from_email']
58
65
  end
59
66
 
60
- def subject
61
- replace_merge_tags(mailchimp_meta['subject'])
67
+ def subject(merge_tags=nil)
68
+ replace_merge_tags(mailchimp_meta['subject'], merge_tags)
62
69
  end
63
70
 
64
71
  def to_name
@@ -87,7 +94,7 @@ class BananaPeels::Campaign
87
94
  end
88
95
 
89
96
  def find_merge_tags_in(string)
90
- string.scan(/\*\|(\w+)\|\*/).flatten.uniq
97
+ string.scan(MERGE_TAG_REGEX).flatten.uniq
91
98
  end
92
99
 
93
100
  def text_content_unmerged
@@ -109,7 +116,7 @@ class BananaPeels::Campaign
109
116
  end
110
117
 
111
118
  def html_content
112
- merge_tags = @merge_tags.dup
119
+ merge_tags = self.merge_tags.dup
113
120
  merge_tags.each do |k,v|
114
121
  merge_tags[k] = CGI.escapeHTML(v.to_s).gsub("\n","\n<br>")
115
122
  end
@@ -117,7 +124,7 @@ class BananaPeels::Campaign
117
124
  end
118
125
 
119
126
  def replace_merge_tags(string, merge_tags=nil)
120
- self.class.replace_merge_tags(string, merge_tags || @merge_tags)
127
+ self.class.replace_merge_tags(string, merge_tags || self.merge_tags)
121
128
  end
122
129
 
123
130
  def normalize_merge_tags(merge_tags)
@@ -129,6 +136,8 @@ class BananaPeels::Campaign
129
136
  end
130
137
  normalized['FNAME'] ||= normalized['FIRST_NAME']
131
138
  normalized['LNAME'] ||= normalized['LAST_NAME']
139
+ normalized['MC:SUBJECT'] ||= subject(normalized)
140
+ normalized['URL:MC_SUBJECT'] ||= CGI.escape(normalized['MC:SUBJECT'])
132
141
  normalized
133
142
  end
134
143
 
@@ -1,3 +1,3 @@
1
1
  module BananaPeels
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: banana_peels
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Bull
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-15 00:00:00.000000000 Z
11
+ date: 2013-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler