zendesk_api 1.13.4 → 1.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/LICENSE +176 -0
- data/lib/zendesk_api/actions.rb +45 -6
- data/lib/zendesk_api/association.rb +3 -3
- data/lib/zendesk_api/associations.rb +2 -2
- data/lib/zendesk_api/client.rb +25 -4
- data/lib/zendesk_api/collection.rb +8 -8
- data/lib/zendesk_api/configuration.rb +5 -1
- data/lib/zendesk_api/error.rb +15 -5
- data/lib/zendesk_api/helpers.rb +8 -8
- data/lib/zendesk_api/middleware/request/etag_cache.rb +4 -0
- data/lib/zendesk_api/middleware/request/raise_rate_limited.rb +31 -0
- data/lib/zendesk_api/middleware/request/retry.rb +1 -1
- data/lib/zendesk_api/middleware/request/upload.rb +5 -2
- data/lib/zendesk_api/middleware/response/callback.rb +1 -1
- data/lib/zendesk_api/middleware/response/logger.rb +6 -1
- data/lib/zendesk_api/middleware/response/parse_iso_dates.rb +1 -1
- data/lib/zendesk_api/middleware/response/raise_error.rb +1 -2
- data/lib/zendesk_api/middleware/response/sanitize_response.rb +0 -2
- data/lib/zendesk_api/resource.rb +7 -2
- data/lib/zendesk_api/resources.rb +98 -94
- data/lib/zendesk_api/sideloading.rb +0 -1
- data/lib/zendesk_api/silent_mash.rb +8 -0
- data/lib/zendesk_api/track_changes.rb +5 -5
- data/lib/zendesk_api/trackie.rb +2 -3
- data/lib/zendesk_api/verbs.rb +1 -1
- data/lib/zendesk_api/version.rb +1 -1
- data/util/resource_handler.rb +2 -2
- metadata +31 -123
@@ -4,10 +4,9 @@ module ZendeskAPI
|
|
4
4
|
module Middleware
|
5
5
|
module Response
|
6
6
|
class RaiseError < Faraday::Response::RaiseError
|
7
|
-
|
8
7
|
def call(env)
|
9
8
|
super
|
10
|
-
rescue Faraday::
|
9
|
+
rescue Faraday::TimeoutError, Faraday::ConnectionFailed => e
|
11
10
|
raise Error::NetworkError.new(e, env)
|
12
11
|
end
|
13
12
|
|
data/lib/zendesk_api/resource.rb
CHANGED
@@ -59,7 +59,7 @@ module ZendeskAPI
|
|
59
59
|
@client = client
|
60
60
|
@attributes = ZendeskAPI::Trackie.new(attributes)
|
61
61
|
|
62
|
-
if self.class.associations.none? {|a| a[:name] == self.class.singular_resource_name}
|
62
|
+
if self.class.associations.none? { |a| a[:name] == self.class.singular_resource_name }
|
63
63
|
ZendeskAPI::Client.check_deprecated_namespace_usage @attributes, self.class.singular_resource_name
|
64
64
|
end
|
65
65
|
|
@@ -81,6 +81,10 @@ module ZendeskAPI
|
|
81
81
|
@attributes.send(*args, &block)
|
82
82
|
end
|
83
83
|
|
84
|
+
def respond_to_missing?(method, include_private = false)
|
85
|
+
@attributes.respond_to?(method) || super
|
86
|
+
end
|
87
|
+
|
84
88
|
# Returns the resource id of the object or nil
|
85
89
|
def id
|
86
90
|
key?(:id) ? method_missing(:id) : nil
|
@@ -117,7 +121,7 @@ module ZendeskAPI
|
|
117
121
|
|
118
122
|
# Compares resources by class and id. If id is nil, then by object_id
|
119
123
|
def ==(other)
|
120
|
-
return true if other.object_id ==
|
124
|
+
return true if other.object_id == object_id
|
121
125
|
|
122
126
|
if other && !(other.is_a?(Data) || other.is_a?(Integer))
|
123
127
|
warn "Trying to compare #{other.class} to a Resource from #{caller.first}"
|
@@ -195,6 +199,7 @@ module ZendeskAPI
|
|
195
199
|
@descendants ||= []
|
196
200
|
@descendants << base
|
197
201
|
end
|
202
|
+
|
198
203
|
def descendants
|
199
204
|
@descendants || []
|
200
205
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
module ZendeskAPI
|
2
|
-
# @internal The following are redefined later, but needed by some circular resources (e.g. Ticket -> User, User -> Ticket)
|
3
|
-
|
2
|
+
# @internal The following are redefined later, but needed by some circular resources (e.g. Ticket -> User, User -> Ticket)
|
4
3
|
|
5
4
|
class Ticket < Resource; end
|
6
|
-
class Forum < Resource; end
|
7
5
|
class User < Resource; end
|
6
|
+
class UserRelated < DataResource; end
|
8
7
|
class Category < Resource; end
|
9
8
|
class OrganizationMembership < ReadResource; end
|
9
|
+
class OrganizationSubscription < ReadResource; end
|
10
10
|
|
11
|
-
# @internal Begin actual Resource definitions
|
11
|
+
# @internal Begin actual Resource definitions
|
12
12
|
|
13
13
|
class Locale < ReadResource; end
|
14
14
|
|
@@ -20,7 +20,14 @@ module ZendeskAPI
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
class Topic < Resource
|
23
|
+
class Topic < Resource
|
24
|
+
class << self
|
25
|
+
def resource_path
|
26
|
+
"community/topics"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
24
31
|
class Bookmark < Resource; end
|
25
32
|
class Ability < DataResource; end
|
26
33
|
class Group < Resource; end
|
@@ -62,7 +69,7 @@ module ZendeskAPI
|
|
62
69
|
end
|
63
70
|
|
64
71
|
true
|
65
|
-
rescue Faraday::
|
72
|
+
rescue Faraday::ClientError => e
|
66
73
|
if method == :save
|
67
74
|
false
|
68
75
|
else
|
@@ -76,8 +83,8 @@ module ZendeskAPI
|
|
76
83
|
end
|
77
84
|
end
|
78
85
|
|
79
|
-
class Attachment <
|
80
|
-
def initialize(client, attributes)
|
86
|
+
class Attachment < ReadResource
|
87
|
+
def initialize(client, attributes = {})
|
81
88
|
attributes[:file] ||= attributes.delete(:id)
|
82
89
|
|
83
90
|
super
|
@@ -97,7 +104,9 @@ module ZendeskAPI
|
|
97
104
|
include Create
|
98
105
|
include Destroy
|
99
106
|
|
100
|
-
def id
|
107
|
+
def id
|
108
|
+
token
|
109
|
+
end
|
101
110
|
|
102
111
|
has_many Attachment
|
103
112
|
|
@@ -113,14 +122,22 @@ module ZendeskAPI
|
|
113
122
|
put :clear_badge
|
114
123
|
end
|
115
124
|
|
125
|
+
class OrganizationRelated < DataResource; end
|
126
|
+
|
116
127
|
class Organization < Resource
|
128
|
+
extend CreateMany
|
129
|
+
extend CreateOrUpdate
|
130
|
+
extend DestroyMany
|
131
|
+
|
117
132
|
has Ability, :inline => true
|
118
133
|
has Group
|
134
|
+
has :related, :class => OrganizationRelated
|
119
135
|
|
120
136
|
has_many Ticket
|
121
137
|
has_many User
|
122
138
|
has_many Tag, :extend => Tag::Update, :inline => :create
|
123
139
|
has_many OrganizationMembership
|
140
|
+
has_many :subscriptions, class: OrganizationSubscription
|
124
141
|
|
125
142
|
# Gets a incremental export of organizations from the start_time until now.
|
126
143
|
# @param [Client] client The {Client} object to be used
|
@@ -140,11 +157,6 @@ module ZendeskAPI
|
|
140
157
|
end
|
141
158
|
end
|
142
159
|
|
143
|
-
class ForumSubscription < Resource
|
144
|
-
has Forum
|
145
|
-
has User
|
146
|
-
end
|
147
|
-
|
148
160
|
class OrganizationMembership < ReadResource
|
149
161
|
include Create
|
150
162
|
include Destroy
|
@@ -156,91 +168,72 @@ module ZendeskAPI
|
|
156
168
|
has Organization
|
157
169
|
end
|
158
170
|
|
159
|
-
class
|
160
|
-
|
161
|
-
|
162
|
-
has Locale
|
171
|
+
class OrganizationSubscription < ReadResource
|
172
|
+
include Create
|
173
|
+
include Destroy
|
163
174
|
|
164
|
-
|
165
|
-
|
175
|
+
has User
|
176
|
+
has Organization
|
166
177
|
end
|
167
178
|
|
168
179
|
class Category < Resource
|
169
|
-
|
170
|
-
|
180
|
+
class << self
|
181
|
+
def resource_path
|
182
|
+
"help_center/categories"
|
183
|
+
end
|
184
|
+
end
|
171
185
|
|
172
|
-
|
173
|
-
|
174
|
-
has User
|
175
|
-
end
|
186
|
+
class Section < Resource
|
187
|
+
end
|
176
188
|
|
177
|
-
|
178
|
-
has Topic
|
179
|
-
has User
|
180
|
-
has_many Attachment
|
189
|
+
has_many Section
|
181
190
|
end
|
182
191
|
|
183
|
-
class
|
184
|
-
class
|
185
|
-
|
186
|
-
|
187
|
-
include Update
|
188
|
-
include Destroy
|
189
|
-
|
190
|
-
has_many :uploads, :class => Attachment, :inline => true
|
191
|
-
|
192
|
-
def self.import!(client, attributes)
|
193
|
-
new(client, attributes).tap do |comment|
|
194
|
-
comment.save!(:path => 'import/' + comment.path)
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
def self.import(client, attributes)
|
199
|
-
comment = new(client, attributes)
|
200
|
-
return unless comment.save(:path => 'import/' + comment.path)
|
201
|
-
comment
|
192
|
+
class Section < ReadResource
|
193
|
+
class << self
|
194
|
+
def resource_path
|
195
|
+
"help_center/sections"
|
202
196
|
end
|
203
197
|
end
|
204
198
|
|
205
|
-
|
206
|
-
has Topic
|
207
|
-
has User
|
208
|
-
|
209
|
-
private
|
199
|
+
has Category
|
210
200
|
|
211
|
-
|
212
|
-
attributes.changes
|
213
|
-
end
|
201
|
+
class Article < Resource
|
214
202
|
end
|
215
203
|
|
216
|
-
|
217
|
-
|
218
|
-
has_many :subscriptions, :class => TopicSubscription
|
219
|
-
has :vote, :class => TopicVote
|
220
|
-
has_many Tag, :extend => Tag::Update, :inline => :create
|
221
|
-
has_many Attachment
|
222
|
-
has_many :uploads, :class => Attachment, :inline => true
|
223
|
-
|
224
|
-
def votes(opts = {})
|
225
|
-
return @votes if @votes && !opts[:reload]
|
204
|
+
has_many Article
|
205
|
+
end
|
226
206
|
|
227
|
-
|
228
|
-
|
207
|
+
class Article < ReadResource
|
208
|
+
class << self
|
209
|
+
def resource_path
|
210
|
+
"help_center/articles"
|
211
|
+
end
|
229
212
|
end
|
213
|
+
end
|
230
214
|
|
231
|
-
|
232
|
-
|
233
|
-
|
215
|
+
class TopicSubscription < Resource
|
216
|
+
class << self
|
217
|
+
def model_key
|
218
|
+
"subscriptions"
|
234
219
|
end
|
235
220
|
end
|
236
221
|
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
222
|
+
has Topic
|
223
|
+
has User
|
224
|
+
|
225
|
+
def path(options = {})
|
226
|
+
super(options.merge(:with_parent => true))
|
241
227
|
end
|
242
228
|
end
|
243
229
|
|
230
|
+
class Topic < Resource
|
231
|
+
has_many :subscriptions, :class => TopicSubscription, :inline => true
|
232
|
+
has_many Tag, :extend => Tag::Update, :inline => :create
|
233
|
+
has_many Attachment
|
234
|
+
has_many :uploads, :class => Attachment, :inline => true
|
235
|
+
end
|
236
|
+
|
244
237
|
class Activity < Resource
|
245
238
|
has User
|
246
239
|
has :actor, :class => User
|
@@ -434,7 +427,6 @@ module ZendeskAPI
|
|
434
427
|
has_many Audit
|
435
428
|
has :metrics, :class => TicketMetric
|
436
429
|
has Group
|
437
|
-
has :forum_topic, :class => Topic
|
438
430
|
has Organization
|
439
431
|
has Brand
|
440
432
|
has :related, :class => TicketRelated
|
@@ -454,7 +446,7 @@ module ZendeskAPI
|
|
454
446
|
# @param [Integer] start_time The start_time parameter
|
455
447
|
# @return [Collection] Collection of {Ticket}
|
456
448
|
def self.incremental_export(client, start_time)
|
457
|
-
ZendeskAPI::Collection.new(client, self, :path => "
|
449
|
+
ZendeskAPI::Collection.new(client, self, :path => "incremental/tickets?start_time=#{start_time.to_i}")
|
458
450
|
end
|
459
451
|
|
460
452
|
# Imports a ticket through the imports/tickets endpoint using save!
|
@@ -485,6 +477,15 @@ module ZendeskAPI
|
|
485
477
|
put :recover
|
486
478
|
end
|
487
479
|
|
480
|
+
class DeletedTicket < ReadResource
|
481
|
+
include Destroy
|
482
|
+
extend DestroyMany
|
483
|
+
|
484
|
+
# Restores this previously deleted ticket to an actual ticket
|
485
|
+
put :restore
|
486
|
+
put :restore_many
|
487
|
+
end
|
488
|
+
|
488
489
|
class UserViewRow < DataResource
|
489
490
|
has User
|
490
491
|
def self.model_key
|
@@ -518,11 +519,13 @@ module ZendeskAPI
|
|
518
519
|
private
|
519
520
|
|
520
521
|
def attributes_for_save
|
521
|
-
to_save = [:conditions, :actions, :output].inject({}) {|h,k| h.merge(k => send(k))}
|
522
|
+
to_save = [:conditions, :actions, :output].inject({}) { |h, k| h.merge(k => send(k)) }
|
522
523
|
{ self.class.singular_resource_name.to_sym => attributes.changes.merge(to_save) }
|
523
524
|
end
|
524
525
|
end
|
525
526
|
|
527
|
+
class TriggerCategory < Resource; end
|
528
|
+
|
526
529
|
module Conditions
|
527
530
|
def all_conditions=(all_conditions)
|
528
531
|
self.conditions ||= {}
|
@@ -601,7 +604,7 @@ module ZendeskAPI
|
|
601
604
|
|
602
605
|
# Returns the update to a ticket that happens when a macro will be applied.
|
603
606
|
# @param [Ticket] ticket Optional {Ticket} to apply this macro to.
|
604
|
-
# @raise [Faraday::
|
607
|
+
# @raise [Faraday::ClientError] Raised for any non-200 response.
|
605
608
|
def apply!(ticket = nil)
|
606
609
|
path = "#{self.path}/apply"
|
607
610
|
|
@@ -610,15 +613,15 @@ module ZendeskAPI
|
|
610
613
|
end
|
611
614
|
|
612
615
|
response = @client.connection.get(path)
|
613
|
-
|
616
|
+
SilentMash.new(response.body.fetch("result", {}))
|
614
617
|
end
|
615
618
|
|
616
619
|
# Returns the update to a ticket that happens when a macro will be applied.
|
617
620
|
# @param [Ticket] ticket Optional {Ticket} to apply this macro to
|
618
621
|
def apply(ticket = nil)
|
619
622
|
apply!(ticket)
|
620
|
-
rescue Faraday::
|
621
|
-
|
623
|
+
rescue Faraday::ClientError
|
624
|
+
SilentMash.new
|
622
625
|
end
|
623
626
|
end
|
624
627
|
|
@@ -639,12 +642,10 @@ module ZendeskAPI
|
|
639
642
|
class User < Resource
|
640
643
|
extend CreateMany
|
641
644
|
extend UpdateMany
|
645
|
+
extend CreateOrUpdate
|
646
|
+
extend CreateOrUpdateMany
|
642
647
|
extend DestroyMany
|
643
648
|
|
644
|
-
class TopicComment < TopicComment
|
645
|
-
include Read
|
646
|
-
end
|
647
|
-
|
648
649
|
class GroupMembership < Resource
|
649
650
|
put :make_default
|
650
651
|
end
|
@@ -723,25 +724,24 @@ module ZendeskAPI
|
|
723
724
|
false
|
724
725
|
end
|
725
726
|
|
727
|
+
put :merge
|
728
|
+
|
726
729
|
has CustomRole, :inline => true, :include => :roles
|
727
730
|
has Role, :inline => true, :include_key => :name
|
728
731
|
has Ability, :inline => true
|
732
|
+
has :related, :class => UserRelated
|
729
733
|
|
730
734
|
has_many Identity
|
731
735
|
|
732
736
|
has_many Request
|
733
737
|
has_many :requested_tickets, :class => Ticket, :path => 'tickets/requested'
|
738
|
+
has_many :assigned_tickets, :class => Ticket, :path => 'tickets/assigned'
|
734
739
|
has_many :ccd_tickets, :class => Ticket, :path => 'tickets/ccd'
|
735
740
|
|
736
741
|
has_many Group
|
737
742
|
has_many GroupMembership
|
738
|
-
has_many Topic
|
739
743
|
has_many OrganizationMembership
|
740
|
-
|
741
|
-
has_many ForumSubscription
|
742
|
-
has_many TopicSubscription
|
743
|
-
has_many :topic_comments, :class => TopicComment
|
744
|
-
has_many :topic_votes, :class => Topic::TopicVote
|
744
|
+
has_many OrganizationSubscription
|
745
745
|
|
746
746
|
has_many Setting
|
747
747
|
has_many Tag, :extend => Tag::Update, :inline => :create
|
@@ -765,6 +765,10 @@ module ZendeskAPI
|
|
765
765
|
end
|
766
766
|
end
|
767
767
|
|
768
|
+
class DeletedUser < ReadResource
|
769
|
+
include Destroy
|
770
|
+
end
|
771
|
+
|
768
772
|
class UserField < Resource; end
|
769
773
|
class OrganizationField < Resource; end
|
770
774
|
|
@@ -956,7 +960,7 @@ module ZendeskAPI
|
|
956
960
|
class PushNotificationDevice < DataResource
|
957
961
|
def self.destroy_many(client, tokens)
|
958
962
|
ZendeskAPI::Collection.new(
|
959
|
-
client, self,"push_notification_devices" => tokens,
|
963
|
+
client, self, "push_notification_devices" => tokens,
|
960
964
|
:path => "push_notification_devices/destroy_many",
|
961
965
|
:verb => :post
|
962
966
|
)
|
@@ -10,7 +10,7 @@ module ZendeskAPI
|
|
10
10
|
base.send :alias_method, :store, :regular_writer
|
11
11
|
base.send :alias_method, :[]=, :store
|
12
12
|
base.send :define_method, :update do |other|
|
13
|
-
other.each{|key, value| store key, value}
|
13
|
+
other.each { |key, value| store key, value }
|
14
14
|
end
|
15
15
|
base.send :alias_method, :merge!, :update
|
16
16
|
end
|
@@ -41,11 +41,11 @@ module ZendeskAPI
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def clear
|
44
|
-
keys.each{|key| delete key}
|
44
|
+
keys.each { |key| delete key }
|
45
45
|
end
|
46
46
|
|
47
47
|
def regular_writer(key, value)
|
48
|
-
if
|
48
|
+
if has_key?(key) && self[key] == value
|
49
49
|
value
|
50
50
|
else
|
51
51
|
changes[key] = value
|
@@ -64,7 +64,7 @@ module ZendeskAPI
|
|
64
64
|
each do |k, v|
|
65
65
|
if v.respond_to?(:changed?) && v.changed?
|
66
66
|
changes[k] = v.changes
|
67
|
-
elsif v.is_a?(Array) && v.any? {|val| val.respond_to?(:changed?) && val.changed?}
|
67
|
+
elsif v.is_a?(Array) && v.any? { |val| val.respond_to?(:changed?) && val.changed? }
|
68
68
|
changes[k] = v
|
69
69
|
end
|
70
70
|
end
|
@@ -73,7 +73,7 @@ module ZendeskAPI
|
|
73
73
|
|
74
74
|
def changed?(key = nil)
|
75
75
|
if key.nil?
|
76
|
-
!changes.empty? || any? {|_, v| v.respond_to?(:changed?) && v.changed?}
|
76
|
+
!changes.empty? || any? { |_, v| v.respond_to?(:changed?) && v.changed? }
|
77
77
|
else
|
78
78
|
changes.key?(key)
|
79
79
|
end
|
data/lib/zendesk_api/trackie.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
|
-
require 'hashie'
|
2
1
|
require 'zendesk_api/track_changes'
|
2
|
+
require 'zendesk_api/silent_mash'
|
3
3
|
|
4
4
|
module ZendeskAPI
|
5
5
|
# @private
|
6
|
-
class Trackie <
|
6
|
+
class Trackie < SilentMash
|
7
7
|
include ZendeskAPI::TrackChanges
|
8
8
|
|
9
9
|
def size
|
10
10
|
self['size']
|
11
11
|
end
|
12
|
-
|
13
12
|
end
|
14
13
|
end
|
data/lib/zendesk_api/verbs.rb
CHANGED
@@ -33,7 +33,7 @@ module ZendeskAPI
|
|
33
33
|
|
34
34
|
if @response.body.is_a?(Hash)
|
35
35
|
resource = @response.body[self.class.singular_resource_name]
|
36
|
-
resource ||= @response.body.fetch(self.class.resource_name, []).detect {|res| res["id"] == id}
|
36
|
+
resource ||= @response.body.fetch(self.class.resource_name, []).detect { |res| res["id"] == id }
|
37
37
|
end
|
38
38
|
|
39
39
|
@attributes.replace @attributes.deep_merge(resource || {})
|
data/lib/zendesk_api/version.rb
CHANGED
data/util/resource_handler.rb
CHANGED
@@ -10,7 +10,7 @@ class ResourceHandler < YARD::Handlers::Ruby::Base
|
|
10
10
|
|
11
11
|
if klass
|
12
12
|
begin
|
13
|
-
klass = klass.split("::").inject(ZendeskAPI) do |p,k|
|
13
|
+
klass = klass.split("::").inject(ZendeskAPI) do |p, k|
|
14
14
|
p.const_get(k)
|
15
15
|
end
|
16
16
|
rescue NameError
|
@@ -61,7 +61,7 @@ class ResourceHandler < YARD::Handlers::Ruby::Base
|
|
61
61
|
def get_klass(statement)
|
62
62
|
statement.traverse do |node|
|
63
63
|
if node.type == :assoc && node.jump(:kw).source == "class"
|
64
|
-
|
64
|
+
node.traverse do |value|
|
65
65
|
if value.type == :const_path_ref || value.type == :var_ref
|
66
66
|
return value.source
|
67
67
|
end
|