kshnurov / mandrill_dm

A basic Mandrill delivery method for Rails.
MIT License
46 stars 45 forks source link

merge_vars support #17

Closed kshnurov closed 8 years ago

kshnurov commented 9 years ago

merge_vars and global_merge_vars will allow to send customized messages to each recipient.

spovich commented 9 years ago

@kshnurov Yep, agreed. For my use case, I only needed merge because I'm using the standard merge tags, so this scratched my itch. But full merge_vars support would be great.

*|FNAME|*
*|LNAME|*
*|EMAIL|*
*|DATE:FORMAT|*
*|CURRENT_YEAR|*
AlexEmerson commented 9 years ago

+1

kshnurov commented 9 years ago

https://github.com/jlberglund/mandrill_dm/pull/14

AlexEmerson commented 9 years ago

Sorry, didn't get it from the conversation you pointed out. I don't seem to be able to use 'merge_vars' option. Could you please clarify how to provide custom data to mandrill api?

blarralde commented 8 years ago

14 supports merge but as far as I see not merge_vars.

I needed it too so looked into how to do it but so far I've only come up with a hack:

In MandrillDm::Message, add:

    def merge_vars
      return unless mail[:merge_vars] and mail[:merge_vars].value

      eval mail[:merge_vars].value
    end

plus merge_vars: merge_vars, in to_json.

Then you can pass the merge variables using the format described here: https://mandrill.zendesk.com/hc/en-us/articles/205582487-How-to-Use-Merge-Tags-to-Add-Dynamic-Content

In my mailer, I add headers[:merge_vars] = [{ rcpt: "email", vars: [] }].to_s. The reason for to_s is because mail[:merge_vars].value will somehow not return the square brackets. eval is used to transform the string into an array again.

That's all super hacky, I don't know if anyone has a better idea on how to solve this.

I pushed the code here: https://github.com/blarralde/mandrill_dm/blob/master/lib/mandrill_dm/message.rb

AlexEmerson commented 8 years ago

That's pretty the same what I did. Though I pass only 'vars' (from { rcpt: "email", vars: [] }) two-dimensional array (as I send to multiple recipients) and map it to the format needed in the dm itself. It's hacky, indeed, but I don't see any other ways yet.

tomasc commented 8 years ago

@Sysqa I guess this can be closed now? PR #22

spovich commented 8 years ago

feature has been added, closing.

tomasc commented 8 years ago

@spovich would be great if we could have new version of the gem with this feature available

spovich commented 8 years ago

@tomasc yes, I was thinking the same. I was hoping the backlog of PR's would settle down but that may be a while yet. @kshnurov what do you think about a new release?

kshnurov commented 8 years ago

@spovich yeah, let's finish with #38 and #39 and release a new version.