2020-02-28 13:34:34 +11:00
|
|
|
//! A lightweight wrapper over some networking components, like `NSURLRequest` and co.
|
|
|
|
//! This is currently not meant to be exhaustive.
|
|
|
|
|
2020-03-01 10:34:07 +11:00
|
|
|
use objc::{msg_send, sel, sel_impl};
|
2020-02-28 13:34:34 +11:00
|
|
|
use objc::runtime::Object;
|
2020-03-18 10:55:09 +11:00
|
|
|
use objc_id::Id;
|
2020-02-28 13:34:34 +11:00
|
|
|
|
2020-03-18 10:55:09 +11:00
|
|
|
use crate::foundation::{id, NSString};
|
2020-02-28 13:34:34 +11:00
|
|
|
|
2020-03-21 12:37:00 +11:00
|
|
|
#[derive(Debug)]
|
2020-02-28 13:34:34 +11:00
|
|
|
pub struct URLRequest {
|
|
|
|
pub inner: Id<Object>
|
|
|
|
}
|
|
|
|
|
|
|
|
impl URLRequest {
|
|
|
|
pub fn with(inner: id) -> Self {
|
|
|
|
URLRequest {
|
|
|
|
inner: unsafe { Id::from_ptr(inner) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn url(&self) -> &'static str {
|
2020-03-18 10:55:09 +11:00
|
|
|
NSString::wrap(unsafe {
|
2020-02-28 13:34:34 +11:00
|
|
|
let url: id = msg_send![&*self.inner, URL];
|
2020-03-18 10:55:09 +11:00
|
|
|
msg_send![url, absoluteString]
|
|
|
|
}).to_str()
|
2020-02-28 13:34:34 +11:00
|
|
|
}
|
|
|
|
}
|