chimpmunk 0.0.1 → 0.0.2

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: d8f65e72ccad48b7480ebab56fc5b64d47db5433
4
- data.tar.gz: 65dcf7c040d7b56806733af6230f8b2040000e14
3
+ metadata.gz: 8d386eba35aefc48e80041d30e14d09a76405b46
4
+ data.tar.gz: 4666331e2c9a3af08a8dad237f88795ca8004359
5
5
  SHA512:
6
- metadata.gz: abb985ee363fead96538780e32aa4279ec985f2d6de6cd6b4dc575ea38402d9bd3de80cd6d406c9c5f71dc2831c225a11499ad125f5c8700cd75124814dceba6
7
- data.tar.gz: 2654c63e2b08158f0566d9cd699e2c91cd631289a58241a752e1118441cd21fd3beddc2cacd15b6a0a30eac4ea2f8e961af3cbc9ed64078b68f017aba94fca0a
6
+ metadata.gz: 9af58d721920b15da3585335185bff6ba724eb2c99ded5204b7d7d55ffaec316cdac28c7957b91c00629c16b692e46f4788fceb0f205db78a042ddf530251645
7
+ data.tar.gz: 333c516acc181af90045ef63d2a054eb9e64b2cf8037b10eeebaf4d61a122cedcbaaf39162e548e39b2bfb71dcaf491895afb9d36fda92360709f122325a10f4
data/README.md CHANGED
@@ -32,8 +32,62 @@ Set your mailchimp api key:
32
32
 
33
33
  ## Usage
34
34
 
35
- TODO: Write usage instructions here
36
-
35
+ 1. create a new model for your campaign `app/models/test_email_campaign.rb` that extends `Chimpmunk::EmailCampaign`
36
+
37
+ 2. create headers, texts and images definitions for any strings, text or images needed in the campaign.
38
+
39
+ 3. If you need assocations with the email campaign, generate the association models and add the `associated` definition in the email campaign subclass.
40
+
41
+ 4. override the content method, details coming soon
42
+
43
+
44
+ example:
45
+
46
+
47
+ ```
48
+ rails g model EmailCampaignPost email_campaign:references post:references
49
+ rails g model EmailCampaignComment email_campaign:references post:references
50
+ ```
51
+
52
+
53
+
54
+ ```
55
+ class TestEmailCampaign < Chimpmunk::EmailCampaign
56
+ headers :hero_header, :bottom_header
57
+ texts :top_body, :info_body
58
+ images :hero_image, :logo, :test_image
59
+ associated :many, :posts # will have many :email_campaign_posts
60
+ associated :one, :comment # will have one :email_campaign_comment
61
+
62
+ #
63
+ # must have a content method
64
+ #
65
+ def content
66
+ sections = {}
67
+ {sections: sections}
68
+ end
69
+
70
+ rails_admin down
71
+ edit do
72
+ field :title
73
+ field :email_list
74
+ field :email_list_group
75
+ field :email_template
76
+ field :subject
77
+ field :from_name
78
+ field :from_email
79
+ field :send_date
80
+ field :hero_header
81
+ field :bottom_header
82
+ field :top_body
83
+ field :info_body
84
+ field :hero_image
85
+ field :logo
86
+ field :test_image
87
+ end
88
+ end
89
+ end
90
+ ```
37
91
  ## Contributing
38
92
 
