Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

Synchronous ChurchTools API client.

Cloning is cheap: the connection pool and the rate limit are shared.

The client blocks (it uses reqwest::blocking) and panics when created, used or dropped inside an async runtime such as Tokio. From async code, call it in tokio::task::spawn_blocking.

Implementations§

Source§

impl Client

Source

pub fn new(base_url: &str, token: Option<String>) -> Result<Self>

Creates a client for base_url, e.g. https://meinegemeinde.church.tools.

A trailing /api is optional. See Client::builder for more options.

Source

pub fn builder(base_url: &str) -> ClientBuilder

Starts configuring a client for base_url.

Source

pub fn with_min_interval(self, min_interval: Duration) -> Self

Limits this client (and its clones) to one request per min_interval.

Useful for bulk jobs and tests, so the instance is not flooded. Independent of this, a 429 Too Many Requests answer is retried after the time the server asks for (Retry-After, at most 60 s, up to 3 times); so are 502/503/504 for idempotent methods (GET, HEAD, PUT, DELETE, OPTIONS). A failed connection is retried once after 1 s.

Source

pub fn login_with_password( &self, username: &str, password: &str, ) -> Result<Self>

Logs in with username (or email) and password and returns a client that uses the login token of that person.

Keeps the rate limit of self. Prefer a stored token for scripts; this is meant for tests and interactive tools.

The token is the person’s persistent login token: ChurchTools creates one if there is none, and it stays valid after this client is dropped, until it is revoked with client.persons().delete_login_token(person_id). The password session used to fetch it is not reused; the API has no logout, so it ends when the server expires it.

Source

pub fn from_env() -> Result<Self>

Reads the instance URL from CT_URL and the login token from CT_TOKEN.

For other options use ClientBuilder::from_env.

Source

pub fn api_url(&self) -> &str

The API root, always ending in /api.

Source

pub fn request( &self, method: Method, path: &str, query: &[(String, String)], body: Option<&Value>, ) -> Result<Vec<u8>>

Sends a request and returns the raw body of a successful response.

path starts with / and is relative to the API root; path parameters must already be encoded (see encode_path_segment).

Source

pub fn request_json_bytes( &self, method: Method, path: &str, query: &[(String, String)], body: Option<&[u8]>, ) -> Result<Vec<u8>>

Like request, with a body that is already encoded JSON; it is sent as is, without parsing it again.

Source

pub fn request_multipart( &self, method: Method, path: &str, query: &[(String, String)], form: &[(String, String)], file_field: &str, files: &[Upload], ) -> Result<Vec<u8>>

Sends a multipart/form-data request: the text fields of form plus one part named file_field (e.g. files[]) per file.

Source

pub fn request_data<T: DeserializeOwned>( &self, method: Method, path: &str, query: &[(String, String)], body: Option<&Value>, ) -> Result<T>

Sends a request and decodes the data field of the response envelope.

Source

pub fn request_json<T: DeserializeOwned>( &self, method: Method, path: &str, query: &[(String, String)], body: Option<&Value>, ) -> Result<T>

Sends a request and decodes the whole response body.

Source

pub fn pages(&self, path: &str, query: Query) -> Pages ⓘ

Iterates over the raw bodies of all pages of a paginated GET endpoint.

Any page entry in query is replaced. Iteration stops after the page whose meta.pagination.current reaches lastPage, after an empty page, or after the first page if the response carries no pagination info.

Pages are fetched one by one with offsets: if entries are added or removed meanwhile, an entry can show up twice or be skipped. From the second page on, the next page is requested in a background thread while the current one is being used, see Pages::prefetch.

Source

pub fn collect_pages<T: DeserializeOwned>( &self, path: &str, query: Query, ) -> Result<Vec<T>>

Fetches all pages and concatenates their data arrays.

Source

pub fn items<T: DeserializeOwned>(&self, path: &str, query: Query) -> Items<T> ⓘ

Iterates over the items of all pages, fetching each page only when the previous one is used up. Stopping early saves the remaining requests.

Ends after the first error; the same rules as for Client::pages apply.

Source§

impl Client

Source

pub fn actions(&self) -> ActionsResource<'_>

Endpoints under /actions (1 operations), see ActionsResource.

Source

pub fn addresses(&self) -> AddressesResource<'_>

Endpoints under /addresses (5 operations), see AddressesResource.

Source

pub fn agenda_templates(&self) -> AgendaTemplatesResource<'_>

