Skip to content

Commit

Permalink
send encoded if thread_id, else not
Browse files Browse the repository at this point in the history
  • Loading branch information
jcaffrey committed Aug 20, 2024
1 parent 2a7b8ea commit d0839d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 35 deletions.
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,12 +391,14 @@ impl GmailClient {
&self,
user_id: &str,
message: InMemoryBody,
thread_id: Option<String>,
) -> FluentRequest<'_, request::MessagesSendRequest> {
FluentRequest {
client: self,
params: request::MessagesSendRequest {
user_id: user_id.to_owned(),
message,
thread_id,
},
}
}
Expand Down
44 changes: 9 additions & 35 deletions src/request/messages_send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ On request success, this will return a [`Message`].*/
pub struct MessagesSendRequest {
pub user_id: String,
pub message: InMemoryBody,
pub thread_id: Option<String>,
}
impl MessagesSendRequest {}
impl FluentRequest<'_, MessagesSendRequest> {}
Expand All @@ -28,46 +29,19 @@ impl<'a> ::std::future::IntoFuture for FluentRequest<'a, MessagesSendRequest> {
user_id = self.params.user_id
);

// let message_bytes = self.params.message.bytes().unwrap();
// let encoded_body= URL_SAFE.encode(httpclient::InMemoryBody::Json(
// json!(
// {
// "raw": self.params.message,
// "threadId": "<CANYxo_FSfNqjc3OWaE2dWjoBh_J5D_pey8b8z-_iFhC-wDyv_w@mail.gmail.com>"
// }
// )
// ).bytes().unwrap()
// );
// let mut r = self
// .client
// .client
// .post(url)
// .body(httpclient::InMemoryBody::Text(encoded_body));
// dbg!(&r);



// let encoded_message = URL_SAFE.encode(self.params.message.bytes().unwrap());
// let mut r = self.client.client.post(url)
// .body(httpclient::InMemoryBody::Json(json!({"raw": encoded_message, "threadId": "<CANYxo_FSfNqjc3OWaE2dWjoBh_J5D_pey8b8z-_iFhC-wDyv_w@mail.gmail.com>"})));
// dbg!(&r);

// r = self.client.authenticate(r);
// let res = r.await?;
// dbg!(res.body());
// res.json().map_err(Into::into)


let encoded_message = URL_SAFE.encode(self.params.message.bytes().unwrap());
let mut r = self.client.client.post(url)
.json(json!({"raw": encoded_message, "threadId": "1913f56101148ff9"}));
dbg!(&r);
let mut r = self.client.client.post(url);

if let Some(thread_id) = &self.params.thread_id {
let encoded_message = URL_SAFE.encode(self.params.message.bytes().unwrap());
r = r.json(json!({"raw": encoded_message, "threadId": self.params.thread_id}));
} else {
r = r.content_type("message/rfc822").body(self.params.message);
}

r = self.client.authenticate(r);
let res = r.await?;
dbg!(res.body());
res.json().map_err(Into::into)

})
}
}

0 comments on commit d0839d0

Please sign in to comment.