zendesk_support_api 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 35ce4e3e27845ca77e9d5436ce5cc053f0430a74ca9765ec708425ce19549f18
4
- data.tar.gz: b0ac9059cbd6aa2ee599d91025d43f89e1b687dbb3f982ab1f32f7ec41f8105a
3
+ metadata.gz: c28881afdb817ca2ba0c6cda69ca7005b7cafc04a85cd7941e5d4dd6faeaf3b0
4
+ data.tar.gz: 20032d3c334cef56ee462deddaca967b057d4ae2edd3d64e21697075838f6392
5
5
  SHA512:
6
- metadata.gz: 753387da38749fd018d1c70370ff0f48112b5b287b91339f59f042e9db8c2bd9106b4c481a3ae6d450d858ff3b07db2cc307c26953991fb9b25890ecaeb190b8
7
- data.tar.gz: fdad54556055bc06e87c0a9bb5bcc62fbbcc73891ba26ad0b9716528cad3cfb754c7e3f6543be14af788137c292a7c7b7513836a033f8cfcab2d5290fd422e2d
6
+ metadata.gz: f3bab94f1e5301ea0afdf086b3b7fdd9fefc8c07f4a07920eab6f6ffe55b48bbf4c69b1fda3bbfa3bf80ab6fe30064b1db925c5488bd6258ea8e91b6d95183e5
7
+ data.tar.gz: e7f1452b31ca1f508c4b12eabd6ac559001fdff33986ffd80b4e19b34b2f0b39fa45d55fa58a547707e44ce16a2b95beb215219559618cc9286de6650e5a4e90
@@ -1,5 +1,6 @@
1
1
  lib/zendesk_support_api.rb fee89f019b11ec8feb844644e000cec6cad6a695
2
- lib/zendesk_support_api/jobs.rb 21241d490bcb750ab702dc07e0d98b194ced2632
3
- lib/zendesk_support_api/users.rb bac3de0bac0a04cbe8cd1d338357470ddbca3bb6
4
- lib/zendesk_support_api/client.rb 157b67cde7b4e66ccdcbcda67d5a34bc9c3b8572
5
- lib/zendesk_support_api/version.rb f929e8c6d528a2522ca83288be610db1c9064a10
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
Binary file
Binary file
data/README.md CHANGED
@@ -37,3 +37,15 @@ require 'zendesk_support_api'
37
37
  client = ZendeskSupportAPI::Client.new('user@example.com', '123abc', 'https://zendesk.com/api/v2')