Endpoints under /agenda_templates (11 operations), see AgendaTemplatesResource.

Source

pub fn agendas(&self) -> AgendasResource<'_>

Endpoints under /agendas (1 operations), see AgendasResource.

Source

pub fn bookings(&self) -> BookingsResource<'_>

Endpoints under /bookings (9 operations), see BookingsResource.

Source

pub fn bulk_jobs(&self) -> BulkJobsResource<'_>

Endpoints under /bulk_jobs (2 operations), see BulkJobsResource.

Source

pub fn bulk_letters(&self) -> BulkLettersResource<'_>

Endpoints under /bulk_letters (6 operations), see BulkLettersResource.

Source

pub fn calendars(&self) -> CalendarsResource<'_>

Endpoints under /calendars (28 operations), see CalendarsResource.

Source

pub fn campuses(&self) -> CampusesResource<'_>

Endpoints under /campuses (5 operations), see CampusesResource.

Source

pub fn captcha(&self) -> CaptchaResource<'_>

Endpoints under /captcha (2 operations), see CaptchaResource.

Source

pub fn chat(&self) -> ChatResource<'_>

Endpoints under /chat (4 operations), see ChatResource.

Source

pub fn checkin(&self) -> CheckinResource<'_>

Endpoints under /checkin (2 operations), see CheckinResource.

Source

pub fn church_query(&self) -> ChurchQueryResource<'_>

Endpoints under /church_query (2 operations), see ChurchQueryResource.

Source

pub fn config(&self) -> ConfigResource<'_>

Endpoints under /config (2 operations), see ConfigResource.

Source

pub fn contact_labels(&self) -> ContactLabelsResource<'_>

Endpoints under /contact_labels (5 operations), see ContactLabelsResource.

Source

pub fn csrf_token(&self) -> CsrfTokenResource<'_>

Endpoints under /csrf_token (1 operations), see CsrfTokenResource.

Source

pub fn db_field_types(&self) -> DbFieldTypesResource<'_>

Endpoints under /db_field_types (1 operations), see DbFieldTypesResource.

Source

pub fn db_fields(&self) -> DbFieldsResource<'_>

Endpoints under /db_fields (10 operations), see DbFieldsResource.

Source

pub fn departments(&self) -> DepartmentsResource<'_>

Endpoints under /departments (1 operations), see DepartmentsResource.

Source

pub fn domain_objects(&self) -> DomainObjectsResource<'_>

Endpoints under /domain_objects (2 operations), see DomainObjectsResource.

Source

pub fn dynamic_groups(&self) -> DynamicGroupsResource<'_>

Endpoints under /dynamic_groups (8 operations), see DynamicGroupsResource.

Source

pub fn emails(&self) -> EmailsResource<'_>

Endpoints under /emails (2 operations), see EmailsResource.

Source

pub fn evangelische_termine(&self) -> EvangelischeTermineResource<'_>

Endpoints under /evangelische_termine (3 operations), see EvangelischeTermineResource.

Source

pub fn event(&self) -> EventResource<'_>

Endpoints under /event (1 operations), see EventResource.

Source

pub fn event_templates(&self) -> EventTemplatesResource<'_>

Endpoints under /event_templates (1 operations), see EventTemplatesResource.

Source

pub fn events(&self) -> EventsResource<'_>

Endpoints under /events (39 operations), see EventsResource.

Source

pub fn external_logins(&self) -> ExternalLoginsResource<'_>

Endpoints under /external_logins (24 operations), see ExternalLoginsResource.

Source

pub fn external_posts(&self) -> ExternalPostsResource<'_>

Endpoints under /external_posts (2 operations), see ExternalPostsResource.

Source

pub fn facts(&self) -> FactsResource<'_>

Endpoints under /facts (5 operations), see FactsResource.

Source

pub fn feature_usage(&self) -> FeatureUsageResource<'_>

Endpoints under /feature_usage (1 operations), see FeatureUsageResource.

Source

pub fn fields(&self) -> FieldsResource<'_>

Endpoints under /fields (1 operations), see FieldsResource.

Source

pub fn files(&self) -> FilesResource<'_>

Endpoints under /files (10 operations), see FilesResource.

Source

pub fn finance(&self) -> FinanceResource<'_>

Endpoints under /finance (134 operations), see FinanceResource.

Source

pub fn followups(&self) -> FollowupsResource<'_>

Endpoints under /followups (9 operations), see FollowupsResource.

Endpoints under /further_links (5 operations), see FurtherLinksResource.

