zendesk_support_api 0.2.0 → 0.3.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: c28881afdb817ca2ba0c6cda69ca7005b7cafc04a85cd7941e5d4dd6faeaf3b0
4
- data.tar.gz: 20032d3c334cef56ee462deddaca967b057d4ae2edd3d64e21697075838f6392
3
+ metadata.gz: 4914120c422052e97716f808fe888ec810bee8977f4fcd9d275cc6b1705c4ca0
4
+ data.tar.gz: 4cded8d95430a510322e44f0310f18ce9c01a5776a4dac4ab476eaee487fbecf
5
5
  SHA512:
6
- metadata.gz: f3bab94f1e5301ea0afdf086b3b7fdd9fefc8c07f4a07920eab6f6ffe55b48bbf4c69b1fda3bbfa3bf80ab6fe30064b1db925c5488bd6258ea8e91b6d95183e5
7
- data.tar.gz: e7f1452b31ca1f508c4b12eabd6ac559001fdff33986ffd80b4e19b34b2f0b39fa45d55fa58a547707e44ce16a2b95beb215219559618cc9286de6650e5a4e90
6
+ metadata.gz: 0065aa4ea3865fd6169a1650ed126d1748e290190dd5a5755c72fda7e37f6f365599e1f73fe178c07d68aa6ed2fed202cad6f6768fec91567c86dd2dafc2817a
7
+ data.tar.gz: 89c5da1d7258032fe2c56369a7d31e69131137012ada8573618b61693be110ac8a5e0b5bb196afa4cdca0ad1a1e20c21b7ddaa4c51da58f4ddda62e1aef7f162
@@ -1,6 +1,7 @@
1
1
  lib/zendesk_support_api.rb fee89f019b11ec8feb844644e000cec6cad6a695
2
2
  lib/zendesk_support_api/jobs.rb 15e3db660bb16f1a2bc580ce17a9368f81fc9d0e
3
- lib/zendesk_support_api/users.rb aae91915f1ffdbaa2b2850f5c3b252e47dc04e6e
4
- lib/zendesk_support_api/client.rb 65afe092b9549b6cb476821d5963b6ef2a933772
3
+ lib/zendesk_support_api/users.rb eb4f8d81f6f9ccf779679f7bfe354c0cc6be8d0c
4
+ lib/zendesk_support_api/client.rb f73dc3643644c6bf5f1a82593971b78a47b384fc
5
+ lib/zendesk_support_api/groups.rb bcc2a0b1af5bf3552c7838d80f339efbf8636e53
5
6
  lib/zendesk_support_api/search.rb e741717c61809c578afbcd44f9b8e8f18a8c0363
6
- lib/zendesk_support_api/version.rb 0d7f1c19d613fc9c5bd48f6be452e934221318fa
7
+ lib/zendesk_support_api/version.rb e6591152418f6cbe5b2a2ff5d68799f735ed597d
Binary file
Binary file
data/README.md CHANGED
@@ -49,3 +49,7 @@ Soon to come
49
49
  * Added Search functions
50
50
  * Fixed some yard syntax/formatting
51
51
  * Changed version number
52
+ * v0.3.0
53
+ * Changed version number
54
+ * Added Group functions
55
+ * Added User.groups function
@@ -3,6 +3,7 @@
3
3
  module ZendeskSupportAPI
4
4
  # Client class - https://developer.zendesk.com/rest_api/docs/support/introduction#security-and-authentication
5
5
  class Client
6
+ require 'zendesk_support_api/groups'
6
7
  require 'zendesk_support_api/jobs'
7
8
  require 'zendesk_support_api/search'
8
9
  require 'zendesk_support_api/users'
@@ -0,0 +1,178 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ZendeskSupportAPI
4
+ # Groups class - https://developer.zendesk.com/rest_api/docs/support/groups
5
+ class Groups
6
+ # Function to return a string that side-loads users
7
+ #
8
+ # @return [String]
9
+
10
+ def self.user_map(groups, users)
11
+ groups.map { |g| group_object(g, users) }
12
+ end
13
+
14
+ # Creates a group hash (for mappping the user into the group Hash)
15
+ #
16
+ # @param group [Hash] The group details to use
17
+ # @param users [Array] The Array of users to use
18
+ # @return [Hash]
19
+
20
+ def self.group_object(group, users)
21
+ group['user'] = users.select { |u| u['id'] == group['user_id'] }
22
+ group
23
+ end
24
+
25
+ # Returns the string of the next_page for pagination
26
+ #
27
+ # @param res [Hash] The Hash containing the response from a request
28
+ # @return [nil|String]
29
+ #
30
+ # @example
31
+ # ZendeskSupportAPI::Users.next_page(response) #=> nil
32
+ # ZendeskSupportAPI::Users.next_page(response)
33
+ # #=> "memberships.json?include=users&page=3
34
+
35
+ def self.next_page(res)
36
+ (res['next_page'].nil? ? nil : res['next_page'].split('/').last)
37
+ end
38
+
39
+ # Lists groups (first 100)
40
+ #
41
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
42
+ # @return [Array]
43
+ #
44
+ # @example
45
+ # ZendeskSupportAPI::Groups.list(client)
46
+ # #=> [
47
+ # #=> {
48
+ # #=> "name": "DJs",
49
+ # #=> "created_at": "2009-05-13T00:07:08Z",
50
+ # #=> "updated_at": "2011-07-22T00:11:12Z",
51
+ # #=> "id": 211
52
+ # #=> },
53
+ # #=> {
54
+ # #=> "name": "MCs",
55
+ # #=> "created_at": "2009-08-26T00:07:08Z",
56
+ # #=> "updated_at": "2010-05-13T00:07:08Z",
57
+ # #=> "id": 122
58
+ # #=> }
59
+ # #=> ]
60
+
61
+ def self.list(client)
62
+ client.request(:get, 'groups.json')['groups']
63
+ end
64
+
65
+ # Shows assignable groups (first 100)
66
+ #
67
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
68
+ # @return [Array]
69
+ #
70
+ # @example
71
+ # ZendeskSupportAPI::Groups.assignable(client)
72
+ # #=> [
73
+ # #=> {
74
+ # #=> "name": "DJs",
75
+ # #=> "created_at": "2009-05-13T00:07:08Z",
76
+ # #=> "updated_at": "2011-07-22T00:11:12Z",
77
+ # #=> "id": 211
78
+ # #=> },
79
+ # #=> {
80
+ # #=> "name": "MCs",
81
+ # #=> "created_at": "2009-08-26T00:07:08Z",
82
+ # #=> "updated_at": "2010-05-13T00:07:08Z",
83
+ # #=> "id": 122
84
+ # #=> }
85
+ # #=> ]
86
+
87
+ def self.assignable(client)
88
+ client.request(:get, 'assignable.json')['groups']
89
+ end
90
+
91
+ # Shows info about a specific group
92
+ #
93
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
94
+ # @param gid [Integer] The Group ID
95
+ # @return [Hash]
96
+ #
97
+ # @example
98
+ # ZendeskSupportAPI::Groups.show(client, 122)
99
+ # #=> {
100
+ # #=> "name": "MCs",
101
+ # #=> "created_at": "2009-08-26T00:07:08Z",
102
+ # #=> "updated_at": "2010-05-13T00:07:08Z",
103
+ # #=> "id": 122
104
+ # #=> }
105
+
106
+ def self.show(client, gid)
107
+ client.request(:get, "groups/#{gid}.json")['group']
108
+ end
109
+
110
+ # Create a group
111
+ #
112
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
113
+ # @param group [Hash] The group details to use
114
+ # @return [String|Hash]
115
+ #
116
+ # @example
117
+ # group = {
118
+ # name: 'Test Group'
119
+ # }
120
+ # ZendeskSupportAPI::Groups.create(client, group)
121
+ # #=> {
122
+ # #=> "name": "Test Group",
123
+ # #=> "created_at": "2011-04-20T17:49:00Z",
124
+ # #=> "updated_at": "2011-04-20T17:49:00Z",
125
+ # #=> "id": 123
126
+ # #=> }
127
+
128
+ def self.create(client, group)
129
+ res = client.request(:post, 'groups.json', group: group)
130
+ return "Creation failed: #{res['details']}" if res['error']
131
+
132
+ res
133
+ end
134
+
135
+ # Updates a group
136
+ #
137
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
138
+ # @param gid [Integer] The group ID to use
139
+ # @param group [Hash] The group details to use
140
+ # @return [String|Hash]
141
+ #
142
+ # @example
143
+ # group = {
144
+ # name: 'Test Group - defunct'
145
+ # }
146
+ # ZendeskSupportAPI::Groups.update(client, 123, group)
147
+ # #=> {
148
+ # #=> "name": "Test Group - defunct",
149
+ # #=> "created_at": "2011-04-20T17:49:00Z",
150
+ # #=> "updated_at": "2011-07-20T17:49:00Z",
151
+ # #=> "id": 123
152
+ # #=> }
153
+
154
+ def self.update(client, gid, group)
155
+ res = client.request(:post, "groups/#{gid}.json", group: group)
156
+ return "Update failed: #{res['details']}" if res['error']
157
+
158
+ res
159
+ end
160
+
161
+ # Deletes a group
162
+ #
163
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
164
+ # @param gid [Integer] The group ID to use
165
+ # @return [String]
166
+ #
167
+ # @example
168
+ # ZendeskSupportAPI::Groups.delete(client, 123)
169
+ # #=> Group 123 has been deleted
170
+
171
+ def self.delete(client, gid)
172
+ res = client.request(:delete, "groups/#{gid}.json")
173
+ return "Deletion of #{gid} failed: #{res['error']}" if res['error']
174
+
175
+ "Group #{gid} has been deleted"
176
+ end
177
+ end
178
+ end
@@ -57,7 +57,7 @@ module ZendeskSupportAPI
57
57
  #
58
58
  # @example
59
59
  # ZendeskSupportAPI::Users.all(client)
60
- # #=> Grabbing users... / ...done
60
+ # #=> Grabbing users (total: 215336)... / ...done
61
61
  # #=> {users:[{user1},{user2}...{user201520}]}
62
62
 
63
63
  def self.all(client)
@@ -286,5 +286,32 @@ module ZendeskSupportAPI
286
286
 
287
287
  "User #{id} suspended" if res['user']['suspended']
288
288
  end
289
+
290
+ # Shows a users groups
291
+ #
292
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
293
+ # @param uid [Integer] The User ID to use
294
+ # @return [Array]
295
+ #
296
+ # @example
297
+ # ZendeskSupportAPI::Users.groups(client, 1234)
298
+ # #=> [
299
+ # #=> {
300
+ # #=> "name": "DJs",
301
+ # #=> "created_at": "2009-05-13T00:07:08Z",
302
+ # #=> "updated_at": "2011-07-22T00:11:12Z",
303
+ # #=> "id": 211
304
+ # #=> },
305
+ # #=> {
306
+ # #=> "name": "MCs",
307
+ # #=> "created_at": "2009-08-26T00:07:08Z",
308
+ # #=> "updated_at": "2010-05-13T00:07:08Z",
309
+ # #=> "id": 122
310
+ # #=> }
311
+ # #=> ]
312
+
313
+ def self.groups(client, uid)
314
+ client.request(:get, "users/#{uid}/groups.json")['groups']
315
+ end
289
316
  end
290
317
  end
@@ -3,5 +3,5 @@
3
3
  module ZendeskSupportAPI
4
4
  # Outputs the gem version
5
5
 
6
- VERSION = '0.2.0'
6
+ VERSION = '0.3.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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Colyer
@@ -53,6 +53,7 @@ files:
53
53
  - README.md
54
54
  - lib/zendesk_support_api.rb
55
55
  - lib/zendesk_support_api/client.rb
56
+ - lib/zendesk_support_api/groups.rb
56
57
  - lib/zendesk_support_api/jobs.rb
57
58
  - lib/zendesk_support_api/search.rb
58
59
  - lib/zendesk_support_api/users.rb