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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//! # NSURLRequest
//!
//! Incomplete bindings to `NSURLRequest`
//!
//! See <https://developer.apple.com/documentation/foundation/nsurlrequest>
use cocoa::base::id;
use cocoa::foundation::NSTimeInterval;

extern "C" {
    pub static NSURLRequest: id;
}

pub trait NSURLRequest: Sized {
    /// # Safety
    /// All the FFI functions are unsafe.
    unsafe fn alloc(_: Self) -> id {
        msg_send![class!(NSURLRequest), alloc]
    }

    // Creating Requests
    /// # Safety
    /// All the FFI functions are unsafe.
    unsafe fn requestWithURL_(_: Self, url: id) -> id;
    /// # Safety
    /// All the FFI functions are unsafe.
    unsafe fn initWithURL_(self, url: id) -> id;
    /// # Safety
    /// All the FFI functions are unsafe.
    unsafe fn requestWithURL_cachePolicy_timeoutInterval(
        _: Self,
        url: id,
        cachePolicy: id,
        timeoutInterval: NSTimeInterval,
    ) -> id;
    /// # Safety
    /// All the FFI functions are unsafe.
    unsafe fn initWithURL_cachePolicy_timeoutInterval(
        self,
        url: id,
        cachePolicy: id,
        timeoutInterval: NSTimeInterval,
    ) -> id;

    // TODO:
    // Working with a Cache Policy
    // Accessing Request Components
    // Getting Header Fields
    // Controlling Request Behavior
    // Accessing the Service Type
    // Supporting Secure Coding
}

impl NSURLRequest for id {
    // Creating Requests
    unsafe fn requestWithURL_(_: Self, url: id) -> id {
        msg_send![class!(NSURLRequest), requestWithURL_: url]
    }

    unsafe fn initWithURL_(self, url: id) -> id {
        msg_send![self, initWithURL: url]
    }

    unsafe fn requestWithURL_cachePolicy_timeoutInterval(
        _: Self,
        url: id,
        cachePolicy: id,
        timeoutInterval: NSTimeInterval,
    ) -> id {
        msg_send![
            class!(NSURLRequest),
            requestWithURL:url
                cachePolicy:cachePolicy
                timeoutInterval:timeoutInterval
        ]
    }

    unsafe fn initWithURL_cachePolicy_timeoutInterval(
        self,
        url: id,
        cachePolicy: id,
        timeoutInterval: NSTimeInterval,
    ) -> id {
        msg_send![
            self,
            initWithURL:url
                cachePolicy:cachePolicy
                timeoutInterval:timeoutInterval
        ]
    }

    // TODO:
    // Working with a Cache Policy
    // Accessing Request Components
    // Getting Header Fields
    // Controlling Request Behavior
    // Accessing the Service Type
    // Supporting Secure Coding
}