gitlab_support_readiness 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/lib/support_readiness/client.rb +108 -0
  3. data/lib/support_readiness/gitlab/client.rb +64 -0
  4. data/lib/support_readiness/gitlab/configuration.rb +46 -0
  5. data/lib/support_readiness/gitlab/groups.rb +180 -0
  6. data/lib/support_readiness/gitlab/issues.rb +410 -0
  7. data/lib/support_readiness/gitlab/namespaces.rb +190 -0
  8. data/lib/support_readiness/gitlab/projects.rb +510 -0
  9. data/lib/support_readiness/gitlab/repositories.rb +267 -0
  10. data/lib/support_readiness/gitlab/users.rb +488 -0
  11. data/lib/support_readiness/gitlab.rb +19 -0
  12. data/lib/support_readiness/pagerduty/client.rb +66 -0
  13. data/lib/support_readiness/pagerduty/configuration.rb +43 -0
  14. data/lib/support_readiness/pagerduty/escalation_policies.rb +123 -0
  15. data/lib/support_readiness/pagerduty/schedules.rb +223 -0
  16. data/lib/support_readiness/pagerduty/services.rb +132 -0
  17. data/lib/support_readiness/pagerduty.rb +16 -0
  18. data/lib/support_readiness/redis.rb +90 -0
  19. data/lib/support_readiness/zendesk/articles.rb +210 -0
  20. data/lib/support_readiness/zendesk/automations.rb +304 -0
  21. data/lib/support_readiness/zendesk/client.rb +84 -0
  22. data/lib/support_readiness/zendesk/configuration.rb +49 -0
  23. data/lib/support_readiness/zendesk/group_memberships.rb +256 -0
  24. data/lib/support_readiness/zendesk/groups.rb +249 -0
  25. data/lib/support_readiness/zendesk/job_statuses.rb +188 -0
  26. data/lib/support_readiness/zendesk/macros.rb +267 -0
  27. data/lib/support_readiness/zendesk/organization_fields.rb +233 -0
  28. data/lib/support_readiness/zendesk/organization_memberships.rb +257 -0
  29. data/lib/support_readiness/zendesk/organizations.rb +515 -0
  30. data/lib/support_readiness/zendesk/roles.rb +194 -0
  31. data/lib/support_readiness/zendesk/search.rb +159 -0
  32. data/lib/support_readiness/zendesk/sla_policies.rb +232 -0
  33. data/lib/support_readiness/zendesk/ticket_fields.rb +222 -0
  34. data/lib/support_readiness/zendesk/ticket_forms.rb +290 -0
  35. data/lib/support_readiness/zendesk/tickets.rb +854 -0
  36. data/lib/support_readiness/zendesk/triggers.rb +269 -0
  37. data/lib/support_readiness/zendesk/users.rb +946 -0
  38. data/lib/support_readiness/zendesk/views.rb +469 -0
  39. data/lib/support_readiness/zendesk.rb +31 -0
  40. data/lib/support_readiness.rb +29 -0
  41. metadata +215 -0
