1#![allow(clippy::too_many_arguments)]
13
14use crate::error::Result;
15use ghl_models::v2::contacts as models;
16
17use crate::contacts::ContactsService;
18
19#[derive(Debug, Clone, Default)]
21pub struct GetContactsParams {
22 pub location_id: String,
25 pub start_after_id: Option<String>,
27 pub start_after: Option<f64>,
29 pub query: Option<String>,
31 pub limit: Option<f64>,
33}
34
35impl GetContactsParams {
36 pub fn new(location_id: impl Into<String>) -> Self {
38 Self {
39 location_id: location_id.into(),
40 ..Default::default()
41 }
42 }
43
44 pub fn start_after_id(mut self, v: impl Into<String>) -> Self {
46 self.start_after_id = Some(v.into());
47 self
48 }
49
50 pub fn start_after(mut self, v: f64) -> Self {
52 self.start_after = Some(v);
53 self
54 }
55
56 pub fn query(mut self, v: impl Into<String>) -> Self {
58 self.query = Some(v.into());
59 self
60 }
61
62 pub fn limit(mut self, v: f64) -> Self {
64 self.limit = Some(v);
65 self
66 }
67
68 fn to_query(&self) -> Vec<(String, String)> {
69 let mut q: Vec<(String, String)> = vec![("locationId".into(), self.location_id.clone())];
70 if let Some(v) = &self.start_after_id {
71 q.push(("startAfterId".into(), v.to_string()));
72 }
73 if let Some(v) = &self.start_after {
74 q.push(("startAfter".into(), v.to_string()));
75 }
76 if let Some(v) = &self.query {
77 q.push(("query".into(), v.to_string()));
78 }
79 if let Some(v) = &self.limit {
80 q.push(("limit".into(), v.to_string()));
81 }
82 q
83 }
84}
85
86#[derive(Debug, Clone, Default)]
88pub struct GetContactsByBusinessIdParams {
89 pub limit: Option<String>,
91 pub location_id: String,
94 pub skip: Option<String>,
96 pub query: Option<String>,
98}
99
100impl GetContactsByBusinessIdParams {
101 pub fn new(location_id: impl Into<String>) -> Self {
103 Self {
104 location_id: location_id.into(),
105 ..Default::default()
106 }
107 }
108
109 pub fn limit(mut self, v: impl Into<String>) -> Self {
111 self.limit = Some(v.into());
112 self
113 }
114
115 pub fn skip(mut self, v: impl Into<String>) -> Self {
117 self.skip = Some(v.into());
118 self
119 }
120
121 pub fn query(mut self, v: impl Into<String>) -> Self {
123 self.query = Some(v.into());
124 self
125 }
126
127 fn to_query(&self) -> Vec<(String, String)> {
128 let mut q: Vec<(String, String)> = vec![("locationId".into(), self.location_id.clone())];
129 if let Some(v) = &self.limit {
130 q.push(("limit".into(), v.to_string()));
131 }
132 if let Some(v) = &self.skip {
133 q.push(("skip".into(), v.to_string()));
134 }
135 if let Some(v) = &self.query {
136 q.push(("query".into(), v.to_string()));
137 }
138 q
139 }
140}
141
142#[derive(Debug, Clone, Default)]
144pub struct GetDuplicateContactParams {
145 pub location_id: String,
148 pub number: Option<String>,
150 pub email: Option<String>,
153}
154
155impl GetDuplicateContactParams {
156 pub fn new(location_id: impl Into<String>) -> Self {
158 Self {
159 location_id: location_id.into(),
160 ..Default::default()
161 }
162 }
163
164 pub fn number(mut self, v: impl Into<String>) -> Self {
166 self.number = Some(v.into());
167 self
168 }
169
170 pub fn email(mut self, v: impl Into<String>) -> Self {
173 self.email = Some(v.into());
174 self
175 }
176
177 fn to_query(&self) -> Vec<(String, String)> {
178 let mut q: Vec<(String, String)> = vec![("locationId".into(), self.location_id.clone())];
179 if let Some(v) = &self.number {
180 q.push(("number".into(), v.to_string()));
181 }
182 if let Some(v) = &self.email {
183 q.push(("email".into(), v.to_string()));
184 }
185 q
186 }
187}
188
189impl ContactsService {
190 pub async fn get_contacts(
200 &self,
201 params: &GetContactsParams,
202 ) -> Result<models::ContactsSearchSuccessfulResponseDto> {
203 let query = params.to_query();
204 self.client
205 .send_versioned(
206 reqwest::Method::GET,
207 "/contacts/",
208 &query,
209 None::<&()>,
210 Some("2021-07-28"),
211 )
212 .await
213 }
214
215 pub async fn create_contact(
223 &self,
224 body: &models::CreateContactDto,
225 ) -> Result<models::CreateContactsSuccessfulResponseDto> {
226 let query = Vec::new();
227 self.client
228 .send_versioned(
229 reqwest::Method::POST,
230 "/contacts/",
231 &query,
232 Some(body),
233 Some("2021-07-28"),
234 )
235 .await
236 }
237
238 pub async fn add_remove_contacts_from_business(
245 &self,
246 body: &models::ContactsBusinessUpdate,
247 ) -> Result<models::ContactsBulkUpateResponse> {
248 let query = Vec::new();
249 self.client
250 .send_versioned(
251 reqwest::Method::POST,
252 "/contacts/bulk/business",
253 &query,
254 Some(body),
255 Some("2021-07-28"),
256 )
257 .await
258 }
259
260 pub async fn update_contacts_tags(
267 &self,
268 type_: &str,
269 body: &models::UpdateTagsDTO,
270 ) -> Result<models::UpdateTagsResponseDTO> {
271 let path = format!(
272 "/contacts/bulk/tags/update/{}",
273 crate::services::encode(type_)
274 );
275 let query = Vec::new();
276 self.client
277 .send_versioned(
278 reqwest::Method::POST,
279 &path,
280 &query,
281 Some(body),
282 Some("2021-07-28"),
283 )
284 .await
285 }
286
287 pub async fn get_contacts_by_business_id(
293 &self,
294 business_id: &str,
295 params: &GetContactsByBusinessIdParams,
296 ) -> Result<models::ContactsSearchSuccessfulResponseDto> {
297 let path = format!(
298 "/contacts/business/{}",
299 crate::services::encode(business_id)
300 );
301 let query = params.to_query();
302 self.client
303 .send_versioned(
304 reqwest::Method::GET,
305 &path,
306 &query,
307 None::<&()>,
308 Some("2021-07-28"),
309 )
310 .await
311 }
312
313 pub async fn search_contacts(
322 &self,
323 body: &models::SearchBodyV2DTO,
324 ) -> Result<serde_json::Value> {
325 let query = Vec::new();
326 self.client
327 .send_versioned(
328 reqwest::Method::POST,
329 "/contacts/search",
330 &query,
331 Some(body),
332 Some("2021-07-28"),
333 )
334 .await
335 }
336
337 pub async fn get_duplicate_contact(
348 &self,
349 params: &GetDuplicateContactParams,
350 ) -> Result<serde_json::Value> {
351 let query = params.to_query();
352 self.client
353 .send_versioned(
354 reqwest::Method::GET,
355 "/contacts/search/duplicate",
356 &query,
357 None::<&()>,
358 Some("2021-07-28"),
359 )
360 .await
361 }
362
363 pub async fn upsert_contact(
377 &self,
378 body: &models::UpsertContactDto,
379 ) -> Result<models::UpsertContactsSuccessfulResponseDto> {
380 let query = Vec::new();
381 self.client
382 .send_versioned(
383 reqwest::Method::POST,
384 "/contacts/upsert",
385 &query,
386 Some(body),
387 Some("2021-07-28"),
388 )
389 .await
390 }
391
392 pub async fn delete_contact(
398 &self,
399 contact_id: &str,
400 ) -> Result<models::DeleteContactsSuccessfulResponseDto> {
401 let path = format!("/contacts/{}", crate::services::encode(contact_id));
402 let query = Vec::new();
403 self.client
404 .send_versioned(
405 reqwest::Method::DELETE,
406 &path,
407 &query,
408 None::<&()>,
409 Some("2021-07-28"),
410 )
411 .await
412 }
413
414 pub async fn get_contact(
420 &self,
421 contact_id: &str,
422 ) -> Result<models::ContactsByIdSuccessfulResponseDto> {
423 let path = format!("/contacts/{}", crate::services::encode(contact_id));
424 let query = Vec::new();
425 self.client
426 .send_versioned(
427 reqwest::Method::GET,
428 &path,
429 &query,
430 None::<&()>,
431 Some("2021-07-28"),
432 )
433 .await
434 }
435
436 pub async fn update_contact(
444 &self,
445 contact_id: &str,
446 body: &models::UpdateContactDto,
447 ) -> Result<models::UpdateContactsSuccessfulResponseDto> {
448 let path = format!("/contacts/{}", crate::services::encode(contact_id));
449 let query = Vec::new();
450 self.client
451 .send_versioned(
452 reqwest::Method::PUT,
453 &path,
454 &query,
455 Some(body),
456 Some("2021-07-28"),
457 )
458 .await
459 }
460
461 pub async fn get_appointments_for_contact(
467 &self,
468 contact_id: &str,
469 ) -> Result<models::GetEventsSuccessfulResponseDto> {
470 let path = format!(
471 "/contacts/{}/appointments",
472 crate::services::encode(contact_id)
473 );
474 let query = Vec::new();
475 self.client
476 .send_versioned(
477 reqwest::Method::GET,
478 &path,
479 &query,
480 None::<&()>,
481 Some("2021-07-28"),
482 )
483 .await
484 }
485
486 pub async fn remove_contact_from_every_campaign(
492 &self,
493 contact_id: &str,
494 ) -> Result<models::CreateDeleteCantactsCampaignsSuccessfulResponseDto> {
495 let path = format!(
496 "/contacts/{}/campaigns/removeAll",
497 crate::services::encode(contact_id)
498 );
499 let query = Vec::new();
500 self.client
501 .send_versioned(
502 reqwest::Method::DELETE,
503 &path,
504 &query,
505 None::<&()>,
506 Some("2021-07-28"),
507 )
508 .await
509 }
510
511 pub async fn remove_contact_from_campaign(
517 &self,
518 contact_id: &str,
519 campaign_id: &str,
520 ) -> Result<models::CreateDeleteCantactsCampaignsSuccessfulResponseDto> {
521 let path = format!(
522 "/contacts/{}/campaigns/{}",
523 crate::services::encode(contact_id),
524 crate::services::encode(campaign_id)
525 );
526 let query = Vec::new();
527 self.client
528 .send_versioned(
529 reqwest::Method::DELETE,
530 &path,
531 &query,
532 None::<&()>,
533 Some("2021-07-28"),
534 )
535 .await
536 }
537
538 pub async fn add_contact_to_campaign(
546 &self,
547 contact_id: &str,
548 campaign_id: &str,
549 body: &models::AddContactToCampaignDto,
550 ) -> Result<models::CreateDeleteCantactsCampaignsSuccessfulResponseDto> {
551 let path = format!(
552 "/contacts/{}/campaigns/{}",
553 crate::services::encode(contact_id),
554 crate::services::encode(campaign_id)
555 );
556 let query = Vec::new();
557 self.client
558 .send_versioned(
559 reqwest::Method::POST,
560 &path,
561 &query,
562 Some(body),
563 Some("2021-07-28"),
564 )
565 .await
566 }
567
568 pub async fn remove_followers(
574 &self,
575 contact_id: &str,
576 body: &models::FollowersDTO,
577 ) -> Result<models::DeleteFollowersSuccessfulResponseDto> {
578 let path = format!(
579 "/contacts/{}/followers",
580 crate::services::encode(contact_id)
581 );
582 let query = Vec::new();
583 self.client
584 .send_versioned(
585 reqwest::Method::DELETE,
586 &path,
587 &query,
588 Some(body),
589 Some("2021-07-28"),
590 )
591 .await
592 }
593
594 pub async fn add_followers(
600 &self,
601 contact_id: &str,
602 body: &models::FollowersDTO,
603 ) -> Result<models::CreateAddFollowersSuccessfulResponseDto> {
604 let path = format!(
605 "/contacts/{}/followers",
606 crate::services::encode(contact_id)
607 );
608 let query = Vec::new();
609 self.client
610 .send_versioned(
611 reqwest::Method::POST,
612 &path,
613 &query,
614 Some(body),
615 Some("2021-07-28"),
616 )
617 .await
618 }
619
620 pub async fn get_all_notes(
626 &self,
627 contact_id: &str,
628 ) -> Result<models::GetNotesListSuccessfulResponseDto> {
629 let path = format!("/contacts/{}/notes", crate::services::encode(contact_id));
630 let query = Vec::new();
631 self.client
632 .send_versioned(
633 reqwest::Method::GET,
634 &path,
635 &query,
636 None::<&()>,
637 Some("2021-07-28"),
638 )
639 .await
640 }
641
642 pub async fn create_note(
648 &self,
649 contact_id: &str,
650 body: &models::NotesDTO,
651 ) -> Result<models::GetCreateUpdateNoteSuccessfulResponseDto> {
652 let path = format!("/contacts/{}/notes", crate::services::encode(contact_id));
653 let query = Vec::new();
654 self.client
655 .send_versioned(
656 reqwest::Method::POST,
657 &path,
658 &query,
659 Some(body),
660 Some("2021-07-28"),
661 )
662 .await
663 }
664
665 pub async fn delete_note(
671 &self,
672 contact_id: &str,
673 id: &str,
674 ) -> Result<models::DeleteNoteSuccessfulResponseDto> {
675 let path = format!(
676 "/contacts/{}/notes/{}",
677 crate::services::encode(contact_id),
678 crate::services::encode(id)
679 );
680 let query = Vec::new();
681 self.client
682 .send_versioned(
683 reqwest::Method::DELETE,
684 &path,
685 &query,
686 None::<&()>,
687 Some("2021-07-28"),
688 )
689 .await
690 }
691
692 pub async fn get_note(
698 &self,
699 contact_id: &str,
700 id: &str,
701 ) -> Result<models::GetCreateUpdateNoteSuccessfulResponseDto> {
702 let path = format!(
703 "/contacts/{}/notes/{}",
704 crate::services::encode(contact_id),
705 crate::services::encode(id)
706 );
707 let query = Vec::new();
708 self.client
709 .send_versioned(
710 reqwest::Method::GET,
711 &path,
712 &query,
713 None::<&()>,
714 Some("2021-07-28"),
715 )
716 .await
717 }
718
719 pub async fn update_note(
725 &self,
726 contact_id: &str,
727 id: &str,
728 body: &models::UpdateNoteDTO,
729 ) -> Result<models::GetCreateUpdateNoteSuccessfulResponseDto> {
730 let path = format!(
731 "/contacts/{}/notes/{}",
732 crate::services::encode(contact_id),
733 crate::services::encode(id)
734 );
735 let query = Vec::new();
736 self.client
737 .send_versioned(
738 reqwest::Method::PUT,
739 &path,
740 &query,
741 Some(body),
742 Some("2021-07-28"),
743 )
744 .await
745 }
746
747 pub async fn remove_tags(
753 &self,
754 contact_id: &str,
755 body: &models::TagsDTO,
756 ) -> Result<models::CreateDeleteTagSuccessfulResponseDto> {
757 let path = format!("/contacts/{}/tags", crate::services::encode(contact_id));
758 let query = Vec::new();
759 self.client
760 .send_versioned(
761 reqwest::Method::DELETE,
762 &path,
763 &query,
764 Some(body),
765 Some("2021-07-28"),
766 )
767 .await
768 }
769
770 pub async fn add_tags(
776 &self,
777 contact_id: &str,
778 body: &models::TagsDTO,
779 ) -> Result<models::CreateAddTagSuccessfulResponseDto> {
780 let path = format!("/contacts/{}/tags", crate::services::encode(contact_id));
781 let query = Vec::new();
782 self.client
783 .send_versioned(
784 reqwest::Method::POST,
785 &path,
786 &query,
787 Some(body),
788 Some("2021-07-28"),
789 )
790 .await
791 }
792
793 pub async fn get_all_tasks(
799 &self,
800 contact_id: &str,
801 ) -> Result<models::TasksListSuccessfulResponseDto> {
802 let path = format!("/contacts/{}/tasks", crate::services::encode(contact_id));
803 let query = Vec::new();
804 self.client
805 .send_versioned(
806 reqwest::Method::GET,
807 &path,
808 &query,
809 None::<&()>,
810 Some("2021-07-28"),
811 )
812 .await
813 }
814
815 pub async fn create_task(
821 &self,
822 contact_id: &str,
823 body: &models::CreateTaskParams,
824 ) -> Result<models::TaskByIsSuccessfulResponseDto> {
825 let path = format!("/contacts/{}/tasks", crate::services::encode(contact_id));
826 let query = Vec::new();
827 self.client
828 .send_versioned(
829 reqwest::Method::POST,
830 &path,
831 &query,
832 Some(body),
833 Some("2021-07-28"),
834 )
835 .await
836 }
837
838 pub async fn delete_task(
844 &self,
845 contact_id: &str,
846 task_id: &str,
847 ) -> Result<models::DeleteTaskSuccessfulResponseDto> {
848 let path = format!(
849 "/contacts/{}/tasks/{}",
850 crate::services::encode(contact_id),
851 crate::services::encode(task_id)
852 );
853 let query = Vec::new();
854 self.client
855 .send_versioned(
856 reqwest::Method::DELETE,
857 &path,
858 &query,
859 None::<&()>,
860 Some("2021-07-28"),
861 )
862 .await
863 }
864
865 pub async fn get_task(
871 &self,
872 contact_id: &str,
873 task_id: &str,
874 ) -> Result<models::TaskByIsSuccessfulResponseDto> {
875 let path = format!(
876 "/contacts/{}/tasks/{}",
877 crate::services::encode(contact_id),
878 crate::services::encode(task_id)
879 );
880 let query = Vec::new();
881 self.client
882 .send_versioned(
883 reqwest::Method::GET,
884 &path,
885 &query,
886 None::<&()>,
887 Some("2021-07-28"),
888 )
889 .await
890 }
891
892 pub async fn update_task(
898 &self,
899 contact_id: &str,
900 task_id: &str,
901 body: &models::UpdateTaskBody,
902 ) -> Result<models::TaskByIsSuccessfulResponseDto> {
903 let path = format!(
904 "/contacts/{}/tasks/{}",
905 crate::services::encode(contact_id),
906 crate::services::encode(task_id)
907 );
908 let query = Vec::new();
909 self.client
910 .send_versioned(
911 reqwest::Method::PUT,
912 &path,
913 &query,
914 Some(body),
915 Some("2021-07-28"),
916 )
917 .await
918 }
919
920 pub async fn update_task_completed(
926 &self,
927 contact_id: &str,
928 task_id: &str,
929 body: &models::UpdateTaskStatusParams,
930 ) -> Result<models::TaskByIsSuccessfulResponseDto> {
931 let path = format!(
932 "/contacts/{}/tasks/{}/completed",
933 crate::services::encode(contact_id),
934 crate::services::encode(task_id)
935 );
936 let query = Vec::new();
937 self.client
938 .send_versioned(
939 reqwest::Method::PUT,
940 &path,
941 &query,
942 Some(body),
943 Some("2021-07-28"),
944 )
945 .await
946 }
947
948 pub async fn delete_contact_from_workflow(
954 &self,
955 contact_id: &str,
956 workflow_id: &str,
957 body: &models::CreateWorkflowDto,
958 ) -> Result<models::ContactsWorkflowSuccessfulResponseDto> {
959 let path = format!(
960 "/contacts/{}/workflow/{}",
961 crate::services::encode(contact_id),
962 crate::services::encode(workflow_id)
963 );
964 let query = Vec::new();
965 self.client
966 .send_versioned(
967 reqwest::Method::DELETE,
968 &path,
969 &query,
970 Some(body),
971 Some("2021-07-28"),
972 )
973 .await
974 }
975
976 pub async fn add_contact_to_workflow(
982 &self,
983 contact_id: &str,
984 workflow_id: &str,
985 body: &models::CreateWorkflowDto,
986 ) -> Result<models::ContactsWorkflowSuccessfulResponseDto> {
987 let path = format!(
988 "/contacts/{}/workflow/{}",
989 crate::services::encode(contact_id),
990 crate::services::encode(workflow_id)
991 );
992 let query = Vec::new();
993 self.client
994 .send_versioned(
995 reqwest::Method::POST,
996 &path,
997 &query,
998 Some(body),
999 Some("2021-07-28"),
1000 )
1001 .await
1002 }
1003}