1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//! Crate for interacting with the Salesforce API
//!
//! This crate includes the tools connecting to Salesforce and manipulating
//! Salesforce objects
//!
//! # Example
//!
//! The following example will connect to Salesforce and insert an Account
//! object
//!
//!
//! ```rust,no_run
//! use rust_sync_force::{Client, Error};
//! use serde::Deserialize;
//! use std::collections::HashMap;
//! use std::env;
//!
//! #[derive(Deserialize, Debug)]
//! #[serde(rename_all = "PascalCase")]
//! struct Account {
//! #[serde(rename = "attributes")]
//! attributes: Attribute,
//! id: String,
//! name: String,
//! }
//!
//! #[derive(Deserialize, Debug)]
//! struct Attribute {
//! url: String,
//! #[serde(rename = "type")]
//! sobject_type: String,
//! }
//!
//! fn main() -> Result<(), Error> {
//! let client_id = env::var("SFDC_CLIENT_ID").unwrap();
//! let client_secret = env::var("SFDC_CLIENT_SECRET").unwrap();
//! let username = env::var("SFDC_USERNAME").unwrap();
//! let password = env::var("SFDC_PASSWORD").unwrap();
//!
//! let mut client = Client::new(Some(client_id), Some(client_secret));
//! client.login_with_credential(username, password)?;
//! let mut params = HashMap::new();
//! params.insert("Name", "hello rust");
//! let res = client.insert("Account", params)?;
//! println!("{:?}", res);
//! Ok(())
//! }
//! ```
//!
//! This example will listen to any change made on any Account records through the Bayeux protocol.
//!
//! ```rust,no_run
//! use rust_sync_force::stream::{CometdClient, StreamResponse};
//! use rust_sync_force::{Client, Error};
//! use serde::Deserialize;
//! use std::{collections::HashMap, env};
//! #[derive(Debug, Deserialize)]
//! #[allow(non_snake_case)]
//! pub struct SFChangeEventHeader {
//! pub commitNumber: usize,
//! pub commitUser: String,
//! pub sequenceNumber: usize,
//! pub entityName: String,
//! pub changeType: String,
//! pub commitTimestamp: usize,
//! pub recordIds: Vec<String>,
//! }
//! #[derive(Debug, Deserialize)]
//! #[allow(non_snake_case)]
//! pub struct SFPayload {
//! pub LastModifiedDate: String,
//! pub ChangeEventHeader: SFChangeEventHeader,
//! }
//! pub fn listen_sf(mut client: CometdClient) {
//! println!("Listen SF loop started");
//! loop {
//! let responses = client.connect();
//! match responses {
//! Ok(responses) => {
//! for response in responses {
//! if let StreamResponse::Delivery(resp) = response {
//! match serde_json::from_value::<SFMetadata>(resp.data.payload.clone()) {
//! Ok(data) => {
//! println!("Data: {:#?}", data);
//! //! Here you should have your patterns matching your own objects
//! }
//! Err(err) => {
//! println!(
//! "SF delivery data could not be parsed: {:?}\nData:{:?}",
//! err, resp
//! )
//! }
//! }
//! }
//! }
//! }
//! Err(err) => println!("{}", err.to_string()),
//! }
//! }
//! }
//! fn main() -> Result<(), Error> {
//! let client_id = env::var("SFDC_CLIENT_ID").unwrap();
//! let client_secret = env::var("SFDC_CLIENT_SECRET").unwrap();
//! let username = env::var("SFDC_USERNAME").unwrap();
//! let password = env::var("SFDC_PASSWORD").unwrap();
//! let mut client = Client::new(Some(client_id), Some(client_secret));
//! client.login_with_credential(username, password)?;
//! let mut stream_client = rust_sync_force::stream::CometdClient::new(
//! client,
//! HashMap::from([("/data/AccountChangeEvent".to_string(), -1)]),
//! );
//! stream_client.init().expect("Could not init cometd client");
//! println!("Cometd client successfully initialized");
//! listen_sf(stream_client);
//! Ok(())
//! }
//! ```
extern crate thiserror;
extern crate ureq;
pub type Client = Client;
pub type Error = Error;