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
mod client;
pub use client::Client;
mod models;
pub use models::*;

pub use chrono;
pub use http;
pub use eiktyrner;

mod analysis; // non generated tmpl
mod debenture; // non generated tmpl


mod accounting;
mod authentication;
mod bank;
mod common;
mod contract_invoice;
mod cost_centers;
mod creditors;
mod debt_collection;
mod debtors;
mod delivery;
mod files;
mod invoice;
mod payments;
mod products;
mod projects;
mod reconciliation_invoice;
mod reminder_invoice;
mod search;
mod self_invoice;
mod users;


pub type Result<T> = std::result::Result<http::Response<T>, eiktyrner::Error>;

pub struct Param {
    value: Option<String>,
}


impl Param {

    fn value<T>(v: T) -> Self where T: std::fmt::Display {
        Self {
            value: Some(v.to_string()),
        }
    }
    
    fn opt<T>(v: Option<T>) -> Self where T: std::fmt::Display {
        Self {
            value: v.map(|v| v.to_string()),
        }
    }
}


pub struct PathAndQueryBuilder {
    buffer: String,
}

impl PathAndQueryBuilder {
    pub fn new() -> Self {
        Self {
            buffer: String::new(),
        }
    }

    pub fn url(&mut self, param: Param) -> &mut Self {
    
        if let Some(ref s) = param.value {
            if !self.buffer.is_empty() {
                self.buffer.push('/');
            }
            self.buffer.push_str(&urlencoding::encode(s));
        }
        
        self
    }
        
    pub fn query(&mut self, name: &str, param: Param) -> &mut Self {
        if let Some(ref s) = param.value {
            if !self.buffer.contains('?') {
                self.buffer.push('?');
            } else {
                self.buffer.push('&');
            }
            self.buffer.push_str(name);
            self.buffer.push('=');
            self.buffer.push_str(&urlencoding::encode(s));
        }
        
           
        self
    
    }



    pub fn build(&mut self) -> http::uri::PathAndQuery {
        use std::str::FromStr;

        http::uri::PathAndQuery::from_str(&self.buffer).expect("Building PathAndQuery")
    }
}