ruby-jss 0.6.5 → 0.6.6

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ruby-jss might be problematic. Click here for more details.

Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +57 -5
  3. data/lib/jss.rb +78 -94
  4. data/lib/jss/api_connection.rb +8 -0
  5. data/lib/jss/api_object.rb +126 -102
  6. data/lib/jss/api_object/creatable.rb +33 -15
  7. data/lib/jss/api_object/distribution_point.rb +4 -1
  8. data/lib/jss/api_object/extension_attribute.rb +1 -1
  9. data/lib/jss/api_object/package.rb +121 -187
  10. data/lib/jss/api_object/policy.rb +590 -251
  11. data/lib/jss/api_object/script.rb +92 -128
  12. data/lib/jss/api_object/self_servable.rb +93 -117
  13. data/lib/jss/api_object/updatable.rb +12 -27
  14. data/lib/jss/api_object/uploadable.rb +12 -15
  15. data/lib/jss/client.rb +178 -156
  16. data/lib/jss/db_connection.rb +34 -49
  17. data/lib/jss/ruby_extensions/string.rb +25 -21
  18. data/lib/jss/version.rb +1 -1
  19. data/lib/jss/webhooks.rb +52 -0
  20. data/lib/jss/webhooks/README.md +269 -0
  21. data/lib/jss/webhooks/configuration.rb +212 -0
  22. data/lib/jss/webhooks/data/sample_handlers/RestAPIOperation-executable +90 -0
  23. data/lib/jss/webhooks/data/sample_handlers/RestAPIOperation.rb +44 -0
  24. data/lib/jss/webhooks/data/sample_jsons/ComputerAdded.json +27 -0
  25. data/lib/jss/webhooks/data/sample_jsons/ComputerCheckIn.json +27 -0
  26. data/lib/jss/webhooks/data/sample_jsons/ComputerInventoryCompleted.json +27 -0
  27. data/lib/jss/webhooks/data/sample_jsons/ComputerPolicyFinished.json +27 -0
  28. data/lib/jss/webhooks/data/sample_jsons/ComputerPushCapabilityChanged.json +27 -0
  29. data/lib/jss/webhooks/data/sample_jsons/JSSShutdown.json +14 -0
  30. data/lib/jss/webhooks/data/sample_jsons/JSSStartup.json +14 -0
  31. data/lib/jss/webhooks/data/sample_jsons/MobileDeviceCheckIn.json +26 -0
  32. data/lib/jss/webhooks/data/sample_jsons/MobileDeviceCommandCompleted.json +26 -0
  33. data/lib/jss/webhooks/data/sample_jsons/MobileDeviceEnrolled.json +26 -0
  34. data/lib/jss/webhooks/data/sample_jsons/MobileDevicePushSent.json +26 -0
  35. data/lib/jss/webhooks/data/sample_jsons/MobileDeviceUnEnrolled.json +26 -0
  36. data/lib/jss/webhooks/data/sample_jsons/PatchSoftwareTitleUpdated.json +14 -0
  37. data/lib/jss/webhooks/data/sample_jsons/PushSent.json +11 -0
  38. data/lib/jss/webhooks/data/sample_jsons/RestAPIOperation.json +15 -0
  39. data/lib/jss/webhooks/data/sample_jsons/SCEPChallenge.json +10 -0
  40. data/lib/jss/webhooks/data/sample_jsons/SmartGroupComputerMembershipChange.json +13 -0
  41. data/lib/jss/webhooks/data/sample_jsons/SmartGroupMobileDeviceMembershipChange.json +13 -0
  42. data/lib/jss/webhooks/event.rb +138 -0
  43. data/lib/jss/webhooks/event/computer_added.rb +37 -0
  44. data/lib/jss/webhooks/event/computer_check_in.rb +37 -0
  45. data/lib/jss/webhooks/event/computer_inventory_completed.rb +37 -0
  46. data/lib/jss/webhooks/event/computer_policy_finished.rb +37 -0
  47. data/lib/jss/webhooks/event/computer_push_capability_changed.rb +37 -0
  48. data/lib/jss/webhooks/event/handlers.rb +191 -0
  49. data/lib/jss/webhooks/event/jss_shutdown.rb +37 -0
  50. data/lib/jss/webhooks/event/jss_startup.rb +37 -0
  51. data/lib/jss/webhooks/event/mobile_device_check_in.rb +37 -0
  52. data/lib/jss/webhooks/event/mobile_device_command_completed.rb +37 -0
  53. data/lib/jss/webhooks/event/mobile_device_enrolled.rb +37 -0
  54. data/lib/jss/webhooks/event/mobile_device_push_sent.rb +37 -0
  55. data/lib/jss/webhooks/event/mobile_device_unenrolled.rb +37 -0
  56. data/lib/jss/webhooks/event/patch_software_title_updated.rb +37 -0
  57. data/lib/jss/webhooks/event/push_sent.rb +37 -0
  58. data/lib/jss/webhooks/event/rest_api_operation.rb +37 -0
  59. data/lib/jss/webhooks/event/scep_challenge.rb +37 -0
  60. data/lib/jss/webhooks/event/smart_group_computer_membership_change.rb +37 -0
  61. data/lib/jss/webhooks/event/smart_group_mobile_device_membership_change.rb +37 -0
  62. data/lib/jss/webhooks/event/webhook.rb +39 -0
  63. data/lib/jss/webhooks/event_objects.rb +111 -0
  64. data/lib/jss/webhooks/event_objects/computer.rb +48 -0
  65. data/lib/jss/webhooks/event_objects/jss.rb +35 -0
  66. data/lib/jss/webhooks/event_objects/mobile_device.rb +47 -0
  67. data/lib/jss/webhooks/event_objects/patch_software_title_update.rb +37 -0
  68. data/lib/jss/webhooks/event_objects/push.rb +32 -0
  69. data/lib/jss/webhooks/event_objects/rest_api_operation.rb +36 -0
  70. data/lib/jss/webhooks/event_objects/scep_challenge.rb +31 -0
  71. data/lib/jss/webhooks/event_objects/smart_group.rb +34 -0
  72. data/lib/jss/webhooks/server_app.rb +36 -0
  73. data/lib/jss/webhooks/server_app/routes.rb +26 -0
  74. data/lib/jss/webhooks/server_app/routes/handle_webhook_event.rb +38 -0
  75. data/lib/jss/webhooks/server_app/routes/home.rb +36 -0
  76. data/lib/jss/webhooks/server_app/self_signed_cert.rb +64 -0
  77. data/lib/jss/webhooks/server_app/server.rb +59 -0
  78. data/lib/jss/webhooks/version.rb +31 -0
  79. metadata +63 -4