Source

pub fn group(&self) -> GroupResource<'_>

Endpoints under /group (31 operations), see GroupResource.

Source

pub fn group_homepages(&self) -> GroupHomepagesResource<'_>

Endpoints under /group_homepages (2 operations), see GroupHomepagesResource.

Source

pub fn groups(&self) -> GroupsResource<'_>

Endpoints under /groups (78 operations), see GroupsResource.

Source

pub fn history(&self) -> HistoryResource<'_>

Endpoints under /history (1 operations), see HistoryResource.

Source

pub fn html_templates(&self) -> HtmlTemplatesResource<'_>

Endpoints under /html_templates (9 operations), see HtmlTemplatesResource.

Source

pub fn images(&self) -> ImagesResource<'_>

Endpoints under /images (4 operations), see ImagesResource.

Source

pub fn info(&self) -> InfoResource<'_>

Endpoints under /info (1 operations), see InfoResource.

Source

pub fn installation_sync(&self) -> InstallationSyncResource<'_>

Endpoints under /installation_sync (1 operations), see InstallationSyncResource.

Source

pub fn job_log(&self) -> JobLogResource<'_>

Endpoints under /job_log (1 operations), see JobLogResource.

Source

pub fn jobs(&self) -> JobsResource<'_>

Endpoints under /jobs (3 operations), see JobsResource.

Source

pub fn labels(&self) -> LabelsResource<'_>

Endpoints under /labels (2 operations), see LabelsResource.

Source

pub fn languages(&self) -> LanguagesResource<'_>

Endpoints under /languages (1 operations), see LanguagesResource.

Source

pub fn license(&self) -> LicenseResource<'_>

Endpoints under /license (1 operations), see LicenseResource.

Source

pub fn login(&self) -> LoginResource<'_>

Endpoints under /login (5 operations), see LoginResource.

Source

pub fn logout(&self) -> LogoutResource<'_>

Endpoints under /logout (1 operations), see LogoutResource.

Source

pub fn logs(&self) -> LogsResource<'_>

Endpoints under /logs (3 operations), see LogsResource.

Source

pub fn markdown(&self) -> MarkdownResource<'_>

Endpoints under /markdown (2 operations), see MarkdownResource.

Source

pub fn master_data(&self) -> MasterDataResource<'_>

Endpoints under /master_data (1 operations), see MasterDataResource.

Source

pub fn meeting_requests(&self) -> MeetingRequestsResource<'_>

Endpoints under /meeting_requests (1 operations), see MeetingRequestsResource.

Source

pub fn menu(&self) -> MenuResource<'_>

Endpoints under /menu (1 operations), see MenuResource.

Source

pub fn news_letter_integrations(&self) -> NewsLetterIntegrationsResource<'_>

Endpoints under /news_letter_integrations (1 operations), see NewsLetterIntegrationsResource.

Source

pub fn notes(&self) -> NotesResource<'_>

Endpoints under /notes (5 operations), see NotesResource.

Source

pub fn notifications(&self) -> NotificationsResource<'_>

Endpoints under /notifications (1 operations), see NotificationsResource.

Source

pub fn nps(&self) -> NpsResource<'_>

Endpoints under /nps (1 operations), see NpsResource.

Source

pub fn oauth_clients(&self) -> OauthClientsResource<'_>

Endpoints under /oauth_clients (4 operations), see OauthClientsResource.

Source

pub fn permissions(&self) -> PermissionsResource<'_>

Endpoints under /permissions (21 operations), see PermissionsResource.

Source

pub fn person(&self) -> PersonResource<'_>

Endpoints under /person (21 operations), see PersonResource.

Source

pub fn persons(&self) -> PersonsResource<'_>

Endpoints under /persons (72 operations), see PersonsResource.

Source

pub fn placeholders(&self) -> PlaceholdersResource<'_>

Endpoints under /placeholders (2 operations), see PlaceholdersResource.

Source

pub fn poll_for_news(&self) -> PollForNewsResource<'_>

Endpoints under /poll_for_news (1 operations), see PollForNewsResource.

Source

pub fn post(&self) -> PostResource<'_>

Endpoints under /post (8 operations), see PostResource.

Source

pub fn posts(&self) -> PostsResource<'_>

Endpoints under /posts (16 operations), see PostsResource.

Source

pub fn pr(&self) -> PrResource<'_>

Endpoints under /pr (1 operations), see PrResource.

Source

