@@ -24,37 +24,70 @@ public protocol ParseHookTriggerable: ParseHookable {
24
24
25
25
// MARK: Default Implementation
26
26
public extension ParseHookTriggerable {
27
+
27
28
/**
28
29
Creates a new Parse hook trigger.
29
30
- parameter className: The name of the `ParseObject` the trigger should act on.
30
- - parameter triggerName : The `ParseHookTriggerType` type.
31
+ - parameter trigger : The `ParseHookTriggerType` type.
31
32
- parameter url: The endpoint of the hook.
32
33
*/
33
- init ( className: String , triggerName : ParseHookTriggerType , url: URL ) {
34
+ init ( className: String , trigger : ParseHookTriggerType , url: URL ) {
34
35
self . init ( )
35
36
self . className = className
36
- self . triggerName = triggerName
37
+ self . triggerName = trigger
37
38
self . url = url
38
39
}
39
40
41
+ /**
42
+ Creates a new Parse hook trigger.
43
+ - parameter className: The name of the `ParseObject` the trigger should act on.
44
+ - parameter triggerName: The `ParseHookTriggerType` type.
45
+ - parameter url: The endpoint of the hook.
46
+ */
47
+ @available ( * , deprecated, message: " Change \" triggerName \" to \" trigger \" " )
48
+ init ( className: String , triggerName: ParseHookTriggerType , url: URL ) {
49
+ self . init ( className: className, trigger: triggerName, url: url)
50
+ }
51
+
52
+ /**
53
+ Creates a new Parse hook trigger.
54
+ - parameter object: The `ParseObject` the trigger should act on.
55
+ - parameter trigger: The `ParseHookTriggerType` type.
56
+ - parameter url: The endpoint of the hook.
57
+ */
58
+ init < T> ( object: T . Type , trigger: ParseHookTriggerType , url: URL ) where T: ParseObject {
59
+ self . init ( className: object. className, trigger: trigger, url: url)
60
+ }
61
+
62
+ /**
63
+ Creates a new Parse hook trigger.
64
+ - parameter object: The `ParseObject` the trigger should act on.
65
+ - parameter trigger: The `ParseHookTriggerType` type.
66
+ - parameter url: The endpoint of the hook.
67
+ */
68
+ init < T> ( object: T , trigger: ParseHookTriggerType , url: URL ) where T: ParseObject {
69
+ self . init ( className: T . className, trigger: trigger, url: url)
70
+ }
71
+
40
72
/**
41
73
Creates a new Parse hook trigger.
42
74
- parameter object: The `ParseObject` the trigger should act on.
43
75
- parameter triggerName: The `ParseHookTriggerType` type.
44
76
- parameter url: The endpoint of the hook.
45
77
*/
78
+ @available ( * , deprecated, message: " Change \" triggerName \" to \" trigger \" " )
46
79
init < T> ( object: T , triggerName: ParseHookTriggerType , url: URL ) where T: ParseObject {
47
- self . init ( className : T . className , triggerName : triggerName, url: url)
80
+ self . init ( object : object , trigger : triggerName, url: url)
48
81
}
49
82
50
83
/**
51
84
Creates a new `ParseFile` or `ParseHookTriggerType.beforeConnect` hook trigger.
52
- - parameter triggerName : The `ParseHookTriggerType` type.
85
+ - parameter trigger : The `ParseHookTriggerType` type.
53
86
- parameter url: The endpoint of the hook.
54
87
*/
55
- init ( triggerName : ParseHookTriggerType , url: URL ) throws {
88
+ init ( trigger : ParseHookTriggerType , url: URL ) throws {
56
89
self . init ( )
57
- self . triggerName = triggerName
90
+ self . triggerName = trigger
58
91
self . url = url
59
92
switch triggerName {
60
93
case . beforeSave, . afterSave, . beforeDelete, . afterDelete:
@@ -66,23 +99,46 @@ public extension ParseHookTriggerable {
66
99
message: " This initializer should only be used for \" ParseFile \" and \" beforeConnect \" " )
67
100
}
68
101
}
102
+
103
+ /**
104
+ Creates a new `ParseFile` or `ParseHookTriggerType.beforeConnect` hook trigger.
105
+ - parameter triggerName: The `ParseHookTriggerType` type.
106
+ - parameter url: The endpoint of the hook.
107
+ */
108
+ @available ( * , deprecated, message: " Change \" triggerName \" to \" trigger \" " )
109
+ init ( triggerName: ParseHookTriggerType , url: URL ) throws {
110
+ try self . init ( trigger: triggerName, url: url)
111
+ }
112
+
69
113
}
70
114
115
+ /// A type of request for Parse Hook Triggers.
71
116
public struct TriggerRequest : Encodable {
72
117
let className : String
73
- let triggerName : ParseHookTriggerType
118
+ let trigger : ParseHookTriggerType
74
119
let url : URL ?
75
120
76
- init < T> ( trigger: T ) throws where T: ParseHookTriggerable {
121
+ /**
122
+ Creates an instance.
123
+ - parameter trigger: A type that conforms to `ParseHookTriggerable`.
124
+ - throws: An error of `ParseError` type.
125
+ */
126
+ public init < T> ( trigger: T ) throws where T: ParseHookTriggerable {
77
127
guard let className = trigger. className,
78
- let triggerName = trigger. triggerName else {
128
+ let triggerType = trigger. triggerName else {
79
129
throw ParseError ( code: . otherCause,
80
130
message: " The \" className \" and \" triggerName \" needs to be set: \( trigger) " )
81
131
}
82
132
self . className = className
83
- self . triggerName = triggerName
133
+ self . trigger = triggerType
84
134
self . url = trigger. url
85
135
}
136
+
137
+ enum CodingKeys : String , CodingKey {
138
+ case className
139
+ case trigger = " triggerName "
140
+ case url
141
+ }
86
142
}
87
143
88
144
// MARK: Fetch
0 commit comments