Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extern crate serde;
use serde::Deserialize;

extern crate reqwest;
use reqwest::{header, Client};
use reqwest::{header, Client, Proxy};

#[macro_use]
extern crate hyper;
Expand Down
21 changes: 17 additions & 4 deletions src/opencage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use std::collections::HashMap;
use super::reqwest;
use super::Deserialize;
use super::UA_STRING;
use super::{header, Client};
use super::{header, Client, Proxy};

use super::Point;
use super::{Forward, Reverse};
Expand All @@ -48,12 +48,25 @@ pub struct Opencage {
}

impl Opencage {
/// Create a new OpenCage geocoding instance

/// Create a new OpenCage geocoding
pub fn new(api_key: String) -> Self {
Opencage::new_with_proxy(api_key, None)
}

/// Create a new OpenCage geocoding instance with a proxy instance
pub fn new_with_proxy(api_key: String, proxy: Option<Proxy>) -> Self {
let mut headers = header::Headers::new();
headers.set(header::UserAgent::new(UA_STRING));
let client = Client::builder()
.default_headers(headers)
let mut client_builder = Client::builder();

client_builder.default_headers(headers);

if let Some(proxy) = proxy {
client_builder.proxy(proxy);
}

let client = client_builder
.build()
.expect("Couldn't build a client!");
Opencage {
Expand Down