zendesk_api 1.34.0 → 1.37.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: 8e138461b731cb580a6e11cd2a67a5864e909d13da934cb42623debe9a4fda60
4
- data.tar.gz: f3ba385fd7563be3e6cce8afc22576a9fd81cd358cbc70635fdf2a30aee27e5b
3
+ metadata.gz: 5c5a2ced45e0201f6f9a45e5b8f7cf6951ca92c15ce893283c2289d0b260dc77
4
+ data.tar.gz: 31fa7566865e7191f49dadf6a5e01573264f4fc62ddfd4f635f8f7edd4be9ab2
5
5
  SHA512:
6
- metadata.gz: 61c2fcf9df4c4a6ffc77042ee63b0cfc11895619083b5e9d80a7c569aac87478a6aa989f4aa8305c853226e260e64741f536247f9dec58237d333571bd1bf3c0
7
- data.tar.gz: 78ee9bb11b950f2abcecd4b792199ffbf7b4cbfe6aef5bb9026dd371bf0f2a27a7b955250f88f9188938ed4e8a51a0310cb225f505fcd75a9cdd2ffcf4c8906c
6
+ metadata.gz: a1b355c67c8126f69f32ff6cd24d03b81b75eec27a0a72044383d0e06a871ba5bd18778119523a013725162048393d7a6bf58f075013e852303255b78bccb73f
7
+ data.tar.gz: 78ecdd8fd4d2fd889df06aea1ac98df7c68e6f89378f1358594b30853b23b3179f304ee4d87a781bda0047bc1970b8c28dfd147907d74223e28ffceb1676d1b1
@@ -19,13 +19,8 @@ module ZendeskAPI
19
19
  nil
20
20
  end
21
21
 
22
- # 1.9+ changed default to search ancestors, added flag to disable behavior.
23
22
  def module_defines_class?(mod, klass_as_string)
24
- if RUBY_VERSION < '1.9'
25
- mod.const_defined?(klass_as_string)
26
- else
27
- mod.const_defined?(klass_as_string, false)
28
- end
23
+ mod.const_defined?(klass_as_string, false)
29
24
  end
30
25
  end
31
26
 
@@ -58,7 +53,6 @@ module ZendeskAPI
58
53
 
59
54
  namespace = @options[:class].to_s.split("::")
60
55
  namespace[-1] = @options[:class].resource_path
61
-
62
56
  # Remove components without path information
63
57
  ignorable_namespace_strings.each { |ns| namespace.delete(ns) }
64
58
  has_parent = namespace.size > 1 || (options[:with_parent] && @options.parent)
@@ -165,7 +165,7 @@ module ZendeskAPI
165
165
 
166
166
  # request
167
167
  if config.access_token && !config.url_based_access_token
168
- builder.authorization("Bearer", config.access_token)
168
+ builder.request(:authorization, "Bearer", config.access_token)
169
169
  elsif config.access_token
170
170
  builder.use ZendeskAPI::Middleware::Request::UrlBasedAccessToken, config.access_token
171
171
  else
@@ -1,5 +1,6 @@
1
1
  require 'zendesk_api/resource'
2
2
  require 'zendesk_api/resources'
3
+ require 'zendesk_api/search'
3
4
 
4
5
  module ZendeskAPI
5
6
  # Represents a collection of resources. Lazily loaded, resources aren't
@@ -28,7 +29,7 @@ module ZendeskAPI
28
29
  # @param [String] resource The resource being collected.
29
30
  # @param [Hash] options Any additional options to be passed in.
30
31
  def initialize(client, resource, options = {})
31
- @client, @resource_class, @resource = client, resource, resource.resource_name
32
+ @client, @resource_class, @resource = client, resource, resource.resource_path
32
33
  @options = SilentMash.new(options)
33
34
 
34
35
  set_association_from_options
@@ -47,7 +48,7 @@ module ZendeskAPI
47
48
  end
48
49
 
49
50
  # Methods that take a Hash argument
