zendesk_api 1.4.3 → 1.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/zendesk_api/client.rb +1 -0
- data/lib/zendesk_api/collection.rb +10 -0
- data/lib/zendesk_api/resources.rb +28 -18
- data/lib/zendesk_api/version.rb +1 -1
- data/spec/core/client_spec.rb +4 -0
- data/spec/core/collection_spec.rb +13 -0
- data/spec/fixtures/zendesk.rb +8 -0
- data/spec/live/request_spec.rb +23 -0
- data/spec/live/tag_spec.rb +0 -2
- data/spec/live/ticket_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04ffe4c8d58e8f4e587f813afee1b867cc8e15a6
|
4
|
+
data.tar.gz: 12bee85ee43c5d1af6fda0a4f069c6f2cfe57334
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03cea5cefaecc99504fdf12040b4dc1fc7b1bb12465d2804aec05f794da7c12b0148b196affcdedc3a77b07d97034e24983a0e4d958a716d07673132e78295dd
|
7
|
+
data.tar.gz: 0fd99e6c20b86d84b5703282fdb2d9d09a5d4a41d62fbda52b7ccb5b43d038d59b3eefdec02ae7a1d6e14a1fd48940cb135578479f0d15c1c0a0d9965de73203
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
zendesk_api (1.4.
|
4
|
+
zendesk_api (1.4.4)
|
5
5
|
faraday (~> 0.9)
|
6
6
|
hashie (>= 1.2, < 4.0)
|
7
7
|
inflection
|
@@ -43,7 +43,7 @@ GEM
|
|
43
43
|
erubis (2.7.0)
|
44
44
|
faraday (0.9.0)
|
45
45
|
multipart-post (>= 1.2, < 3)
|
46
|
-
hashie (3.
|
46
|
+
hashie (3.3.1)
|
47
47
|
hike (1.2.3)
|
48
48
|
i18n (0.6.11)
|
49
49
|
inflection (1.0.0)
|
data/lib/zendesk_api/client.rb
CHANGED
@@ -40,6 +40,7 @@ module ZendeskAPI
|
|
40
40
|
cached
|
41
41
|
else
|
42
42
|
@resource_cache[method][:class] ||= method_as_class(method)
|
43
|
+
raise "Resource for #{method} does not exist" unless @resource_cache[method][:class]
|
43
44
|
@resource_cache[method][:cache].write(options.hash, ZendeskAPI::Collection.new(self, @resource_cache[method][:class], options))
|
44
45
|
end
|
45
46
|
end
|
@@ -19,6 +19,9 @@ module ZendeskAPI
|
|
19
19
|
# @return [Hash] query options
|
20
20
|
attr_reader :options
|
21
21
|
|
22
|
+
# @return [ZendeskAPI::ClientError] The last response error
|
23
|
+
attr_reader :error
|
24
|
+
|
22
25
|
# Creates a new Collection instance. Does not fetch resources.
|
23
26
|
# Additional options are: verb (default: GET), path (default: resource param), page, per_page.
|
24
27
|
# @param [Client] client The {Client} to use.
|
@@ -176,6 +179,8 @@ module ZendeskAPI
|
|
176
179
|
def fetch(*args)
|
177
180
|
fetch!(*args)
|
178
181
|
rescue Faraday::Error::ClientError => e
|
182
|
+
@error = e
|
183
|
+
|
179
184
|
[]
|
180
185
|
end
|
181
186
|
|
@@ -373,6 +378,7 @@ module ZendeskAPI
|
|
373
378
|
## Fetch
|
374
379
|
|
375
380
|
def get_response(path)
|
381
|
+
@error = nil
|
376
382
|
@response = @client.connection.send(@verb || "get", path) do |req|
|
377
383
|
opts = @options.delete_if {|_, v| v.nil?}
|
378
384
|
|
@@ -394,6 +400,10 @@ module ZendeskAPI
|
|
394
400
|
body = response_body.dup
|
395
401
|
results = body.delete(@resource_class.model_key) || body.delete("results")
|
396
402
|
|
403
|
+
unless results
|
404
|
+
raise ZendeskAPI::Error::ClientError, "Expected #{@resource_class.model_key} or 'results' in response keys: #{body.keys.inspect}"
|
405
|
+
end
|
406
|
+
|
397
407
|
@resources = results.map do |res|
|
398
408
|
wrap_resource(res)
|
399
409
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module ZendeskAPI
|
2
2
|
# @internal The following are redefined later, but needed by some circular resources (e.g. Ticket -> User, User -> Ticket)
|
3
3
|
|
4
|
-
|
5
4
|
class Ticket < Resource; end
|
6
5
|
class Forum < Resource; end
|
7
6
|
class User < Resource; end
|
@@ -103,9 +102,21 @@ module ZendeskAPI
|
|
103
102
|
end
|
104
103
|
end
|
105
104
|
|
106
|
-
|
107
|
-
|
108
|
-
|
105
|
+
# @internal This isn't a real resource, it is used by ticket and request comments
|
106
|
+
module CommentMixin
|
107
|
+
include Save
|
108
|
+
|
109
|
+
def self.included(klass)
|
110
|
+
klass.has_many :uploads, :class => Attachment, :inline => true
|
111
|
+
klass.has :author, :class => User
|
112
|
+
end
|
113
|
+
|
114
|
+
def save
|
115
|
+
save_associations
|
116
|
+
true
|
117
|
+
end
|
118
|
+
|
119
|
+
alias :save! :save
|
109
120
|
end
|
110
121
|
|
111
122
|
class Organization < Resource
|
@@ -290,11 +301,11 @@ module ZendeskAPI
|
|
290
301
|
end
|
291
302
|
|
292
303
|
class Request < Resource
|
293
|
-
class Comment <
|
294
|
-
|
295
|
-
has :author, :class => User
|
304
|
+
class Comment < DataResource
|
305
|
+
include CommentMixin
|
296
306
|
end
|
297
307
|
|
308
|
+
has Comment, :inline => true
|
298
309
|
has_many Comment
|
299
310
|
|
300
311
|
has Organization
|
@@ -302,6 +313,14 @@ module ZendeskAPI
|
|
302
313
|
has :requester, :class => User
|
303
314
|
end
|
304
315
|
|
316
|
+
class AnonymousRequest < CreateResource
|
317
|
+
def self.singular_resource_name
|
318
|
+
'request'
|
319
|
+
end
|
320
|
+
|
321
|
+
namespace 'portal'
|
322
|
+
end
|
323
|
+
|
305
324
|
class TicketField < Resource; end
|
306
325
|
|
307
326
|
class TicketMetric < DataResource
|
@@ -325,17 +344,7 @@ module ZendeskAPI
|
|
325
344
|
end
|
326
345
|
|
327
346
|
class Comment < DataResource
|
328
|
-
include
|
329
|
-
|
330
|
-
has_many :uploads, :class => Attachment, :inline => true
|
331
|
-
has :author, :class => User
|
332
|
-
|
333
|
-
def save
|
334
|
-
save_associations
|
335
|
-
true
|
336
|
-
end
|
337
|
-
|
338
|
-
alias :save! :save
|
347
|
+
include CommentMixin
|
339
348
|
end
|
340
349
|
|
341
350
|
put :mark_as_spam
|
@@ -605,6 +614,7 @@ module ZendeskAPI
|
|
605
614
|
|
606
615
|
module Voice
|
607
616
|
include DataNamespace
|
617
|
+
|
608
618
|
class PhoneNumber < Resource
|
609
619
|
namespace "channels/voice"
|
610
620
|
end
|
data/lib/zendesk_api/version.rb
CHANGED
data/spec/core/client_spec.rb
CHANGED
@@ -249,6 +249,10 @@ describe ZendeskAPI::Client do
|
|
249
249
|
it "looks in the appropriate namespaces" do
|
250
250
|
expect(subject.greetings.association.options['class']).to eq(ZendeskAPI::Voice::Greeting)
|
251
251
|
end
|
252
|
+
|
253
|
+
it 'raises if the resource does not exist' do
|
254
|
+
expect { subject.random_resource }.to raise_error(RuntimeError)
|
255
|
+
end
|
252
256
|
end
|
253
257
|
|
254
258
|
it "can be subclassed" do
|
@@ -374,6 +374,19 @@ describe ZendeskAPI::Collection do
|
|
374
374
|
end
|
375
375
|
end
|
376
376
|
|
377
|
+
context "with an invalid model key expectation" do
|
378
|
+
before(:each) do
|
379
|
+
stub_json_request(:get, %r{test_resources}, json(
|
380
|
+
:test_resource_stuff => [{:id => 2}],
|
381
|
+
:next_page => "/test_resources?page=2"
|
382
|
+
))
|
383
|
+
end
|
384
|
+
|
385
|
+
it "should properly be handled" do
|
386
|
+
expect(subject.fetch(true)).to be_empty
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
377
390
|
context "with nil body" do
|
378
391
|
before(:each) do
|
379
392
|
stub_request(:get, %r{test_resources}).to_return(:status => 200)
|
data/spec/fixtures/zendesk.rb
CHANGED
@@ -67,6 +67,14 @@ module ZendeskAPI
|
|
67
67
|
def suspended_ticket
|
68
68
|
VCR.use_cassette('valid_suspended_ticket') do
|
69
69
|
@suspended_ticket ||= client.suspended_tickets.first
|
70
|
+
@suspended_ticket ||= begin
|
71
|
+
client.anonymous_requests.create(
|
72
|
+
:subject => "Test Ticket",
|
73
|
+
:comment => { :value => "Help! I need somebody." },
|
74
|
+
:requester => { :email => "zendesk-api-client-ruby-anonymous-#{client.config.username}", :name => 'Anonymous User' }
|
75
|
+
)
|
76
|
+
client.suspended_tickets(:reload => true).first
|
77
|
+
end
|
70
78
|
end
|
71
79
|
end
|
72
80
|
|
data/spec/live/request_spec.rb
CHANGED
@@ -12,4 +12,27 @@ describe ZendeskAPI::Request do
|
|
12
12
|
it_should_be_updatable :subject
|
13
13
|
it_should_be_readable :requests
|
14
14
|
it_should_be_readable user, :requests
|
15
|
+
|
16
|
+
it "can upload while creating" do
|
17
|
+
VCR.use_cassette("request_inline_uploads") do
|
18
|
+
request = ZendeskAPI::Request.new(client, valid_attributes)
|
19
|
+
request.comment.uploads << "spec/fixtures/Argentina.gif"
|
20
|
+
request.comment.uploads << File.new("spec/fixtures/Argentina.gif")
|
21
|
+
|
22
|
+
request.save!
|
23
|
+
expect(request.changes).to eq({}) # uploads were set before save
|
24
|
+
expect(request.comment.attributes[:uploads].map(&:class)).to eq([String, String]) # upload was sent as tokens
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it "can comment while creating" do
|
29
|
+
VCR.use_cassette("request_inline_comments") do
|
30
|
+
request = ZendeskAPI::Request.new(client, valid_attributes)
|
31
|
+
request.comment = ZendeskAPI::Request::Comment.new(client, :value => "My comment")
|
32
|
+
request.save!
|
33
|
+
|
34
|
+
expect(request.changes).to eq({}) # comment was set before save
|
35
|
+
expect(request.attributes[:comment]).to eq({"value" => "My comment"})
|
36
|
+
end
|
37
|
+
end
|
15
38
|
end
|
data/spec/live/tag_spec.rb
CHANGED
data/spec/live/ticket_spec.rb
CHANGED
@@ -67,7 +67,7 @@ describe ZendeskAPI::Ticket do
|
|
67
67
|
it "can import" do
|
68
68
|
VCR.use_cassette("ticket_import_can_import") do
|
69
69
|
old = Time.now - 5*365*24*60*60
|
70
|
-
ticket = ZendeskAPI::Ticket.import(client, valid_attributes.merge(:created_at => old))
|
70
|
+
ticket = ZendeskAPI::Ticket.import(client, valid_attributes.merge(:created_at => old.iso8601))
|
71
71
|
expect(ZendeskAPI::Ticket.find(client, ticket).created_at.year).to eq(old.year)
|
72
72
|
end
|
73
73
|
end
|
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.
|
4
|
+
version: 1.4.4
|
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: 2014-
|
12
|
+
date: 2014-10-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bump
|