kintone/
lib.rs

1//! A client library of Kintone REST APIs for Rust.
2//!
3//! **DISCLAIMER**: this OSS is my own personal work and does not have any relationship with Cybozu Inc. or any other organization which I belong to.
4//!
5//! **WARNING**: This library is under development and is likely to undergo incompatible changes in the future.
6//!
7//! ## Usage
8//!
9//! This library provides a fluent API for interacting with Kintone REST APIs using method chaining. All API functions return request builders that can be configured with additional parameters and then sent to the Kintone server.
10//!
11//! ### Basic Example
12//!
13//! Here's a simple example that retrieves a record from a Kintone app and displays it:
14//!
15//! ```no_run
16//! use kintone::client::{Auth, KintoneClient};
17//!
18//! fn main() -> Result<(), Box<dyn std::error::Error>> {
19//!     // Create a client with your Kintone base URL and API token
20//!     let base_url = "https://your-domain.cybozu.com";
21//!     let api_token = "your-api-token".to_owned();
22//!     let client = KintoneClient::new(base_url, Auth::api_token(api_token));
23//!
24//!     // Get a single record by ID
25//!     let response = kintone::v1::record::get_record(123, 456)  // app_id: 123, record_id: 456
26//!         .send(&client)?;
27//!
28//!     println!("Retrieved record:");
29//!     for (field_code, field_value) in response.record.fields() {
30//!         println!("  '{}' = {:?}", field_code, field_value);
31//!     }
32//!
33//!     // Get multiple records with filtering
34//!     let response = kintone::v1::record::get_records(123)
35//!         .query("status = \"Active\"")
36//!         .fields(&["name", "email", "status"])
37//!         .send(&client)?;
38//!
39//!     for record in response.records {
40//!         println!("Record:");
41//!         for (field_code, field_value) in record.fields() {
42//!             println!("  '{}' = {:?}", field_code, field_value);
43//!         }
44//!     }
45//!
46//!     Ok(())
47//! }
48//! ```
49//!
50//! ## Supported APIs
51//!
52//! The library currently supports the following Kintone REST API endpoints:
53//!
54//! - [`v1::record`]: Record management APIs
55//!     - [`v1::record::get_record`], [`v1::record::get_records`], [`v1::record::add_record`], [`v1::record::add_records`], [`v1::record::update_record`], [`v1::record::update_records`], [`v1::record::delete_records`], [`v1::record::bulk_request`], [`v1::record::update_assignees`], [`v1::record::update_status`], [`v1::record::get_comments`], [`v1::record::add_comment`], [`v1::record::delete_comment`], [`v1::record::create_cursor`], [`v1::record::get_records_by_cursor`], [`v1::record::delete_cursor`]
56//! - [`v1::file`]: File management APIs
57//!     - [`v1::file::upload`], [`v1::file::download`]
58//! - [`v1::space`]: Space management APIs
59//!     - [`v1::space::add_space`], [`v1::space::delete_space`], [`v1::space::add_thread`], [`v1::space::add_thread_comment`]
60//! - [`v1::app`]: App management APIs
61//!     - [`v1::app::add_app`], [`v1::app::settings::deploy_app`], [`v1::app::settings::get_app_deploy_status`], [`v1::app::form::add_form_field`]
62//!
63//! ### Builder Pattern and Method Chaining
64//!
65//! Each API function follows the same pattern: create a request builder, optionally configure it
66//! with additional parameters using method chaining, and then call `.send(&client)` to execute the request.
67//!
68//! ```no_run
69//! # use std::error::Error;
70//! # use kintone::client::{Auth, KintoneClient};
71//! # let client = KintoneClient::new("https://example.cybozu.com", Auth::api_token("token".to_owned()));
72//! # let app_id = 1;
73//! let response = kintone::v1::record::get_records(app_id) // Returns a request builder
74//!     .query("status = \"Active\"") // Optional parameter: query filter
75//!     .fields(&["name", "email"])   // Optional parameter: field selection
76//!     .send(&client)?;              // Execute the request
77//! # Ok::<(), Box<dyn std::error::Error>>(())
78//! ```
79//!
80//! This builder pattern allows us to add optional parameters to our APIs while maintaining
81//! backward compatibility. You can call multiple methods on the builder to configure your
82//! request, and only the final `.send(&client)` call actually sends the request to the server.
83//!
84//! **Note**: If you forget to call `.send(&client)`, the compiler will help you catch this mistake
85//! with a helpful warning:
86//!
87//! ```text
88//! unused `kintone::v1::space::AddThreadCommentRequest` that must be used
89//! ```
90//!
91//! This happens because all request builders are marked with `#[must_use]`, so you'll
92//! quickly notice if you accidentally create a request without sending it. The compiler
93//! warning ensures you won't miss this important step!
94//!
95//! ## Examples
96//!
97//! For more detailed examples and usage patterns, check out the `examples` directory in this repository.
98//! Each example demonstrates how to use specific API endpoints and can be run directly to test the functionality.
99//!
100//! The examples use environment variables for configuration:
101//!
102//! - `KINTONE_BASE_URL`: Your Kintone domain URL (e.g., `https://your-domain.cybozu.com`)
103//! - `KINTONE_API_TOKEN`: Your API token for authentication
104//! - `KINTONE_USERNAME`: Your username for Kintone
105//! - `KINTONE_PASSWORD`: Your password for Kintone
106//!
107//! You can run an example like this:
108//!
109//! ```bash
110//! export KINTONE_BASE_URL=https://your-domain.cybozu.com
111//! export KINTONE_API_TOKEN=your-token
112//! export KINTONE_USERNAME=your-username
113//! export KINTONE_PASSWORD=your-password
114//! cargo run --example get_record
115//! ```
116
117pub mod client;
118pub mod error;
119pub mod middleware;
120pub mod model;
121pub mod v1;
122
123mod internal;