50
- methods = %w{create find update update_many destroy}
51
+ methods = %w{create find update update_many destroy create_or_update}
51
52
  methods += methods.map { |method| method + "!" }
52
53
  methods.each do |deferrable|
53
54
  # Passes arguments and the proper path to the resource class method.
@@ -185,9 +186,15 @@ module ZendeskAPI
185
186
  elsif association && association.options.parent && association.options.parent.new_record?
186
187
  return (@resources = [])
187
188
  end
189
+ path_query_link = (@query || path)
188
190
 
189
- @response = get_response(@query || path)
190
- handle_response(@response.body)
191
+ @response = get_response(path_query_link)
192
+
193
+ if path_query_link == "search/export"
194
+ handle_cursor_response(@response.body)
195
+ else
196
+ handle_response(@response.body)
197
+ end
191
198
 
192
199
  @resources
193
200
  end
@@ -248,7 +255,7 @@ module ZendeskAPI
248
255
  if @options["page"]
249
256
  clear_cache
250
257
  @options["page"] += 1
251
- elsif @query = @next_page
258
+ elsif (@query = @next_page)
252
259
  fetch(true)
253
260
  else
254
261
  clear_cache
@@ -264,7 +271,7 @@ module ZendeskAPI
264
271
  if @options["page"] && @options["page"] > 1
265
272
  clear_cache
266
273
  @options["page"] -= 1
267
- elsif @query = @prev_page
274
+ elsif (@query = @prev_page)
268
275
  fetch(true)
269
276
  else
270
277
  clear_cache
@@ -313,12 +320,35 @@ module ZendeskAPI
313
320
  end
314
321
  end
315
322
 
316
- alias :to_str :to_s
323
+ alias to_str to_s
317
324
 
318
325
  def to_param
319
326
  map(&:to_param)
320
327
  end
321
328
 
329
+ def more_results?(response)
330
+ response["meta"].present? && response["results"].present?
331
+ end
332
+ alias_method :has_more_results?, :more_results? # For backward compatibility with 1.33.0 and 1.34.0
333
+
334
+ def get_response_body(link)
335
+ @client.connection.send("get", link).body
336
+ end
337
+
338
+ def get_next_page_data(original_response_body)
339
+ link = original_response_body["links"]["next"]
340
+
341
+ while link
342
+ response = get_response_body(link)
343
+
344
+ original_response_body["results"] = original_response_body["results"] + response["results"]
345
+
346
+ link = response["meta"]["has_more"] ? response["links"]["next"] : nil
347
+ end
348
+
349
+ original_response_body
350
+ end
351
+
322
352
  private
323
353
 
324
354
  def set_page_and_count(body)
@@ -372,8 +402,6 @@ module ZendeskAPI
372
402
  result
373
403
  end
374
404
 
375
- ## Initialize
376
-
377
405
  def join_special_params
378
406
  # some params use comma-joined strings instead of query-based arrays for multiple values
379
407
  @options.each do |k, v|
@@ -389,12 +417,9 @@ module ZendeskAPI
389
417
  association_options = { :path => @options.delete(:path) }
390
418
  association_options[:path] ||= @collection_path.join("/") if @collection_path
391
419
  @association = @options.delete(:association) || Association.new(association_options.merge(:class => @resource_class))
392
-
393
420
  @collection_path ||= [@resource]
394
421
  end
395
422
 
396
- ## Fetch
397
-
398
423
  def get_response(path)
399
424
  @error = nil
400
425
  @response = @client.connection.send(@verb || "get", path) do |req|
@@ -410,6 +435,25 @@ module ZendeskAPI
410
435
  end
411
436
  end
412
437
 
438
+ def handle_cursor_response(response_body)
439
+ unless response_body.is_a?(Hash)
440
+ raise ZendeskAPI::Error::NetworkError, @response.env
441
+ end
442
+
443
+ response_body = get_next_page_data(response_body) if more_results?(response_body)
444
+
445
+ body = response_body.dup
446
+ results = body.delete(@resource_class.model_key) || body.delete("results")
447
+
448
+ unless results
449
+ raise ZendeskAPI::Error::ClientError, "Expected #{@resource_class.model_key} or 'results' in response keys: #{body.keys.inspect}"
450
+ end
451
+
452
+ @resources = results.map do |res|
453
+ wrap_resource(res)
454
+ end
455
+ end
456
+
413
457
  def handle_response(response_body)