@@ -0,0 +1,194 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module Readiness.
4
+ module Readiness
5
+ # Defines the module Zendesk
6
+ module Zendesk
7
+ ##
8
+ # Defines the class Roles within the module {Readiness::Zendesk}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ class Roles < Readiness::Client
13
+ attr_accessor :configuration, :description, :id, :name, :role_type, :team_member_count
14
+
15
+ ##
16
+ # Creates a new {Readiness::Zendesk::Roles} instance
17
+ #
18
+ # @author Jason Colyer
19
+ # @since 1.0.0
20
+ # @param object [Object] An instance of {Readiness::Zendesk::Roles}
21
+ # @example
22
+ # require 'support_readiness'
23
+ # Readiness::Zendesk::Roles.new
24
+ def initialize(object = {})
25
+ @configuration = object['configuration']
26
+ @description = object['description']
27
+ @id = object['id']
28
+ @name = object['name']
29
+ @role_type = object['role_type']
30
+ @team_member_count = object['team_member_count']
31
+ end
32
+
33
+ ##
34
+ # Lists the Custom Roles
35
+ #
36
+ # @author Jason Colyer
37
+ # @since 1.0.0
38
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
39
+ # @return [Array]
40
+ # @see https://developer.zendesk.com/api-reference/ticketing/account-configuration/custom_roles/#list-custom-roles Zendesk API > Custom Roles > List Custom Roles
41
+ # @example
42
+ # require 'support_readiness'
43
+ # config = Readiness::Zendesk::Configuration.new
44
+ # config.username = 'alice@example.com'
45
+ # config.token = 'test123abc'
46
+ # config.url = 'https://example.zendesk.com/api/v2'
47
+ # client = Readiness::Zendesk::Client.new(config)
48
+ # roles = Readiness::Zendesk::Roles.list(client)
49
+ # pp roles.first.configuration['end_user_profile_access']
50
+ # # => "readonly"
51
+ def self.list(client)
52
+ response = client.connection.get('custom_roles/')
53
+ handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
54
+ Oj.load(response.body)['custom_roles'].map { |s| Roles.new(s) }
55
+ end
56
+
57
+ ##
58
+ # Locates a Custom Role within Zendesk. This will not exit on error (except Authentication errors)
59
+ #
60
+ # @author Jason Colyer
61
+ # @since 1.0.0
62
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
63
+ # @param rid [Integer] The Custom Role ID to find
64
+ # @return [Hash]
65
+ # @see https:/developer.zendesk.com/api-reference/ticketing/account-configuration/custom_roles/#show-custom-role Zendesk API > Custom Roles > Show Custom Role
66
+ # @example
67
+ # require 'support_readiness'
68
+ # config = Readiness::Zendesk::Configuration.new
69
+ # config.username = 'alice@example.com'
70
+ # config.token = 'test123abc'
71
+ # config.url = 'https://example.zendesk.com/api/v2'
72
+ # client = Readiness::Zendesk::Client.new(config)
73
+ # role = Readiness::Zendesk::Roles.find(client, 10127)
74
+ # pp role.team_member_count
75
+ # # => 10
76
+ def self.find(client, rid)
77
+ response = client.connection.get("custom_roles/#{rid}")
78
+ handle_request_error(0, 'Zendesk', response.status, { action: 'get', id: rid }) unless response.status == 200
79
+ return Roles.new(Oj.load(response.body)['custom_role']) if response.status == 200
80
+
81
+ Oj.load(response.body)
82
+ end
83
+
84
+ ##
85
+ # Locates a Custom Role within within Zendesk. This will exit on error
86
+ #
87
+ # @author Jason Colyer
88
+ # @since 1.0.0
89
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
90
+ # @param rid [Integer] The Custom Role ID to find
91
+ # @return [Object] An instance of {Readiness::Zendesk::Roles}
92
+ # @see https:/developer.zendesk.com/api-reference/ticketing/account-configuration/custom_roles/#show-custom-role Zendesk API > Custom Roles > Show Custom Role
93
+ # @example
94
+ # require 'support_readiness'
95
+ # config = Readiness::Zendesk::Configuration.new
96
+ # config.username = 'alice@example.com'
97
+ # config.token = 'test123abc'
98
+ # config.url = 'https://example.zendesk.com/api/v2'
99
+ # client = Readiness::Zendesk::Client.new(config)
100
+ # role = Readiness::Zendesk::Roles.find!(client, 10127)
101
+ # pp role.team_member_count
102
+ # # => 10
103
+ def self.find!(client, rid)
104
+ response = client.connection.get("custom_roles/#{rid}")
105
+ handle_request_error(1, 'Zendesk', response.status, { action: 'Find Custom Role', id: rid }) unless response.status == 200
106
+ Roles.new(Oj.load(response.body)['custom_role'])
107
+ end
108
+
109
+ ##
110
+ # Creates a Custom Role. Will exit if unsuccessful
111
+ #
112
+ # @author Jason Colyer
113
+ # @since 1.0.0
114
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
115
+ # @param role [Object] An instance of {Readiness::Zendesk::Roles}
116
+ # @return [Object] An instance of {Readiness::Zendesk::Roles}
117
+ # @see https:/developer.zendesk.com/api-reference/ticketing/account-configuration/custom_roles/#create-custom-role Zendesk API > Custom Roles > Create Custom Role
118
+ # @example
119
+ # require 'support_readiness'
120
+ # config = Readiness::Zendesk::Configuration.new
121
+ # config.username = 'alice@example.com'
122
+ # config.token = 'test123abc'
123
+ # config.url = 'https://example.zendesk.com/api/v2'
124
+ # client = Readiness::Zendesk::Client.new(config)
125
+ # orig_role = Readiness::Zendesk::Roles.find!(client, 10127)
126
+ # new_role = Readiness::Zendesk::Roles.new
127
+ # new_role.configuration = orig_role.configuration
128
+ # new_role.configuration['explore_access'] = 'edit'
129
+ # new_role.description = 'sample description'
130
+ # new_role.name = 'sample role'
131
+ # create = Readiness::Zendesk::Roles.create!(client, new_role)
132
+ # pp create.id
133
+ # # => 10127
134
+ def self.create!(client, role)
135
+ response = client.connection.post 'custom_roles/', to_clean_json_with_key(role, 'custom_role')
136
+ handle_request_error(1, 'Zendesk', response.status, { action: 'Create Custom Role', message: Oj.load(response.body)}) unless response.status == 201
137
+ Roles.new(Oj.load(response.body)['custom_role'])
138
+ end
139
+
140
+ ##
141
+ # Updates a Custom Role. Will exit if unsuccessful
142
+ #
143
+ # @author Jason Colyer
144
+ # @since 1.0.0
145
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
146
+ # @param role [Object] An instance of {Readiness::Zendesk::Roles}
147
+ # @return [Object] An instance of {Readiness::Zendesk::Roles}
148
+ # @see https:/developer.zendesk.com/api-reference/ticketing/account-configuration/custom_roles/#update-custom-role Zendesk API > Custom Roles > Update Custom Role
149
+ # @example
150
+ # require 'support_readiness'
151
+ # config = Readiness::Zendesk::Configuration.new
152
+ # config.username = 'alice@example.com'
153
+ # config.token = 'test123abc'
154
+ # config.url = 'https://example.zendesk.com/api/v2'
155
+ # client = Readiness::Zendesk::Client.new(config)
156
+ # role = Readiness::Zendesk::Roles.find!(client, 10127)
157
+ # role.configuration['explore_access'] = 'edit'
158
+ # update = Readiness::Zendesk::Roles.update!(client, role)
159
+ # pp update.configuration['explore_access']
160
+ # # => "edit"
161
+ def self.update!(client, role)
162
+ response = client.connection.put "custom_roles/#{role.id}", to_clean_json_with_key(role, 'custom_role')
163
+ handle_request_error(1, 'Zendesk', response.status, { action: 'Update Custom Role', id: role.id, message: Oj.load(response.body)}) unless response.status == 200
164
+ Roles.new(Oj.load(response.body)['custom_role'])
165
+ end
166
+
167
+ ##
168
+ # Deletes a Custom Role. Will exit if unsuccessful
169
+ #
170
+ # @author Jason Colyer
171
+ # @since 1.0.0
172
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
173
+ # @param role [Object] An instance of {Readiness::Zendesk::Roles}
174
+ # @return [Boolean]
175
+ # @see https:/developer.zendesk.com/api-reference/ticketing/account-configuration/custom_roles/#delete-custom-role Zendesk API > Custom Roles > Delete Custom Role
176
+ # @example
177
+ # require 'support_readiness'
178
+ # config = Readiness::Zendesk::Configuration.new
179
+ # config.username = 'alice@example.com'
180
+ # config.token = 'test123abc'
181
+ # config.url = 'https://example.zendesk.com/api/v2'
182
+ # client = Readiness::Zendesk::Client.new(config)
183
+ # role = Readiness::Zendesk::Roles.find!(client, 10127)
184
+ # delete = Readiness::Zendesk::Roles.delete!(client, role)
185
+ # pp delete
186
+ # # => true
187
+ def self.delete!(client, role)
188
+ response = client.connection.delete "custom_roles/#{role.id}"
189
+ handle_request_error(1, 'Zendesk', response.status, { action: 'Delete a Custom Role', id: role.id, message: Oj.load(response.body)}) unless response.status == 204
190
+ true
191
+ end
192
+ end
193
+ end
194
+ end
@@ -0,0 +1,159 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module Readiness.
4
+ module Readiness
5
+ # Defines the module Zendesk
6
+ module Zendesk
7
+ ##
8
+ # Defines the class Search within the module {Readiness::Zendesk}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ class Search < Readiness::Client
13
+ ##
14
+ # A wrapper for {Readiness::Zendesk::Search#search} that specifies to use type:ticket
15
+ #
16
+ # @author Jason Colyer
17
+ # @since 1.0.0
18
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
19
+ # @param query [String] The query String to use
20
+ # @return [Array]
21
+ # @see https://developer.zendesk.com/api-reference/ticketing/ticket-management/search/#list-search-results Zendesk API > Search > List Search Results
22
+ # @example
23
+ # require 'support_readiness'
24
+ # config = Readiness::Zendesk::Configuration.new
25
+ # config.username = 'alice@example.com'
26
+ # config.token = 'test123abc'
27
+ # config.url = 'https://example.zendesk.com/api/v2'
28
+ # client = Readiness::Zendesk::Client.new(config)
29
+ # search = Readiness::Zendesk::Search.tickets(client, 'custom_field_360018253094:americas__usa tags:ultimate satisfaction:badwithcomment')
30
+ # pp search.first.id
31
+ # # => 125834
32
+ def self.tickets(client, query)
33
+ search(client, 'ticket', query)
34
+ end
35
+
36
+ ##
37
+ # A wrapper for {Readiness::Zendesk::Search#search} that specifies to use type:user
38
+ #
39
+ # @author Jason Colyer
40
+ # @since 1.0.0
41
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
42
+ # @param query [String] The query String to use
43
+ # @return [Array]
44
+ # @see https://developer.zendesk.com/api-reference/ticketing/ticket-management/search/#list-search-results Zendesk API > Search > List Search Results
45
+ # @example
46
+ # require 'support_readiness'
47
+ # config = Readiness::Zendesk::Configuration.new
48
+ # config.username = 'alice@example.com'
49
+ # config.token = 'test123abc'
50
+ # config.url = 'https://example.zendesk.com/api/v2'
51
+ # client = Readiness::Zendesk::Client.new(config)
52
+ # search = Readiness::Zendesk::Search.users(client, 'email:alice@example.com')
53
+ # pp search.first.name
54
+ # # => "Alice Example"
55
+ def self.users(client, query)
56
+ search(client, 'user', query)
57
+ end
58
+
59
+ ##
60
+ # A wrapper for {Readiness::Zendesk::Search#search} that specifies to use type:organization
61
+ #
62
+ # @author Jason Colyer
63
+ # @since 1.0.0
64
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
65
+ # @param query [String] The query String to use
66
+ # @return [Array]
67
+ # @see https://developer.zendesk.com/api-reference/ticketing/ticket-management/search/#list-search-results Zendesk API > Search > List Search Results
68
+ # @example
69
+ # require 'support_readiness'
70
+ # config = Readiness::Zendesk::Configuration.new
71
+ # config.username = 'alice@example.com'
72
+ # config.token = 'test123abc'
73
+ # config.url = 'https://example.zendesk.com/api/v2'
74
+ # client = Readiness::Zendesk::Client.new(config)
75
+ # search = Readiness::Zendesk::Search.organzations(client, 'salesforce_id:ABCDEFGH0123456*')
76
+ # pp search.first.notes
77
+ # # => "This org is escalated. Please talk to support managers."
78
+ def self.organizations(client, query)
79
+ search(client, 'organization', query)
80
+ end
81
+
82
+ ##
83
+ # A wrapper for {Readiness::Zendesk::Search#search} that specifies to use type:group
84
+ #
85
+ # @author Jason Colyer
86
+ # @since 1.0.0
87
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
88
+ # @param query [String] The query String to use
89
+ # @return [Array]
90
+ # @see https://developer.zendesk.com/api-reference/ticketing/ticket-management/search/#list-search-results Zendesk API > Search > List Search Results
91
+ # @see https://developer.zendesk.com/api-reference/ticketing/ticket-management/search/#list-search-results Zendesk API > Search > List Search Results
92
+ # @example
93
+ # require 'support_readiness'
94
+ # config = Readiness::Zendesk::Configuration.new
95
+ # config.username = 'alice@example.com'
96
+ # config.token = 'test123abc'
97
+ # config.url = 'https://example.zendesk.com/api/v2'
98
+ # client = Readiness::Zendesk::Client.new(config)
99
+ # search = Readiness::Zendesk::Search.organzations(client, 'Support')
100
+ # pp search.first.name
101
+ # # => "Support AMER"
102
+ def self.group(client, query)
103
+ search(client, 'group', query)
104
+ end
105
+
106
+ ##
107
+ # Perform a search and list the first 1000 results
108
+ #
109
+ # @author Jason Colyer
110
+ # @since 1.0.0
111
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
112
+ # @param type [String] The type of search to perform
113
+ # @param query [String] The query String to use
114
+ # @return [Array]
115
+ # @see https://developer.zendesk.com/api-reference/ticketing/ticket-management/search/#list-search-results Zendesk API > Search > List Search Results
116
+ # @example
117
+ # require 'support_readiness'
118
+ # config = Readiness::Zendesk::Configuration.new
119
+ # config.username = 'alice@example.com'
120
+ # config.token = 'test123abc'
121
+ # config.url = 'https://example.zendesk.com/api/v2'
122
+ # client = Readiness::Zendesk::Client.new(config)
123
+ # search = Readiness::Zendesk::Search.searc(client, 'organization', 'salesforce_id:ABCDEFGH0123456*')
124
+ # pp search.first.notes
125
+ # # => "This org is escalated. Please talk to support managers."
126
+ def self.search(client, type, query)
127
+ array = []
128
+ page = 1
129
+ loop do
130
+ response = client.connection.get "search?page=#{page}&query=type:#{type} #{query}"
131
+ handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
132
+ body = Oj.load(response.body)
133
+ array += body['results'].map { |r| object_from_type(type, r) }
134
+ break if array.count >= 1000
135
+ break if body['next_page'].nil?
136
+ page += 1
137
+ end
138
+ array
139
+ end
140
+
141
+ ##
142
+ # Returns the type of Object to use depending on the type of query
143
+ #
144
+ # @author Jason Colyer
145
+ # @since 1.0.0
146
+ # @param type [String] The type of search to perform
147
+ # @param result [Hash] The search result item
148
+ # @return [Object]
149
+ def self.object_from_type(type, result)
150
+ return Tickets.new(result) if type == 'ticket'
151
+ return Users.new(result) if type == 'user'
152
+ return Organizations.new(result) if type == 'organization'
153
+ return Groups.new(result) if type == 'group'
154
+
155
+ nil
156
+ end
157
+ end
158
+ end
159
+ end
@@ -0,0 +1,232 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module Readiness.
4
+ module Readiness
5
+ # Defines the module Zendesk
6
+ module Zendesk
7
+ ##
8
+ # Defines the class SLAs within the module {Readiness::Zendesk}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ class SLAs < Readiness::Client
13
+ attr_accessor :description, :filter, :id, :metric_settings, :policy_metrics, :position, :title
14
+
15
+ ##
16
+ # Creates a new {Readiness::Zendesk::SLAs} instance
17
+ #
18
+ # @author Jason Colyer
19
+ # @since 1.0.0
20
+ # @param object [Object] An instance of {Readiness::Zendesk::SLAs}
21
+ # @example
22
+ # require 'support_readiness'
23
+ # Readiness::Zendesk::SLAs.new
24
+ def initialize(object = {})
25
+ @description = object['description']
26
+ @filter = object['filter']
27
+ @id = object['id']
28
+ @metric_settings = object['metric_settings']
29
+ @policy_metrics = object['policy_metrics']
30
+ @position = object['position']
31
+ @title = object['title']
32
+ end
33
+
34
+ ##
35
+ # Lists the SLA policies
36
+ #
37
+ # @author Jason Colyer
38
+ # @since 1.0.0
39
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
40
+ # @return [Array]
41
+ # @see https://developer.zendesk.com/api-reference/ticketing/business-rules/sla_policies/#list-sla-policies Zendesk API > SLA Policies > List SLA Policies
42
+ # @example
43
+ # require 'support_readiness'
44
+ # config = Readiness::Zendesk::Configuration.new
45
+ # config.username = 'alice@example.com'
46
+ # config.token = 'test123abc'
47
+ # config.url = 'https://example.zendesk.com/api/v2'
48
+ # client = Readiness::Zendesk::Client.new(config)
49
+ # slas = Readiness::Zendesk::SLAs.list(client)
50
+ # pp slas.first.title
51
+ # # => "Incidents"
52
+ def self.list(client)
53
+ response = client.connection.get('slas/policies')
54
+ handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
55
+ Oj.load(response.body)['sla_policies'].map { |s| SLAs.new(s) }
56
+ end
57
+
58
+ ##
59
+ # Locates a SLA policy within Zendesk. This will not exit on error (except Authentication errors)
60
+ #
61
+ # @author Jason Colyer
62
+ # @since 1.0.0
63
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
64
+ # @param sid [Integer] The SLA Policy ID to find
65
+ # @return [Hash]
66
+ # @see https://developer.zendesk.com/api-reference/ticketing/business-rules/sla_policies/#show-sla-policy Zendesk API > SLA Policies > Show SLA Policy
67
+ # @example
68
+ # require 'support_readiness'
69
+ # config = Readiness::Zendesk::Configuration.new
70
+ # config.username = 'alice@example.com'
71
+ # config.token = 'test123abc'
72
+ # config.url = 'https://example.zendesk.com/api/v2'
73
+ # client = Readiness::Zendesk::Client.new(config)
74
+ # sla = Readiness::Zendesk::SLAs.find(client, 36)
75
+ # pp sla.title
76
+ # # => "Incidents"
77
+ def self.find(client, sid)
78
+ response = client.connection.get("slas/policies/#{sid}")
79
+ handle_request_error(0, 'Zendesk', response.status, { action: 'get', id: sid }) unless response.status == 200
80
+ return SLAs.new(Oj.load(response.body)['sla_policy']) if response.status == 200
81
+
82
+ Oj.load(response.body)
83
+ end
84
+
85
+ ##
86
+ # Locates a SLA policy within within Zendesk. This will exit on error
87
+ #
88
+ # @author Jason Colyer
89
+ # @since 1.0.0
90
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
91
+ # @param sid [Integer] The SLA Policy ID to find
92
+ # @return [Object] An instance of {Readiness::Zendesk::SLAs}
93
+ # @see https://developer.zendesk.com/api-reference/ticketing/business-rules/sla_policies/#show-sla-policy Zendesk API > SLA Policies > Show SLA Policy
94
+ # @example
95
+ # require 'support_readiness'
96
+ # config = Readiness::Zendesk::Configuration.new
97
+ # config.username = 'alice@example.com'
98
+ # config.token = 'test123abc'
99
+ # config.url = 'https://example.zendesk.com/api/v2'
100
+ # client = Readiness::Zendesk::Client.new(config)
101
+ # sla = Readiness::Zendesk::SLAs.find!(client, 36)
102
+ # pp sla.title
103
+ # # => "Incidents"
104
+ def self.find!(client, sid)
105
+ response = client.connection.get("slas/policies/#{sid}")
106
+ handle_request_error(1, 'Zendesk', response.status, { action: 'Find SLA Policy', id: sid }) unless response.status == 200
107
+ SLAs.new(Oj.load(response.body)['sla_policy'])
108
+ end
109
+
110
+ ##
111
+ # Creates a SLA Policy. Will exit if unsuccessful
112
+ #
113
+ # @author Jason Colyer
114
+ # @since 1.0.0
115
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
116
+ # @param policy [Object] An instance of {Readiness::Zendesk::SLAs}
117
+ # @return [Object] An instance of {Readiness::Zendesk::SLAs}
118
+ # @see https://developer.zendesk.com/api-reference/ticketing/business-rules/sla_policies/#create-sla-policy Zendesk API > SLA Policies > Create SLA Policy
119
+ # @example
120
+ # require 'support_readiness'
121
+ # config = Readiness::Zendesk::Configuration.new
122
+ # config.username = 'alice@example.com'
123
+ # config.token = 'test123abc'
124
+ # config.url = 'https://example.zendesk.com/api/v2'
125
+ # client = Readiness::Zendesk::Client.new(config)
126
+ # sla = Readiness::Zendesk::SLAs.new
127
+ # sla.title = 'Incidents'
128
+ # sla.description = 'For urgent incidents, we will respond to tickets in 10 minutes'
129
+ # sla.position = 3
130
+ # sla.filter = {
131
+ # all: [
132
+ # { field: 'type', operator: 'is', value: 'incident' }
133
+ # ],
134
+ # any: []
135
+ # }
136
+ # sla.policy_metrics = [
137
+ # { priority: 'normal', metric: 'first_reply_time', target: 30, business_hours: false },
138
+ # { priority: 'urgent', metric: 'first_reply_time', target: 10, business_hours: false },
139
+ # { priority: 'low', metric: 'requester_wait_time', target: 180, business_hours: false },
140
+ # { priority: 'normal', metric: 'requester_wait_time', target: 160, business_hours: false },
141
+ # { priority: 'high', metric: 'requester_wait_time', target: 140, business_hours: false },
142
+ # { priority: 'urgent', metric: 'requester_wait_time', target: 120, business_hours: false }
143
+ # ]
144
+ # create = Readiness::Zendesk::SLAs.create!(find, sla)
145
+ # pp create.id
146
+ # # => 36
147
+ def self.create!(client, policy)
148
+ response = client.connection.post 'slas/policies', to_clean_json_with_key(policyt, 'sla_policy')
149
+ handle_request_error(1, 'Zendesk', response.status, { action: 'Create SLA Policy', message: Oj.load(response.body)}) unless response.status == 201
150
+ SLAs.new(Oj.load(response.body)['sla_policy'])
151
+ end
152
+
153
+ ##
154
+ # Updates a SLA Policy. Will exit if unsuccessful
155
+ #
156
+ # @author Jason Colyer
157
+ # @since 1.0.0
158
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
159
+ # @param policy [Object] An instance of {Readiness::Zendesk::SLAs}
160
+ # @return [Object] An instance of {Readiness::Zendesk::SLAs}
161
+ # @see https://developer.zendesk.com/api-reference/ticketing/business-rules/sla_policies/#update-sla-policy Zendesk API > SLA Policies > Update SLA Policy
162
+ # @example
163
+ # require 'support_readiness'
164
+ # config = Readiness::Zendesk::Configuration.new
165
+ # config.username = 'alice@example.com'
166
+ # config.token = 'test123abc'
167
+ # config.url = 'https://example.zendesk.com/api/v2'
168
+ # client = Readiness::Zendesk::Client.new(config)
169
+ # sla = Readiness::Zendesk::SLAs.find!(client, 36)
170
+ # sla.title = 'Urgent Incidents'
171
+ # update = Readiness::Zendesk::SLAs.update!(find, sla)
172
+ # pp update.title
173
+ # # => "Urgent Incidents"
174
+ def self.update!(client, policy)
175
+ response = client.connection.put "slas/policies/#{policy.id}", to_clean_json_with_key(policy, 'sla_policy')
176
+ handle_request_error(1, 'Zendesk', response.status, { action: 'Update SLA Policy', id: policy.id, message: Oj.load(response.body)}) unless response.status == 200
177
+ SLAs.new(Oj.load(response.body)['sla_policy'])
178
+ end
179
+
180
+ ##
181
+ # Deletes a SLA Policy. Will exit if unsuccessful
182
+ #
183
+ # @author Jason Colyer
184
+ # @since 1.0.0
185
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
186
+ # @param policy [Object] An instance of {Readiness::Zendesk::SLAs}
187
+ # @return [Boolean]
188
+ # @see https://developer.zendesk.com/api-reference/ticketing/business-rules/sla_policies/#delete-sla-policy Zendesk API > SLA Policies > Delete SLA Policy
189
+ # @example
190
+ # require 'support_readiness'
191
+ # config = Readiness::Zendesk::Configuration.new
192
+ # config.username = 'alice@example.com'
193
+ # config.token = 'test123abc'
194
+ # config.url = 'https://example.zendesk.com/api/v2'
195
+ # client = Readiness::Zendesk::Client.new(config)
196
+ # sla = Readiness::Zendesk::SLAs.find!(client, 36)
197
+ # delete = Readiness::Zendesk::SLAs.delete!(find, sla)
198
+ # pp delete
199
+ # # => true
200
+ def self.delete!(client, policy)
201
+ response = client.connection.delete "slas/policies/#{policy.id}"
202
+ handle_request_error(1, 'Zendesk', response.status, { action: 'Delete a SLA policy', id: policy.id, message: Oj.load(response.body)}) unless response.status == 204
203
+ true
204
+ end
205
+
206
+ ##
207
+ # Reorder SLA Policies. Will exit if unsuccessful
208
+ #
209
+ # @author Jason Colyer
210
+ # @since 1.0.0
211
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
212
+ # @param pids [Array] An Array of SLA Policy IDs (order is important)
213
+ # @return [Boolean]
214
+ # @see https://developer.zendesk.com/api-reference/ticketing/business-rules/sla_policies/#reorder-sla-policies Zendesk API > SLA Policies > Reorder SLA Policies
215
+ # @example
216
+ # require 'support_readiness'
217
+ # config = Readiness::Zendesk::Configuration.new
218
+ # config.username = 'alice@example.com'
219
+ # config.token = 'test123abc'
220
+ # config.url = 'https://example.zendesk.com/api/v2'
221
+ # client = Readiness::Zendesk::Client.new(config)
222
+ # reorder = Readiness::Zendesk::SLAs.reorder!(client, 12, 55])
223
+ # pp reorder
224
+ # # => true
225
+ def self.reorder!(client, pids)
226
+ response = client.connection.put 'slas/policies/reorder', { sla_policy_ids: pids }.to_json
227
+ handle_request_error(1, 'Zendesk', response.status, { action: 'Reorder SLA policies', id: pids, message: Oj.load(response.body)}) unless response.status == 200
228
+ true
229
+ end
230
+ end
231
+ end
232
+ end