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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
//! The Boomack API Client library.
//!
//! # Overview
//!
//! ## Configuration
//! Module: [`boomack::client::config`](config/)
//!
//! The configuration contains the server URL, the API authorization token,
//! and other parameters for the HTTP requests.
//!
//! * The [`Config`](config/struct.Config.html) struct with methods
//! for loading configuration values from different sources
//!
//! ## JSON
//! Module: [`boomack::client::json`](json/)
//!
//! JSON specific functions are required for the dynamic or extensible
//! request parts, like e. g. display options.
//!
//! * The [`JsonMap`](json/type.JsonMap.html) type to hold the JSON data
//! * Conversion of your structures into a JSON map with
//! [`to_json_map`](json/fn.to_json_map.html)
//! (Your structure must implement serde serialization)
//! * Setter for manipulation
//! + [`set_json_bool_value`](json/fn.set_json_bool_value.html)
//! + [`set_json_num_value`](json/fn.set_json_num_value.html)
//! + [`set_json_str_value`](json/fn.set_json_str_value.html)
//! + [`set_json_str_arr_value`](json/fn.set_json_str_arr_value.html)
//! + [`set_json_arr_value`](json/fn.set_json_arr_value.html)
//! + [`set_json_obj_value`](json/fn.set_json_obj_value.html)
//! * Pretty printing with [`pprint_json`](json/fn.pprint_json.html)
//!
//! ## Request Building
//! Module: [`boomack::client::api::ClientRequest`](api/struct.ClientRequest.html)
//!
//! In order to send a request to the HTTP API you need to first build a request structure.
//! Every group of request has its own module with functions to create a request.
//! Usually a parameters structure is involved to hold some or all information for the request.
//!
//! * Display Request [`boomack::client::display`](display/)
//! + [`DisplayParameters`](display/struct.DisplayParameters.html)
//! + [`display_text_request`](display/fn.display_text_request.html)
//! + [`display_url_request`](display/fn.display_url_request.html)
//! + [`display_file_request`](display/fn.display_file_request.html)
//! + [`display_stdin_request`](display/fn.display_stdin_request.html)
//! * Evaluation Request [`boomack::client::eval`](eval/)
//! + [`EvalParameters`](eval/struct.EvalParameters.html)
//! + [`eval_file_request`](eval/fn.eval_file_request.html)
//! + [`eval_stdin_request`](eval/fn.eval_stdin_request.html)
//! + [`eval_text_request`](eval/fn.eval_text_request.html)
//! * Panel Management [`boomack::client::panels`](panels/)
//! + [`get_panel_ids_request`](panels/fn.get_panel_ids_request.html)
//! + [`get_panel_layout_request`](panels/fn.get_panel_layout_request.html)
//! + [`set_panel_layout_request`](panels/fn.set_panel_layout_request.html)
//! + [`delete_panel_request`](panels/fn.delete_panel_request.html)
//! * Preset Management [`boomack::client::presets`](presets/)
//! + [`get_preset_ids_request`](presets/fn.get_preset_ids_request.html)
//! + [`get_preset_layout_request`](presets/fn.get_preset_layout_request.html)
//! + [`set_preset_layout_request`](presets/fn.set_preset_layout_request.html)
//! + [`delete_preset_request`](presets/fn.delete_preset_request.html)
//! * Media Type Management [`boomack::client::types`](types/)
//! + [`get_type_ids_request`](types/fn.get_type_ids_request.html)
//! + [`get_type_layout_request`](types/fn.get_type_layout_request.html)
//! + [`set_type_layout_request`](types/fn.set_type_layout_request.html)
//! + [`delete_type_request`](types/fn.delete_type_request.html)
//! * Action Management [`boomack::client::actions`](actions/)
//! + [`get_action_ids_request`](actions/fn.get_action_ids_request.html)
//! + [`get_action_layout_request`](actions/fn.get_action_layout_request.html)
//! + [`set_action_layout_request`](actions/fn.set_action_layout_request.html)
//! + [`delete_action_request`](actions/fn.delete_action_request.html)
//! * Clearing Request
//! + [`boomack::client::panels::clear_panel_request`](panels/fn.clear_panel_request.html)
//! + [`boomack::client::slots::clear_slot_request`](slots/fn.clear_slot_request.html)
//! * Export Request
//! + [`boomack::client::panels::AllPanelExportParameters`](panels/struct.AllPanelExportParameters.html)
//! + [`boomack::client::panels::export_all_panels_request`](panels/fn.export_all_panels_request.html)
//! + [`boomack::client::panels::PanelExportParameters`](panels/struct.PanelExportParameters.html)
//! + [`boomack::client::panels::export_panel_request`](panels/fn.export_panel_request.html)
//! + [`boomack::client::slots::SlotExportParameters`](slots/struct.SlotExportParameters.html)
//! + [`boomack::client::slots::export_slot_request`](slots/fn.export_slot_request.html)
//!
//! ## Sending Request
//! Module: [`boomack::client::api`](api/)
//!
//! After a request was built, it is send to the server.
//! There are two alternative functions available.
//!
//! * [`send_request`](api/fn.send_request.html)
//! * [`send_request_with_retry`](api/fn.send_request_with_retry.html)
//!
//! # Example
//!
//! ```
//! use boomack::client::config::Config;
//! use boomack::client::json::*;
//! use boomack::client::display::{ DisplayParameters, display_text_request };
//! use boomack::client::api::{ ClientRequest, send_request };
//!
//! fn build_config() -> Config {
//! let mut cfg = Config::new();
//! // you can use different sources to set up the configuration
//! // start with the sources having the highest priority
//! // then fill gaps left from sources with lower priority
//!
//! // explicit configuration values, could come from command line arguments
//! cfg.client.format = Some(String::from("text/plain"));
//!
//! // usually environment variables are next in line
//! cfg.fill_gaps_with(&Config::from_env());
//!
//! // load one or more specific configuration file
//! //let config_files = vec![String::from("my-config-file.yaml")];
//! //cfg.load_unknown_config_files(&config_files);
//!
//! // load the default config files from user profile and current working directory:
//! // - boomack[.json|.yaml|.yml] from current working directory
//! // - .boomack[.json|.yaml|.yml] from user profile
//! // - boomack-server[.json|.yaml|.yml] from current working directory
//! // - .boomack-server[.json|.yaml|.yml] from user profile
//! cfg.load_known_config_files();
//!
//! // and at last, load the default media type mappings
//! cfg.load_default_media_types();
//!
//! return cfg;
//! }
//!
//! fn prepare_request() -> ClientRequest {
//! // prepare the display options
//! let mut display_options = JsonMap::new();
//! set_json_str_value(&mut display_options, "background", "#AAFFCC44");
//! set_json_bool_value(&mut display_options, "debug", false);
//!
//! // prepare display parameters with the display options
//! let display_params = DisplayParameters {
//! panel: Some("default"),
//! slot: None,
//! content_type: Some("text/markdown"),
//! title: Some("Example"),
//! presets: Vec::new(),
//! options: display_options,
//! };
//!
//! // create the request with some text content
//! let markdown = r##"
//! # Headline
//! Hello World!
//!
//! This is an example showing...
//!
//! * Request Configuration
//! * Display Options
//! * Display Parameters
//! * Sending the Request
//! "##;
//!
//! display_text_request(&display_params, markdown)
//! }
//!
//! fn main() {
//! // first prepare the configuration for HTTP requests
//! let cfg = build_config();
//!
//! // then build the client request
//! let mut request = prepare_request();
//!
//! // set the accepted response format from the configuration
//! request.set_header("Accept", cfg.client.get_format());
//!
//! // send the request
//! let result = send_request(&cfg, &request);
//!
//! // handle the result
//! match result {
//! Ok(response) => {
//! println!("STATUS: [{}] {}", response.status(), response.status_text());
//! if response.status() != 204 {
//! print!("RESPONSE:\n{}\n", response.into_string().unwrap());
//! }
//! },
//! Err(err) => {
//! println!("ERROR: {}", err.to_string());
//! },
//! };
//! }
//! ```