Skip to content

Commit

Permalink
Add example for search
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaspustina committed May 16, 2019
1 parent 0bdd768 commit 53d141f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
28 changes: 28 additions & 0 deletions examples/search.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use centerdevice::client::{self, CenterDeviceConfig};
use centerdevice::client::search::NamedSearches;
use std::env;

fn main() {
let client_id = env::var_os("CENTERDEVICE_CLIENT_ID").expect("Environment variable 'CENTERDEVICE_CLIENT_ID' is not set.");
let client_secret = env::var_os("CENTERDEVICE_CLIENT_SECRET").expect("Environment variable 'CENTERDEVICE_CLIENT_SECRET' is not set.");
let access_token = env::var_os("CENTERDEVICE_ACCESS_TOKEN").expect("Environment variable 'CENTERDEVICE_ACCESS_TOKEN' is not set.");

let config = CenterDeviceConfig {
client_id: client_id.to_string_lossy().to_string(),
client_secret: client_secret.to_string_lossy().to_string(),
refresh_token: None,
access_token: access_token.to_string_lossy().to_string(),
api_base_url: "centerdevice.de".to_string()
};

let search_results= client::search::search_documents(
&config.api_base_url,
&config.access_token,
None,
None,
Some("centerdevice"),
NamedSearches::None
).expect("Search failed.");

println!("{}", search_results);
}
10 changes: 5 additions & 5 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ error_chain! {}

#[derive(Debug, Deserialize)]
pub struct CenterDeviceConfig {
client_id: String,
client_secret: String,
refresh_token: Option<String>,
access_token: Option<String>,
api_base_url: String,
pub client_id: String,
pub client_secret: String,
pub refresh_token: Option<String>,
pub access_token: String,
pub api_base_url: String,
}

fn prepare_request<'a, 'b>(client: &'a Client, method: Method, url: &'b str, token: String) -> Result<RequestBuilder<'a>> {
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use serde::Deserialize;

#[derive(Debug, Deserialize)]
pub struct GeneralConfig {
pub cache_dir: String,
pub output_format: bool,
pub verbosity: bool,
}
Expand Down

0 comments on commit 53d141f

Please sign in to comment.