gitlab-customer-support-operations_zendesk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/lib/support_ops_zendesk/packages.rb +89 -0
  3. data/lib/support_ops_zendesk/zendesk/app_installations.rb +62 -0
  4. data/lib/support_ops_zendesk/zendesk/app_job_statuses.rb +157 -0
  5. data/lib/support_ops_zendesk/zendesk/apps.rb +476 -0
  6. data/lib/support_ops_zendesk/zendesk/articles.rb +362 -0
  7. data/lib/support_ops_zendesk/zendesk/audit_logs.rb +166 -0
  8. data/lib/support_ops_zendesk/zendesk/automations.rb +390 -0
  9. data/lib/support_ops_zendesk/zendesk/base.rb +472 -0
  10. data/lib/support_ops_zendesk/zendesk/brands.rb +172 -0
  11. data/lib/support_ops_zendesk/zendesk/client.rb +91 -0
  12. data/lib/support_ops_zendesk/zendesk/comments.rb +37 -0
  13. data/lib/support_ops_zendesk/zendesk/configuration.rb +138 -0
  14. data/lib/support_ops_zendesk/zendesk/custom_roles.rb +224 -0
  15. data/lib/support_ops_zendesk/zendesk/dynamic_content.rb +297 -0
  16. data/lib/support_ops_zendesk/zendesk/dynamic_content_variants.rb +309 -0
  17. data/lib/support_ops_zendesk/zendesk/group_memberships.rb +337 -0
  18. data/lib/support_ops_zendesk/zendesk/groups.rb +385 -0
  19. data/lib/support_ops_zendesk/zendesk/help_center_categories.rb +332 -0
  20. data/lib/support_ops_zendesk/zendesk/help_center_content_tags.rb +237 -0
  21. data/lib/support_ops_zendesk/zendesk/help_center_management_permission_groups.rb +271 -0
  22. data/lib/support_ops_zendesk/zendesk/help_center_sections.rb +378 -0
  23. data/lib/support_ops_zendesk/zendesk/help_center_topics.rb +274 -0
  24. data/lib/support_ops_zendesk/zendesk/help_center_user_segments.rb +279 -0
  25. data/lib/support_ops_zendesk/zendesk/job_statuses.rb +231 -0
  26. data/lib/support_ops_zendesk/zendesk/locales.rb +326 -0
  27. data/lib/support_ops_zendesk/zendesk/macros.rb +407 -0
  28. data/lib/support_ops_zendesk/zendesk/oauth_clients.rb +186 -0
  29. data/lib/support_ops_zendesk/zendesk/oauth_tokens.rb +114 -0
  30. data/lib/support_ops_zendesk/zendesk/organization_fields.rb +282 -0
  31. data/lib/support_ops_zendesk/zendesk/organization_memberships.rb +336 -0
  32. data/lib/support_ops_zendesk/zendesk/organizations.rb +568 -0
  33. data/lib/support_ops_zendesk/zendesk/requester_roles.rb +58 -0
  34. data/lib/support_ops_zendesk/zendesk/satisfaction_reasons.rb +161 -0
  35. data/lib/support_ops_zendesk/zendesk/schedule_holidays.rb +27 -0
  36. data/lib/support_ops_zendesk/zendesk/schedules.rb +192 -0
  37. data/lib/support_ops_zendesk/zendesk/search.rb +185 -0
  38. data/lib/support_ops_zendesk/zendesk/sla_policies.rb +302 -0
  39. data/lib/support_ops_zendesk/zendesk/targets.rb +96 -0
  40. data/lib/support_ops_zendesk/zendesk/theme_job_statuses.rb +154 -0
  41. data/lib/support_ops_zendesk/zendesk/themes.rb +328 -0
  42. data/lib/support_ops_zendesk/zendesk/ticket_field_options.rb +154 -0
  43. data/lib/support_ops_zendesk/zendesk/ticket_fields.rb +357 -0
  44. data/lib/support_ops_zendesk/zendesk/ticket_forms.rb +370 -0
  45. data/lib/support_ops_zendesk/zendesk/ticket_user_types.rb +67 -0
  46. data/lib/support_ops_zendesk/zendesk/tickets.rb +837 -0
  47. data/lib/support_ops_zendesk/zendesk/translations.rb +310 -0
  48. data/lib/support_ops_zendesk/zendesk/trigger_categories.rb +275 -0
  49. data/lib/support_ops_zendesk/zendesk/triggers.rb +427 -0
  50. data/lib/support_ops_zendesk/zendesk/user_field_options.rb +153 -0
  51. data/lib/support_ops_zendesk/zendesk/user_fields.rb +312 -0
  52. data/lib/support_ops_zendesk/zendesk/users.rb +889 -0
  53. data/lib/support_ops_zendesk/zendesk/via_types.rb +137 -0
  54. data/lib/support_ops_zendesk/zendesk/views.rb +636 -0
  55. data/lib/support_ops_zendesk/zendesk/webhooks.rb +206 -0
  56. data/lib/support_ops_zendesk/zendesk.rb +66 -0
  57. data/lib/support_ops_zendesk.rb +29 -0
  58. metadata +274 -0
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module SupportOps.
4
+ module SupportOps
5
+ # Defines the module Zendesk
6
+ module Zendesk
7
+ ##
8
+ # Defines the class Client within the module {SupportOps::Zendesk}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ class Client
13
+ class Error < StandardError; end
14
+ class RequestError < Error; end
15
+ class ResourceNotFound < Error; end
16
+
17
+ attr_reader :connection
18
+
19
+ def initialize(config = SupportOps::Zendesk::Configuration.new)
20
+ @connection = determine_connnection(config)
21
+ end
22
+
23
+ def retry_options(config)
24
+ {
25
+ max: config[:retry_max],
26
+ interval: config[:retry_interval],
27
+ interval_randomness: config[:retry_randomness],
28
+ backoff_factor: config[:retry_backoff],
29
+ exceptions: config[:retry_exceptions]
30
+ }
31
+ end
32
+
33
+ def determine_connnection(config)
34
+ case config[:connection_type]
35
+ when 'standard'
36
+ generate_connection(config)
37
+ when 'upload'
38
+ generate_upload_connection(config)
39
+ when 'impersonation'
40
+ generate_impersonation_connection(config)
41
+ else
42
+ raise "Unknown connection type => #{config[:connection_type]}"
43
+ end
44
+ end
45
+
46
+ def generate_connection(config)
47
+ Faraday.new(config[:url]) do |c|
48
+ c.request :retry, retry_options(config)
49
+ c.adapter Faraday.default_adapter
50
+ c.headers['Content-Type'] = 'application/json'
51
+ c.headers['Authorization'] = authentication_string(config)
52
+ end
53
+ end
54
+
55
+ def generate_upload_connection(config)
56
+ Faraday.new(config[:url]) do |c|
57
+ c.request :retry, retry_options(config)
58
+ c.request :multipart
59
+ c.request :url_encoded
60
+ c.adapter Faraday.default_adapter
61
+ c.headers['Authorization'] = authentication_string(config)
62
+ end
63
+ end
64
+
65
+ def generate_impersonation_connection(config)
66
+ if config[:auth_type] != 'OAuth'
67
+ puts 'This type of connection only supports OAuth'
68
+ exit 1
69
+ end
70
+ Faraday.new(config[:url]) do |c|
71
+ c.request :retry, retry_options(config)
72
+ c.adapter Faraday.default_adapter
73
+ c.headers['Content-Type'] = 'application/json'
74
+ c.headers['Authorization'] = authentication_string(config)
75
+ c.headers['X-On-Behalf-Of'] = config[:on_behalf_of]
76
+ end
77
+ end
78
+
79
+ def authentication_string(config)
80
+ case config[:auth_type]
81
+ when 'API token'
82
+ "Basic " + Base64.encode64("#{config[:username]}/token:#{config[:token]}").gsub("\n", '')
83
+ when 'Oauth'
84
+ "Bearer #{config[:token]}"
85
+ else
86
+ raise "Unknown authentication type => #{config[:auth_type]}"
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module SupportOps.
4
+ module SupportOps
5
+ # Defines the module Zendesk
6
+ module Zendesk
7
+ ##
8
+ # Defines the class Comments within the module {SupportOps::Zendesk}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [Array] attachments Attachments, if any
13
+ # @attr [Integer] audit_id The id of the ticket audit record
14
+ # @attr [Integer] author_id The id of the comment author
15
+ # @attr [String] body The comment string
16
+ # @attr [String] created_at The time the comment was created
17
+ # @attr [String] html_body The comment formatted as HTML
18
+ # @attr [Integer] id Automatically assigned when the comment is created
19
+ # @attr [Hash] metadata System information (web client, IP address, etc.) and comment flags, if any
20
+ # @attr [String] plain_body The comment presented as plain text
21
+ # @attr [Boolean] public true if a public comment; false if an internal note
22
+ # @attr [String] type Comment or VoiceComment
23
+ # @attr [Array] uploads List of tokens received from uploading files for comment attachments
24
+ # @attr [Hash] via Describes how the object was created
25
+ # @todo List Comments => https://developer.zendesk.com/api-reference/ticketing/tickets/ticket_comments/#list-comments
26
+ # @todo Count Ticket Comments => https://developer.zendesk.com/api-reference/ticketing/tickets/ticket_comments/#count-ticket-comments
27
+ # @todo Make Comment Private => https://developer.zendesk.com/api-reference/ticketing/tickets/ticket_comments/#make-comment-private
28
+ class Comments < SupportOps::Zendesk::Base
29
+ define_attributes :attachments, :audit_id, :author_id, :body, :created_at,
30
+ :html_body, :id, :metadata, :plain_body, :public, :type,
31
+ :uploads, :via
32
+ readonly_attributes :id, :created_at
33
+
34
+ private
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,138 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module SupportOps.
4
+ module SupportOps
5
+ # Defines the module Zendesk
6
+ module Zendesk
7
+ ##
8
+ # Defines the module Configuration within the module {SupportOps::Zendesk}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ module Configuration
13
+ ##
14
+ # Setup a Zendesk client configuration
15
+ #
16
+ # @author Jason Colyer
17
+ # @since 1.0.0
18
+ # @overload configure(key: value)
19
+ # @param auth_type [String] See {Config#auth_type}
20
+ # @param connection_type [String] See {Config#connection_type}
21
+ # @param on_behalf_of [String] See {Config#on_behalf_of}
22
+ # @param password [String] See {Config#password}
23
+ # @param retry_backoff [Integer] See {Config#retry_backoff}
24
+ # @param retry_exceptions [Array] See {Config#retry_exceptions}
25
+ # @param retry_interval [Integer] See {Config#retry_interval}
26
+ # @param retry_max [Integer] See {Config#retry_max}
27
+ # @param retry_randomness [Integer] See {Config#retry_randomness}
28
+ # @param token [String] See {Config#token}
29
+ # @param url [String] See {Config#url}
30
+ # @param username [String] See {Config#username}
31
+ # @example Standard usage using an API token
32
+ # require 'support_ops_zendesk'
33
+ #
34
+ # SupportOps::Zendesk::Configuration.configure do |config|
35
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
36
+ # config.username = 'jason@example.com'
37
+ # config.token = 'abc123'
38
+ # end
39
+ # @example Standard usage using an OAuth token
40
+ # require 'support_ops_zendesk'
41
+ #
42
+ # SupportOps::Zendesk::Configuration.configure do |config|
43
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
44
+ # config.auth_type = 'OAuth'
45
+ # config.token = 'abc123'
46
+ # end
47
+ # @example Using impersonation
48
+ # require 'support_ops_zendesk'
49
+ #
50
+ # SupportOps::Zendesk::Configuration.configure do |config|
51
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
52
+ # config.auth_type = 'OAuth'
53
+ # config.connection_type = 'impersonation'
54
+ # config.token = 'abc123'
55
+ # config.on_behalf_of = 'test_user@example.com'
56
+ # end
57
+ # @example A connection for uploads using an API token
58
+ # require 'support_ops_zendesk'
59
+ #
60
+ # SupportOps::Zendesk::Configuration.configure do |config|
61
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
62
+ # config.connection_type = 'upload'
63
+ # config.username = 'jason@example.com'
64
+ # config.token = 'abc123'
65
+ # end
66
+ # @example A connection for uploads using an OAuth token
67
+ # require 'support_ops_zendesk'
68
+ #
69
+ # SupportOps::Zendesk::Configuration.configure do |config|
70
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
71
+ # config.auth_type = 'OAuth'
72
+ # config.connection_type = 'upload'
73
+ # config.token = 'abc123'
74
+ # end
75
+ def self.configure
76
+ yield config
77
+ end
78
+
79
+ def self.config
80
+ @config ||= Config.new
81
+ end
82
+
83
+ def self.reset!
84
+ @config = Config.new
85
+ end
86
+
87
+ ##
88
+ # Defined the class Config within the module {SupportOps::Zendesk::Configuration}
89
+ #
90
+ # @author Jason Colyer
91
+ # @since 1.0.0
92
+ # @attr [String] auth_type The type of authentication being used, available options are 'API token' and 'OAuth'
93
+ # @attr [String] connection_type The type of connection being made, available options are 'standard', 'upload', and 'impersonation'
94
+ # @attr [String] on_behalf_of The email of the user the connection is impersonating. Only used in 'OAuth' connections
95
+ # @attr [String] password The password to use for authenitcation (deprecated)
96
+ # @attr [Integer] retry_backoff multiplier applied to the retry_interval after each retry attempt, causing exponential backoff. Defaults to 2
97
+ # @attr [Array] retry_exceptions Specifies which types of exceptions or errors should trigger the retry mechanism.
98
+ # @attr [Integer] retry_interval The base time interval (typically in seconds or milliseconds) between retry attempts. Defaults to 1
99
+ # @attr [Integer] retry_max The maximum number of retry attempts that will be made when an operation fails. Defaults to 5
100
+ # @attr [Float] retry_randomness Adds a random element to the retry interval to prevent "thundering herd" problems where many systems retry simultaneously. Defaults to 0.5
101
+ # @attr [String] token The token to use for authentication
102
+ # @attr [String] url The API url to connect to, it should alwaus be in the format of 'https:\/\/YOUR_SUBDOMAIN.zendesk.com/api/v2' (note the lack of a trailing /)
103
+ # @attr [String] username The username (email) you are connecting via, it should only ever be an email address (there is no need to add '/token' or the like to the end of it). Only used in 'API token' connections
104
+ class Config
105
+ attr_accessor :url, :username, :token, :retry_max, :retry_interval,
106
+ :retry_randomness, :retry_backoff, :retry_exceptions,
107
+ :connection_type, :auth_type, :password, :on_behalf_of
108
+
109
+ def initialize
110
+ @auth_type = 'API token'
111
+ @connection_type = 'standard'
112
+ @retry_backoff = 2
113
+ @retry_exceptions = Faraday::Retry::Middleware::DEFAULT_EXCEPTIONS + [Faraday::ConnectionFailed]
114
+ @retry_interval = 1
115
+ @retry_max = 5
116
+ @retry_randomness = 0.5
117
+ end
118
+
119
+ def client
120
+ @client ||= Client.new(
121
+ auth_type: auth_type,
122
+ connection_type: connection_type,
123
+ on_behalf_of: on_behalf_of,
124
+ password: password,
125
+ retry_max: retry_max,
126
+ retry_interval: retry_interval,
127
+ retry_randomness: retry_randomness,
128
+ retry_backoff: retry_backoff,
129
+ retry_exceptions: retry_exceptions,
130
+ url: url,
131
+ username: username,
132
+ token: token,
133
+ )
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,224 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module SupportOps.
4
+ module SupportOps
5
+ # Defines the module Zendesk
6
+ module Zendesk
7
+ ##
8
+ # Defines the class CustomRoles within the module {SupportOps::Zendesk}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [Hash] configuration Configuration settings for the role
13
+ # @attr [String] created_at The time the record was created
14
+ # @attr [String] description A description of the role
15
+ # @attr [Integer] id Automatically assigned on creation
16
+ # @attr [String] name Name of the custom role
17
+ # @attr [Integer] role_type The user's role; 0 stands for a custom agent, 1 for a light agent, 2 for a chat agent, 3 for a contributor, 4 for an admin and 5 for a billing admin
18
+ # @attr [Integer] team_member_count The number of team members assigned to this role
19
+ # @attr [String] updated_at The time the record was last updated
20
+ class CustomRoles < SupportOps::Zendesk::Base
21
+ # @!parse
22
+ # # Creates/updates a custom role
23
+ # #
24
+ # # @author Jason Colyer
25
+ # # @since 1.0.0
26
+ # # @return [Object] Instance of {SupportOps::Zendesk::CustomRoles}
27
+ # # @note This is inherited from {SupportOps::Zendesk::Base#save!}
28
+ # # @see
29
+ # # https://developer.zendesk.com/api-reference/ticketing/account-configuration/custom_roles/#create-custom-role
30
+ # # Zendesk API > Custom Roles > Create Custom Roles
31
+ # # @see
32
+ # # https://developer.zendesk.com/api-reference/ticketing/account-configuration/custom_roles/#update-custom-role
33
+ # # Zendesk API > Custom Roles > Update Custom Roles
34
+ # # @example
35
+ # # require 'support_ops_zendesk'
36
+ # #
37
+ # # SupportOps::Zendesk::Configuration.configure do |config|
38
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
39
+ # # config.username = 'jason@example.com'
40
+ # # config.token = 'abc123'
41
+ # # end
42
+ # #
43
+ # # orig_role = SupportOps::Zendesk::CustomRoles.get!(10127)
44
+ # # new_role = SupportOps::Zendesk::CustomRoles.new
45
+ # # new_role.name = 'Sample role'
46
+ # # new_role.configuration = orig_role.configuration
47
+ # # new_role.configuration['explore_access'] = 'edit'
48
+ # #
49
+ # # new_role.save!
50
+ # #
51
+ # # pp new_role.id
52
+ # # # => 23409462
53
+ # # @example
54
+ # # require 'support_ops_zendesk'
55
+ # #
56
+ # # SupportOps::Zendesk::Configuration.configure do |config|
57
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
58
+ # # config.username = 'jason@example.com'
59
+ # # config.token = 'abc123'
60
+ # # end
61
+ # #
62
+ # # existing_role = SupportOps::Zendesk::CustomRoles.get!(23409462)
63
+ # # existing_role.name = 'Sample role cloned from 10127'
64
+ # #
65
+ # # existing_role.save!
66
+ # #
67
+ # # pp existing_role.name
68
+ # # # => "Sample role cloned from 10127"
69
+ # def save!; end
70
+ # @!parse
71
+ # # Deletes a custom role
72
+ # #
73
+ # # @author Jason Colyer
74
+ # # @since 1.0.0
75
+ # # @return [Boolean]
76
+ # # @note This is inherited from {SupportOps::Zendesk::Base#delete!}
77
+ # # @see
78
+ # # https://developer.zendesk.com/api-reference/ticketing/account-configuration/custom_roles/#delete-custom-role
79
+ # # Zendesk API > Custom Roles > Delete Custom Role
80
+ # # @example
81
+ # # require 'support_ops_zendesk'
82
+ # #
83
+ # # SupportOps::Zendesk::Configuration.configure do |config|
84
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
85
+ # # config.username = 'jason@example.com'
86
+ # # config.token = 'abc123'
87
+ # # end
88
+ # #
89
+ # # existing_role = SupportOps::Zendesk::CustomRoles.get!(23409462)
90
+ # # existing_role.delete!
91
+ # def delete!; end
92
+ define_attributes :configuration, :created_at, :description, :id, :name,
93
+ :role_type, :team_member_count, :updated_at
94
+ readonly_attributes :created_at, :id, :role_type, :team_member_count,
95
+ :updated_at
96
+
97
+ ##
98
+ # Lists custom roles in the Zendesk system
99
+ #
100
+ # @author Jason Colyer
101
+ # @since 1.0.0
102
+ # @return [Array]
103
+ # @see
104
+ # https://developer.zendesk.com/api-reference/ticketing/account-configuration/custom_roles/#list-custom-roles
105
+ # Zendesk API > Custom Roles > ist Custom Roles
106
+ # @see SupportOps::Zendesk::Configuration Setting up a client
107
+ # @example
108
+ # require 'support_ops_zendesk'
109
+ #
110
+ # SupportOps::Zendesk::Configuration.configure do |config|
111
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
112
+ # config.username = 'jason@example.com'
113
+ # config.token = 'abc123'
114
+ # end
115
+ #
116
+ # roles = SupportOps::Zendesk::CustomRoles.list
117
+ # pp roles.count
118
+ # # => 12
119
+ # pp roles.last.name
120
+ # # => "I'm the 12th custom role"
121
+ def self.list
122
+ response = client.connection.get('custom_roles')
123
+ body = Oj.load(response.body)
124
+ body['custom_roles'].map { |c| CustomRoles.new(c) }
125
+ end
126
+
127
+ ##
128
+ # Locates a specific custom role in the Zendesk system
129
+ #
130
+ # @author Jason Colyer
131
+ # @since 1.0.0
132
+ # @see
133
+ # https://developer.zendesk.com/api-reference/ticketing/account-configuration/custom_roles/#show-custom-role
134
+ # Zendesk API > Custom Roles > Show Custom Role
135
+ # @see SupportOps::Zendesk::Configuration Setting up a client
136
+ # @example
137
+ # require 'support_ops_zendesk'
138
+ #
139
+ # SupportOps::Zendesk::Configuration.configure do |config|
140
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
141
+ # config.username = 'jason@example.com'
142
+ # config.token = 'abc123'
143
+ # end
144
+ #
145
+ # role = SupportOps::Zendesk::CustomRoles.get(25)
146
+ # pp role.title
147
+ # # => "I'm the 25th custom role"
148
+ def self.get(object)
149
+ if object.is_a? CustomRoles
150
+ CustomRoles.new(id: id).find
151
+ else
152
+ CustomRoles.new(id: object).find
153
+ end
154
+ end
155
+
156
+ ##
157
+ # Locates a specific custom role in the Zendesk system
158
+ #
159
+ # @author Jason Colyer
160
+ # @since 1.0.0
161
+ # @see
162
+ # https://developer.zendesk.com/api-reference/ticketing/account-configuration/custom_roles/#show-custom-role
163
+ # Zendesk API > Custom Roles > Show Custom Role
164
+ # @see SupportOps::Zendesk::Configuration Setting up a client
165
+ # @example
166
+ # require 'support_ops_zendesk'
167
+ #
168
+ # SupportOps::Zendesk::Configuration.configure do |config|
169
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
170
+ # config.username = 'jason@example.com'
171
+ # config.token = 'abc123'
172
+ # end
173
+ #
174
+ # role = SupportOps::Zendesk::CustomRoles.get!(25)
175
+ # pp role.title
176
+ # # => "I'm the 25th custom role"
177
+ def self.get!(object)
178
+ if object.is_a? CustomRoles
179
+ CustomRoles.new(id: id).find!
180
+ else
181
+ CustomRoles.new(id: object).find!
182
+ end
183
+ end
184
+
185
+ private
186
+
187
+ ##
188
+ # @private
189
+ def get_record
190
+ response = self.client.connection.get("custom_roles/#{self.id}")
191
+ return nil if response.status != 200
192
+
193
+ Oj.load(response.body)['custom_role']
194
+ end
195
+
196
+ ##
197
+ # @private
198
+ def create_record
199
+ response = self.client.connection.post("custom_roles", { custom_role: attributes_for_save }.to_json)
200
+ body = Oj.load(response.body)
201
+ raise "Failed to create custom role => #{body}" if response.status != 200
202
+ body['custom_role']
203
+ end
204
+
205
+ ##
206
+ # @private
207
+ def update_record
208
+ raise "Failed to update automation => You didn't change anything in the object" if attributes_for_save.keys == [:id]
209
+ response = self.client.connection.put("custom_roles/#{self.id}", { custom_role: attributes_for_save }.to_json)
210
+ body = Oj.load(response.body)
211
+ raise "Failed to update custom role #{self.id} => #{body['details']}" if response.status != 200
212
+ body['custom_role']
213
+ end
214
+
215
+ ##
216
+ # @private
217
+ def delete_record
218
+ response = self.client.connection.delete("custom_roles/#{self.id}")
219
+ raise "Failed to delete custom role => #{body['details']}" if response.status != 204
220
+ true
221
+ end
222
+ end
223
+ end
224
+ end