pub fn printers(&self) -> PrintersResource<'_>

Endpoints under /printers (1 operations), see PrintersResource.

Source

pub fn probes(&self) -> ProbesResource<'_>

Endpoints under /probes (1 operations), see ProbesResource.

Source

pub fn profiles(&self) -> ProfilesResource<'_>

Endpoints under /profiles (5 operations), see ProfilesResource.

Source

pub fn public_groups(&self) -> PublicGroupsResource<'_>

Endpoints under /public_groups (11 operations), see PublicGroupsResource.

Source

pub fn queues(&self) -> QueuesResource<'_>

Endpoints under /queues (2 operations), see QueuesResource.

Source

pub fn registration_config(&self) -> RegistrationConfigResource<'_>

Endpoints under /registration_config (2 operations), see RegistrationConfigResource.

Source

pub fn registrations(&self) -> RegistrationsResource<'_>

Endpoints under /registrations (5 operations), see RegistrationsResource.

Source

pub fn repeat_calculation(&self) -> RepeatCalculationResource<'_>

Endpoints under /repeat_calculation (5 operations), see RepeatCalculationResource.

Source

pub fn reset_password(&self) -> ResetPasswordResource<'_>

Endpoints under /reset_password (1 operations), see ResetPasswordResource.

Source

pub fn resource(&self) -> ResourceResource<'_>

Endpoints under /resource (1 operations), see ResourceResource.

Source

pub fn resource_types(&self) -> ResourceTypesResource<'_>

Endpoints under /resource_types (5 operations), see ResourceTypesResource.

Source

pub fn resources(&self) -> ResourcesResource<'_>

Endpoints under /resources (6 operations), see ResourcesResource.

Source

pub fn routines(&self) -> RoutinesResource<'_>

Endpoints under /routines (10 operations), see RoutinesResource.

Source

pub fn saml(&self) -> SamlResource<'_>

Endpoints under /saml (3 operations), see SamlResource.

Source

pub fn search(&self) -> SearchResource<'_>

Endpoints under /search (1 operations), see SearchResource.

Source

pub fn security_levels(&self) -> SecurityLevelsResource<'_>

Endpoints under /security_levels (5 operations), see SecurityLevelsResource.

Source

pub fn service_groups(&self) -> ServiceGroupsResource<'_>

Endpoints under /service_groups (5 operations), see ServiceGroupsResource.

Source

pub fn services(&self) -> ServicesResource<'_>

Endpoints under /services (5 operations), see ServicesResource.

Source

pub fn simulate(&self) -> SimulateResource<'_>

Endpoints under /simulate (2 operations), see SimulateResource.

Source

pub fn song(&self) -> SongResource<'_>

Endpoints under /song (10 operations), see SongResource.

Source

pub fn songs(&self) -> SongsResource<'_>

Endpoints under /songs (12 operations), see SongsResource.

Source

pub fn sso_logins(&self) -> SsoLoginsResource<'_>

Endpoints under /sso_logins (1 operations), see SsoLoginsResource.

Source

pub fn start_page(&self) -> StartPageResource<'_>

Endpoints under /start_page (1 operations), see StartPageResource.

Source

pub fn statuses(&self) -> StatusesResource<'_>

Endpoints under /statuses (6 operations), see StatusesResource.

Source

pub fn subscriptions(&self) -> SubscriptionsResource<'_>

Endpoints under /subscriptions (5 operations), see SubscriptionsResource.

Source

pub fn sync(&self) -> SyncResource<'_>

Endpoints under /sync (55 operations), see SyncResource.

Source

pub fn tags(&self) -> TagsResource<'_>

Endpoints under /tags (9 operations), see TagsResource.

Source

pub fn translations(&self) -> TranslationsResource<'_>

Endpoints under /translations (5 operations), see TranslationsResource.

Source

pub fn two_factor(&self) -> TwoFactorResource<'_>

Endpoints under /two_factor (1 operations), see TwoFactorResource.

Source

pub fn website(&self) -> WebsiteResource<'_>

Endpoints under /website (4 operations), see WebsiteResource.

Source

pub fn whoami(&self) -> WhoamiResource<'_>

Endpoints under /whoami (1 operations), see WhoamiResource.

Source

pub fn widgets(&self) -> WidgetsResource<'_>

Endpoints under /widgets (2 operations), see WidgetsResource.

Source

pub fn wiki(&self) -> WikiResource<'_>

Endpoints under /wiki (13 operations), see WikiResource.

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more