gitlab_support_readiness 1.0.11 → 1.0.13
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.
- checksums.yaml +4 -4
- data/lib/support_readiness/calendly/client.rb +64 -0
- data/lib/support_readiness/calendly/configuration.rb +45 -0
- data/lib/support_readiness/calendly/organization_memberships.rb +67 -0
- data/lib/support_readiness/calendly/organizations.rb +123 -0
- data/lib/support_readiness/calendly/users.rb +105 -0
- data/lib/support_readiness/calendly.rb +16 -0
- data/lib/support_readiness/client.rb +88 -1
- data/lib/support_readiness/dates.rb +90 -0
- data/lib/support_readiness/gitlab/configuration.rb +0 -1
- data/lib/support_readiness/gitlab/groups.rb +35 -0
- data/lib/support_readiness/gitlab/jobs.rb +189 -0
- data/lib/support_readiness/gitlab/markdown.rb +37 -0
- data/lib/support_readiness/gitlab/merge_requests.rb +127 -0
- data/lib/support_readiness/gitlab/namespaces.rb +22 -0
- data/lib/support_readiness/gitlab/pipelines.rb +191 -0
- data/lib/support_readiness/gitlab/projects.rb +85 -1
- data/lib/support_readiness/gitlab/repositories.rb +174 -0
- data/lib/support_readiness/gitlab/users.rb +24 -0
- data/lib/support_readiness/gitlab.rb +4 -0
- data/lib/support_readiness/google_calendar/client.rb +59 -0
- data/lib/support_readiness/google_calendar/configuration.rb +39 -0
- data/lib/support_readiness/google_calendar/events.rb +169 -0
- data/lib/support_readiness/google_calendar.rb +14 -0
- data/lib/support_readiness/mailgun/bounces.rb +103 -0
- data/lib/support_readiness/mailgun/client.rb +65 -0
- data/lib/support_readiness/mailgun/configuration.rb +46 -0
- data/lib/support_readiness/mailgun/emails.rb +95 -0
- data/lib/support_readiness/mailgun.rb +15 -0
- data/lib/support_readiness/pagerduty/escalation_policies.rb +1 -1
- data/lib/support_readiness/pagerduty/schedules.rb +27 -3
- data/lib/support_readiness/pagerduty/services.rb +1 -1
- data/lib/support_readiness/pagerduty/users.rb +197 -0
- data/lib/support_readiness/pagerduty.rb +1 -0
- data/lib/support_readiness/repos/articles.rb +335 -0
- data/lib/support_readiness/repos/automations.rb +247 -0
- data/lib/support_readiness/repos/groups.rb +188 -0
- data/lib/support_readiness/repos/macros.rb +224 -0
- data/lib/support_readiness/repos/organization_fields.rb +193 -0
- data/lib/support_readiness/repos/sla_policies.rb +192 -0
- data/lib/support_readiness/repos/ticket_fields.rb +200 -0
- data/lib/support_readiness/repos/ticket_forms.rb +200 -0
- data/lib/support_readiness/repos/triggers.rb +255 -0
- data/lib/support_readiness/repos/user_fields.rb +201 -0
- data/lib/support_readiness/repos/views.rb +362 -0
- data/lib/support_readiness/repos.rb +22 -0
- data/lib/support_readiness/salesforce/accounts.rb +109 -0
- data/lib/support_readiness/salesforce/cases.rb +109 -0
- data/lib/support_readiness/salesforce/client.rb +64 -0
- data/lib/support_readiness/salesforce/configuration.rb +49 -0
- data/lib/support_readiness/salesforce/queries.rb +62 -0
- data/lib/support_readiness/salesforce.rb +16 -0
- data/lib/support_readiness/slack/client.rb +63 -0
- data/lib/support_readiness/slack/configuration.rb +43 -0
- data/lib/support_readiness/slack/messages.rb +37 -0
- data/lib/support_readiness/slack.rb +14 -0
- data/lib/support_readiness/zendesk/app_job_statuses.rb +140 -0
- data/lib/support_readiness/zendesk/apps.rb +209 -0
- data/lib/support_readiness/zendesk/automations.rb +1 -2
- data/lib/support_readiness/zendesk/macros.rb +1 -3
- data/lib/support_readiness/zendesk/organization_fields.rb +1 -1
- data/lib/support_readiness/zendesk/theme_job_statuses.rb +136 -0
- data/lib/support_readiness/zendesk/themes.rb +303 -0
- data/lib/support_readiness/zendesk/ticket_field_options.rb +110 -0
- data/lib/support_readiness/zendesk/ticket_fields.rb +85 -16
- data/lib/support_readiness/zendesk/ticket_forms.rb +65 -2
- data/lib/support_readiness/zendesk/tickets.rb +77 -0
- data/lib/support_readiness/zendesk/triggers.rb +1 -2
- data/lib/support_readiness/zendesk/user_field_options.rb +110 -0
- data/lib/support_readiness/zendesk/user_fields.rb +257 -0
- data/lib/support_readiness/zendesk/views.rb +49 -2
- data/lib/support_readiness/zendesk.rb +7 -0
- data/lib/support_readiness.rb +16 -0
- metadata +122 -2
@@ -170,7 +170,7 @@ module Readiness
|
|
170
170
|
# field = Readiness::Zendesk::OrganizationFields.find!(client, 75)
|
171
171
|
# field.title = 'Support description'
|
172
172
|
# update = Readiness::Zendesk::OrganizationFields.update!(client, field)
|
173
|
-
# pp
|
173
|
+
# pp update.title
|
174
174
|
# # => "Support description"
|
175
175
|
def self.update!(client, field)
|
176
176
|
response = client.connection.put "organization_fields/#{field.id}", to_clean_json_with_key(field, 'organization_field')
|
@@ -0,0 +1,136 @@
|
|
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 ThemeJobStatuses within the module {Readiness::Zendesk}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.12
|
12
|
+
class ThemeJobStatuses < Readiness::Client
|
13
|
+
attr_accessor :data, :id, :errors, :status
|
14
|
+
|
15
|
+
##
|
16
|
+
# Creates a new {Readiness::Zendesk::ThemeJobStatuses} instance
|
17
|
+
#
|
18
|
+
# @author Jason Colyer
|
19
|
+
# @since 1.0.12
|
20
|
+
# @param object [Object] An instance of {Readiness::Zendesk::ThemeJobStatuses}
|
21
|
+
# @example
|
22
|
+
# require 'support_readiness'
|
23
|
+
# Readiness::Zendesk::ThemeJobStatuses.new
|
24
|
+
def initialize(object = {})
|
25
|
+
@data = object['data']
|
26
|
+
@id = object['id']
|
27
|
+
@errors = object['errors']
|
28
|
+
@status = object['status']
|
29
|
+
end
|
30
|
+
|
31
|
+
##
|
32
|
+
# Locates an theme job status within Zendesk. This will not exit on error (except Authentication errors)
|
33
|
+
#
|
34
|
+
# @author Jason Colyer
|
35
|
+
# @since 1.0.12
|
36
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
37
|
+
# @param jid [String] The job status ID to find
|
38
|
+
# @return [Hash]
|
39
|
+
# @see https://developer.zendesk.com/api-reference/help_center/help-center-api/theming/#json-format-for-jobs Zendesk API > Theme > Show Job
|
40
|
+
# @example
|
41
|
+
# require 'support_readiness'
|
42
|
+
# config = Readiness::Zendesk::Configuration.new
|
43
|
+
# config.username = 'alice@example.com'
|
44
|
+
# config.token = 'test123abc'
|
45
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
46
|
+
# client = Readiness::Zendesk::Client.new(config)
|
47
|
+
# job = Readiness::Zendesk::ThemeJobStatuses.find(client, '8b726e606741012ffc2d782bcb7848fe')
|
48
|
+
# pp job.status
|
49
|
+
# # => "completed"
|
50
|
+
def self.find(client, jid)
|
51
|
+
response = client.connection.get("guide/theming/jobs/#{jid}")
|
52
|
+
handle_request_error(0, 'Zendesk', response.status, { action: 'get', id: jid }) unless response.status == 200
|
53
|
+
return ThemeJobStatuses.new(Oj.load(response.body)) if response.status == 200
|
54
|
+
|
55
|
+
Oj.load(response.body)
|
56
|
+
end
|
57
|
+
|
58
|
+
##
|
59
|
+
# Locates a theme job status within Zendesk. This will exit on error
|
60
|
+
#
|
61
|
+
# @author Jason Colyer
|
62
|
+
# @since 1.0.12
|
63
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
64
|
+
# @param jid [String] The job status ID to find
|
65
|
+
# @return [Object]
|
66
|
+
# @see https://developer.zendesk.com/api-reference/help_center/help-center-api/theming/#json-format-for-jobs Zendesk API > Theme > Show Job
|
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
|
+
# job = Readiness::Zendesk::ThemeJobStatuses.find!(client, '8b726e606741012ffc2d782bcb7848fe')
|
75
|
+
# pp job.status
|
76
|
+
# # => "completed"
|
77
|
+
def self.find!(client, jid)
|
78
|
+
response = client.connection.get("guide/theming/jobs/#{jid}")
|
79
|
+
handle_request_error(1, 'Zendesk', response.status, { action: 'Find theme job status', id: jid }) unless response.status == 200
|
80
|
+
ThemeJobStatuses.new(Oj.load(response.body))
|
81
|
+
end
|
82
|
+
|
83
|
+
##
|
84
|
+
# Waits for a job to complete. Be mindful of API limits when setting the wait interval
|
85
|
+
#
|
86
|
+
# @author Jason Colyer
|
87
|
+
# @since 1.0.12
|
88
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
89
|
+
# @param job [Object] An instance of {Readiness::Zendesk::ThemeJobStatuses}
|
90
|
+
# @param interval [Integer] The time (in seconds) between checks
|
91
|
+
# @param verbose [Boolean] Whether or not to output messages
|
92
|
+
# @return [Object] An instance of {Readiness::Zendesk::ThemeJobStatuses}
|
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
|
+
# job = Readiness::Zendesk::ThemeJobStatuses.find!(client, '8b726e606741012ffc2d782bcb7848fe')
|
101
|
+
# completed_job = Readiness::Zendesk::ThemeJobStatuses.wait_for_completetion(client, job, 10, true)
|
102
|
+
# # => Waiting 10 seconds before checking 8b726e606741012ffc2d782bcb7848fe
|
103
|
+
# # => Rechecking status of 8b726e606741012ffc2d782bcb7848fe...status is queued
|
104
|
+
# # => Waiting 10 seconds before checking 8b726e606741012ffc2d782bcb7848fe
|
105
|
+
# # => Rechecking status of 8b726e606741012ffc2d782bcb7848fe...status is working
|
106
|
+
# # => Waiting 10 seconds before checking 8b726e606741012ffc2d782bcb7848fe
|
107
|
+
# # => Rechecking status of 8b726e606741012ffc2d782bcb7848fe...status is completed
|
108
|
+
# # => Job is finished with status of completed
|
109
|
+
# pp completed_job.status
|
110
|
+
# # => "completed"
|
111
|
+
# @example
|
112
|
+
# require 'support_readiness'
|
113
|
+
# config = Readiness::Zendesk::Configuration.new
|
114
|
+
# config.username = 'alice@example.com'
|
115
|
+
# config.token = 'test123abc'
|
116
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
117
|
+
# client = Readiness::Zendesk::Client.new(config)
|
118
|
+
# job = Readiness::Zendesk::ThemeJobStatuses.find!(client, '8b726e606741012ffc2d782bcb7848fe')
|
119
|
+
# completed_job = Readiness::Zendesk::ThemeJobStatuses.wait_for_completetion(client, job, 5, false)
|
120
|
+
# pp completed_job.status
|
121
|
+
# # => "completed"
|
122
|
+
def self.wait_for_completetion(client, job, interval = 5, verbose = true)
|
123
|
+
loop do
|
124
|
+
puts "Waiting #{interval} seconds before checking #{job.id}" if verbose
|
125
|
+
sleep interval
|
126
|
+
print "Rechecking status of #{job.id}..." if verbose
|
127
|
+
job = ThemeJobStatuses.find!(client, job.id)
|
128
|
+
puts "status is #{job.status}" if verbose
|
129
|
+
break if %w[failed completed].include? job.status
|
130
|
+
end
|
131
|
+
puts "Job is finished with status of #{job.status}" if verbose
|
132
|
+
job
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,303 @@
|
|
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 Themes within the module {Readiness::Zendesk}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.12
|
12
|
+
class Themes < Readiness::Client
|
13
|
+
attr_accessor :author, :brand_id, :id, :live, :name, :version
|
14
|
+
|
15
|
+
##
|
16
|
+
# Creates a new {Readiness::Zendesk::Themes} instance
|
17
|
+
#
|
18
|
+
# @author Jason Colyer
|
19
|
+
# @since 1.0.12
|
20
|
+
# @param object [Object] An instance of {Readiness::Zendesk::Themes}
|
21
|
+
# @example
|
22
|
+
# require 'support_readiness'
|
23
|
+
# Readiness::Zendesk::Themes.new
|
24
|
+
def initialize(object = {})
|
25
|
+
@author = object['author']
|
26
|
+
@brand_id = object['brand_id']
|
27
|
+
@id = object['id']
|
28
|
+
@live = object['live']
|
29
|
+
@name = object['name']
|
30
|
+
@version = object['version']
|
31
|
+
end
|
32
|
+
|
33
|
+
##
|
34
|
+
# Lists themes within Zendesk
|
35
|
+
#
|
36
|
+
# @author Jason Colyer
|
37
|
+
# @since 1.0.12
|
38
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
39
|
+
# @return [Array]
|
40
|
+
# @see https://developer.zendesk.com/api-reference/help_center/help-center-api/theming/#list-themes Zendesk API > Themes > List Themes
|
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
|
+
# themes = Readiness::Zendesk::Themes.list(client)
|
49
|
+
# pp themes.first.name
|
50
|
+
# # => "GitLab Zendesk Global Theme"
|
51
|
+
def self.list(client)
|
52
|
+
response = client.connection.get 'guide/theming/themes'
|
53
|
+
handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
|
54
|
+
Oj.load(response.body)['themes'].map { |t| Themes.new(t) }
|
55
|
+
end
|
56
|
+
|
57
|
+
##
|
58
|
+
# Returns the live theme for the Zendesk instance
|
59
|
+
#
|
60
|
+
# @author Jason Colyer
|
61
|
+
# @since 1.0.12
|
62
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
63
|
+
# @return [Object]
|
64
|
+
# @example
|
65
|
+
# require 'support_readiness'
|
66
|
+
# config = Readiness::Zendesk::Configuration.new
|
67
|
+
# config.username = 'alice@example.com'
|
68
|
+
# config.token = 'test123abc'
|
69
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
70
|
+
# client = Readiness::Zendesk::Client.new(config)
|
71
|
+
# theme = Readiness::Zendesk::Themes.live_theme(client)
|
72
|
+
# pp theme.id
|
73
|
+
# # => "28a0b408-626a-4bea-88ab-2d48a8078870"
|
74
|
+
def self.live_theme(client)
|
75
|
+
themes = Themes.list(client)
|
76
|
+
themes.detect { |t| t.live }
|
77
|
+
end
|
78
|
+
|
79
|
+
##
|
80
|
+
# Locates a theme within Zendesk. This will not exit on error (except Authentication errors)
|
81
|
+
#
|
82
|
+
# @author Jason Colyer
|
83
|
+
# @since 1.0.12
|
84
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
85
|
+
# @param tid [String] The theme ID to locate
|
86
|
+
# @return [Object]
|
87
|
+
# @see https://developer.zendesk.com/api-reference/help_center/help-center-api/theming/#show-theme Zendesk API > themes > Show Theme
|
88
|
+
# @example
|
89
|
+
# require 'support_readiness'
|
90
|
+
# config = Readiness::Zendesk::Configuration.new
|
91
|
+
# config.username = 'alice@example.com'
|
92
|
+
# config.token = 'test123abc'
|
93
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
94
|
+
# client = Readiness::Zendesk::Client.new(config)
|
95
|
+
# theme = Readiness::Zendesk::Themes.find(client, '6d7ccf08-5674-467c-9036-3403b6c5e91d')
|
96
|
+
# pp app.name
|
97
|
+
# # => "GitLab Zendesk Global Theme"
|
98
|
+
def self.find(client, tid)
|
99
|
+
response = client.connection.get "guide/theming/themes/#{tid}"
|
100
|
+
handle_request_error(0, 'Zendesk', response.status, { action: 'get', id: tid }) unless response.status == 200
|
101
|
+
return Themes.new(Oj.load(response.body)['theme']) if response.status == 200
|
102
|
+
|
103
|
+
Oj.load(response.body)
|
104
|
+
end
|
105
|
+
|
106
|
+
##
|
107
|
+
# Locates a theme within Zendesk. This will exit on error
|
108
|
+
#
|
109
|
+
# @author Jason Colyer
|
110
|
+
# @since 1.0.12
|
111
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
112
|
+
# @param tid [String] The theme ID to locate
|
113
|
+
# @return [Object]
|
114
|
+
# @see https://developer.zendesk.com/api-reference/help_center/help-center-api/theming/#show-theme Zendesk API > themes > Show Theme
|
115
|
+
# @example
|
116
|
+
# require 'support_readiness'
|
117
|
+
# config = Readiness::Zendesk::Configuration.new
|
118
|
+
# config.username = 'alice@example.com'
|
119
|
+
# config.token = 'test123abc'
|
120
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
121
|
+
# client = Readiness::Zendesk::Client.new(config)
|
122
|
+
# theme = Readiness::Zendesk::Themes.find!(client, '6d7ccf08-5674-467c-9036-3403b6c5e91d')
|
123
|
+
# pp app.name
|
124
|
+
# # => "GitLab Zendesk Global Theme"
|
125
|
+
def self.find!(client, tid)
|
126
|
+
response = client.connection.get "guide/theming/themes/#{tid}"
|
127
|
+
handle_request_error(1, 'Zendesk', response.status, { action: 'Find theme', id: tid }) unless response.status == 200
|
128
|
+
Themes.new(Oj.load(response.body)['theme'])
|
129
|
+
end
|
130
|
+
|
131
|
+
##
|
132
|
+
# Creates a zip file from the given directory for a Zendesk app. This will exit on error
|
133
|
+
#
|
134
|
+
# @author Jason Colyer
|
135
|
+
# @since 1.0.12
|
136
|
+
# @param location [location] The relative path to the location of the theme files
|
137
|
+
# @return [String] The path to the zip file
|
138
|
+
# @example
|
139
|
+
# require 'support_readiness'
|
140
|
+
# file = Readiness::Zendesk::Themes.package!
|
141
|
+
# pp file
|
142
|
+
# # => "data/20241007151228578.zip"
|
143
|
+
def self.package!(location = './')
|
144
|
+
item_list = %w[ assets manifest.json script.js settings style.css templates thumbnail.png translations ]
|
145
|
+
create_package!(item_list, location)
|
146
|
+
end
|
147
|
+
|
148
|
+
##
|
149
|
+
# Creates an update job for creating a Zendesk theme. This will exit on error
|
150
|
+
#
|
151
|
+
# @author Jason Colyer
|
152
|
+
# @since 1.0.12
|
153
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
154
|
+
# @param theme [Object] An instance of {Readiness::Zendesk::Themes}
|
155
|
+
# @return [Object] An instance of {Readiness::Zendesk::ThemeJobStatuses}
|
156
|
+
# @example
|
157
|
+
# require 'support_readiness'
|
158
|
+
# config = Readiness::Zendesk::Configuration.new
|
159
|
+
# config.username = 'alice@example.com'
|
160
|
+
# config.token = 'test123abc'
|
161
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
162
|
+
# client = Readiness::Zendesk::Client.new(config)
|
163
|
+
# theme = Readiness::Zendesk::Themes.live_theme(client)
|
164
|
+
# job = Readiness::Zendesk::Themes.generate_update_job!(client, theme)
|
165
|
+
# pp job.id
|
166
|
+
# # => "a66e7bde543c6b6d018f0e07a654feaf"
|
167
|
+
def self.generate_update_job!(client, theme)
|
168
|
+
object = {
|
169
|
+
job: {
|
170
|
+
attributes: {
|
171
|
+
theme_id: theme.id,
|
172
|
+
replace_settings: true,
|
173
|
+
format: 'zip'
|
174
|
+
}
|
175
|
+
}
|
176
|
+
}
|
177
|
+
response = client.connection.post 'guide/theming/jobs/themes/updates', object.to_json
|
178
|
+
handle_request_error(1, 'Zendesk', response.status, { action: 'Upload app', id: file }) unless response.status == 200
|
179
|
+
ThemeJobStatuses.new(Oj.load(response.body)['job'])
|
180
|
+
end
|
181
|
+
|
182
|
+
##
|
183
|
+
# Creates an import job for creating a Zendesk theme. This will exit on error
|
184
|
+
#
|
185
|
+
# @author Jason Colyer
|
186
|
+
# @since 1.0.12
|
187
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
188
|
+
# @param theme [Object] An instance of {Readiness::Zendesk::Themes}
|
189
|
+
# @return [Object] An instance of {Readiness::Zendesk::ThemeJobStatuses}
|
190
|
+
# @example
|
191
|
+
# require 'support_readiness'
|
192
|
+
# config = Readiness::Zendesk::Configuration.new
|
193
|
+
# config.username = 'alice@example.com'
|
194
|
+
# config.token = 'test123abc'
|
195
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
196
|
+
# client = Readiness::Zendesk::Client.new(config)
|
197
|
+
# theme = Readiness::Zendesk::Themes.new
|
198
|
+
# theme.brand_id = 123
|
199
|
+
# job = Readiness::Zendesk::Themes.generate_import_job!(client, theme)
|
200
|
+
# pp job.id
|
201
|
+
# # => "a66e7bde543c6b6d018f0e07a654feaf"
|
202
|
+
def self.generate_import_job!(client, theme)
|
203
|
+
object = {
|
204
|
+
job: {
|
205
|
+
attributes: {
|
206
|
+
brand_id: theme.brand_id,
|
207
|
+
format: 'zip'
|
208
|
+
}
|
209
|
+
}
|
210
|
+
}
|
211
|
+
response = client.connection.post 'guide/theming/jobs/themes/imports', object.to_json
|
212
|
+
handle_request_error(1, 'Zendesk', response.status, { action: 'Upload app', id: file }) unless response.status == 200
|
213
|
+
ThemeJobStatuses.new(Oj.load(response.body)['job'])
|
214
|
+
end
|
215
|
+
|
216
|
+
##
|
217
|
+
# Uploads a zip file to an import or update job. This will exit on error
|
218
|
+
#
|
219
|
+
# @author Jason Colyer
|
220
|
+
# @since 1.0.12
|
221
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
222
|
+
# @param job [Object] An instance of {Readiness::Zendesk::ThemeJobStatuses}
|
223
|
+
# @param file [String] The relative path to the zip file
|
224
|
+
# @return [Object] An instance of {Readiness::Zendesk::ThemeJobStatuses}
|
225
|
+
# @example
|
226
|
+
# require 'support_readiness'
|
227
|
+
# config = Readiness::Zendesk::Configuration.new
|
228
|
+
# config.username = 'alice@example.com'
|
229
|
+
# config.token = 'test123abc'
|
230
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
231
|
+
# client = Readiness::Zendesk::Client.new(config)
|
232
|
+
# file = Readiness::Zendesk::Themes.package!('data/modified_theme')
|
233
|
+
# theme = Readiness::Zendesk::Themes.live_theme(client)
|
234
|
+
# job = Readiness::Zendesk::Themes.generate_import_job!(client, theme)
|
235
|
+
# job = Readiness::Zendesk::Themes.upload!(client, job, file)
|
236
|
+
# pp job.id
|
237
|
+
# # => "a66e7bde543c6b6d018f0e07a654feaf"
|
238
|
+
def self.upload!(client, job, file)
|
239
|
+
object = job.data['upload']['parameters'].merge(
|
240
|
+
file: ::Faraday::UploadIO.new(file, 'application/zip')
|
241
|
+
)
|
242
|
+
response = client.upload_connection.post job.data['upload']['url'], object.to_json
|
243
|
+
ThemeJobStatuses.find!(client, job.id)
|
244
|
+
end
|
245
|
+
|
246
|
+
##
|
247
|
+
# Creates a theme. This will exit on error
|
248
|
+
#
|
249
|
+
# @author Jason Colyer
|
250
|
+
# @since 1.0.12
|
251
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
252
|
+
# @param theme [Object] An instance of {Readiness::Zendesk::Themes}
|
253
|
+
# @param location [location] The relative path to the location of the theme files
|
254
|
+
# @return [Object] An instance of {Readiness::Zendesk::ThemeJobStatuses}
|
255
|
+
# @example
|
256
|
+
# require 'support_readiness'
|
257
|
+
# config = Readiness::Zendesk::Configuration.new
|
258
|
+
# config.username = 'alice@example.com'
|
259
|
+
# config.token = 'test123abc'
|
260
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
261
|
+
# client = Readiness::Zendesk::Client.new(config)
|
262
|
+
# theme = Readiness::Zendesk::Themes.new
|
263
|
+
# theme.brand_id = 123
|
264
|
+
# theme.live = false
|
265
|
+
# job = Readiness::Zendesk::Themes.update!(client, theme, 'data/modified_theme')
|
266
|
+
# job = Readiness::Zendesk::Themes.upload!(client, job, file)
|
267
|
+
# pp job.id
|
268
|
+
# # => "a66e7bde543c6b6d018f0e07a654feaf"
|
269
|
+
def self.update!(client, theme, location = './')
|
270
|
+
file = Themes.package!(location)
|
271
|
+
job = generate_update_job!(client, theme)
|
272
|
+
upload!(client, job, file)
|
273
|
+
end
|
274
|
+
|
275
|
+
##
|
276
|
+
# Updatea a theme. This will exit on error
|
277
|
+
#
|
278
|
+
# @author Jason Colyer
|
279
|
+
# @since 1.0.12
|
280
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
281
|
+
# @param theme [Object] An instance of {Readiness::Zendesk::Themes}
|
282
|
+
# @param location [location] The relative path to the location of the theme files
|
283
|
+
# @return [Object] An instance of {Readiness::Zendesk::ThemeJobStatuses}
|
284
|
+
# @example
|
285
|
+
# require 'support_readiness'
|
286
|
+
# config = Readiness::Zendesk::Configuration.new
|
287
|
+
# config.username = 'alice@example.com'
|
288
|
+
# config.token = 'test123abc'
|
289
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
290
|
+
# client = Readiness::Zendesk::Client.new(config)
|
291
|
+
# theme = Readiness::Zendesk::Themes.live_theme(client)
|
292
|
+
# job = Readiness::Zendesk::Themes.update!(client, theme, 'data/modified_theme')
|
293
|
+
# job = Readiness::Zendesk::Themes.upload!(client, job, file)
|
294
|
+
# pp job.id
|
295
|
+
# # => "a66e7bde543c6b6d018f0e07a654feaf"
|
296
|
+
def self.create!(client, theme, location = './')
|
297
|
+
file = Themes.package!(location)
|
298
|
+
job = generate_import_job!(client, theme)
|
299
|
+
upload!(client, job, file)
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
303
|
+
end
|
@@ -0,0 +1,110 @@
|
|
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 TicketFieldOptions within the module {Readiness::Zendesk}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.12
|
12
|
+
class TicketFieldOptions < Readiness::Client
|
13
|
+
attr_accessor :id, :name, :position, :value
|
14
|
+
|
15
|
+
##
|
16
|
+
# Creates a new {Readiness::Zendesk::TicketFieldOptions} instance
|
17
|
+
#
|
18
|
+
# @author Jason Colyer
|
19
|
+
# @since 1.0.12
|
20
|
+
# @param object [Object] An instance of {Readiness::Zendesk::TicketFieldOptions}
|
21
|
+
# @example
|
22
|
+
# require 'support_readiness'
|
23
|
+
# Readiness::Zendesk::TicketFieldOptions.new
|
24
|
+
def initialize(object = {})
|
25
|
+
@id = object['id']
|
26
|
+
@name = object['name']
|
27
|
+
@position = object['position']
|
28
|
+
@value = object['value']
|
29
|
+
end
|
30
|
+
|
31
|
+
##
|
32
|
+
# Lists all ticket fields.
|
33
|
+
#
|
34
|
+
# @author Jason Colyer
|
35
|
+
# @since 1.0.12
|
36
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
37
|
+
# @param fid [Integer] The field ID to get the field options for
|
38
|
+
# @return [Array]
|
39
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/tickets/ticket_fields/#list-ticket-field-options Zendesk API > Ticket Fields > List Ticket Field Options
|
40
|
+
# @example
|
41
|
+
# require 'support_readiness'
|
42
|
+
# config = Readiness::Zendesk::Configuration.new
|
43
|
+
# config.username = 'alice@example.com'
|
44
|
+
# config.token = 'test123abc'
|
45
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
46
|
+
# client = Readiness::Zendesk::Client.new(config)
|
47
|
+
# options = Readiness::Zendesk::TicketFieldOptions.list(client, 123)
|
48
|
+
# pp fields.count
|
49
|
+
# # => 5
|
50
|
+
def self.list(client, fid)
|
51
|
+
array = []
|
52
|
+
page = 1
|
53
|
+
loop do
|
54
|
+
response = client.connection.get("ticket_fields/#{fid}/options?page=#{page}")
|
55
|
+
handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
|
56
|
+
body = Oj.load(response.body)
|
57
|
+
array += body['custom_field_options'].map { |f| TicketFieldOptions.new(f) }
|
58
|
+
break unless body['custom_field_options'].count == 100
|
59
|
+
|
60
|
+
page += 1
|
61
|
+
end
|
62
|
+
array
|
63
|
+
end
|
64
|
+
|
65
|
+
##
|
66
|
+
# Creates or updates a ticket field option. This will exit on error.
|
67
|
+
#
|
68
|
+
# @author Jason Colyer
|
69
|
+
# @since 1.0.12
|
70
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
71
|
+
# @param field [Object] An instance of {Readiness::Zendesk::TicketFields}
|
72
|
+
# @param option [Object] An instance of {Readiness::Zendesk::TicketFieldOptions}
|
73
|
+
# @return [Object]
|
74
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/tickets/ticket_fields/#create-or-update-ticket-field-option Zendesk API > Ticket Fields > Create or Update Ticket Field Option
|
75
|
+
def self.create_or_update!(client, field, option)
|
76
|
+
response = client.connection.post "ticket_fields/#{field.id}/options", to_clean_json_with_key(option, 'custom_field_option')
|
77
|
+
handle_request_error(1, 'Zendesk', response.status, { action: 'Create/update ticket field option', message: Oj.load(response.body)}) unless [200, 201].include?(response.status)
|
78
|
+
TicketFieldOptions.new(Oj.load(response.body)['custom_field_option'])
|
79
|
+
end
|
80
|
+
|
81
|
+
##
|
82
|
+
# Deletes a ticket field option. Will exit if unsuccessful
|
83
|
+
#
|
84
|
+
# @author Jason Colyer
|
85
|
+
# @since 1.0.12
|
86
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
87
|
+
# @param field [Object] An instance of {Readiness::Zendesk::TicketFields}
|
88
|
+
# @param option [Object] An instance of {Readiness::Zendesk::TicketFieldOptions}
|
89
|
+
# @return [Boolean]
|
90
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/tickets/ticket_fields/#delete-ticket-field-option Zendesk API > Ticket Fields > Delete Ticket Field Option
|
91
|
+
# @example
|
92
|
+
# require 'support_readiness'
|
93
|
+
# config = Readiness::Zendesk::Configuration.new
|
94
|
+
# config.username = 'alice@example.com'
|
95
|
+
# config.token = 'test123abc'
|
96
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
97
|
+
# client = Readiness::Zendesk::Client.new(config)
|
98
|
+
# field = Readiness::Zendesk::TicketFields.find!(client, 75)
|
99
|
+
# option = field.custom_field_options.last
|
100
|
+
# delete = Readiness::Zendesk::TicketFieldOptions.delete!(client, field, option)
|
101
|
+
# pp delete
|
102
|
+
# # => true
|
103
|
+
def self.delete!(client, field, option)
|
104
|
+
response = client.connection.delete "ticket_fields/#{field.id}/options/#{option.id}"
|
105
|
+
handle_request_error(1, 'Zendesk', response.status, { action: 'Delete a ticket field option', id: "ticket_fields/#{field.id}/options/#{option.id}", message: Oj.load(response.body)}) unless response.status == 204
|
106
|
+
true
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|