{"action":"created","comment":{"url":"https://api.github.com/repos/Gastrograph/RMandrill/pulls/comments/28159847","id":28159847,"diff_hunk":"@@ -1,32 +1,111 @@\n-require(jsonlite)\n-require(httr)\n-\n #' Send an email with template\n #'\n #' This sends an email with template\n #'\n #' @param api_key Your Stripe API Key\n #'\n-#' @param args An optional list which can contain an amount to refund\n+#' @param template_name name of template on Mandrill to use\n+#' @param variables list of variables used in template to be filled in\n+#' @param subject character vector (single element) to populate email subject line\n+#' @param recipient character vector of email addresses of recipients\n+#' @param sender characer vector of sendes' email addresses\n+#' @param contents  contents of email\n+#' @param images character vector of PNGs to include in email.  names (minus the suffix)\n+#' must match the image declaration in the Mandrill template. Also note that images must \n+#' saved in same directory as calling environment.\n+#' @param css whether to include inline CSS or not. \n #'\n #' @return nothing\n #'\n #' @export\n #'\n-mandrill_send_template <- function(api_key, template_name, variables, subject, recipient, sender) {\n-  to <- data.frame(email=recipient)\n-  merge_vars <- data.frame(rcpt=recipient)\n+mandrill_send_template <- function(api_key=NA, \n+                                   template_name=NA, \n+                                   variables=NA, \n+                                   subject=NA, \n+                                   recipient=NA, \n+                                   sender=NA,\n+                                   contents=NULL,\n+                                   images=NULL,\n+                                   css=FALSE) {\n+  to <- data.frame(email=recipient, stringsAsFactors = FALSE)\n+  merge_vars <- data.frame(rcpt=recipient, stringsAsFactors = FALSE)\n   merge_vars$vars <- list(variables)\n-  sendData <- list(key=api_key, template_name=template_name, \n-                   template_content=list(), \n-                   message=list(subject=subject, merge_vars=merge_vars, \n-                                to=to, from_email=sender))\n+\n+  images_out<-NA\n+  if(!missing(images)){    \n+    process_images <- function(image){\n+      # create tempfile\n+      temp<-tempfile()\n+      \n+      #get image name\n+      image_name<-gsub(\"(.+\\\\/)(.+$)\", \"\\\\2\", image, perl = T) %>% \n+        stringr::str_replace(\"(//|/)\", \"\") %>% \n+        stringr::str_replace(\".png\", \"\")\n+        \n+      \n+      #enocde png as base64\n+      base64::encode(image, temp) # called for side effect.  saves encoded image in temp\n+      \n+      # get encoded image\n+      image_encoded<-paste(readLines(temp), collapse=\"\")\n+      \n+      #unlink temp file\n+      unlink(temp)\n+      \n+      out_df<-data.frame(type=\"img/png\", \n+                         name=image_name, \n+                         content=image_encoded,\n+                         stringsAsFactors = FALSE\n+                         )\n+      \n+      \n+      return(out_df)\n+    }\n+    \n+    images_out<-dplyr::rbind_all(lapply(images, process_images))\n+    \n+  }\n+\n+  template_contents<-data.frame()\n+  if(!missing(contents)){\n+    \n+    process_contents<-function(content){","path":"R/send.R","position":84,"original_position":84,"commit_id":"41722ad2419c6b841768980adfc97f32fd61e1fe","original_commit_id":"41722ad2419c6b841768980adfc97f32fd61e1fe","user":{"login":"JasonCEC","id":4601814,"avatar_url":"https://avatars.githubusercontent.com/u/4601814?v=3","gravatar_id":"","url":"https://api.github.com/users/JasonCEC","html_url":"https://github.com/JasonCEC","followers_url":"https://api.github.com/users/JasonCEC/followers","following_url":"https://api.github.com/users/JasonCEC/following{/other_user}","gists_url":"https://api.github.com/users/JasonCEC/gists{/gist_id}","starred_url":"https://api.github.com/users/JasonCEC/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JasonCEC/subscriptions","organizations_url":"https://api.github.com/users/JasonCEC/orgs","repos_url":"https://api.github.com/users/JasonCEC/repos","events_url":"https://api.github.com/users/JasonCEC/events{/privacy}","received_events_url":"https://api.github.com/users/JasonCEC/received_events","type":"User","site_admin":false},"body":"This function is not currently in use, or commented. (I'm having trouble understanding what it does)\r\nIt should either be moved to `helperFunctions.R` with comments or removed. ","created_at":"2015-04-10T16:37:59Z","updated_at":"2015-04-10T16:37:59Z","html_url":"https://github.com/Gastrograph/RMandrill/pull/1#discussion_r28159847","pull_request_url":"https://api.github.com/repos/Gastrograph/RMandrill/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/Gastrograph/RMandrill/pulls/comments/28159847"},"html":{"href":"https://github.com/Gastrograph/RMandrill/pull/1#discussion_r28159847"},"pull_request":{"href":"https://api.github.com/repos/Gastrograph/RMandrill/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/Gastrograph/RMandrill/pulls/1","id":33060888,"html_url":"https://github.com/Gastrograph/RMandrill/pull/1","diff_url":"https://github.com/Gastrograph/RMandrill/pull/1.diff","patch_url":"https://github.com/Gastrograph/RMandrill/pull/1.patch","issue_url":"https://api.github.com/repos/Gastrograph/RMandrill/issues/1","number":1,"state":"open","locked":false,"title":"Add images","user":{"login":"chrishaid","id":974079,"avatar_url":"https://avatars.githubusercontent.com/u/974079?v=3","gravatar_id":"","url":"https://api.github.com/users/chrishaid","html_url":"https://github.com/chrishaid","followers_url":"https://api.github.com/users/chrishaid/followers","following_url":"https://api.github.com/users/chrishaid/following{/other_user}","gists_url":"https://api.github.com/users/chrishaid/gists{/gist_id}","starred_url":"https://api.github.com/users/chrishaid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrishaid/subscriptions","organizations_url":"https://api.github.com/users/chrishaid/orgs","repos_url":"https://api.github.com/users/chrishaid/repos","events_url":"https://api.github.com/users/chrishaid/events{/privacy}","received_events_url":"https://api.github.com/users/chrishaid/received_events","type":"User","site_admin":false},"body":"Hi Gastrograph team:\r\n\r\nThanks for putting all these nice little helpers up on Github.  I've extended `send_mandrill_template()` (chrishaid/RMandrill@f25f1eba982d708bdd8e5922f6dec46d77f64a35) to accept multiple png images and include them with a properly set up template on Mandrill.  The png images processed by `base64::encode` and added to the json payload sent to Mandrill. \r\n\r\nI've also added a parameter for inlining CSS (the CSS must be included in the Mandrill template). \r\n\r\nFeel free to reject the pull request.  I'll be putting this into production today, so I'll be using my fork for the time being. \r\n\r\nBest,\r\n\r\nChris","created_at":"2015-04-10T16:15:29Z","updated_at":"2015-04-10T16:37:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ffe1cae51b6a8c41948cf65bbbc7ab07cebca7fa","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Gastrograph/RMandrill/pulls/1/commits","review_comments_url":"https://api.github.com/repos/Gastrograph/RMandrill/pulls/1/comments","review_comment_url":"https://api.github.com/repos/Gastrograph/RMandrill/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Gastrograph/RMandrill/issues/1/comments","statuses_url":"https://api.github.com/repos/Gastrograph/RMandrill/statuses/41722ad2419c6b841768980adfc97f32fd61e1fe","head":{"label":"chrishaid:add-images","ref":"add-images","sha":"41722ad2419c6b841768980adfc97f32fd61e1fe","user":{"login":"chrishaid","id":974079,"avatar_url":"https://avatars.githubusercontent.com/u/974079?v=3","gravatar_id":"","url":"https://api.github.com/users/chrishaid","html_url":"https://github.com/chrishaid","followers_url":"https://api.github.com/users/chrishaid/followers","following_url":"https://api.github.com/users/chrishaid/following{/other_user}","gists_url":"https://api.github.com/users/chrishaid/gists{/gist_id}","starred_url":"https://api.github.com/users/chrishaid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrishaid/subscriptions","organizations_url":"https://api.github.com/users/chrishaid/orgs","repos_url":"https://api.github.com/users/chrishaid/repos","events_url":"https://api.github.com/users/chrishaid/events{/privacy}","received_events_url":"https://api.github.com/users/chrishaid/received_events","type":"User","site_admin":false},"repo":{"id":31217126,"name":"RMandrill","full_name":"chrishaid/RMandrill","owner":{"login":"chrishaid","id":974079,"avatar_url":"https://avatars.githubusercontent.com/u/974079?v=3","gravatar_id":"","url":"https://api.github.com/users/chrishaid","html_url":"https://github.com/chrishaid","followers_url":"https://api.github.com/users/chrishaid/followers","following_url":"https://api.github.com/users/chrishaid/following{/other_user}","gists_url":"https://api.github.com/users/chrishaid/gists{/gist_id}","starred_url":"https://api.github.com/users/chrishaid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrishaid/subscriptions","organizations_url":"https://api.github.com/users/chrishaid/orgs","repos_url":"https://api.github.com/users/chrishaid/repos","events_url":"https://api.github.com/users/chrishaid/events{/privacy}","received_events_url":"https://api.github.com/users/chrishaid/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/chrishaid/RMandrill","description":"","fork":true,"url":"https://api.github.com/repos/chrishaid/RMandrill","forks_url":"https://api.github.com/repos/chrishaid/RMandrill/forks","keys_url":"https://api.github.com/repos/chrishaid/RMandrill/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chrishaid/RMandrill/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chrishaid/RMandrill/teams","hooks_url":"https://api.github.com/repos/chrishaid/RMandrill/hooks","issue_events_url":"https://api.github.com/repos/chrishaid/RMandrill/issues/events{/number}","events_url":"https://api.github.com/repos/chrishaid/RMandrill/events","assignees_url":"https://api.github.com/repos/chrishaid/RMandrill/assignees{/user}","branches_url":"https://api.github.com/repos/chrishaid/RMandrill/branches{/branch}","tags_url":"https://api.github.com/repos/chrishaid/RMandrill/tags","blobs_url":"https://api.github.com/repos/chrishaid/RMandrill/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chrishaid/RMandrill/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chrishaid/RMandrill/git/refs{/sha}","trees_url":"https://api.github.com/repos/chrishaid/RMandrill/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chrishaid/RMandrill/statuses/{sha}","languages_url":"https://api.github.com/repos/chrishaid/RMandrill/languages","stargazers_url":"https://api.github.com/repos/chrishaid/RMandrill/stargazers","contributors_url":"https://api.github.com/repos/chrishaid/RMandrill/contributors","subscribers_url":"https://api.github.com/repos/chrishaid/RMandrill/subscribers","subscription_url":"https://api.github.com/repos/chrishaid/RMandrill/subscription","commits_url":"https://api.github.com/repos/chrishaid/RMandrill/commits{/sha}","git_commits_url":"https://api.github.com/repos/chrishaid/RMandrill/git/commits{/sha}","comments_url":"https://api.github.com/repos/chrishaid/RMandrill/comments{/number}","issue_comment_url":"https://api.github.com/repos/chrishaid/RMandrill/issues/comments{/number}","contents_url":"https://api.github.com/repos/chrishaid/RMandrill/contents/{+path}","compare_url":"https://api.github.com/repos/chrishaid/RMandrill/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chrishaid/RMandrill/merges","archive_url":"https://api.github.com/repos/chrishaid/RMandrill/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chrishaid/RMandrill/downloads","issues_url":"https://api.github.com/repos/chrishaid/RMandrill/issues{/number}","pulls_url":"https://api.github.com/repos/chrishaid/RMandrill/pulls{/number}","milestones_url":"https://api.github.com/repos/chrishaid/RMandrill/milestones{/number}","notifications_url":"https://api.github.com/repos/chrishaid/RMandrill/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chrishaid/RMandrill/labels{/name}","releases_url":"https://api.github.com/repos/chrishaid/RMandrill/releases{/id}","created_at":"2015-02-23T16:30:47Z","updated_at":"2015-02-23T16:30:48Z","pushed_at":"2015-04-10T16:00:31Z","git_url":"git://github.com/chrishaid/RMandrill.git","ssh_url":"git@github.com:chrishaid/RMandrill.git","clone_url":"https://github.com/chrishaid/RMandrill.git","svn_url":"https://github.com/chrishaid/RMandrill","homepage":null,"size":103,"stargazers_count":0,"watchers_count":0,"language":"R","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Gastrograph:master","ref":"master","sha":"f25f1eba982d708bdd8e5922f6dec46d77f64a35","user":{"login":"Gastrograph","id":3424082,"avatar_url":"https://avatars.githubusercontent.com/u/3424082?v=3","gravatar_id":"","url":"https://api.github.com/users/Gastrograph","html_url":"https://github.com/Gastrograph","followers_url":"https://api.github.com/users/Gastrograph/followers","following_url":"https://api.github.com/users/Gastrograph/following{/other_user}","gists_url":"https://api.github.com/users/Gastrograph/gists{/gist_id}","starred_url":"https://api.github.com/users/Gastrograph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gastrograph/subscriptions","organizations_url":"https://api.github.com/users/Gastrograph/orgs","repos_url":"https://api.github.com/users/Gastrograph/repos","events_url":"https://api.github.com/users/Gastrograph/events{/privacy}","received_events_url":"https://api.github.com/users/Gastrograph/received_events","type":"Organization","site_admin":false},"repo":{"id":24392977,"name":"RMandrill","full_name":"Gastrograph/RMandrill","owner":{"login":"Gastrograph","id":3424082,"avatar_url":"https://avatars.githubusercontent.com/u/3424082?v=3","gravatar_id":"","url":"https://api.github.com/users/Gastrograph","html_url":"https://github.com/Gastrograph","followers_url":"https://api.github.com/users/Gastrograph/followers","following_url":"https://api.github.com/users/Gastrograph/following{/other_user}","gists_url":"https://api.github.com/users/Gastrograph/gists{/gist_id}","starred_url":"https://api.github.com/users/Gastrograph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gastrograph/subscriptions","organizations_url":"https://api.github.com/users/Gastrograph/orgs","repos_url":"https://api.github.com/users/Gastrograph/repos","events_url":"https://api.github.com/users/Gastrograph/events{/privacy}","received_events_url":"https://api.github.com/users/Gastrograph/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Gastrograph/RMandrill","description":"","fork":false,"url":"https://api.github.com/repos/Gastrograph/RMandrill","forks_url":"https://api.github.com/repos/Gastrograph/RMandrill/forks","keys_url":"https://api.github.com/repos/Gastrograph/RMandrill/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Gastrograph/RMandrill/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Gastrograph/RMandrill/teams","hooks_url":"https://api.github.com/repos/Gastrograph/RMandrill/hooks","issue_events_url":"https://api.github.com/repos/Gastrograph/RMandrill/issues/events{/number}","events_url":"https://api.github.com/repos/Gastrograph/RMandrill/events","assignees_url":"https://api.github.com/repos/Gastrograph/RMandrill/assignees{/user}","branches_url":"https://api.github.com/repos/Gastrograph/RMandrill/branches{/branch}","tags_url":"https://api.github.com/repos/Gastrograph/RMandrill/tags","blobs_url":"https://api.github.com/repos/Gastrograph/RMandrill/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Gastrograph/RMandrill/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Gastrograph/RMandrill/git/refs{/sha}","trees_url":"https://api.github.com/repos/Gastrograph/RMandrill/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Gastrograph/RMandrill/statuses/{sha}","languages_url":"https://api.github.com/repos/Gastrograph/RMandrill/languages","stargazers_url":"https://api.github.com/repos/Gastrograph/RMandrill/stargazers","contributors_url":"https://api.github.com/repos/Gastrograph/RMandrill/contributors","subscribers_url":"https://api.github.com/repos/Gastrograph/RMandrill/subscribers","subscription_url":"https://api.github.com/repos/Gastrograph/RMandrill/subscription","commits_url":"https://api.github.com/repos/Gastrograph/RMandrill/commits{/sha}","git_commits_url":"https://api.github.com/repos/Gastrograph/RMandrill/git/commits{/sha}","comments_url":"https://api.github.com/repos/Gastrograph/RMandrill/comments{/number}","issue_comment_url":"https://api.github.com/repos/Gastrograph/RMandrill/issues/comments{/number}","contents_url":"https://api.github.com/repos/Gastrograph/RMandrill/contents/{+path}","compare_url":"https://api.github.com/repos/Gastrograph/RMandrill/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Gastrograph/RMandrill/merges","archive_url":"https://api.github.com/repos/Gastrograph/RMandrill/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Gastrograph/RMandrill/downloads","issues_url":"https://api.github.com/repos/Gastrograph/RMandrill/issues{/number}","pulls_url":"https://api.github.com/repos/Gastrograph/RMandrill/pulls{/number}","milestones_url":"https://api.github.com/repos/Gastrograph/RMandrill/milestones{/number}","notifications_url":"https://api.github.com/repos/Gastrograph/RMandrill/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Gastrograph/RMandrill/labels{/name}","releases_url":"https://api.github.com/repos/Gastrograph/RMandrill/releases{/id}","created_at":"2014-09-23T23:19:24Z","updated_at":"2015-04-10T16:26:01Z","pushed_at":"2015-04-10T16:15:29Z","git_url":"git://github.com/Gastrograph/RMandrill.git","ssh_url":"git@github.com:Gastrograph/RMandrill.git","clone_url":"https://github.com/Gastrograph/RMandrill.git","svn_url":"https://github.com/Gastrograph/RMandrill","homepage":null,"size":140,"stargazers_count":1,"watchers_count":1,"language":"R","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Gastrograph/RMandrill/pulls/1"},"html":{"href":"https://github.com/Gastrograph/RMandrill/pull/1"},"issue":{"href":"https://api.github.com/repos/Gastrograph/RMandrill/issues/1"},"comments":{"href":"https://api.github.com/repos/Gastrograph/RMandrill/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/Gastrograph/RMandrill/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/Gastrograph/RMandrill/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Gastrograph/RMandrill/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/Gastrograph/RMandrill/statuses/41722ad2419c6b841768980adfc97f32fd61e1fe"}}}}