414
458
  unless response_body.is_a?(Hash)
415
459
  raise ZendeskAPI::Error::NetworkError, @response.env
@@ -2,6 +2,19 @@ module ZendeskAPI
2
2
  # @private
3
3
  module Helpers
4
4
  # From https://github.com/rubyworks/facets/blob/master/lib/core/facets/string/modulize.rb
5
+ # Converts a string to module name representation.
6
+ #
7
+ # This is essentially #camelcase, but it also converts
8
+ # '/' to '::' which is useful for converting paths to
9
+ # namespaces.
10
+ #
11
+ # Examples
12
+ #
13
+ # "method_name".modulize #=> "MethodName"
14
+ # "method/name".modulize #=> "Method::Name"
15
+ #
16
+ # @param string [string] input, `module/class_name`
17
+ # @return [string] a string that can become a class, `Module::ClassName`
5
18
  def self.modulize_string(string)
6
19
  # gsub('__','/'). # why was this ever here?
7
20
  string.gsub(/__(.?)/) { "::#{$1.upcase}" }.
@@ -11,6 +24,14 @@ module ZendeskAPI
11
24
  end
12
25
 
13
26
  # From https://github.com/rubyworks/facets/blob/master/lib/core/facets/string/snakecase.rb
27
+ # Underscore a string such that camelcase, dashes and spaces are
28
+ # replaced by underscores. This is the reverse of {#camelcase},
29
+ # albeit not an exact inverse.
30
+ #
31
+ # "SnakeCase".snakecase #=> "snake_case"
32
+ # "Snake-Case".snakecase #=> "snake_case"
33
+ # "Snake Case".snakecase #=> "snake_case"
34
+ # "Snake - Case".snakecase #=> "snake_case"
14
35
  def self.snakecase_string(string)
15
36
  # gsub(/::/, '/').
16
37
  string.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
@@ -5,8 +5,9 @@ require 'zendesk_api/association'
5
5
  require 'zendesk_api/associations'
6
6
  require 'zendesk_api/verbs'
7
7
 
8
+ # See docs: https://developer.zendesk.com/api-reference/
8
9
  module ZendeskAPI
9
- # Represents a resource that only holds data.
10
+ # Represents an abstract resource that only holds data.
10
11
  class Data
11
12
  include Associations
12
13
 
@@ -54,6 +55,7 @@ module ZendeskAPI
54
55
  # @param [Hash] attributes The optional attributes that describe the resource
55
56
  def initialize(client, attributes = {})
56
57
  raise "Expected a Hash for attributes, got #{attributes.inspect}" unless attributes.is_a?(Hash)
58
+
57
59
  @association = attributes.delete(:association) || Association.new(:class => self.class)
58
60
  @global_params = attributes.delete(:global) || {}
59
61
  @client = client
@@ -144,10 +146,16 @@ module ZendeskAPI
144
146
 
145
147
  alias :to_param :attributes
146
148
 
149
+ def attributes_for_save
150
+ { self.class.singular_resource_name.to_sym => attribute_changes }
151
+ end
152
+
147
153
  private
148
154
 
149
- def attributes_for_save
150
- { self.class.singular_resource_name.to_sym => attributes.changes }
155
+ # Send only the changes, for example, if the "status" attriubte
156
+ # goes from "new" to "new", we don't need to send anything
157
+ def attribute_changes
158
+ attributes.changes
151
159
  end
152
160
  end
153
161
 
@@ -177,7 +185,7 @@ module ZendeskAPI
177
185
  include Destroy
178
186
  end
179
187
 