38
38
  ```
39
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
@@ -4,6 +4,7 @@ module ZendeskSupportAPI
4
4
  # Client class - https://developer.zendesk.com/rest_api/docs/support/introduction#security-and-authentication
5
5
  class Client
6
6
  require 'zendesk_support_api/jobs'
7
+ require 'zendesk_support_api/search'
7
8
  require 'zendesk_support_api/users'
8
9
 
9
10
  # Create a new instance of Client
@@ -5,7 +5,7 @@ module ZendeskSupportAPI
5
5
  class Jobs
6
6
  # Make a request to show the job status
7
7
  #
8
- # @param client [ZendeskSupportAPI::Client] The client instance
8
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
9
9
  # @param id [String] The id of the job to check
10
10
  # @return [Hash]
11
11
  #
@@ -38,5 +38,58 @@ module ZendeskSupportAPI
38
38
  def self.show(client, id)
39
39
  client.request(:get, "job_statuses/#{id}.json")
40
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
41
94
  end
42
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
@@ -85,41 +85,8 @@ module ZendeskSupportAPI
85
85
  # #=> "id"=>123,
86
86
  # #=> "url"=>"https://zendesk.com/api/users/123.json",
87
87
  # #=> "name"=>"Test User",
88
- # #=> "email"=>"test@example.com",
89
- # #=> "created_at"=>"2020-04-28T13:45:54Z",
90
- # #=> "updated_at"=>"2020-04-28T13:45:54Z",
91
- # #=> "time_zone"=>"Eastern Time (US & Canada)",
92
- # #=> "iana_time_zone"=>"America/New_York",
93
- # #=> "phone"=>nil,
94
- # #=> "shared_phone_number"=>nil,
95
- # #=> "photo"=>nil,
96
- # #=> "locale_id"=>1,
97
- # #=> "locale"=>"en-US",
98
- # #=> "organization_id"=>nil,
99
- # #=> "role"=>"end-user",
100
- # #=> "verified"=>false,
101
- # #=> "external_id"=>nil,
102
- # #=> "tags"=>[],
103
- # #=> "alias"=>nil,
104
- # #=> "active"=>true,
105
- # #=> "shared"=>false,
106
- # #=> "shared_agent"=>false,
107
- # #=> "last_login_at"=>nil,
108
- # #=> "two_factor_auth_enabled"=>false,
109
- # #=> "signature"=>nil,
110
- # #=> "details"=>nil,
111
- # #=> "notes"=>nil,
112
- # #=> "role_type"=>nil,
113
- # #=> "custom_role_id"=>nil,
114
- # #=> "moderator"=>false,
115
- # #=> "ticket_restriction"=>"requested",
116
- # #=> "only_private_comments"=>false,
117
- # #=> "restricted_agent"=>true,
118
- # #=> "suspended"=>false,
119
- # #=> "chat_only"=>false,
120
- # #=> "default_group_id"=>nil,
121
- # #=> "report_csv"=>false,
122
- # #=> "organization"=>[]}
88
+ # #=> ...
89
+ # #=> }
123
90
 
124
91
  def self.show(client, id)
125
92
  res = client.request(:get, "users/#{id}.json?#{included}")
@@ -133,8 +100,19 @@ module ZendeskSupportAPI
133
100
  # @return [Array]
134
101
  #
135
102
  # @example
136
- # ZendeskSupportAPI::Users.show_many(client, [123, 456, 789])
137
- # #=> [{user123},{user456},{user789}]
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
+ # #=> ]
138
116
 
139
117
  def self.show_many(client, ids)
140
118
  ids = ids.join(',')
@@ -162,11 +140,19 @@ module ZendeskSupportAPI
162
140
  # @return [Hash|String] Either the user details or the error
163
141
  #
164
142
  # @example
165
- # ZendeskSupportAPI::User.create(client, user)
166
- # #=> {user}
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
+ # #=> }
167
153
  # ZendeskSupportAPI::User.create(client, user)
168
154
  # #=> Creation failed: => "Creation failed: {\"email\"=>[{\"description\"
169
- # #=> =>\"Email: test@example.com is already being used by another user\",
155
+ # #=> =>\"Email: rw@example.com is already being used by another user\",
170
156
  # #=> \"error\"=>\"DuplicateValue\"}]}"
171
157
 
172
158
  def self.create(client, user)
@@ -180,7 +166,7 @@ module ZendeskSupportAPI
180
166
  #
181
167
  # @param client [ZendeskSupportAPI::Client] The client instance to use
182
168
  # @param users [Array] The users to create
183
- # @return [ZendeskSupportAPI::Client.handle_job] Either the user details or the error
169
+ # @return [ZendeskSupportAPI::Client.handle_job]
184
170
 
185
171
  def self.create_many(client, users)
186
172
  res = client.request(:post, 'users/create_many.json', users: users)
@@ -195,7 +181,14 @@ module ZendeskSupportAPI
195
181
  #
196
182
  # @example
197
183
  # ZendeskSupportAPI::User.create_or_update(client, user)
198
- # #=> {user}
184
+ # #=> {
185
+ # #=> "user": {
186
+ # #=> "id": 9873843,
187
+ # #=> "name": "Roger Wilco",
188
+ # #=> "email": "rw@example.com"
189
+ # #=> ...
190
+ # #=> }
191
+ # #=> }
199
192
 
200
193
  def self.create_or_update(client, user)
201
194
  res = client.request(:post, 'users/create_or_update.json', user: user)
@@ -208,7 +201,7 @@ module ZendeskSupportAPI
208
201
  #
209
202
  # @param client [ZendeskSupportAPI::Client] The client instance to use
210
203
  # @param users [Array] The users to create/update
211
- # @return [ZendeskSupportAPI::Client.handle_job] Either the user details or the error
204
+ # @return [ZendeskSupportAPI::Client.handle_job]
212
205
 
213
206
  def self.create_or_update_many(client, users)
214
207
  res = client.request(:post,
@@ -239,7 +232,7 @@ module ZendeskSupportAPI
239
232
  #
240
233
  # @param client [ZendeskSupportAPI::Client] The client instance to use
241
234
  # @param users [Array] The users to update
242
- # @return [ZendeskSupportAPI::Client.handle_job] Either the user details or the error
235
+ # @return [ZendeskSupportAPI::Client.handle_job]
243
236
 
244
237
  def self.update_many(client, users)
245
238
  res = client.request(:put, 'users/update_many.json', users: users)
@@ -269,7 +262,7 @@ module ZendeskSupportAPI
269
262
  #
270
263
  # @param client [ZendeskSupportAPI::Client] The client instance to use
271
264
  # @param ids [Array] The array of User IDs to delete
272
- # @return [ZendeskSupportAPI::Client.handle_job] Either the user details or the error
265
+ # @return [ZendeskSupportAPI::Client.handle_job]
273
266
 
274
267
  def self.delete_many(client, ids)
275
268
  ids = ids.join(',')
@@ -3,5 +3,5 @@
3
3
  module ZendeskSupportAPI
4
4
  # Outputs the gem version
5
5
 
6
- VERSION = '0.1.0'
6
+ VERSION = '0.2.0'
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zendesk_support_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Colyer
@@ -54,6 +54,7 @@ files:
54
54
  - lib/zendesk_support_api.rb
55
55
  - lib/zendesk_support_api/client.rb
56
56
  - lib/zendesk_support_api/jobs.rb
57
+ - lib/zendesk_support_api/search.rb
57
58
  - lib/zendesk_support_api/users.rb
58
59
  - lib/zendesk_support_api/version.rb
59
60
  - zendesk_support_api.gemspec