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
use objc::runtime::Object;
use objc::{msg_send, sel, sel_impl};
use objc_id::ShareId;
use crate::foundation::{id, NSString};
#[derive(Debug)]
pub struct URLRequest(ShareId<Object>);
impl URLRequest {
pub fn with(request: id) -> Self {
URLRequest(unsafe { ShareId::from_ptr(request) })
}
pub fn absolute_url(&self) -> String {
NSString::from_retained(unsafe {
let url: id = msg_send![&*self.0, URL];
msg_send![url, absoluteString]
})
.to_string()
}
}
#[cfg(test)]
mod tests {
use objc::{class, msg_send, sel, sel_impl};
use crate::foundation::{id, NSString};
use crate::networking::URLRequest;
#[test]
fn test_urlrequest() {
let endpoint = "https://rymc.io/";
let url = unsafe {
let url = NSString::new(endpoint);
let url: id = msg_send![class!(NSURL), URLWithString:&*url];
URLRequest::with(msg_send![class!(NSURLRequest), requestWithURL: url])
};
assert_eq!(&url.absolute_url(), endpoint);
}
}