39
93
  1. Fork it ( https://github.com/[my-github-username]/chimpmunk/fork )
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency 'activerecord', ['>= 3.2', '< 5']
22
22
  spec.add_dependency 'gibbon', '>= 1.1'
23
+ spec.add_dependency 'paperclip', '>= 4.1'
23
24
 
24
25
  spec.add_development_dependency "bundler", "~> 1.6"
25
26
  spec.add_development_dependency "rake"
@@ -90,6 +90,31 @@ class ChimpmunkMigration < ActiveRecord::Migration
90
90
  t.integer :email_list_group_id
91
91
  t.integer :email_subscriber_id
92
92
  end
93
+
94
+ create_table :email_campaign_headers do |t|
95
+ t.references :email_campaign, index: true
96
+ t.string :text
97
+ t.string :name
98
+
99
+ t.timestamps
100
+ end
101
+
102
+ create_table :email_campaign_texts do |t|
103
+ t.references :email_campaign, index: true
104
+ t.text :text
105
+ t.string :name
106
+
107
+ t.timestamps
108
+ end
109
+
110
+ create_table :email_campaign_images do |t|
111
+ t.references :email_campaign, index: true
112
+ t.string :name
113
+
114
+ t.timestamps
115
+ end
116
+
117
+ add_attachment :email_campaign_images, :image
93
118
  end
94
119
 
95
120
  def self.down
@@ -98,5 +123,10 @@ class ChimpmunkMigration < ActiveRecord::Migration
98
123
  drop_table :email_list_groups
99
124
  drop_table :email_templates
100
125
  drop_table :email_list_groupings
126
+ drop_table :email_subscribers
127
+ drop_table :email_list_groups_subscribers
128
+ drop_table :email_campaign_headers
129
+ drop_table :email_campaign_texts
130
+ drop_table :email_campaign_images
101
131
  end
102
132
  end
@@ -13,6 +13,9 @@ module Chimpmunk
13
13
  autoload :EmailListGrouping
14
14
  autoload :EmailSubscriber
15
15
  autoload :EmailTemplate
16
+ autoload :EmailCampaignHeader
17
+ autoload :EmailCampaignText
18
+ autoload :EmailCampaignImage
16
19
  autoload :VERSION
17
20
 
18
21
  def self.mailchimp
@@ -28,18 +28,51 @@ module Chimpmunk
28
28
  before_update :update_content, if: Proc.new{|campaign| campaign.email_template_id_changed? && !campaign.skip_update_callbacks }
29
29
  before_destroy :destroy_mailchimp_campaign
30
30
 
31
- # TODO: figure out attachments, example below
32
- # has_attached_file :intro_image
33
- # validates_attachment_content_type :intro_image, :content_type => /\Aimage\/.*\Z/
34
-
35
- # TODO: figure out association, example below
36
- # has_many :email_campaign_trending_posts, dependent: :destroy
37
- # has_many :trending_posts, source: :post, through: :email_campaign_trending_posts
38
-
39
31
  ##
40
32
  # CLASS METHODS
41
33
  ##
42
34
 
35
+ #
36
+ # create header associations
37
+ #
38
+ def self.headers(*headers)
39
+ headers.each do |header|
40
+ has_one header.to_sym, -> { where(name: header.to_s) }, class_name: 'Chimpmunk::EmailCampaignHeader', foreign_key: :email_campaign_id
41
+ accepts_nested_attributes_for header.to_sym, allow_destroy: true
42
+ end
43
+ end
44
+
45
+ #
46
+ # create text associations
47
+ #
48
+ def self.texts(*texts)
49
+ texts.each do |text|
50
+ has_one text.to_sym, -> { where(name: text.to_s) }, class_name: 'Chimpmunk::EmailCampaignText', foreign_key: :email_campaign_id
51
+ accepts_nested_attributes_for text.to_sym, allow_destroy: true
52
+ end
53
+ end
54
+
55
+ #
56
+ # create image associations
57
+ #
58
+ def self.images(*images)
59
+ images.each do |image|
60
+ has_one image.to_sym, -> { where(name: image.to_s) }, class_name: 'Chimpmunk::EmailCampaignImage', foreign_key: :email_campaign_id
61
+ accepts_nested_attributes_for image.to_sym, allow_destroy: true
62
+ end
63
+ end
64
+
65
+ #
66
+ # create has_many associations
67
+ #
68
+ def self.associated(association_type = :many, *associations)
69
+ associations.each do |association|
70
+ association_name = "email_campaign_#{association}".to_sym
71
+ send("has_#{association_type}", association_name, foreign_key: 'email_campaign_id')
72
+ accepts_nested_attributes_for association_name, allow_destroy: true
73
+ end
74
+ end
75
+
43
76
  ##
44
77
  # Refreshes the list of email campaigns
45
78
  def self.refresh_email_campaigns
@@ -136,6 +169,13 @@ module Chimpmunk
136
169
  end
137
170
  end
138
171
 
172
+ ##
173
+ # TODO: figure out how to do this
174
+ # returns the html content for the new campaign
175
+ def content
176
+ raise "Content must be overriden"
177
+ end
178
+
139
179
  private
140
180
 
141
181
  def action_view
@@ -168,7 +208,7 @@ module Chimpmunk
168
208
  response = Chimpmunk.mailchimp.campaigns.update(
169
209
  cid: self.mailchimp_campaign_id,
170
210
  name: "content",
171
- value: get_content
211
+ value: content
172
212
  )
173
213
 
174
214
  !response['errors'].any?
@@ -225,7 +265,7 @@ module Chimpmunk
225
265
  template_id: self.email_template.try(:mailchimp_id),
226
266
  inline_css: true
227
267
  },
228
- content: get_content
268
+ content: content
229
269
  }
230
270
 
231
271
  # list or segment(group)
@@ -254,61 +294,10 @@ module Chimpmunk
254
294
  end
255
295
  end
256
296
 
