pub struct KsefClient { /* private fields */ }Implementations§
Source§impl KsefClient
impl KsefClient
Sourcepub fn new(base_url: String, sleep_time: u64) -> Result<Self, ParseError>
pub fn new(base_url: String, sleep_time: u64) -> Result<Self, ParseError>
Examples found in repository?
examples/get_access_token.rs (line 4)
2async fn main() {
3
4 let client = ksef_client::KsefClient::new("https://api.ksef.mf.gov.pl".to_string(), 2000).unwrap();
5
6 let company_info = ksef_client::CompanyInfo {
7 ksef_token: "<ksef_token>".to_string(),
8 nip: "<nip>".to_string(),
9 };
10
11 let access_tokens = match client.get_access_tokens(&company_info).await {
12 Ok(access_tokens) => access_tokens,
13 Err(e) => {
14 eprintln!("Error getting access_tokens: {}", e);
15 return;
16 }
17 };
18
19 let access_token = access_tokens.access_token.token;
20
21 println!("access_token {}", access_token);
22}More examples
examples/invoice_export.rs (line 6)
4async fn main() {
5
6 let client = ksef_client::KsefClient::new("https://api.ksef.mf.gov.pl".to_string(), 2000).unwrap();
7 let access_token = "<access_token>".to_string();
8
9 let invoice_query_filters = ksef_client::invoice::InvoiceQueryFilters {
10 subject_type: ksef_client::invoice::InvoiceSubjectType::Subject1,
11 date_range: ksef_client::invoice::DateRange {
12 from: Utc::now() - chrono::Duration::days(90),
13 to: Some(Utc::now()),
14 date_type: ksef_client::invoice::DateType::PermanentStorage,
15 restrict_to_permanent_storage_hwm_date: Some(true),
16 },
17 };
18
19 let get_invoice_export_result = match client.get_invoice_export(&invoice_query_filters, &access_token).await {
20 Ok(get_invoice_export_result) => get_invoice_export_result,
21 Err(e) => {
22 eprintln!("Error: {}; {}", e.code, e.message);
23 return;
24 }
25 };
26
27 println!("{:#?}", get_invoice_export_result);
28}examples/query_invoice_metadata.rs (line 6)
4async fn main() {
5
6 let client = ksef_client::KsefClient::new("https://api.ksef.mf.gov.pl".to_string(), 2000).unwrap();
7 let access_token = "<access_token>".to_string();
8
9 let invoice_query_filters = ksef_client::invoice::InvoiceQueryFilters {
10 subject_type: ksef_client::invoice::InvoiceSubjectType::Subject1,
11 date_range: ksef_client::invoice::DateRange {
12 from: Utc::now() - chrono::Duration::days(90),
13 to: Some(Utc::now()),
14 date_type: ksef_client::invoice::DateType::Issue,
15 restrict_to_permanent_storage_hwm_date: None,
16 },
17 };
18
19 let query_invoice_metadata_result = match client.query_invoice_metadata(&invoice_query_filters, &access_token, 0, 10, ksef_client::invoice::SortOrder::Asc).await {
20 Ok(query_invoice_metadata_result) => query_invoice_metadata_result,
21 Err(e) => {
22 eprintln!("Error: {}; {}", e.code, e.message);
23 return;
24 }
25 };
26
27 println!("{:#?}", query_invoice_metadata_result);
28}examples/refresh_token.rs (line 6)
4async fn main() {
5
6 let client = ksef_client::KsefClient::new("https://api.ksef.mf.gov.pl".to_string(), 2000).unwrap();
7
8 let company_info = ksef_client::CompanyInfo {
9 ksef_token: "<ksef_token>".to_string(),
10 nip: "<nip>".to_string(),
11 };
12
13 let access_tokens = match client.get_access_tokens(&company_info).await {
14 Ok(access_tokens) => access_tokens,
15 Err(e) => {
16 eprintln!("Error getting access_tokens: {}", e);
17 return;
18 }
19 };
20
21 // if access token has expired
22 if access_tokens.access_token.valid_until < Utc::now() {
23 // refresh token ->
24 let access_token_info = match client
25 .refresh_access_token(&access_tokens.refresh_token.token)
26 .await
27 {
28 Ok(access_token_info) => access_token_info,
29 Err(e) => {
30 eprintln!("Error getting refresh token: {}", e);
31 return;
32 }
33 };
34
35 let access_token = access_token_info.token;
36
37 println!("access_token {}", access_token);
38 }
39}Sourcepub async fn get_access_tokens(
&self,
company_info: &CompanyInfo,
) -> Result<TokenPair, &str>
pub async fn get_access_tokens( &self, company_info: &CompanyInfo, ) -> Result<TokenPair, &str>
Examples found in repository?
examples/get_access_token.rs (line 11)
2async fn main() {
3
4 let client = ksef_client::KsefClient::new("https://api.ksef.mf.gov.pl".to_string(), 2000).unwrap();
5
6 let company_info = ksef_client::CompanyInfo {
7 ksef_token: "<ksef_token>".to_string(),
8 nip: "<nip>".to_string(),
9 };
10
11 let access_tokens = match client.get_access_tokens(&company_info).await {
12 Ok(access_tokens) => access_tokens,
13 Err(e) => {
14 eprintln!("Error getting access_tokens: {}", e);
15 return;
16 }
17 };
18
19 let access_token = access_tokens.access_token.token;
20
21 println!("access_token {}", access_token);
22}More examples
examples/refresh_token.rs (line 13)
4async fn main() {
5
6 let client = ksef_client::KsefClient::new("https://api.ksef.mf.gov.pl".to_string(), 2000).unwrap();
7
8 let company_info = ksef_client::CompanyInfo {
9 ksef_token: "<ksef_token>".to_string(),
10 nip: "<nip>".to_string(),
11 };
12
13 let access_tokens = match client.get_access_tokens(&company_info).await {
14 Ok(access_tokens) => access_tokens,
15 Err(e) => {
16 eprintln!("Error getting access_tokens: {}", e);
17 return;
18 }
19 };
20
21 // if access token has expired
22 if access_tokens.access_token.valid_until < Utc::now() {
23 // refresh token ->
24 let access_token_info = match client
25 .refresh_access_token(&access_tokens.refresh_token.token)
26 .await
27 {
28 Ok(access_token_info) => access_token_info,
29 Err(e) => {
30 eprintln!("Error getting refresh token: {}", e);
31 return;
32 }
33 };
34
35 let access_token = access_token_info.token;
36
37 println!("access_token {}", access_token);
38 }
39}Sourcepub async fn refresh_access_token(
&self,
refresh_token: &String,
) -> Result<TokenInfo, &str>
pub async fn refresh_access_token( &self, refresh_token: &String, ) -> Result<TokenInfo, &str>
Examples found in repository?
examples/refresh_token.rs (line 25)
4async fn main() {
5
6 let client = ksef_client::KsefClient::new("https://api.ksef.mf.gov.pl".to_string(), 2000).unwrap();
7
8 let company_info = ksef_client::CompanyInfo {
9 ksef_token: "<ksef_token>".to_string(),
10 nip: "<nip>".to_string(),
11 };
12
13 let access_tokens = match client.get_access_tokens(&company_info).await {
14 Ok(access_tokens) => access_tokens,
15 Err(e) => {
16 eprintln!("Error getting access_tokens: {}", e);
17 return;
18 }
19 };
20
21 // if access token has expired
22 if access_tokens.access_token.valid_until < Utc::now() {
23 // refresh token ->
24 let access_token_info = match client
25 .refresh_access_token(&access_tokens.refresh_token.token)
26 .await
27 {
28 Ok(access_token_info) => access_token_info,
29 Err(e) => {
30 eprintln!("Error getting refresh token: {}", e);
31 return;
32 }
33 };
34
35 let access_token = access_token_info.token;
36
37 println!("access_token {}", access_token);
38 }
39}Sourcepub async fn query_invoice_metadata(
&self,
request: &InvoiceQueryFilters,
access_token: &String,
page_offset: i32,
page_size: i32,
sort_order: SortOrder,
) -> Result<PagedInvoiceResponse, ErrorResponse>
pub async fn query_invoice_metadata( &self, request: &InvoiceQueryFilters, access_token: &String, page_offset: i32, page_size: i32, sort_order: SortOrder, ) -> Result<PagedInvoiceResponse, ErrorResponse>
Examples found in repository?
examples/query_invoice_metadata.rs (line 19)
4async fn main() {
5
6 let client = ksef_client::KsefClient::new("https://api.ksef.mf.gov.pl".to_string(), 2000).unwrap();
7 let access_token = "<access_token>".to_string();
8
9 let invoice_query_filters = ksef_client::invoice::InvoiceQueryFilters {
10 subject_type: ksef_client::invoice::InvoiceSubjectType::Subject1,
11 date_range: ksef_client::invoice::DateRange {
12 from: Utc::now() - chrono::Duration::days(90),
13 to: Some(Utc::now()),
14 date_type: ksef_client::invoice::DateType::Issue,
15 restrict_to_permanent_storage_hwm_date: None,
16 },
17 };
18
19 let query_invoice_metadata_result = match client.query_invoice_metadata(&invoice_query_filters, &access_token, 0, 10, ksef_client::invoice::SortOrder::Asc).await {
20 Ok(query_invoice_metadata_result) => query_invoice_metadata_result,
21 Err(e) => {
22 eprintln!("Error: {}; {}", e.code, e.message);
23 return;
24 }
25 };
26
27 println!("{:#?}", query_invoice_metadata_result);
28}Sourcepub async fn get_invoice_export(
&self,
filters: &InvoiceQueryFilters,
access_token: &String,
) -> Result<InvoiceExportResult, ErrorResponse>
pub async fn get_invoice_export( &self, filters: &InvoiceQueryFilters, access_token: &String, ) -> Result<InvoiceExportResult, ErrorResponse>
Examples found in repository?
examples/invoice_export.rs (line 19)
4async fn main() {
5
6 let client = ksef_client::KsefClient::new("https://api.ksef.mf.gov.pl".to_string(), 2000).unwrap();
7 let access_token = "<access_token>".to_string();
8
9 let invoice_query_filters = ksef_client::invoice::InvoiceQueryFilters {
10 subject_type: ksef_client::invoice::InvoiceSubjectType::Subject1,
11 date_range: ksef_client::invoice::DateRange {
12 from: Utc::now() - chrono::Duration::days(90),
13 to: Some(Utc::now()),
14 date_type: ksef_client::invoice::DateType::PermanentStorage,
15 restrict_to_permanent_storage_hwm_date: Some(true),
16 },
17 };
18
19 let get_invoice_export_result = match client.get_invoice_export(&invoice_query_filters, &access_token).await {
20 Ok(get_invoice_export_result) => get_invoice_export_result,
21 Err(e) => {
22 eprintln!("Error: {}; {}", e.code, e.message);
23 return;
24 }
25 };
26
27 println!("{:#?}", get_invoice_export_result);
28}Auto Trait Implementations§
impl !Freeze for KsefClient
impl !RefUnwindSafe for KsefClient
impl Send for KsefClient
impl !Sync for KsefClient
impl Unpin for KsefClient
impl UnsafeUnpin for KsefClient
impl UnwindSafe for KsefClient
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more