@@ -0,0 +1,37 @@
1
+ ### Copyright 2016 Pixar
2
+ ###
3
+ ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
+ ### with the following modification; you may not use this file except in
5
+ ### compliance with the Apache License and the following modification to it:
6
+ ### Section 6. Trademarks. is deleted and replaced with:
7
+ ###
8
+ ### 6. Trademarks. This License does not grant permission to use the trade
9
+ ### names, trademarks, service marks, or product names of the Licensor
10
+ ### and its affiliates, except as required to comply with Section 4(c) of
11
+ ### the License and to reproduce the content of the NOTICE file.
12
+ ###
13
+ ### You may obtain a copy of the Apache License at
14
+ ###
15
+ ### http://www.apache.org/licenses/LICENSE-2.0
16
+ ###
17
+ ### Unless required by applicable law or agreed to in writing, software
18
+ ### distributed under the Apache License with the above modification is
19
+ ### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20
+ ### KIND, either express or implied. See the Apache License for the specific
21
+ ### language governing permissions and limitations under the Apache License.
22
+ ###
23
+ ###
24
+
25
+ module JSSWebHooks
26
+
27
+ class MobileDeviceCommandCompletedEvent < Event
28
+
29
+ EVENT_NAME = 'MobileDeviceCommandCompleted'.freeze
30
+ OBJECT_CLASS = JSSWebHooks::EventObjects::MobileDevice
31
+
32
+ end # class
33
+
34
+ # map the EVENT_NAME (which comes from the JSS) with this class
35
+ JSSWebHooks::Event.event_to_class_names[MobileDeviceCommandCompletedEvent::EVENT_NAME] = MobileDeviceCommandCompletedEvent
36
+
37
+ end # module
@@ -0,0 +1,37 @@
1
+ ### Copyright 2016 Pixar
2
+ ###
3
+ ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
+ ### with the following modification; you may not use this file except in
5
+ ### compliance with the Apache License and the following modification to it:
6
+ ### Section 6. Trademarks. is deleted and replaced with:
7
+ ###
8
+ ### 6. Trademarks. This License does not grant permission to use the trade
9
+ ### names, trademarks, service marks, or product names of the Licensor
10
+ ### and its affiliates, except as required to comply with Section 4(c) of
11
+ ### the License and to reproduce the content of the NOTICE file.
12
+ ###
13
+ ### You may obtain a copy of the Apache License at
14
+ ###
15
+ ### http://www.apache.org/licenses/LICENSE-2.0
16
+ ###
17
+ ### Unless required by applicable law or agreed to in writing, software
18
+ ### distributed under the Apache License with the above modification is
19
+ ### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20
+ ### KIND, either express or implied. See the Apache License for the specific
21
+ ### language governing permissions and limitations under the Apache License.
22
+ ###
23
+ ###
24
+
25
+ module JSSWebHooks
26
+
27
+ class MobileDeviceEnrolledEvent < Event
28
+
29
+ EVENT_NAME = 'MobileDeviceEnrolled'.freeze
30
+ OBJECT_CLASS = JSSWebHooks::EventObjects::MobileDevice
31
+
32
+ end # class
33
+
34
+ # map the EVENT_NAME (which comes from the JSS) with this class
35
+ JSSWebHooks::Event.event_to_class_names[MobileDeviceEnrolledEvent::EVENT_NAME] = MobileDeviceEnrolledEvent
36
+
37
+ end # module
@@ -0,0 +1,37 @@
1
+ ### Copyright 2016 Pixar
2
+ ###
3
+ ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
+ ### with the following modification; you may not use this file except in
5
+ ### compliance with the Apache License and the following modification to it:
6
+ ### Section 6. Trademarks. is deleted and replaced with:
7
+ ###
8
+ ### 6. Trademarks. This License does not grant permission to use the trade
9
+ ### names, trademarks, service marks, or product names of the Licensor
10
+ ### and its affiliates, except as required to comply with Section 4(c) of
11
+ ### the License and to reproduce the content of the NOTICE file.
12
+ ###
13
+ ### You may obtain a copy of the Apache License at
14
+ ###
15
+ ### http://www.apache.org/licenses/LICENSE-2.0
16
+ ###
17
+ ### Unless required by applicable law or agreed to in writing, software
18
+ ### distributed under the Apache License with the above modification is
19
+ ### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20
+ ### KIND, either express or implied. See the Apache License for the specific
21
+ ### language governing permissions and limitations under the Apache License.
22
+ ###
23
+ ###
24
+
25
+ module JSSWebHooks
26
+
27
+ class MobileDevicePushSentEvent < Event
28
+
29
+ EVENT_NAME = 'MobileDevicePushSent'.freeze
30
+ OBJECT_CLASS = JSSWebHooks::EventObjects::MobileDevice
31
+
32
+ end # class
33
+
34
+ # map the EVENT_NAME (which comes from the JSS) with this class
35
+ JSSWebHooks::Event.event_to_class_names[MobileDevicePushSentEvent::EVENT_NAME] = MobileDevicePushSentEvent
36
+
37
+ end # module
@@ -0,0 +1,37 @@
1
+ ### Copyright 2016 Pixar
2
+ ###
3
+ ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
+ ### with the following modification; you may not use this file except in
5
+ ### compliance with the Apache License and the following modification to it:
6
+ ### Section 6. Trademarks. is deleted and replaced with:
7
+ ###
8
+ ### 6. Trademarks. This License does not grant permission to use the trade
9
+ ### names, trademarks, service marks, or product names of the Licensor
10
+ ### and its affiliates, except as required to comply with Section 4(c) of
11
+ ### the License and to reproduce the content of the NOTICE file.
12
+ ###
13
+ ### You may obtain a copy of the Apache License at
14
+ ###
15
+ ### http://www.apache.org/licenses/LICENSE-2.0
16
+ ###
17
+ ### Unless required by applicable law or agreed to in writing, software
18
+ ### distributed under the Apache License with the above modification is
19
+ ### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20
+ ### KIND, either express or implied. See the Apache License for the specific
21
+ ### language governing permissions and limitations under the Apache License.
22
+ ###
23
+ ###
24
+
25
+ module JSSWebHooks
26
+
27
+ class MobileDeviceUnEnrolledEvent < Event
28
+
29
+ EVENT_NAME = 'MobileDeviceUnEnrolled'.freeze
30
+ OBJECT_CLASS = JSSWebHooks::EventObjects::MobileDevice
31
+
32
+ end # class
33
+
34
+ # map the EVENT_NAME (which comes from the JSS) with this class
35
+ JSSWebHooks::Event.event_to_class_names[MobileDeviceUnEnrolledEvent::EVENT_NAME] = MobileDeviceUnEnrolledEvent
36
+
37
+ end # module
@@ -0,0 +1,37 @@
1
+ ### Copyright 2016 Pixar
2
+ ###
3
+ ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
+ ### with the following modification; you may not use this file except in
5
+ ### compliance with the Apache License and the following modification to it:
6
+ ### Section 6. Trademarks. is deleted and replaced with:
7
+ ###
8
+ ### 6. Trademarks. This License does not grant permission to use the trade
9
+ ### names, trademarks, service marks, or product names of the Licensor
10
+ ### and its affiliates, except as required to comply with Section 4(c) of
11
+ ### the License and to reproduce the content of the NOTICE file.
12
+ ###
13
+ ### You may obtain a copy of the Apache License at
14
+ ###
15
+ ### http://www.apache.org/licenses/LICENSE-2.0
16
+ ###
17
+ ### Unless required by applicable law or agreed to in writing, software
18
+ ### distributed under the Apache License with the above modification is
19
+ ### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20
+ ### KIND, either express or implied. See the Apache License for the specific
21
+ ### language governing permissions and limitations under the Apache License.
22
+ ###
23
+ ###
24
+
25
+ module JSSWebHooks
26
+
27
+ class PatchSoftwareTitleUpdatedEvent < Event
28
+
29
+ EVENT_NAME = 'PatchSoftwareTitleUpdated'.freeze
30
+ OBJECT_CLASS = JSSWebHooks::EventObjects::PatchSoftwareTitleUpdate
31
+
32
+ end # class
33
+
34
+ # map the EVENT_NAME (which comes from the JSS) with this class
35
+ JSSWebHooks::Event.event_to_class_names[PatchSoftwareTitleUpdatedEvent::EVENT_NAME] = PatchSoftwareTitleUpdatedEvent
36
+
37
+ end # module
@@ -0,0 +1,37 @@
1
+ ### Copyright 2016 Pixar
2
+ ###
3
+ ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
+ ### with the following modification; you may not use this file except in
5
+ ### compliance with the Apache License and the following modification to it:
6
+ ### Section 6. Trademarks. is deleted and replaced with:
7
+ ###
8
+ ### 6. Trademarks. This License does not grant permission to use the trade
9
+ ### names, trademarks, service marks, or product names of the Licensor
10
+ ### and its affiliates, except as required to comply with Section 4(c) of
11
+ ### the License and to reproduce the content of the NOTICE file.
12
+ ###
13
+ ### You may obtain a copy of the Apache License at
14
+ ###
15
+ ### http://www.apache.org/licenses/LICENSE-2.0
16
+ ###
17
+ ### Unless required by applicable law or agreed to in writing, software
18
+ ### distributed under the Apache License with the above modification is
19
+ ### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20
+ ### KIND, either express or implied. See the Apache License for the specific
21
+ ### language governing permissions and limitations under the Apache License.
22
+ ###
23
+ ###
24
+
25
+ module JSSWebHooks
26
+
27
+ class PushSentEvent < Event
28
+
29
+ EVENT_NAME = 'PushSent'.freeze
30
+ OBJECT_CLASS = JSSWebHooks::EventObjects::Push
31
+
32
+ end # class
33
+
34
+ # map the EVENT_NAME (which comes from the JSS) with this class
35
+ JSSWebHooks::Event.event_to_class_names[PushSentEvent::EVENT_NAME] = PushSentEvent
36
+
37
+ end # module
@@ -0,0 +1,37 @@
1
+ ### Copyright 2016 Pixar
2
+ ###
3
+ ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
+ ### with the following modification; you may not use this file except in
5
+ ### compliance with the Apache License and the following modification to it:
6
+ ### Section 6. Trademarks. is deleted and replaced with:
7
+ ###
8
+ ### 6. Trademarks. This License does not grant permission to use the trade
9
+ ### names, trademarks, service marks, or product names of the Licensor
10
+ ### and its affiliates, except as required to comply with Section 4(c) of
11
+ ### the License and to reproduce the content of the NOTICE file.
12
+ ###
13
+ ### You may obtain a copy of the Apache License at
14
+ ###
15
+ ### http://www.apache.org/licenses/LICENSE-2.0
16
+ ###
17
+ ### Unless required by applicable law or agreed to in writing, software
18
+ ### distributed under the Apache License with the above modification is
19
+ ### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20
+ ### KIND, either express or implied. See the Apache License for the specific
21
+ ### language governing permissions and limitations under the Apache License.
22
+ ###
23
+ ###
24
+
25
+ module JSSWebHooks
26
+
27
+ class RestAPIOperationEvent < Event
28
+
29
+ EVENT_NAME = 'RestAPIOperation'.freeze
30
+ OBJECT_CLASS = JSSWebHooks::EventObjects::RestAPIOperation
31
+
32
+ end # class
33
+
34
+ # map the EVENT_NAME (which comes from the JSS) with this class
35
+ JSSWebHooks::Event.event_to_class_names[RestAPIOperationEvent::EVENT_NAME] = RestAPIOperationEvent
36
+
37
+ end # module
@@ -0,0 +1,37 @@
1
+ ### Copyright 2016 Pixar
2
+ ###
3
+ ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
+ ### with the following modification; you may not use this file except in
5
+ ### compliance with the Apache License and the following modification to it:
6
+ ### Section 6. Trademarks. is deleted and replaced with:
7
+ ###
8
+ ### 6. Trademarks. This License does not grant permission to use the trade
9
+ ### names, trademarks, service marks, or product names of the Licensor
10
+ ### and its affiliates, except as required to comply with Section 4(c) of
11
+ ### the License and to reproduce the content of the NOTICE file.
12
+ ###
13
+ ### You may obtain a copy of the Apache License at
14
+ ###
15
+ ### http://www.apache.org/licenses/LICENSE-2.0
16
+ ###
17
+ ### Unless required by applicable law or agreed to in writing, software
18
+ ### distributed under the Apache License with the above modification is
19
+ ### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20
+ ### KIND, either express or implied. See the Apache License for the specific
21
+ ### language governing permissions and limitations under the Apache License.
22
+ ###
23
+ ###
24
+
25
+ module JSSWebHooks
26
+
27
+ class SCEPChallengeEvent < Event
28
+
29
+ EVENT_NAME = 'SCEPChallenge'.freeze
30
+ OBJECT_CLASS = JSSWebHooks::EventObjects::SCEPChallenge
31
+
32
+ end # class
33
+
34
+ # map the EVENT_NAME (which comes from the JSS) with this class
35
+ JSSWebHooks::Event.event_to_class_names[SCEPChallengeEvent::EVENT_NAME] = SCEPChallengeEvent
36
+
37
+ end # module
@@ -0,0 +1,37 @@
1
+ ### Copyright 2016 Pixar
2
+ ###
3
+ ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
+ ### with the following modification; you may not use this file except in
5
+ ### compliance with the Apache License and the following modification to it:
6
+ ### Section 6. Trademarks. is deleted and replaced with:
7
+ ###
8
+ ### 6. Trademarks. This License does not grant permission to use the trade
9
+ ### names, trademarks, service marks, or product names of the Licensor
10
+ ### and its affiliates, except as required to comply with Section 4(c) of
11
+ ### the License and to reproduce the content of the NOTICE file.
12
+ ###
13
+ ### You may obtain a copy of the Apache License at
14
+ ###
15
+ ### http://www.apache.org/licenses/LICENSE-2.0
16
+ ###
17
+ ### Unless required by applicable law or agreed to in writing, software
18
+ ### distributed under the Apache License with the above modification is
19
+ ### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20
+ ### KIND, either express or implied. See the Apache License for the specific
21
+ ### language governing permissions and limitations under the Apache License.
22
+ ###
23
+ ###
24
+
25
+ module JSSWebHooks
26
+
27
+ class SmartGroupComputerMembershipChangeEvent < Event
28
+
29
+ EVENT_NAME = 'SmartGroupComputerMembershipChange'.freeze
30
+ OBJECT_CLASS = JSSWebHooks::EventObjects::SmartGroup
31
+
32
+ end # class
33
+
34
+ # map the EVENT_NAME (which comes from the JSS) with this class
35
+ JSSWebHooks::Event.event_to_class_names[SmartGroupComputerMembershipChangeEvent::EVENT_NAME] = SmartGroupComputerMembershipChangeEvent
36
+
37
+ end # module
@@ -0,0 +1,37 @@
1
+ ### Copyright 2016 Pixar
2
+ ###
3
+ ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
+ ### with the following modification; you may not use this file except in
5
+ ### compliance with the Apache License and the following modification to it:
6
+ ### Section 6. Trademarks. is deleted and replaced with:
7
+ ###
8
+ ### 6. Trademarks. This License does not grant permission to use the trade
9
+ ### names, trademarks, service marks, or product names of the Licensor
10
+ ### and its affiliates, except as required to comply with Section 4(c) of
11
+ ### the License and to reproduce the content of the NOTICE file.
12
+ ###
13
+ ### You may obtain a copy of the Apache License at
14
+ ###
15
+ ### http://www.apache.org/licenses/LICENSE-2.0
16
+ ###
17
+ ### Unless required by applicable law or agreed to in writing, software
18
+ ### distributed under the Apache License with the above modification is
19
+ ### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20
+ ### KIND, either express or implied. See the Apache License for the specific
21
+ ### language governing permissions and limitations under the Apache License.
22
+ ###
23
+ ###
24
+
25
+ module JSSWebHooks
26
+
27
+ class SmartGroupMobileDeviceMembershipChangeEvent < Event
28
+
29
+ EVENT_NAME = 'SmartGroupMobileDeviceMembershipChange'.freeze
30
+ OBJECT_CLASS = JSSWebHooks::EventObjects::SmartGroup
31
+
32
+ end # class
33
+
34
+ # map the EVENT_NAME (which comes from the JSS) with this class
35
+ JSSWebHooks::Event.event_to_class_names[SmartGroupMobileDeviceMembershipChangeEvent::EVENT_NAME] = SmartGroupMobileDeviceMembershipChangeEvent
36
+
37
+ end # module
@@ -0,0 +1,39 @@
1
+ ### Copyright 2016 Pixar
2
+ ###
3
+ ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
+ ### with the following modification; you may not use this file except in
5
+ ### compliance with the Apache License and the following modification to it:
6
+ ### Section 6. Trademarks. is deleted and replaced with:
7
+ ###
8
+ ### 6. Trademarks. This License does not grant permission to use the trade
9
+ ### names, trademarks, service marks, or product names of the Licensor
10
+ ### and its affiliates, except as required to comply with Section 4(c) of
11
+ ### the License and to reproduce the content of the NOTICE file.
12
+ ###
13
+ ### You may obtain a copy of the Apache License at
14
+ ###
15
+ ### http://www.apache.org/licenses/LICENSE-2.0
16
+ ###
17
+ ### Unless required by applicable law or agreed to in writing, software
18
+ ### distributed under the Apache License with the above modification is
19
+ ### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20
+ ### KIND, either express or implied. See the Apache License for the specific
21
+ ### language governing permissions and limitations under the Apache License.
22
+ ###
23
+ ###
24
+
25
+ module JSSWebHooks
26
+
27
+ class Event
28
+
29
+ WEBHOOK_ATTRIBUTES = [
30
+ :id,
31
+ :name,
32
+ :webhookEvent
33
+ ].freeze
34
+
35
+ WebHook = ImmutableStruct.new(*WEBHOOK_ATTRIBUTES)
36
+
37
+ end # class event
38
+
39
+ end # module
@@ -0,0 +1,111 @@
1
+ ### Copyright 2016 Pixar
2
+ ###
3
+ ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
+ ### with the following modification; you may not use this file except in
5
+ ### compliance with the Apache License and the following modification to it:
6
+ ### Section 6. Trademarks. is deleted and replaced with:
7
+ ###
8
+ ### 6. Trademarks. This License does not grant permission to use the trade
9
+ ### names, trademarks, service marks, or product names of the Licensor
10
+ ### and its affiliates, except as required to comply with Section 4(c) of
11
+ ### the License and to reproduce the content of the NOTICE file.
12
+ ###
13
+ ### You may obtain a copy of the Apache License at
14
+ ###
15
+ ### http://www.apache.org/licenses/LICENSE-2.0
16
+ ###
17
+ ### Unless required by applicable law or agreed to in writing, software
18
+ ### distributed under the Apache License with the above modification is
19
+ ### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20
+ ### KIND, either express or implied. See the Apache License for the specific
21
+ ### language governing permissions and limitations under the Apache License.
22
+ ###
23
+ ###
24
+
25
+ module JSSWebHooks
26
+
27
+ # Event Objects are JSON structures that come from the JSS
28
+ # with every webhook event. They represent the object that was affected
29
+ # by the event. For example, A ComputerAdded event affects
30
+ # a computer, and a RestAPIOperation event affects a REST API
31
+ # object.
32
+ #
33
+ # Since these Event Objects are mostly just short-lived static data
34
+ # they don't need to be represented full-blown Classes, but they would
35
+ # be nicer to work with if they weren't just Hashes.
36
+ #
37
+ # Ruby's Struct class provides a handy way to create something that's
38
+ # more than a Hash but less than a full Class. Unfortuantely, Struct-
39
+ # derived classes are fully mutable, and require positional parameters
40
+ # when creating instances.
41
+ #
42
+ # The ImmutableStruct class, provided by the immutable-struct gem,
43
+ # (https://github.com/stitchfix/immutable-struct)
44
+ # creates classes whose instances have immutable attributes, but allow
45
+ # (nay, require) named parameters when creating instances.
46
+ #
47
+ # This module dynamically creates ImmutableStruct classes for the various
48
+ # Event Objects that come with each webhook event. Each Event Objects class
49
+ # is defined in the @object_definitions Hash, which is accessible via the
50
+ # JSSWebHooks::EventObjects::object_definitions method.
51
+ #
52
+ # Each object is defined in that Hash thus:
53
+ #
54
+ # Key: Symbol, the name of the object e.g. :computer
55
+ # Value: Hash, the attributes and other data for created the object's Class
56
+ #
57
+ # The value hash has these keys:
58
+ #
59
+ # :class_name => String, the name of the ImmutableStruct Class for this
60
+ # object, e.g. "Computer"
61
+ # :attributes => Array[<Symbol>], The instance-attributes for the Class, to
62
+ # be passed in as the keys of a hash when creating an instance.
63
+ # :methods => Array[<Hash>], if any methods are needed for the Class, other
64
+ # than the default getters for the attributes, each Hash in this array
65
+ # defines one. The :name key contains a symbol, the name of the method,
66
+ # and the :proc key contains a Proc object, the method code. See
67
+ # JSSWebHooks::EventObjects.object_definitions[:patch_software_title_update]
68
+ # for an example.
69
+ #
70
+ module EventObjects
71
+
72
+ # This will hold the object definitions for each Event Object
73
+ # it will be populated by the require statements below.
74
+ @object_definitions = {}
75
+
76
+ # Access to the Module-instance var @object_definitions
77
+ #
78
+ # @return [Hash] the @object_definitions Hash
79
+ #
80
+ def self.object_definitions
81
+ @object_definitions
82
+ end
83
+
84
+ # load in the definitions of the Event Objects
85
+ Pathname.new(__FILE__).parent.+('event_objects').children.each do |file|
86
+ require file.to_s if file.extname == '.rb'
87
+ end
88
+
89
+ # loop thru the event object definitions,
90
+ # creating a class for each, via ImmutableStruct
91
+ @object_definitions.each do |_object_key, object_def|
92
+ new_class = ImmutableStruct.new(*object_def[:attributes]) do
93
+ # Class Method to return the list of attributes for this class
94
+ @attributes = object_def[:attributes]
95
+ def self.attributes
96
+ @attributes
97
+ end
98
+
99
+ # if any non-getter methods are needed for this class,
100
+ # create them here
101
+ object_def[:methods].to_a.each do |meth|
102
+ next unless meth[:name] && meth[:proc]
103
+ define_method meth[:name], meth[:proc]
104
+ end
105
+ end
106
+ const_set object_def[:class_name], new_class
107
+ end # @object_definitions.each
108
+
109
+ end # module event object
110
+
111
+ end # module