Skip to main content

KsefClient

Struct KsefClient 

Source
pub struct KsefClient { /* private fields */ }

Implementations§

Source§

impl KsefClient

Source

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
Hide additional 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}
Source

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
Hide additional 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}
Source

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}
Source

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}
Source

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§

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> 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: 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: 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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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