Repository: gsquire/sendgrid-rs (language: rust)

Issue:
Implement an `add_headers` function to `Personalization` struct in V3
This is so that I can add custom x headers to my email messages.

I was thinking something like https://github.com/gsquire/sendgrid-rs/blob/master/src/v3.rs#L233-L244 that will receive a vector of headers as an argument, loop over that and add them one by one.

I'd be happy to send a PR for that, I just wanted to make sure that it's something that you guys agree with and if I got that right.


Discussion / hints:
Sure, I'd be happy to take a PR. Feel free to ping me if you need any help.

Fix patch:
diff --git a/examples/v3.rs b/examples/v3.rs
index df6dfcc..b2b79a0 100644
--- a/examples/v3.rs
+++ b/examples/v3.rs
@@ -1,5 +1,7 @@
 extern crate sendgrid;
 
+use std::collections::HashMap;
+
 use sendgrid::v3::*;
 
 fn main() {
@@ -15,6 +17,11 @@ fn main() {
     let mut p = Personalization::new();
     p.add_to(e.clone());
 
+    let mut cool_header = HashMap::new();
+    cool_header.insert(String::from("x-cool"), String::from("indeed"));
+    cool_header.insert(String::from("x-cooler"), String::from("cold"));
+    p.add_headers(cool_header);
+
     m.set_from(e.clone());
     m.set_subject("Subject");
     m.add_content(c);
diff --git a/src/v3.rs b/src/v3.rs
index 095d400..5249507 100644
--- a/src/v3.rs
+++ b/src/v3.rs
@@ -256,6 +256,22 @@ impl Personalization {
             }
         }
     }
+
+    /// Add a headers field.
+    pub fn add_headers(&mut self, headers: SGMap) {
+        match self.headers {
+            None => {
+                let mut h = HashMap::new();
+                for (name, value) in headers {
+                    h.insert(name, value);
+                }
+                self.headers = Some(h);
+            },
+            Some(ref mut h) => {
+                h.extend(headers);
+            }
+        }
+    }
 }
 
 impl Attachment {


Test patch: