zendesk_api 1.34.0 → 1.35.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zendesk_api/association.rb +1 -7
- data/lib/zendesk_api/collection.rb +56 -10
- data/lib/zendesk_api/helpers.rb +21 -0
- data/lib/zendesk_api/resource.rb +3 -2
- data/lib/zendesk_api/resources.rb +5 -38
- data/lib/zendesk_api/search.rb +51 -0
- data/lib/zendesk_api/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1cb0a6ce03a083efc37a6f742e90e58955a411ce76c3bfffb78ad5fc61f336b6
|
4
|
+
data.tar.gz: 10d25156b4961da61e2c1b7276ef5a8e4a17664c93d4a24e8f466ec9dc2e85b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da965fc1a9d28cb7edafdb82a56a1e73b64930f7706ac32bc9980ee3da415e540362f036c8dd6101b7615ce3781e4cc9e5645780bd83c504c714c60879450dcc
|
7
|
+
data.tar.gz: edbee03ff02ea28e78f88c9e1766d0cccbd0d59b068ae103f80d9c83f10cf734707e96a3341710131f93ffc346066f04a0e3d0200cc9def631cb984285086679
|
@@ -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
|
-
|
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)
|
@@ -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.
|
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(
|
190
|
-
|
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
|
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,7 +417,6 @@ 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
|
|
@@ -410,6 +437,25 @@ module ZendeskAPI
|
|
410
437
|
end
|
411
438
|
end
|
412
439
|
|
440
|
+
def handle_cursor_response(response_body)
|
441
|
+
unless response_body.is_a?(Hash)
|
442
|
+
raise ZendeskAPI::Error::NetworkError, @response.env
|
443
|
+
end
|
444
|
+
|
445
|
+
response_body = get_next_page_data(response_body) if more_results?(response_body)
|
446
|
+
|
447
|
+
body = response_body.dup
|
448
|
+
results = body.delete(@resource_class.model_key) || body.delete("results")
|
449
|
+
|
450
|
+
unless results
|
451
|
+
raise ZendeskAPI::Error::ClientError, "Expected #{@resource_class.model_key} or 'results' in response keys: #{body.keys.inspect}"
|
452
|
+
end
|
453
|
+
|
454
|
+
@resources = results.map do |res|
|
455
|
+
wrap_resource(res)
|
456
|
+
end
|
457
|
+
end
|
458
|
+
|
413
459
|
def handle_response(response_body)
|
414
460
|
unless response_body.is_a?(Hash)
|
415
461
|
raise ZendeskAPI::Error::NetworkError, @response.env
|
data/lib/zendesk_api/helpers.rb
CHANGED
@@ -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').
|
data/lib/zendesk_api/resource.rb
CHANGED
@@ -6,7 +6,7 @@ require 'zendesk_api/associations'
|
|
6
6
|
require 'zendesk_api/verbs'
|
7
7
|
|
8
8
|
module ZendeskAPI
|
9
|
-
# Represents
|
9
|
+
# Represents an abstract resource that only holds data.
|
10
10
|
class Data
|
11
11
|
include Associations
|
12
12
|
|
@@ -54,6 +54,7 @@ module ZendeskAPI
|
|
54
54
|
# @param [Hash] attributes The optional attributes that describe the resource
|
55
55
|
def initialize(client, attributes = {})
|
56
56
|
raise "Expected a Hash for attributes, got #{attributes.inspect}" unless attributes.is_a?(Hash)
|
57
|
+
|
57
58
|
@association = attributes.delete(:association) || Association.new(:class => self.class)
|
58
59
|
@global_params = attributes.delete(:global) || {}
|
59
60
|
@client = client
|
@@ -177,7 +178,7 @@ module ZendeskAPI
|
|
177
178
|
include Destroy
|
178
179
|
end
|
179
180
|
|
180
|
-
# Represents
|
181
|
+
# Represents an abstract resource that can CRUD (create, read, update, delete).
|
181
182
|
class Resource < DataResource
|
182
183
|
include Read
|
183
184
|
include Create
|
@@ -277,44 +277,6 @@ module ZendeskAPI
|
|
277
277
|
has Group
|
278
278
|
end
|
279
279
|
|
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
|
291
|
-
|
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
|
304
|
-
|
305
|
-
class << self
|
306
|
-
def resource_name
|
307
|
-
"search"
|
308
|
-
end
|
309
|
-
|
310
|
-
alias :resource_path :resource_name
|
311
|
-
|
312
|
-
def model_key
|
313
|
-
"results"
|
314
|
-
end
|
315
|
-
end
|
316
|
-
end
|
317
|
-
|
318
280
|
class Request < Resource
|
319
281
|
class Comment < DataResource
|
320
282
|
include Save
|
@@ -796,6 +758,11 @@ module ZendeskAPI
|
|
796
758
|
|
797
759
|
class Target < Resource; end
|
798
760
|
|
761
|
+
class Invocation < Resource; end
|
762
|
+
class Webhook < Resource
|
763
|
+
has_many Invocation
|
764
|
+
end
|
765
|
+
|
799
766
|
module Voice
|
800
767
|
include DataNamespace
|
801
768
|
|
@@ -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
|
data/lib/zendesk_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zendesk_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.35.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Davidovitz
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-01-
|
12
|
+
date: 2022-01-31 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,9 +144,9 @@ 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.
|
147
|
-
documentation_uri: https://www.rubydoc.info/gems/zendesk_api/1.
|
148
|
-
source_code_uri: https://github.com/zendesk/zendesk_api_client_rb/tree/v1.
|
147
|
+
changelog_uri: https://github.com/zendesk/zendesk_api_client_rb/blob/v1.35.0/CHANGELOG.md
|
148
|
+
documentation_uri: https://www.rubydoc.info/gems/zendesk_api/1.35.0
|
149
|
+
source_code_uri: https://github.com/zendesk/zendesk_api_client_rb/tree/v1.35.0
|
149
150
|
wiki_uri: https://github.com/zendesk/zendesk_api_client_rb/wiki
|
150
151
|
post_install_message:
|
151
152
|
rdoc_options: []
|