Change Syntax & Add Name Personalization (#9)

Change Syntax & Add Name Personalization (#9)

  • Changed syntax

  • Change Syntax and Add Name

  • Cleaning Up Work

diff --git a/app/jobs/bcc_post.rb b/app/jobs/bcc_post.rb
index 86fcbcb..8f0a5fc 100644
--- a/app/jobs/bcc_post.rb
+++ b/app/jobs/bcc_post.rb
@@ -22,8 +22,12 @@ class ::Jobs::BccPost < ::Jobs::Base
   def send_to(targets, targets_key, params, sender)
     targets.each do |target|
       temp_params = params
-      temp_params["raw"] = temp_params["raw"].gsub(/{username}/i, target)
-      temp_params["raw"] = temp_params["raw"].gsub(/{@username}/i, "@" + target)
+      temp_params["raw"] = temp_params["raw"].gsub(/%{username}/i, target)
+      temp_params["raw"] = temp_params["raw"].gsub(/%{@username}/i, "@" + target)
+      user = User.find_by_username_or_email(target)
+      if !user.nil? then
+        temp_params["raw"] = temp_params["raw"].gsub(/%{name}/i, user.name)
+      end
       creator = PostCreator.new(sender, temp_params.merge(Hash[targets_key, target]))
       creator.create
     end
diff --git a/spec/jobs/bcc_post_spec.rb b/spec/jobs/bcc_post_spec.rb
index a2623c1..8ed4aac 100644
--- a/spec/jobs/bcc_post_spec.rb
+++ b/spec/jobs/bcc_post_spec.rb
@@ -59,7 +59,7 @@ describe ::Jobs::BccPost do
     
     it 'works with standard personalization' do
 
-      ::Jobs::BccPost.new.execute(user_id: sender.id, create_params: create_params.merge("raw": "this is the content I want to send to {username}", target_emails: 'test@test.com'))
+      ::Jobs::BccPost.new.execute(user_id: sender.id, create_params: create_params.merge("raw": "this is the content I want to send to %{username}", target_emails: 'test@test.com'))
 
       post = Post.find_by(raw: "this is the content I want to send to #{user0.username}")
 
@@ -68,12 +68,20 @@ describe ::Jobs::BccPost do
 
     it 'works with mention personalization' do
 
-      ::Jobs::BccPost.new.execute(user_id: sender.id, create_params: create_params.merge("raw": "this is the content I want to send to {@username}", target_emails: 'test@test.com'))
+      ::Jobs::BccPost.new.execute(user_id: sender.id, create_params: create_params.merge("raw": "this is the content I want to send to %{@username}", target_emails: 'test@test.com'))
 
       post = Post.find_by(raw: "this is the content I want to send to @#{user0.username}")
 
       expect(post).to_not be_nil
     end 
       
+
+    it 'works with name personalization' do
+      ::Jobs::BccPost.new.execute(user_id: sender.id, create_params: create_params.merge("raw": "this is the content I want to send to %{name}", target_emails: 'test@test.com'))
+     
+      post = Post.find_by(raw: "this is the content I want to send to #{user0.name}")
+
+      expect(post).to_not be_nil
+    end
   end
 end

GitHub sha: ebc42ee6

This commit appears in #9 which was approved by eviltrout. It was merged by eviltrout.