180
- # Represents a resource that can CRUD (create, read, update, delete).
188
+ # Represents an abstract resource that can CRUD (create, read, update, delete).
181
189
  class Resource < DataResource
182
190
  include Read
183
191
  include Create
@@ -188,7 +196,7 @@ module ZendeskAPI
188
196
 
189
197
  class SingularResource < Resource
190
198
  def attributes_for_save
191
- { self.class.resource_name.to_sym => attributes.changes }
199
+ { self.class.resource_name.to_sym => attribute_changes }
192
200
  end
193
201
  end
194
202
 
@@ -6,6 +6,7 @@ module ZendeskAPI
6
6
  class UserRelated < DataResource; end
7
7
  class Category < Resource; end
8
8
  class OrganizationSubscription < ReadResource; end
9
+ class CustomStatus < Resource; end
9
10
 
10
11
  # @internal Begin actual Resource definitions
11
12
 
@@ -190,8 +191,10 @@ module ZendeskAPI
190
191
 
191
192
  class Section < Resource
192
193
  end
194
+ class Translation < Resource; end
193
195
 
194
196
  has_many Section
197
+ has_many Translation
195
198
  end
196
199
 
197
200
  class Section < ReadResource
@@ -203,9 +206,14 @@ module ZendeskAPI
203
206
 
204
207
  has Category
205
208
 
209
+ class Vote < Resource; end
210
+ class Translation < Resource; end
206
211
  class Article < Resource
212
+ has_many Vote
213
+ has_many Translation
207
214
  end
208
215
 
216
+ has_many Translation
209
217
  has_many Article
210
218
  end
211
219
 
@@ -215,6 +223,11 @@ module ZendeskAPI
215
223
  "help_center/articles"
216
224
  end
217
225
  end
226
+
227
+ class Vote < Resource; end
228
+ has_many Vote
229
+ class Translation < Resource; end
230
+ has_many Translation
218
231
  end
219
232
 
220
233
  class TopicSubscription < Resource
@@ -277,40 +290,14 @@ module ZendeskAPI
277
290
  has Group
278
291
  end
279
292
 
280
- class Search
281
- class Result < Data; end
282
-
283
- # Creates a search collection
284
- def self.search(client, options = {})
285
- unless (%w{query external_id} & options.keys.map(&:to_s)).any?
286
- warn "you have not specified a query for this search"
287
- end
288
-
289
- ZendeskAPI::Collection.new(client, self, options)
290
- end
293
+ class Interval < Resource; end
291
294
 
292
- # Quack like a Resource
293
- # Creates the correct resource class from the result_type passed in
294
- def self.new(client, attributes)
295
- result_type = attributes["result_type"]
296
-
297
- if result_type
298
- result_type = ZendeskAPI::Helpers.modulize_string(result_type)
299
- klass = ZendeskAPI.const_get(result_type) rescue nil
300
- end
301
-
302
- (klass || Result).new(client, attributes)
303
- end
295
+ class Schedule < Resource
296
+ has_many Interval
304
297
 
305
298
  class << self
306
- def resource_name
307
- "search"
308
- end
309
-
310
- alias :resource_path :resource_name
311
-
312
- def model_key
313
- "results"
299
+ def resource_path
300
+ "business_hours/schedules"
314
301
  end
315
302
  end
316
303
  end
@@ -379,6 +366,13 @@ module ZendeskAPI
379
366
  extend UpdateMany
380
367
  extend DestroyMany
381
368
 
369
+ # Unlike other attributes, "comment" is not a property of the ticket,
370
+ # but is used as a "comment on save", so it should be kept unchanged,
371
+ # See https://github.com/zendesk/zendesk_api_client_rb/issues/321
372
+ def attribute_changes
373
+ attributes.changes.merge("comment" => attributes["comment"])
374
+ end
375
+
382
376
  class Audit < DataResource
383
377
  class Event < Data
384
378
  has :author, :class => User
@@ -796,6 +790,11 @@ module ZendeskAPI
796
790
 
797
791
  class Target < Resource; end
798
792
 
