zendesk_support_api 0.2.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c28881afdb817ca2ba0c6cda69ca7005b7cafc04a85cd7941e5d4dd6faeaf3b0
4
+ data.tar.gz: 20032d3c334cef56ee462deddaca967b057d4ae2edd3d64e21697075838f6392
5
+ SHA512:
6
+ metadata.gz: f3bab94f1e5301ea0afdf086b3b7fdd9fefc8c07f4a07920eab6f6ffe55b48bbf4c69b1fda3bbfa3bf80ab6fe30064b1db925c5488bd6258ea8e91b6d95183e5
7
+ data.tar.gz: e7f1452b31ca1f508c4b12eabd6ac559001fdff33986ffd80b4e19b34b2f0b39fa45d55fa58a547707e44ce16a2b95beb215219559618cc9286de6650e5a4e90
@@ -0,0 +1,13 @@
1
+ image: ruby:2.6.1-alpine
2
+
3
+ pages:
4
+ script:
5
+ - gem install yard
6
+ - yard doc
7
+ - rm -rf public
8
+ - mv doc public
9
+ artifacts:
10
+ paths:
11
+ - public
12
+ only:
13
+ - master
@@ -0,0 +1,6 @@
1
+ lib/zendesk_support_api.rb fee89f019b11ec8feb844644e000cec6cad6a695
2
+ lib/zendesk_support_api/jobs.rb 15e3db660bb16f1a2bc580ce17a9368f81fc9d0e
3
+ lib/zendesk_support_api/users.rb aae91915f1ffdbaa2b2850f5c3b252e47dc04e6e
4
+ lib/zendesk_support_api/client.rb 65afe092b9549b6cb476821d5963b6ef2a933772
5
+ lib/zendesk_support_api/search.rb e741717c61809c578afbcd44f9b8e8f18a8c0363
6
+ lib/zendesk_support_api/version.rb 0d7f1c19d613fc9c5bd48f6be452e934221318fa
File without changes
Binary file
Binary file
Binary file
@@ -0,0 +1,51 @@
1
+ # ZendeskSupportAPI
2
+
3
+
4
+ ## Documentation
5
+
6
+ Documentation (generated via yard) can be found [here](https://reyloc.gitlab.io/zendesk_support_api/)
7
+
8
+ ## Installation
9
+
10
+ The gem can be installed either via rubygems or bundler:
11
+
12
+ ### Rubygems
13
+
14
+ ```bash
15
+ gem install zendesk_support_api
16
+ ```
17
+
18
+ ### Bundler
19
+
20
+ ```ruby
21
+ gem "zendesk_support_api"
22
+ ```
23
+
24
+ The current requirements for the gem are:
25
+
26
+ * 'faraday', '~>1.0.0'
27
+ * 'oj', '~>3.10.6'
28
+
29
+ ## Configuration
30
+
31
+ Configuration is done through the creation of a `ZendeskSupportAPI::Client`
32
+ instance:
33
+
34
+ ```ruby
35
+ require 'zendesk_support_api'
36
+
37
+ client = ZendeskSupportAPI::Client.new('user@example.com', '123abc', 'https://zendesk.com/api/v2')
38
+ ```
39
+
40
+ ## Usage
41
+
42
+ Soon to come
43
+
44
+ ## Changelog
45
+
46
+ * v0.1.0
47
+ * Initial creation of gem
48
+ * v0.2.0
49
+ * Added Search functions
50
+ * Fixed some yard syntax/formatting
51
+ * Changed version number
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'oj'
5
+
6
+ # ZendeskSupportAPI - https://developer.zendesk.com/rest_api/docs/support/introduction
7
+ module ZendeskSupportAPI
8
+ require 'zendesk_support_api/client'
9
+ require 'zendesk_support_api/version'
10
+ end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ZendeskSupportAPI
4
+ # Client class - https://developer.zendesk.com/rest_api/docs/support/introduction#security-and-authentication
5
+ class Client
6
+ require 'zendesk_support_api/jobs'
7
+ require 'zendesk_support_api/search'
8
+ require 'zendesk_support_api/users'
9
+
10
+ # Create a new instance of Client
11
+ #
12
+ # @param user [String] - The API username to use
13
+ # @param token [String] - The API token to use
14
+ # @param url [String] - The API URL to use
15
+ #
16
+ # @example
17
+ # ZendeskSupportAPI::Client.new('user', '123', 'zendesk.com/api')
18
+ # #=> #<ZendeskSupportAPI::Client:0x00007f88779cb330 @user="user",
19
+ # #=> @token="123", @url="zendesk.com/api">
20
+ def initialize(user, token, url)
21
+ @user = user
22
+ @token = token
23
+ @url = url
24
+ end
25
+
26
+ # Make a request to the Zendesk Support API
27
+ #
28
+ # @param http_method [Symbol] The HTTP method to utilize
29
+ # @param endpoint [String] The endpoint to hit
30
+ # @param params [Hash] Parameters for the request
31
+ # @return [Hash]
32
+ #
33
+ # @example
34
+ # client = ZendeskSupportAPI::Client.new('user', '123', 'zendesk.com/api')
35
+ # client.response(:get, 'users.json')
36
+ # #=> {users:[{user1},{user2}...{user100}]}
37
+
38
+ def request(http_method, endpoint, params = {})
39
+ response = client.public_send(http_method, endpoint, params)
40
+ Oj.load(response.body)
41
+ end
42
+
43
+ # Outputs a spinner symbol
44
+ #
45
+ # @param string [String] The string to output at the beginning
46
+ # @param num [Integer] The index of the iteration
47
+ # @return [String]
48
+ #
49
+ # @example
50
+ # ZendeskSupportAPI::Client.spinner('users', 1) #=> Grabbing users... \
51
+ # ZendeskSupportAPI::Client.spinner('groups', 3) #=> /
52
+
53
+ def spinner(string, num)
54
+ print "Grabbing #{string}... " if num.to_i == 1
55
+ symbols = ['-', '\\', '|', '/']
56
+ print symbols[num.to_i % 4]
57
+ print "\b"
58
+ end
59
+
60
+ # Handles responses that create jobs
61
+ #
62
+ # @param job [Hash] - The output from a request that created a job
63
+ # @return [Hash]
64
+
65
+ def handle_job(job)
66
+ print 'Checking job'
67
+ while job['job_status']['status'] != 'completed'
68
+ print '.'
69
+ job = ZendeskSupportAPI::Jobs.show(self, job['job_status']['id'])
70
+ end
71
+ puts 'completed'
72
+ job['job_status']['results']
73
+ end
74
+
75
+ private
76
+
77
+ # Creates a new Faraday instance
78
+ #
79
+ # @return [ZendeskSupportAPI::Client]
80
+
81
+ def client
82
+ @client ||= Faraday.new(@url) do |c|
83
+ c.request :url_encoded
84
+ c.adapter Faraday.default_adapter
85
+ c.basic_auth "#{@user}/token", @token
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ZendeskSupportAPI
4
+ # Jobs class - https://developer.zendesk.com/rest_api/docs/support/job_statuses
5
+ class Jobs
6
+ # Make a request to show the job status
7
+ #
8
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
9
+ # @param id [String] The id of the job to check
10
+ # @return [Hash]
11
+ #
12
+ # @example
13
+ # client = ZendeskSupportAPI::Client.new('user', '123', 'zendesk.com/api')
14
+ # ZendeskSupportAPI::Jobs.show(client, 'abc123')
15
+ # #=> {
16
+ # #=> "job_status"=> {
17
+ # #=> "id"=>"abc123",
18
+ # #=> "url"=>"abc123.json",
19
+ # #=> "total"=>2,
20
+ # #=> "progress"=>2,
21
+ # #=> "status"=>"completed",
22
+ # #=> "message"=>"Completed at 2020-04-29 13:26:40 +0000",
23
+ # #=> "results"=> [
24
+ # #=> {
25
+ # #=> "id"=>369731992959,
26
+ # #=> "status"=>"Updated",
27
+ # #=> "email"=>"test@example.com"
28
+ # #=> },
29
+ # #=> {
30
+ # #=> "id"=>369728778639,
31
+ # #=> "status"=>"Updated",
32
+ # #=> "email"=>"test2@example.com"
33
+ # #=> }
34
+ # #=> ]
35
+ # #=> }
36
+ # #=> }
37
+
38
+ def self.show(client, id)
39
+ client.request(:get, "job_statuses/#{id}.json")
40
+ end
41
+
42
+ # Make a request to show all job statuses
43
+ #
44
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
45
+ # @return [Hash]
46
+ #
47
+ # @example
48
+ # ZendeskSupportAPI::Jobs.show_many(client, ['abc123', 'def456'])
49
+ # #=> {
50
+ # #=> "job_statuses": [
51
+ # #=> {
52
+ # #=> "id": "abc123",
53
+ # #=> "status": "completed",
54
+ # #=> ...
55
+ # #=> },
56
+ # #=> {
57
+ # #=> "id": "def456",
58
+ # #=> "status": "completed",
59
+ # #=> ...
60
+ # #=> }
61
+ # #=> ]
62
+ # #=> }
63
+
64
+ def self.list(client)
65
+ client.request(:get, 'job_statuses.json')['job_statuses']
66
+ end
67
+
68
+ # Show many job statuses
69
+ #
70
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
71
+ # @param ids [Array] An Array of job IDs to show
72
+ # @return [Hash]
73
+ #
74
+ # @example
75
+ # ZendeskSupportAPI::Jobs.show_many(client, ['abc123', 'def456'])
76
+ # #=> {
77
+ # #=> "job_statuses": [
78
+ # #=> {
79
+ # #=> "id": "abc123",
80
+ # #=> "status": "completed",
81
+ # #=> ...
82
+ # #=> },
83
+ # #=> {
84
+ # #=> "id": "def456",
85
+ # #=> "status": "completed",
86
+ # #=> ...
87
+ # #=> }
88
+ # #=> ]
89
+ # #=> }
90
+
91
+ def self.show_many(client, ids)
92
+ client.request(:get, "job_statuses/show_many.json?ids=#{ids.join(',')}")
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,115 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ZendeskSupportAPI
4
+ # Search class - https://developer.zendesk.com/rest_api/docs/support/search
5
+ class Search
6
+ # Perform a search and list results (first 100)
7
+ #
8
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
9
+ # @param query [String] The query to use
10
+ # @param sort [String] The sorting method to use (defaults to revelance)
11
+ # @param order [String] The order to use (defaults to desc)
12
+ # @return [Array]
13
+ #
14
+ # @example
15
+ # ZendeskSupportAPI::Search.list(client, 'bob')
16
+ # #=> [
17
+ # #=> {
18
+ # #=> "name": "Bob McBob",
19
+ # #=> "created_at": "2009-05-13T00:07:08Z",
20
+ # #=> "updated_at": "2011-07-22T00:11:12Z",
21
+ # #=> "id": 211,
22
+ # #=> "result_type": "user"
23
+ # #=> "url": "https://zendesk.com/api/v2/users/211.json"
24
+ # #=> },
25
+ # #=> {
26
+ # #=> "name": "Bob's Company",
27
+ # #=> "created_at": "2009-08-26T00:07:08Z",
28
+ # #=> "updated_at": "2010-05-13T00:07:08Z",
29
+ # #=> "id": 122,
30
+ # #=> "result_type": "group"
31
+ # #=> "url": "https://zendesk.com/api/v2/groups/122.json"
32
+ # #=> },
33
+ # #=> ...
34
+ # #=> ]
35
+
36
+ def self.list(client, query, sort = '', order = 'desc')
37
+ return bad_search("invalid sort - #{sort}") unless sort_valid?(sort)
38
+ return bad_search("invalid order - #{order}") unless order_valid?(order)
39
+
40
+ sort_order = sort_order_string(sort, order)
41
+ client.request(:get, "search.json?query=#{query}#{sort_order}")['results']
42
+ end
43
+
44
+ # Determines if a given sort string is valid
45
+ #
46
+ # @param sort [String] The sort string to check
47
+ # @return [Boolean]
48
+ #
49
+ # @example
50
+ # ZendeskSupportAPI::Search.sort_valid? 'updated_at'
51
+ # #=> true
52
+ # ZendeskSupportAPI::Search.sort_valid? 'ticket_type'
53
+ # #=> true
54
+ # ZendeskSupportAPI::Search.sort_valid? 'random'
55
+ # #=> false
56
+
57
+ def self.sort_valid?(sort)
58
+ return true if sort.empty?
59
+
60
+ valid = %w[updated_at created_at priority status ticket_type]
61
+ valid.include? sort
62
+ end
63
+
64
+ # Determines if a given order string is valid
65
+ #
66
+ # @param order [String] The order string to check
67
+ # @return [Boolean]
68
+ #
69
+ # @example
70
+ # ZendeskSupportAPI::Search.order_valid? 'asc'
71
+ # #=> true
72
+ # ZendeskSupportAPI::Search.order_valid? 'desc'
73
+ # #=> true
74
+ # ZendeskSupportAPI::Search.order_valid? 'random'
75
+ # #=> false
76
+
77
+ def self.order_valid?(order)
78
+ valid = %w[asc desc]
79
+ valid.include? order
80
+ end
81
+
82
+ # Prints out an error message
83
+ #
84
+ # @param string [String] The error that occurred
85
+ # @return [String]
86
+ #
87
+ # @example
88
+ # ZendeskSupportAPI::Search.bad_search('invalid sort - name')
89
+ # #=> "Search cannot be completed: invalid sort - name"
90
+
91
+ def self.bad_search(string)
92
+ "Search cannot be completed: #{string}"
93
+ end
94
+
95
+ # Determines the sort and order to use in the query
96
+ #
97
+ # @param sort [String] The sort string to use
98
+ # @param order [String] The order string to use
99
+ # @return [String]
100
+ #
101
+ # @example
102
+ # ZendeskSupportAPI::Search.sort_order_string('', 'asc')
103
+ # #=> "&order_by=asc"
104
+ # ZendeskSupportAPI::Search.sort_order_string('priority', 'desc')
105
+ # #=> "&sort_by=priority"
106
+ # ZendeskSupportAPI::Search.sort_order_string('updated_at', 'asc')
107
+ # #=> "&sort_by=updated_at&order_by=asc"
108
+
109
+ def self.sort_order_string(sort, order)
110
+ sort = (sort.empty? ? '' : "&sort_by=#{sort}")
111
+ order = (order == 'desc' ? '' : '&order_by=asc')
112
+ "#{sort}#{order}"
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,290 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ZendeskSupportAPI
4
+ # Users class - https://developer.zendesk.com/rest_api/docs/support/users
5
+ class Users
6
+ # Function to return a string that side-loads organizations
7
+ #
8
+ # @return [String]
9
+
10
+ def self.included
11
+ 'include=organizations'
12
+ end
13
+
14
+ # Maps users into user_objects
15
+ #
16
+ # @param users [Array] The Array of users to map
17
+ # @param orgs [Array] The Array of orgs to use in mapping
18
+ # @return [Hash]
19
+
20
+ def self.user_map(users, orgs)
21
+ users.map { |u| user_object(u, orgs) }
22
+ end
23
+
24
+ # Returns the string of the next_page for pagination
25
+ #
26
+ # @param res [Hash] The Hash containing the response from a request
27
+ # @return [nil|String]
28
+ #
29
+ # @example
30
+ # ZendeskSupportAPI::Users.next_page(response) #=> nil
31
+ # ZendeskSupportAPI::Users.next_page(response)
32
+ # #=> "users.json?include=organizations&page=56
33
+
34
+ def self.next_page(res)
35
+ (res['next_page'].nil? ? nil : res['next_page'].split('/').last)
36
+ end
37
+
38
+ # Lists out users (first 100)
39
+ #
40
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
41
+ # @return [Hash]
42
+ #
43
+ # @example
44
+ # ZendeskSupportAPI::Users.list(client)
45
+ # #=> {users:[{user1},{user2}...{user100}]}
46
+
47
+ def self.list(client)
48
+ res = client.request(:get, "users.json?#{included}")
49
+ res['users'].map { |u| user_object(u, res['organizations']) }
50
+ res['users']
51
+ end
52
+
53
+ # Lists out all users (paginates over every page)
54
+ #
55
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
56
+ # @return [Hash]
57
+ #
58
+ # @example
59
+ # ZendeskSupportAPI::Users.all(client)
60
+ # #=> Grabbing users... / ...done
61
+ # #=> {users:[{user1},{user2}...{user201520}]}
62
+
63
+ def self.all(client)
64
+ users = []
65
+ page = "users.json?#{included}&page=1"
66
+ until page.nil?
67
+ res = client.request(:get, page)
68
+ client.spinner("users (total: #{res['count']})", page.split('=').last)
69
+ users += user_map(res['users'], res['organizations'])
70
+ page = next_page(res)
71
+ end
72
+ puts ' ...done'
73
+ users
74
+ end
75
+
76
+ # Grabs a specific user
77
+ #
78
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
79
+ # @param id [Integer] The User's ID to use
80
+ # @return [Hash]
81
+ #
82
+ # @example
83
+ # ZendeskSupportAPI::Users.show(client, 123)
84
+ # #=> {
85
+ # #=> "id"=>123,
86
+ # #=> "url"=>"https://zendesk.com/api/users/123.json",
87
+ # #=> "name"=>"Test User",
88
+ # #=> ...
89
+ # #=> }
90
+
91
+ def self.show(client, id)
92
+ res = client.request(:get, "users/#{id}.json?#{included}")
93
+ user_object(res['user'], res['organizations'])
94
+ end
95
+
96
+ # Shows many users
97
+ #
98
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
99
+ # @param ids [Array] An array of User IDs to use
100
+ # @return [Array]
101
+ #
102
+ # @example
103
+ # ZendeskSupportAPI::Users.show_many(client, [123, 456])
104
+ # #=> [
105
+ # #=> {
106
+ # #=> "id": 123,
107
+ # #=> "name": "Johnny Appleseed",
108
+ # #=> ...
109
+ # #=> },
110
+ # #=> {
111
+ # #=> "id": 456,
112
+ # #=> "name": "Rupert Root",
113
+ # #=> ...
114
+ # #=> }
115
+ # #=> ]
116
+
117
+ def self.show_many(client, ids)
118
+ ids = ids.join(',')
119
+ res = client.request(:get, "users/show_many.json?#{included}&ids=#{ids}")
120
+ res['users'].map { |u| user_object(u, res['organizations']) }
121
+ res['users']
122
+ end
123
+
124
+ # Creates a user hash (for mapping the org into the user Hash)
125
+ #
126
+ # @param user [Hash] The user details to use
127
+ # @param orgs [Array] The Array of orgs to use
128
+ # @return [Hash]
129
+
130
+ def self.user_object(user, orgs)
131
+ oid = 'organization_id'
132
+ user['organization'] = orgs.select { |o| o['id'] == user[oid] }
133
+ user
134
+ end
135
+
136
+ # Creates a user
137
+ #
138
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
139
+ # @param user [Hash] The user to create
140
+ # @return [Hash|String] Either the user details or the error
141
+ #
142
+ # @example
143
+ # user = {name: 'Roger Wilco', email: 'rw@example.com'}
144
+ # ZendeskSupportAPI::Users.create(client, user)
145
+ # #=> {
146
+ # #=> "user": {
147
+ # #=> "id": 9873843,
148
+ # #=> "name": "Roger Wilco",
149
+ # #=> "email": "rw@example.com"
150
+ # #=> ...
151
+ # #=> }
152
+ # #=> }
153
+ # ZendeskSupportAPI::User.create(client, user)
154
+ # #=> Creation failed: => "Creation failed: {\"email\"=>[{\"description\"
155
+ # #=> =>\"Email: rw@example.com is already being used by another user\",
156
+ # #=> \"error\"=>\"DuplicateValue\"}]}"
157
+
158
+ def self.create(client, user)
159
+ res = client.request(:post, 'users.json', user: user)
160
+ return "Creation failed: #{res['details']}" if res['error']
161
+
162
+ res
163
+ end
164
+
165
+ # Creates many users
166
+ #
167
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
168
+ # @param users [Array] The users to create
169
+ # @return [ZendeskSupportAPI::Client.handle_job]
170
+
171
+ def self.create_many(client, users)
172
+ res = client.request(:post, 'users/create_many.json', users: users)
173
+ client.handle_job(res)
174
+ end
175
+
176
+ # Creates or updates a user
177
+ #
178
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
179
+ # @param user [Hash] The user to create/update
180
+ # @return [Hash|String] Either the user details or the error
181
+ #
182
+ # @example
183
+ # ZendeskSupportAPI::User.create_or_update(client, user)
184
+ # #=> {
185
+ # #=> "user": {
186
+ # #=> "id": 9873843,
187
+ # #=> "name": "Roger Wilco",
188
+ # #=> "email": "rw@example.com"
189
+ # #=> ...
190
+ # #=> }
191
+ # #=> }
192
+
193
+ def self.create_or_update(client, user)
194
+ res = client.request(:post, 'users/create_or_update.json', user: user)
195
+ return "Create/Update failed: #{res['description']}" if res['error']
196
+
197
+ res
198
+ end
199
+
200
+ # Creates or updates many users
201
+ #
202
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
203
+ # @param users [Array] The users to create/update
204
+ # @return [ZendeskSupportAPI::Client.handle_job]
205
+
206
+ def self.create_or_update_many(client, users)
207
+ res = client.request(:post,
208
+ 'users/create_or_update_many.json',
209
+ users: users)
210
+ client.handle_job(res)
211
+ end
212
+
213
+ # Updates a user
214
+ #
215
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
216
+ # @param uid [Integer] The User's ID
217
+ # @param user [Hash] The user details to update
218
+ # @return [Hash|String] Either the user details or the error
219
+ #
220
+ # @example
221
+ # ZendeskSupportAPI::User.update(client, 123, user)
222
+ # #=> {user}
223
+
224
+ def self.update(client, uid, user)
225
+ res = client.request(:put, "users/#{uid}.json", user: user)
226
+ return "Update of #{uid} failed: #{res['error']}" if res['error']
227
+
228
+ res
229
+ end
230
+
231
+ # Updates many users
232
+ #
233
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
234
+ # @param users [Array] The users to update
235
+ # @return [ZendeskSupportAPI::Client.handle_job]
236
+
237
+ def self.update_many(client, users)
238
+ res = client.request(:put, 'users/update_many.json', users: users)
239
+ client.handle_job(res)
240
+ end
241
+
242
+ # Deletes a user
243
+ #
244
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
245
+ # @param uid [Integer] The User ID to delete
246
+ # @return [String]
247
+ #
248
+ # @example
249
+ # ZendeskSupportAPI::Users.delete(client, 123)
250
+ # #=> User 123 has been deleted
251
+ # ZendeskSupportAPI::Users.delete(client, 123)
252
+ # #=> "Deletion of 123 failed: RecordNotFound"
253
+
254
+ def self.delete(client, uid)
255
+ res = client.request(:delete, "users/#{uid}.json")
256
+ return "Deletion of #{uid} failed: #{res['error']}" if res['error']
257
+
258
+ "User #{uid} has been deleted"
259
+ end
260
+
261
+ # Deletes many users
262
+ #
263
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
264
+ # @param ids [Array] The array of User IDs to delete
265
+ # @return [ZendeskSupportAPI::Client.handle_job]
266
+
267
+ def self.delete_many(client, ids)
268
+ ids = ids.join(',')
269
+ res = client.request(:delete, "users/destroy_many.json?ids=#{ids}")
270
+ client.handle_job(res)
271
+ end
272
+
273
+ # Suspends a user
274
+ #
275
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
276
+ # @param id [Integer] The User ID to suspend
277
+ # @return [String] Either a success message or an error
278
+ #
279
+ # @example
280
+ # ZendeskSupportAPI::Users.suspend(client, 123)
281
+ # #=> User 123 is suspended
282
+
283
+ def self.suspend(client, id)
284
+ res = client.request(:put, "users/#{id}.json", user: { suspended: true })
285
+ return "Suspension of #{id} failed: #{res['error']}" if res['error']
286
+
287
+ "User #{id} suspended" if res['user']['suspended']
288
+ end
289
+ end
290
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ZendeskSupportAPI
4
+ # Outputs the gem version
5
+
6
+ VERSION = '0.2.0'
7
+ end
@@ -0,0 +1,21 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'zendesk_support_api/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'zendesk_support_api'
7
+ s.version = ZendeskSupportAPI::VERSION
8
+ s.date = '2020-04-28'
9
+ s.summary = 'Zendesk Support API wrapper gem'
10
+ s.description = 'TBD'
11
+ s.authors = ['Jason Colyer']
12
+ s.email = 'jcolyer2007@gmail.com'
13
+ s.homepage = 'https://gitlab.com/reyloc/zendesk_support_api'
14
+ s.files = Dir.chdir(File.expand_path('..', __FILE__)) do
15
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r(^(test|spec|features)/)) }
16
+ end
17
+ # s.homepage = 'TBD'
18
+ s.license = 'MIT'
19
+ s.add_dependency 'faraday', '~>1.0.0'
20
+ s.add_dependency 'oj', '~>3.10.6'
21
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zendesk_support_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Jason Colyer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-04-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: oj
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.10.6
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.10.6
41
+ description: TBD
42
+ email: jcolyer2007@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - ".gitlab-ci.yml"
48
+ - ".yardoc/checksums"
49
+ - ".yardoc/complete"
50
+ - ".yardoc/object_types"
51
+ - ".yardoc/objects/root.dat"
52
+ - ".yardoc/proxy_types"
53
+ - README.md
54
+ - lib/zendesk_support_api.rb
55
+ - lib/zendesk_support_api/client.rb
56
+ - lib/zendesk_support_api/jobs.rb
57
+ - lib/zendesk_support_api/search.rb
58
+ - lib/zendesk_support_api/users.rb
59
+ - lib/zendesk_support_api/version.rb
60
+ - zendesk_support_api.gemspec
61
+ homepage: https://gitlab.com/reyloc/zendesk_support_api
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubygems_version: 3.0.3
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Zendesk Support API wrapper gem
84
+ test_files: []