257
- ##
258
- # TODO: figure out how to do this
259
- # returns the html content for the new campaign
260
- def get_content
261
- content = {sections: {}}
262
-
263
- # insert intro section if it exists
264
- unless intro_section_blank?
265
- content[:sections][:intro_section] = action_view.render 'eflyers/newsletter/intro', email_campaign: self
266
- end
267
-
268
- # insert divider if both intro sections and featured post exist
269
- unless intro_section_blank? || featured_post.nil?
270
- content[:sections][:divider] = action_view.render 'eflyers/newsletter/divider'
271
- end
272
-
273
- # insert featured post if it exists
274
- unless featured_post.nil?
275
- content[:sections][:featured_article] = action_view.render 'eflyers/newsletter/featured_article', email_campaign: self
276
- end
277
-
278
- # insert tending posts
279
- content[:sections][:trending_section] = ''
280
- trending_posts.in_groups_of(2) do |first_post, second_post|
281
- content[:sections][:trending_section] += action_view.render 'eflyers/newsletter/trending', first_post: first_post, second_post: second_post
282
- end
283
-
284
- # insert sponsored section if it exsists
285
- unless sponsored_section_blank?
286
- content[:sections][:sponsored_section] = action_view.render 'eflyers/newsletter/sponsored', email_campaign: self
287
- end
288
-
289
- content[:sections][:directory_section] = action_view.render 'eflyers/newsletter/directory',
290
- teacher_1: self.directory_teachers.first,
291
- teacher_2: self.directory_teachers.second,
292
- event_1: self.directory_events.first,
293
- event_2: self.directory_events.second,
294
- studio_1: self.directory_studios.first,
295
- studio_2: self.directory_studios.second
296
-
297
- unless teacher_tip_post.nil?
298
- content[:sections][:teacher_tip] = action_view.render 'eflyers/newsletter/teacher_tip', email_campaign: self
299
- end
300
-
301
- content
302
- end
303
-
304
297
  if defined?(RailsAdmin)
305
298
 
306
299
  rails_admin do
307
300
  navigation_label 'Mailchimp'
308
-
309
- configure :background_color, :color
310
- configure :foreground_color, :color
311
- configure :send_date, :datetime
312
301
 
313
302
  list do
314
303
  field :title
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+ module Chimpmunk
3
+ class EmailCampaignHeader < ::ActiveRecord::Base
4
+ belongs_to :email_campaign
5
+
6
+ private
7
+
8
+ rails_admin do
9
+ visible false
10
+ edit do
11
+ field :text do
12
+ label do
13
+ bindings[:object].name
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ module Chimpmunk
3
+ class EmailCampaignImage < ::ActiveRecord::Base
4
+ belongs_to :email_campaign
5
+ has_attached_file :image, styles: {original: '1000x1000>'}
6
+ validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
7
+
8
+ rails_admin do
9
+ visible false
10
+ edit do
11
+ field :image
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+ module Chimpmunk
3
+ class EmailCampaignText < ::ActiveRecord::Base
4
+ belongs_to :email_campaign
5
+
6
+ rails_admin do
7
+ visible false
8
+ edit do
9
+ field :text do
10
+ label do
11
+ bindings[:object].name
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,6 +1,7 @@
1
1
  require 'rails'
2
2
  require 'rails/engine'
3
3
  require 'chimpmunk'
4
+ require 'paperclip'
4
5
 
5
6
  module Chimpmunk
6
7
  class Engine < Rails::Engine
@@ -1,3 +1,3 @@
1
1
  module Chimpmunk
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -11,7 +11,9 @@ module Chimpmunk
11
11
  Dir["#{Rails.root}/lib/rails_admin/*.rb"].each {|file| require file }
12
12
 
13
13
  # include all existing models and Chimpmunk models
14
- config.included_models = Dir.glob("#{Rails.root}/app/models/*.rb").map{|x| File.basename(x, ".rb").camelize} + ['Chimpmunk::EmailCampaign', 'Chimpmunk::EmailList', 'Chimpmunk::EmailListGroup', 'Chimpmunk::EmailListGrouping', 'Chimpmunk::EmailSubscriber', 'Chimpmunk::EmailTemplate']
14
+ config.included_models = Dir.glob("#{Rails.root}/app/models/*.rb").map{|x| File.basename(x, ".rb").camelize} +
15
+ ['Chimpmunk::EmailCampaign', 'Chimpmunk::EmailList', 'Chimpmunk::EmailListGroup', 'Chimpmunk::EmailListGrouping',
16
+ 'Chimpmunk::EmailSubscriber', 'Chimpmunk::EmailTemplate', 'Chimpmunk::EmailCampaignHeader', 'Chimpmunk::EmailCampaignText', 'Chimpmunk::EmailCampaignImage']
15
17
 
16
18
  TEMPLATE
17
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chimpmunk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Franken
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-10 00:00:00.000000000 Z
11
+ date: 2015-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -44,6 +44,20 @@ dependencies:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: '1.1'
47
+ - !ruby/object:Gem::Dependency
48
+ name: paperclip
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '4.1'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '4.1'
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: bundler
49
63
  requirement: !ruby/object:Gem::Requirement
@@ -89,6 +103,9 @@ files:
89
103
  - db/migrate/1_chimpmunk_migration.rb
90
104
  - lib/chimpmunk.rb
91
105
  - lib/chimpmunk/email_campaign.rb
106
+ - lib/chimpmunk/email_campaign_header.rb
107
+ - lib/chimpmunk/email_campaign_image.rb
108
+ - lib/chimpmunk/email_campaign_text.rb
92
109
  - lib/chimpmunk/email_list.rb
93
110
  - lib/chimpmunk/email_list_group.rb
94
111
  - lib/chimpmunk/email_list_grouping.rb