-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom Client Constructors #43
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -232,6 +232,50 @@ impl YahooConnector { | |
search_url: YSEARCH_URL, | ||
} | ||
} | ||
|
||
/// Constructs a new instance of the object. | ||
/// | ||
/// # Parameters | ||
/// - `url`: Proxy url | ||
/// - `auth`: Opt(username, password) | ||
/// # Example | ||
/// ``` | ||
/// use yahoo_finance_api as yf; | ||
/// let instance = yf::YahooConnector::new_w_proxy( | ||
/// "https://secure.example", | ||
/// Some(("user123", "password123")) | ||
/// ); | ||
/// ``` | ||
pub fn new_w_proxy(url: &str, auth: Option<(&str, &str)>) -> Result<Self, YahooError> { | ||
let client = if auth.is_some() { | ||
let auth = auth.expect("Conditioned"); | ||
let proxy = reqwest::Proxy::all(url)? | ||
.basic_auth(auth.0, auth.1); | ||
|
||
reqwest::Client::builder() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
.proxy(proxy) | ||
.build()? | ||
} else { | ||
reqwest::Client::builder() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
.proxy(reqwest::Proxy::all(url)?) | ||
.build()? | ||
}; | ||
|
||
Ok(YahooConnector { | ||
client, | ||
url: YCHART_URL, | ||
search_url: YSEARCH_URL, | ||
}) | ||
|
||
} | ||
|
||
pub fn new_w_client(client: Client) -> Self { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a comment here. |
||
YahooConnector { | ||
client, | ||
url: YCHART_URL, | ||
search_url: YSEARCH_URL, | ||
} | ||
} | ||
|
||
pub fn builder() -> YahooConnectorBuilder { | ||
YahooConnectorBuilder { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, use something like
.map_err(...)?
instead. It is no good practice to let a library panic.