zendesk_api 1.33.0 → 1.36.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: ac58a5fc63f870e31bd1a7d33ce398aef60c203fc5ec7bba79b1422b81aa3402
4
- data.tar.gz: 1a315f8e08e96b2f1d1c20decb998459ec5f7ddc7ee233cb6cdaa7c0374da452
3
+ metadata.gz: 2cdeab11096a461873b1005a9ba2a51c249c574c743a98529d6b0e8ec110a2b5
4
+ data.tar.gz: d0a14003fa34b2b5e719911a7525530aec6d73675d532651517ac7eddb7c241a
5
5
  SHA512:
6
- metadata.gz: e4021bc4c21f5b0ac9257ef8a8c0ee34e22244865f8737167be27aa057505f240d9c6996d262162cce3734759ac8b93eacf3ab3c9454066976ae1e835e5631fa
7
- data.tar.gz: 750d62cb5fc7f404a034ff8c5cc5e3c85c59a5852e4d46d55facb224dcfc7b3f41daf29ab7cb228d06993158108cba7a76ae72c50b0acbf9ee03adcab83e73f6
6
+ metadata.gz: d2b921604df568c16f2dafa908a349f90e52b8dafef9b409b2a4d94b6735ade3fa49243acac03aa8e76bbde74007e8ddde85e48f0bc90515e665746d442a73cb
7
+ data.tar.gz: bcb624be64595a6d5e31ed26dc4f0feff63c18788b2353a6f55888eeb438ab9a56bd62e1e63d198258a431c7ba3a2745e6cd3d514afb3ba8eb4d635cbdc40046
@@ -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)
@@ -198,7 +198,7 @@ module ZendeskAPI
198
198
  end
199
199
 
200
200
  def check_url
201
- if !config.allow_http && config.url !~ /^https/
201
+ if !config.allow_http && !config.url.start_with?('https://')
202
202
  raise ArgumentError, "zendesk_api is ssl only; url must begin with https://"
203
203
  end
204
204
  end
@@ -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
 
@@ -5,8 +5,8 @@ module ZendeskAPI
5
5
  class User < Resource; end
6
6
  class UserRelated < DataResource; end
7
7
  class Category < Resource; end
8
- class OrganizationMembership < ReadResource; end
9
8
  class OrganizationSubscription < ReadResource; end
9
+ class CustomStatus < Resource; end
10
10
 
11
11
  # @internal Begin actual Resource definitions
12
12
 
@@ -126,6 +126,10 @@ module ZendeskAPI
126
126
 
127
127
  class OrganizationRelated < DataResource; end
128
128
 
129
+ class OrganizationMembership < ReadResource
130
+ extend CreateOrUpdate
131
+ end
132
+
129
133
  class Organization < Resource
130
134
  extend CreateMany
131
135
  extend CreateOrUpdate
@@ -187,8 +191,10 @@ module ZendeskAPI
187
191
 
188
192
  class Section < Resource
189
193
  end
194
+ class Translation < Resource; end
190
195
 
191
196
  has_many Section
197
+ has_many Translation
192
198
  end
193
199
 
194
200
  class Section < ReadResource
@@ -200,9 +206,14 @@ module ZendeskAPI
200
206
 
201
207
  has Category
202
208
 
209
+ class Vote < Resource; end
210
+ class Translation < Resource; end
203
211
  class Article < Resource
212
+ has_many Vote
213
+ has_many Translation
204
214
  end
205
215
 
216
+ has_many Translation
206
217
  has_many Article
207
218
  end
208
219
 
@@ -212,6 +223,11 @@ module ZendeskAPI
212
223
  "help_center/articles"
213
224
  end
214
225
  end
226
+
227
+ class Vote < Resource; end
228
+ has_many Vote
229
+ class Translation < Resource; end
230
+ has_many Translation
215
231
  end
216
232
 
217
233
  class TopicSubscription < Resource
@@ -274,40 +290,14 @@ module ZendeskAPI
274
290
  has Group
275
291
  end
276
292
 
277
- class Search
278
- class Result < Data; end
279
-
280
- # Creates a search collection
281
- def self.search(client, options = {})
282
- unless (%w{query external_id} & options.keys.map(&:to_s)).any?
283
- warn "you have not specified a query for this search"
284
- end
285
-
286
- ZendeskAPI::Collection.new(client, self, options)
287
- end
288
-
289
- # Quack like a Resource
290
- # Creates the correct resource class from the result_type passed in
291
- def self.new(client, attributes)
292
- result_type = attributes["result_type"]
293
-
294
- if result_type
295
- result_type = ZendeskAPI::Helpers.modulize_string(result_type)
296
- klass = ZendeskAPI.const_get(result_type) rescue nil
297
- end
293
+ class Interval < Resource; end
298
294
 
299
- (klass || Result).new(client, attributes)
300
- end
295
+ class Schedule < Resource
296
+ has_many Interval
301
297
 
302
298
  class << self
303
- def resource_name
304
- "search"
305
- end
306
-
307
- alias :resource_path :resource_name
308
-
309
- def model_key
310
- "results"
299
+ def resource_path
300
+ "business_hours/schedules"
311
301
  end
312
302
  end
313
303
  end
@@ -376,6 +366,13 @@ module ZendeskAPI
376
366
  extend UpdateMany
377
367
  extend DestroyMany
378
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
+
379
376
  class Audit < DataResource
380
377
  class Event < Data
381
378
  has :author, :class => User
@@ -793,6 +790,11 @@ module ZendeskAPI
793
790
 
794
791
  class Target < Resource; end
795
792
 
793
+ class Invocation < Resource; end
794
+ class Webhook < Resource
795
+ has_many Invocation
796
+ end
797
+
796
798
  module Voice
797
799
  include DataNamespace
798
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.33.0"
2
+ VERSION = "1.36.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.33.0
4
+ version: 1.36.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: 2021-08-31 00:00:00.000000000 Z
12
+ date: 2022-05-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -40,7 +40,7 @@ dependencies:
40
40
  version: 3.5.2
41
41
  - - "<"
42
42
  - !ruby/object:Gem::Version
43
- version: 5.0.0
43
+ version: 6.0.0
44
44
  type: :runtime
45
45
  prerelease: false
46
46
  version_requirements: !ruby/object:Gem::Requirement
@@ -50,7 +50,7 @@ dependencies:
50
50
  version: 3.5.2
51
51
  - - "<"
52
52
  - !ruby/object:Gem::Version
53
- version: 5.0.0
53
+ version: 6.0.0
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: inflection
56
56
  requirement: !ruby/object:Gem::Requirement
@@ -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.33.0/CHANGELOG.md
147
- documentation_uri: https://www.rubydoc.info/gems/zendesk_api/1.33.0
148
- source_code_uri: https://github.com/zendesk/zendesk_api_client_rb/tree/v1.33.0
147
+ changelog_uri: https://github.com/zendesk/zendesk_api_client_rb/blob/v1.36.0/CHANGELOG.md
148
+ documentation_uri: https://www.rubydoc.info/gems/zendesk_api/1.36.0
149
+ source_code_uri: https://github.com/zendesk/zendesk_api_client_rb/tree/v1.36.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
@@ -162,8 +163,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
163
  - !ruby/object:Gem::Version
163
164
  version: 1.3.6
164
165
  requirements: []
165
- rubygems_version: 3.1.2
166
- signing_key:
166
+ rubygems_version: 3.3.7
167
+ signing_key:
167
168
  specification_version: 4
168
169
  summary: Zendesk REST API Client
169
170
  test_files: []