Classes.ps1

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
class GraphBatch {
    [string]$id 
    [string]$method = "GET"
    [string]$url
    [PSCustomObject]$body
    [HashTable]$headers

    GraphBatch ([string]$url) {
        $this.url = $url.Replace("https://graph.microsoft.com/v1.0", "").Replace("https://graph.microsoft.com/beta", "").Replace("//", "/")
        $this.id = $this.url
    }
    GraphBatch ([string]$idOrMethod, [string]$url) {
        $this.url = $url.Replace("https://graph.microsoft.com/v1.0", "").Replace("https://graph.microsoft.com/beta", "").Replace("//", "/")
        if ($idOrMethod -in ("Default", "Delete", "Get", "Head", "Merge", "Options", "Patch", "Post", "Put")) { $this.Method = $idOrMethod.ToUpper() } else { $this.id = $idOrMethod }
    }
    GraphBatch ([string]$id, [string]$method, [string]$url) {
        if ($Method -notin ("Default", "Delete", "Get", "Head", "Merge", "Options", "Patch", "Post", "Put")) { Throw "Invalid Method" }
        $this.Method = $method.ToUpper()
        $this.id = $id
        $this.url = $url.Replace("https://graph.microsoft.com/v1.0", "").Replace("https://graph.microsoft.com/beta", "").Replace("//", "/")
    }
    GraphBatch ([string]$id, [string]$method, [string]$url, [HashTable]$headers) {
        if ($Method -notin ("Default", "Delete", "Get", "Head", "Merge", "Options", "Patch", "Post", "Put")) { Throw "Invalid Method" }
        $this.Method = $method.ToUpper()
        $this.id = $id
        $this.url = $url.Replace("https://graph.microsoft.com/v1.0", "").Replace("https://graph.microsoft.com/beta", "").Replace("//", "/")
        $this.headers = $headers
    }
    GraphBatch ([string]$id, [string]$method, [string]$url, [string]$body, [HashTable]$headers) {
        if ($Method -notin ("Default", "Delete", "Get", "Head", "Merge", "Options", "Patch", "Post", "Put")) { Throw "Invalid Method" }
        $this.Method = $method.ToUpper()
        $this.id = $id
        $this.url = $url.Replace("https://graph.microsoft.com/v1.0", "").Replace("https://graph.microsoft.com/beta", "").Replace("//", "/")
        $this.body = $body | ConvertFrom-Json
        $this.headers = $headers
        $this.headers."Content-Type" = "application/json"
    }
    GraphBatch ([string]$id, [string]$method, [string]$url, [PSCustomObject]$body, [HashTable]$headers) {
        if ($Method -notin ("Default", "Delete", "Get", "Head", "Merge", "Options", "Patch", "Post", "Put")) { Throw "Invalid Method" }
        $this.Method = $method.ToUpper()
        $this.id = $id
        $this.url = $url.Replace("https://graph.microsoft.com/v1.0", "").Replace("https://graph.microsoft.com/beta", "").Replace("//", "/")
        $this.body = $body
        $this.headers = $headers
        $this.headers."Content-Type" = "application/json"
    }
}