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,161 @@
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 SatisfactionReasons within the module {SupportOps::Zendesk}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [String] created_at The time the reason was created
13
+ # @attr [String] deleted_at The time the reason was deleted
14
+ # @attr [Integer] id Automatically assigned upon creation
15
+ # @attr [String] raw_value The dynamic content placeholder, if present, or the current "value", if not.
16
+ # @attr [Integer] reason_code An account-level code for referencing the reason. Custom reasons are assigned an auto-incrementing integer (non-system reason codes begin at 1000).
17
+ # @attr [String] updated_at The time the reason was updated
18
+ # @attr [String] value Translated value of the reason in the account locale
19
+ # @todo list
20
+ # @todo find_by_name
21
+ # @todo get
22
+ # @todo get!
23
+ class SatisfactionReasons < SupportOps::Zendesk::Base
24
+ define_attributes :created_at, :deleted_at, :id, :raw_value, :reason_code,
25
+ :updated_at, :value
26
+ readonly_attributes :created_at, :deleted_at, :id, :reason_code,
27
+ :updated_at
28
+
29
+ ##
30
+ # Lists all satisfaction reasons in the Zendesk system
31
+ #
32
+ # @author Jason Colyer
33
+ # @since 1.0.0
34
+ # @return [Array]
35
+ # @see
36
+ # https://developer.zendesk.com/api-reference/ticketing/ticket-management/satisfaction_reasons/#list-reasons-for-satisfaction-rating
37
+ # Zendesk API > Satisfaction Reasons > List Reasons for Satisfaction Rating
38
+ # @see SupportOps::Zendesk::Configuration Setting up a client
39
+ # @example
40
+ # require 'support_ops_zendesk'
41
+ #
42
+ # SupportOps::Zendesk::Configuration.configure do |config|
43
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
44
+ # config.username = 'jason@example.com'
45
+ # config.token = 'abc123'
46
+ # end
47
+ #
48
+ # reasons = SupportOps::Zendesk::SatisfactionReasons.list
49
+ # pp reasons.first.reason_code
50
+ # # => 1003
51
+ def self.list
52
+ response = client.connection.get('satisfaction_reasons')
53
+ Oj.load(response.body)['satisfaction_reasons'].map { |s| SatisfactionReasons.new(s) }
54
+ end
55
+
56
+ ##
57
+ # Locates a satisfaction reason within Zendesk by name. Can utilize a cache for quicker results
58
+ #
59
+ # @author Jason Colyer
60
+ # @since 1.0.0
61
+ # @overload find_by_name(key: value)
62
+ # @param name [String required] The name to search for
63
+ # @param cache [Array] An Array of SupportOps::Zendesk::SatisfactionReasons to use as a cache
64
+ # @return [Object] An instance of {SupportOps::Zendesk::SatisfactionReasons}
65
+ # @example
66
+ # require 'support_ops_zendesk'
67
+ #
68
+ # SupportOps::Zendesk::Configuration.configure do |config|
69
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
70
+ # config.username = 'jason@example.com'
71
+ # config.token = 'abc123'
72
+ # end
73
+ #
74
+ # reasons = SupportOps::Zendesk::SatisfactionReasons.list
75
+ # reason = SupportOps::Zendesk::SatisfactionReasons.find_by_name(name: 'Agent did not respond quickly', cache: reasons)
76
+ # pp reason.value
77
+ # # => "Agent did not respond quickly"
78
+ # pp reason.reason_code
79
+ # # => 1003
80
+ def self.find_by_name(**args)
81
+ raise 'You have to provide a name' unless args[:name]
82
+ if args[:cache]
83
+ raise 'Provided cache is not an Array' unless args[:cache].is_a? Array
84
+ reasons = args[:cache]
85
+ else
86
+ reasons = list
87
+ end
88
+ reasons.detect { |c| c.value.downcase == args[:name].to_s.downcase }
89
+ end
90
+
91
+ ##
92
+ # Locates a specific satisfaction reason in the Zendesk system
93
+ #
94
+ # @author Jason Colyer
95
+ # @since 1.0.0
96
+ # @see
97
+ # https://developer.zendesk.com/api-reference/ticketing/ticket-management/satisfaction_reasons/#show-reason-for-satisfaction-rating
98
+ # Zendesk API > Satisfaction Reasons > Show Reason for Satisfaction Rating
99
+ # @see SupportOps::Zendesk::Configuration Setting up a client
100
+ # @example
101
+ # require 'support_ops_zendesk'
102
+ #
103
+ # SupportOps::Zendesk::Configuration.configure do |config|
104
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
105
+ # config.username = 'jason@example.com'
106
+ # config.token = 'abc123'
107
+ # end
108
+ #
109
+ # reason = SupportOps::Zendesk::SatisfactionReasons.get(120447)
110
+ # pp reason.reason_code
111
+ # # => 1001
112
+ def self.get(object)
113
+ if object.is_a? SatisfactionReasons
114
+ SatisfactionReasons.new(id: id).find
115
+ else
116
+ SatisfactionReasons.new(id: object).find
117
+ end
118
+ end
119
+
120
+ ##
121
+ # Locates a specific satisfaction reason in the Zendesk system
122
+ #
123
+ # @author Jason Colyer
124
+ # @since 1.0.0
125
+ # @see
126
+ # https://developer.zendesk.com/api-reference/ticketing/ticket-management/satisfaction_reasons/#show-reason-for-satisfaction-rating
127
+ # Zendesk API > Satisfaction Reasons > Show Reason for Satisfaction Rating
128
+ # @see SupportOps::Zendesk::Configuration Setting up a client
129
+ # @example
130
+ # require 'support_ops_zendesk'
131
+ #
132
+ # SupportOps::Zendesk::Configuration.configure do |config|
133
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
134
+ # config.username = 'jason@example.com'
135
+ # config.token = 'abc123'
136
+ # end
137
+ #
138
+ # reason = SupportOps::Zendesk::SatisfactionReasons.get!(120447)
139
+ # pp reason.reason_code
140
+ # # => 1001
141
+ def self.get!(object)
142
+ if object.is_a? SatisfactionReasons
143
+ SatisfactionReasons.new(id: id).find!
144
+ else
145
+ SatisfactionReasons.new(id: object).find!
146
+ end
147
+ end
148
+
149
+ private
150
+
151
+ ##
152
+ # @private
153
+ def get_record
154
+ response = self.client.connection.get("satisfaction_reasons/#{self.id}")
155
+ return nil if response.status != 200
156
+
157
+ Oj.load(response.body)['satisfaction_reason']
158
+ end
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,27 @@
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 ScheduleHolidays within the module {SupportOps::Zendesk}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [String] end_date Must be in ISO 8601 date format. For example: "2021-01-01".
13
+ # @attr [Integer] id Automatically assigned upon creation
14
+ # @attr [String] name Name of the schedule holiday
15
+ # @attr [String] start_date Must be in ISO 8601 date format. For example, "2021-01-01".
16
+ # @todo List Holidays for Schedule => https://developer.zendesk.com/api-reference/ticketing/ticket-management/schedules/#list-holidays-for-schedule
17
+ # @todo Show Holiday => https://developer.zendesk.com/api-reference/ticketing/ticket-management/schedules/#show-holiday
18
+ # @todo Create Holiday => https://developer.zendesk.com/api-reference/ticketing/ticket-management/schedules/#create-holiday
19
+ # @todo Update Holiday => https://developer.zendesk.com/api-reference/ticketing/ticket-management/schedules/#update-holiday
20
+ # @todo Delete Holiday => https://developer.zendesk.com/api-reference/ticketing/ticket-management/schedules/#delete-holiday
21
+ class ScheduleHolidays < SupportOps::Zendesk::Base
22
+ define_attributes :end_date, :id, :name, :start_date
23
+
24
+ private
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,192 @@
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 Schedules within the module {SupportOps::Zendesk}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [String] created_at Time the schedule was created
13
+ # @attr [Integer] id Automatically assigned upon creation
14
+ # @attr [Array] intervals An array of starting and ending times for the schedule
15
+ # @attr [String] name Name of the schedule
16
+ # @attr [String] time_zone Time zone of the schedule
17
+ # @attr [String] updated_at Time the schedule was last updated
18
+ # @todo Create Schedule => https://developer.zendesk.com/api-reference/ticketing/ticket-management/schedules/#create-schedule
19
+ # @todo Update Schedule => https://developer.zendesk.com/api-reference/ticketing/ticket-management/schedules/#update-schedule
20
+ # @todo Delete Schedule => https://developer.zendesk.com/api-reference/ticketing/ticket-management/schedules/#delete-schedule
21
+ # @todo Update Intervals for a Schedule => https://developer.zendesk.com/api-reference/ticketing/ticket-management/schedules/#update-intervals-for-a-schedule
22
+ class Schedules < SupportOps::Zendesk::Base
23
+ # @!parse
24
+ # # Lists holidays on a schedule
25
+ # #
26
+ # # @author Jason Colyer
27
+ # # @since 1.0.0
28
+ # # @return [Boolean]
29
+ # # @note This is inherited from {SupportOps::Zendesk::Base#holidays}
30
+ # # @see
31
+ # # https://developer.zendesk.com/api-reference/ticketing/ticket-management/schedules/#list-holidays-for-schedule
32
+ # # Zendesk API > Schedules > List Holidays for Schedule
33
+ # # @example
34
+ # # require 'support_ops_zendesk'
35
+ # #
36
+ # # SupportOps::Zendesk::Configuration.configure do |config|
37
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
38
+ # # config.username = 'jason@example.com'
39
+ # # config.token = 'abc123'
40
+ # # end
41
+ # #
42
+ # # existing_schedule = SupportOps::Zendesk::Schedules.get!(123456)
43
+ # # holidays = existing_schedule.holidays
44
+ # # pp holidays.last.name
45
+ # # # => "Boxing Day"
46
+ # def holidays; end
47
+ define_attributes :created_at, :id, :intervals, :name, :time_zone,
48
+ :updated_at
49
+ readonly_attributes :created_at, :id, :updated_at
50
+
51
+ ##
52
+ # Lists schedules in the Zendesk system
53
+ #
54
+ # @author Jason Colyer
55
+ # @since 1.0.0
56
+ # @return [Array]
57
+ # @see
58
+ # https://developer.zendesk.com/api-reference/ticketing/ticket-management/schedules/#list-schedules
59
+ # Zendesk API > Schedules > List Schedules
60
+ # @see SupportOps::Zendesk::Configuration Setting up a client
61
+ # @example
62
+ # require 'support_ops_zendesk'
63
+ #
64
+ # SupportOps::Zendesk::Configuration.configure do |config|
65
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
66
+ # config.username = 'jason@example.com'
67
+ # config.token = 'abc123'
68
+ # end
69
+ #
70
+ # schedules = SupportOps::Zendesk::Schedules.list
71
+ # pp schedules.count
72
+ # # => 5
73
+ def self.list
74
+ response = client.connection.get('business_hours/schedules')
75
+ body = Oj.load(response.body)
76
+ body['schedules'].map { |s| Schedules.new(s) }
77
+ end
78
+
79
+ ##
80
+ # Locates a specific schedule in the Zendesk system
81
+ #
82
+ # @author Jason Colyer
83
+ # @since 1.0.0
84
+ # @see
85
+ # https://developer.zendesk.com/api-reference/ticketing/ticket-management/schedules/#show-schedule
86
+ # Zendesk API > Schedules > Show Schedule
87
+ # @see SupportOps::Zendesk::Configuration Setting up a client
88
+ # @example
89
+ # require 'support_ops_zendesk'
90
+ #
91
+ # SupportOps::Zendesk::Configuration.configure do |config|
92
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
93
+ # config.username = 'jason@example.com'
94
+ # config.token = 'abc123'
95
+ # end
96
+ #
97
+ # schedule = SupportOps::Zendesk::Schedule.get(123456)
98
+ # pp schedule.name
99
+ # # => "Business Hours"
100
+ def self.get(object)
101
+ if object.is_a? Schedules
102
+ Schedules.new(id: id).find
103
+ else
104
+ Schedules.new(id: object).find
105
+ end
106
+ end
107
+
108
+ ##
109
+ # Locates a specific schedule in the Zendesk system
110
+ #
111
+ # @author Jason Colyer
112
+ # @since 1.0.0
113
+ # @see
114
+ # https://developer.zendesk.com/api-reference/ticketing/ticket-management/schedules/#show-schedule
115
+ # Zendesk API > Schedules > Show Schedule
116
+ # @see SupportOps::Zendesk::Configuration Setting up a client
117
+ # @example
118
+ # require 'support_ops_zendesk'
119
+ #
120
+ # SupportOps::Zendesk::Configuration.configure do |config|
121
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
122
+ # config.username = 'jason@example.com'
123
+ # config.token = 'abc123'
124
+ # end
125
+ #
126
+ # schedule = SupportOps::Zendesk::Schedule.get(123456)
127
+ # pp schedule.name
128
+ # # => "Business Hours"
129
+ def self.get!(object)
130
+ if object.is_a? Schedules
131
+ Schedules.new(id: id).find!
132
+ else
133
+ Schedules.new(id: object).find!
134
+ end
135
+ end
136
+
137
+ ##
138
+ # Locates a schedule within Zendesk by name. Can utilize a cache for quicker results
139
+ #
140
+ # @author Jason Colyer
141
+ # @since 1.0.0
142
+ # @overload find_by_name(key: value)
143
+ # @param name [String required] The name to search for
144
+ # @param cache [Array] An Array of SupportOps::Zendesk::Schedules to use as a cache
145
+ # @return [Object] An instance of {SupportOps::Zendesk::Schedules}
146
+ # @example
147
+ # require 'support_ops_zendesk'
148
+ #
149
+ # SupportOps::Zendesk::Configuration.configure do |config|
150
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
151
+ # config.username = 'jason@example.com'
152
+ # config.token = 'abc123'
153
+ # end
154
+ #
155
+ # schedules = SupportOps::Zendesk::Schedules.list
156
+ # schedule = SupportOps::Zendesk::Schedules.find_by_name(name: 'Business Hours', cache: schedules)
157
+ # pp schedule.name
158
+ # # => "Business Hours"
159
+ # pp schedule.id
160
+ # # => 123456
161
+ def self.find_by_name(**args)
162
+ raise 'You have to provide a name' unless args[:name]
163
+ if args[:cache]
164
+ raise 'Provided cache is not an Array' unless args[:cache].is_a? Array
165
+ schedules = args[:cache]
166
+ else
167
+ schedules = list
168
+ end
169
+ schedules.detect { |c| c.name.downcase == args[:name].to_s.downcase }
170
+ end
171
+
172
+ private
173
+
174
+ ##
175
+ # @private
176
+ def get_record
177
+ response = self.client.connection.get("business_hours/schedules/#{self.id}")
178
+ return nil if response.status != 200
179
+
180
+ Oj.load(response.body)['schedule']
181
+ end
182
+
183
+ ##
184
+ # @private
185
+ def holidays_record
186
+ response = self.client.connection.get("business_hours/schedules/#{self.id}/holidays")
187
+ body = Oj.load(response.body)
188
+ body['holidays'].map { |h| ScheduleHolidays.new(h) }
189
+ end
190
+ end
191
+ end
192
+ end
@@ -0,0 +1,185 @@
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 Search within the module {SupportOps::Zendesk}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ class Search < SupportOps::Zendesk::Base
13
+ ##
14
+ # A wrapper for {SupportOps::Zendesk::Search#search} that specifies to use type:ticket
15
+ #
16
+ # @author Jason Colyer
17
+ # @since 1.0.0
18
+ # @overload tickets(key: value)
19
+ # @param query [String required] The search query to perform to search for
20
+ # @return [Array]
21
+ # @see
22
+ # https://developer.zendesk.com/api-reference/ticketing/ticket-management/search/#list-search-results
23
+ # Zendesk API > Search > List Search Results
24
+ # @example
25
+ # require 'support_ops_zendesk'
26
+ #
27
+ # SupportOps::Zendesk::Configuration.configure do |config|
28
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
29
+ # config.username = 'jason@example.com'
30
+ # config.token = 'abc123'
31
+ # end
32
+ #
33
+ # results = SupportOps::Zendesk::Search.tickets(query: 'custom_field_360018253094:americas__usa tags:ultimate satisfaction:badwithcomment')
34
+ # pp results.first.id
35
+ # # => 125834
36
+ def self.tickets(**args)
37
+ raise 'You have to provide a search query' unless args[:query]
38
+ search(type: 'ticket', query: args[:query])
39
+ end
40
+
41
+ ##
42
+ # A wrapper for {SupportOps::Zendesk::Search#search} that specifies to use type:user
43
+ #
44
+ # @author Jason Colyer
45
+ # @since 1.0.0
46
+ # @overload users(key: value)
47
+ # @param query [String required] The search query to perform to search for
48
+ # @return [Array]
49
+ # @see
50
+ # https://developer.zendesk.com/api-reference/ticketing/ticket-management/search/#list-search-results
51
+ # Zendesk API > Search > List Search Results
52
+ # @example
53
+ # require 'support_ops_zendesk'
54
+ #
55
+ # SupportOps::Zendesk::Configuration.configure do |config|
56
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
57
+ # config.username = 'jason@example.com'
58
+ # config.token = 'abc123'
59
+ # end
60
+ #
61
+ # results = SupportOps::Zendesk::Search.users(query: 'email:alice@example.com')
62
+ # pp results.first.name
63
+ # # => "Alice Example"
64
+ def self.users(**args)
65
+ raise 'You have to provide a search query' unless args[:query]
66
+ search(type: 'user', query: args[:query])
67
+ end
68
+
69
+ ##
70
+ # A wrapper for {SupportOps::Zendesk::Search#search} that specifies to use type:organization
71
+ #
72
+ # @author Jason Colyer
73
+ # @since 1.0.0
74
+ # @overload organizations(key: value)
75
+ # @param query [String required] The search query to perform to search for
76
+ # @return [Array]
77
+ # @see
78
+ # https://developer.zendesk.com/api-reference/ticketing/ticket-management/search/#list-search-results
79
+ # Zendesk API > Search > List Search Results
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
+ # results = SupportOps::Zendesk::Search.organizations(query: 'salesforce_id:ABCDEFGH0123456*')
90
+ # pp results.first.notes
91
+ # # => "This org is escalated. Please talk to support managers."
92
+ def self.organizations(**args)
93
+ raise 'You have to provide a search query' unless args[:query]
94
+ search(type: 'organization', query: args[:query])
95
+ end
96
+
97
+ ##
98
+ # A wrapper for {SupportOps::Zendesk::Search#search} that specifies to use type:group
99
+ #
100
+ # @author Jason Colyer
101
+ # @since 1.0.0
102
+ # @overload groups(key: value)
103
+ # @param query [String required] The search query to perform to search for
104
+ # @return [Array]
105
+ # @see
106
+ # https://developer.zendesk.com/api-reference/ticketing/ticket-management/search/#list-search-results
107
+ # Zendesk API > Search > List Search Results
108
+ # @example
109
+ # require 'support_ops_zendesk'
110
+ #
111
+ # SupportOps::Zendesk::Configuration.configure do |config|
112
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
113
+ # config.username = 'jason@example.com'
114
+ # config.token = 'abc123'
115
+ # end
116
+ #
117
+ # results = SupportOps::Zendesk::Search.groups(query: 'Support')
118
+ # pp results.first.name
119
+ # # => "Support AMER"
120
+ def self.groups(**args)
121
+ raise 'You have to provide a search query' unless args[:query]
122
+ search(type: 'group', query: args[:query])
123
+ end
124
+
125
+ ##
126
+ # Perform a search and list the first 1000 results
127
+ #
128
+ # @author Jason Colyer
129
+ # @since 1.0.0
130
+ # @overload search(key: value)
131
+ # @param type [String required] The search type to perform
132
+ # @param query [String required] The search query to perform to search for
133
+ # @return [Array]
134
+ # @see
135
+ # https://developer.zendesk.com/api-reference/ticketing/ticket-management/search/#list-search-results
136
+ # Zendesk API > Search > List Search Results
137
+ # @example
138
+ # require 'support_ops_zendesk'
139
+ #
140
+ # SupportOps::Zendesk::Configuration.configure do |config|
141
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
142
+ # config.username = 'jason@example.com'
143
+ # config.token = 'abc123'
144
+ # end
145
+ #
146
+ # search = SupportOps::Zendesk::Search.search(type: 'organization', query: 'salesforce_id:ABCDEFGH0123456*')
147
+ # pp search.first.notes
148
+ # # => "This org is escalated. Please talk to support managers."
149
+ def self.search(**args)
150
+ raise 'You have to provide a search type' unless args[:type]
151
+ raise 'You have to provide a search query' unless args[:query]
152
+ array = []
153
+ page = 1
154
+ loop do
155
+ response = client.connection.get "search?page=#{page}&query=type:#{args[:type]} #{ERB::Util.url_encode(args[:query])}"
156
+ body = Oj.load(response.body)
157
+ raise "Bad search performed => #{body}" if response.status == 422
158
+ array += body['results'].map { |r| object_from_type(args[:type], r) }
159
+ break if array.count >= 1000
160
+ break if body['next_page'].nil?
161
+
162
+ page += 1
163
+ end
164
+ array
165
+ end
166
+
167
+ ##
168
+ # Returns the type of Object to use depending on the type of query
169
+ #
170
+ # @author Jason Colyer
171
+ # @since 1.0.0
172
+ # @param type [String] The type of search to perform
173
+ # @param result [Hash] The search result item
174
+ # @return [Object]
175
+ def self.object_from_type(type, result)
176
+ return Tickets.new(result) if type == 'ticket'
177
+ return Users.new(result) if type == 'user'
178
+ return Organizations.new(result) if type == 'organization'
179
+ return Groups.new(result) if type == 'group'
180
+
181
+ nil
182
+ end
183
+ end
184
+ end
185
+ end