793
+ class Invocation < Resource; end
794
+ class Webhook < Resource
795
+ has_many Invocation
796
+ end
797
+
799
798
  module Voice
800
799
  include DataNamespace
801
800
 
@@ -0,0 +1,51 @@
1
+ # `zendesk_api` gem root
2
+ module ZendeskAPI
3
+ # A rich factory that returns a class for your searches
4
+ class Search
5
+ # Creates a search collection
6
+ def self.search(client, options = {})
7
+ if (options.keys.map(&:to_s) & %w[query external_id]).empty?
8
+ warn "you have not specified a query for this search"
9
+ end
10
+
11
+ ZendeskAPI::Collection.new(client, self, options)
12
+ end
13
+
14
+ # Quack like a Resource
15
+ # Creates the correct resource class from `attributes[:result_type]`
16
+ def self.new(client, attributes)
17
+ present_result_type = (attributes[:result_type] || attributes["result_type"]).to_s
18
+ result_type = ZendeskAPI::Helpers.modulize_string(present_result_type)
19
+ klass = begin
20
+ ZendeskAPI.const_get(result_type)
21
+ rescue NameError
22
+ Result
23
+ end
24
+
25
+ (klass || Result).new(client, attributes)
26
+ end
27
+
28
+ class Result < Data; end
29
+
30
+ class << self
31
+ def resource_name
32
+ "search"
33
+ end
34
+ alias resource_path resource_name
35
+
36
+ def model_key
37
+ "results"
38
+ end
39
+ end
40
+ end
41
+
42
+ # This will use cursor pagination by default
43
+ class SearchExport < Search
44
+ class << self
45
+ def resource_name
46
+ "search/export"
47
+ end
48
+ alias resource_path resource_name
49
+ end
50
+ end
51
+ end
@@ -1,3 +1,3 @@
1
1
  module ZendeskAPI
2
- VERSION = "1.34.0"
2
+ VERSION = "1.37.0"
3
3
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zendesk_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.34.0
4
+ version: 1.37.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Davidovitz
8
8
  - Michael Grosser
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-01-04 00:00:00.000000000 Z
12
+ date: 2022-09-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -130,6 +130,7 @@ files:
130
130
  - lib/zendesk_api/middleware/response/sanitize_response.rb
131
131
  - lib/zendesk_api/resource.rb
132
132
  - lib/zendesk_api/resources.rb
133
+ - lib/zendesk_api/search.rb
133
134
  - lib/zendesk_api/sideloading.rb
134
135
  - lib/zendesk_api/silent_mash.rb
135
136
  - lib/zendesk_api/track_changes.rb
@@ -143,11 +144,11 @@ licenses:
143
144
  - Apache-2.0
144
145
  metadata:
145
146
  bug_tracker_uri: https://github.com/zendesk/zendesk_api_client_rb/issues
146
- changelog_uri: https://github.com/zendesk/zendesk_api_client_rb/blob/v1.34.0/CHANGELOG.md
147
- documentation_uri: https://www.rubydoc.info/gems/zendesk_api/1.34.0
148
- source_code_uri: https://github.com/zendesk/zendesk_api_client_rb/tree/v1.34.0
147
+ changelog_uri: https://github.com/zendesk/zendesk_api_client_rb/blob/v1.37.0/CHANGELOG.md
148
+ documentation_uri: https://www.rubydoc.info/gems/zendesk_api/1.37.0
149
+ source_code_uri: https://github.com/zendesk/zendesk_api_client_rb/tree/v1.37.0
149
150
  wiki_uri: https://github.com/zendesk/zendesk_api_client_rb/wiki
150
- post_install_message:
151
+ post_install_message:
151
152
  rdoc_options: []
152
153
  require_paths:
153
154
  - lib
@@ -163,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
164
  version: 1.3.6
164
165
  requirements: []
165
166
  rubygems_version: 3.0.3
166
- signing_key:
167
+ signing_key:
167
168
  specification_version: 4
168
169
  summary: Zendesk REST API Client
169
170
  test_files: []