zendesk_api 1.1.2 → 1.1.3
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.
- data/Gemfile.lock +1 -1
- data/lib/zendesk_api/resources.rb +27 -0
- data/lib/zendesk_api/verbs.rb +33 -10
- data/lib/zendesk_api/version.rb +1 -1
- data/spec/core/resource_spec.rb +99 -10
- data/spec/live/user_spec.rb +10 -0
- metadata +2 -2
data/Gemfile.lock
CHANGED
|
@@ -273,6 +273,8 @@ module ZendeskAPI
|
|
|
273
273
|
extend Read
|
|
274
274
|
end
|
|
275
275
|
|
|
276
|
+
class TicketRelated < DataResource; end
|
|
277
|
+
|
|
276
278
|
class Ticket < Resource
|
|
277
279
|
class Audit < DataResource
|
|
278
280
|
class Event < Data
|
|
@@ -299,6 +301,8 @@ module ZendeskAPI
|
|
|
299
301
|
alias :save! :save
|
|
300
302
|
end
|
|
301
303
|
|
|
304
|
+
put :mark_as_spam
|
|
305
|
+
|
|
302
306
|
has :requester, :class => User, :inline => :create
|
|
303
307
|
has :submitter, :class => User
|
|
304
308
|
has :assignee, :class => User
|
|
@@ -308,6 +312,7 @@ module ZendeskAPI
|
|
|
308
312
|
has Group
|
|
309
313
|
has :forum_topic, :class => Topic
|
|
310
314
|
has Organization
|
|
315
|
+
has :related, :class => TicketRelated
|
|
311
316
|
|
|
312
317
|
has :comment, :class => Comment, :inline => true
|
|
313
318
|
has :last_comment, :class => Comment, :inline => true
|
|
@@ -449,6 +454,28 @@ module ZendeskAPI
|
|
|
449
454
|
self.role_id = role.name if key?(:role)
|
|
450
455
|
end
|
|
451
456
|
|
|
457
|
+
any :password
|
|
458
|
+
|
|
459
|
+
# Set a user's password
|
|
460
|
+
def set_password(opts = {})
|
|
461
|
+
password(opts.merge(:verb => :post))
|
|
462
|
+
end
|
|
463
|
+
|
|
464
|
+
# Change a user's password
|
|
465
|
+
def change_password(opts = {})
|
|
466
|
+
password(opts.merge(:verb => :put))
|
|
467
|
+
end
|
|
468
|
+
|
|
469
|
+
# Set a user's password
|
|
470
|
+
def set_password!(opts = {})
|
|
471
|
+
password!(opts.merge(:verb => :post))
|
|
472
|
+
end
|
|
473
|
+
|
|
474
|
+
# Change a user's password
|
|
475
|
+
def change_password!(opts = {})
|
|
476
|
+
password!(opts.merge(:verb => :put))
|
|
477
|
+
end
|
|
478
|
+
|
|
452
479
|
has Organization
|
|
453
480
|
|
|
454
481
|
has CustomRole, :inline => true, :include => :roles
|
data/lib/zendesk_api/verbs.rb
CHANGED
|
@@ -10,24 +10,46 @@ module ZendeskAPI
|
|
|
10
10
|
# Reloads the resource's attributes if any are in the response body.
|
|
11
11
|
#
|
|
12
12
|
# Created method takes an optional options hash. Valid options to be passed in to the created method: reload (for caching, default: false)
|
|
13
|
-
def create_verb(
|
|
14
|
-
define_method
|
|
15
|
-
define_method method do |*method_args|
|
|
13
|
+
def create_verb(method_verb)
|
|
14
|
+
define_method method_verb do |method|
|
|
15
|
+
define_method "#{method}!" do |*method_args|
|
|
16
16
|
opts = method_args.last.is_a?(Hash) ? method_args.pop : {}
|
|
17
|
-
return instance_variable_get("@_#{verb}_#{method}") if instance_variable_defined?("@_#{verb}_#{method}") && !opts[:reload]
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
if method_verb == :any
|
|
19
|
+
verb = opts.delete(:verb)
|
|
20
|
+
raise(ArgumentError, ":verb required for method defined as :any") unless verb
|
|
21
|
+
else
|
|
22
|
+
verb = method_verb
|
|
21
23
|
end
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
@attributes = ZendeskAPI::Trackie.new(res)
|
|
26
|
-
@attributes.clear_changes
|
|
25
|
+
@response = @client.connection.send(verb, "#{path}/#{method}") do |req|
|
|
26
|
+
req.body = opts
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
+
return false unless @response.success?
|
|
30
|
+
return false unless @response.body
|
|
31
|
+
|
|
32
|
+
resource = @response.body[self.class.singular_resource_name] ||
|
|
33
|
+
@response.body.fetch(self.class.resource_name, []).detect {|res| res["id"] == id} ||
|
|
34
|
+
{}
|
|
35
|
+
|
|
36
|
+
@attributes.replace @attributes.deep_merge(resource)
|
|
37
|
+
@attributes.clear_changes
|
|
38
|
+
clear_associations
|
|
39
|
+
|
|
29
40
|
true
|
|
30
41
|
end
|
|
42
|
+
|
|
43
|
+
define_method method do |*method_args|
|
|
44
|
+
begin
|
|
45
|
+
send("#{method}!", *method_args)
|
|
46
|
+
rescue ZendeskAPI::Error::RecordInvalid => e
|
|
47
|
+
@errors = e.errors
|
|
48
|
+
false
|
|
49
|
+
rescue ZendeskAPI::Error::ClientError
|
|
50
|
+
false
|
|
51
|
+
end
|
|
52
|
+
end
|
|
31
53
|
end
|
|
32
54
|
end
|
|
33
55
|
end
|
|
@@ -35,5 +57,6 @@ module ZendeskAPI
|
|
|
35
57
|
create_verb :put
|
|
36
58
|
create_verb :post
|
|
37
59
|
create_verb :delete
|
|
60
|
+
create_verb :any
|
|
38
61
|
end
|
|
39
62
|
end
|
data/lib/zendesk_api/version.rb
CHANGED
data/spec/core/resource_spec.rb
CHANGED
|
@@ -305,6 +305,74 @@ describe ZendeskAPI::Resource do
|
|
|
305
305
|
end
|
|
306
306
|
end
|
|
307
307
|
|
|
308
|
+
context "on any" do
|
|
309
|
+
let(:method) { "test_any_method" }
|
|
310
|
+
|
|
311
|
+
before(:each) do
|
|
312
|
+
ZendeskAPI::TestResource.any method
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
context "class method" do
|
|
316
|
+
subject { ZendeskAPI::TestResource }
|
|
317
|
+
|
|
318
|
+
it "should create a method of the same name" do
|
|
319
|
+
subject.instance_methods.map(&:to_s).should include(method)
|
|
320
|
+
end
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
context "instance method" do
|
|
324
|
+
subject { ZendeskAPI::TestResource.new(client, :id => 1) }
|
|
325
|
+
|
|
326
|
+
it "throws an argumenterror without a :verb" do
|
|
327
|
+
expect { subject.send(method) }.to raise_error(ArgumentError)
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
context "with an array response" do
|
|
331
|
+
before(:each) do
|
|
332
|
+
stub_json_request(:put, %r{test_resources/1/#{method}}, json(:test_resources => [{ :id => 1, :method => method }]))
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
it "should return true" do
|
|
336
|
+
subject.send(method, :verb => :put).should be_true
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
it "should update the attributes if they exist" do
|
|
340
|
+
subject.send(method, :verb => :put)
|
|
341
|
+
subject[:method].should == method
|
|
342
|
+
end
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
context "with a resource response" do
|
|
346
|
+
before(:each) do
|
|
347
|
+
stub_json_request(:put, %r{test_resources/1/#{method}}, json(:test_resource => { :id => 1, :method => method }))
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
it "should return true" do
|
|
351
|
+
subject.send(method, :verb => :put).should be_true
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
it "should update the attributes if they exist" do
|
|
355
|
+
subject.send(method, :verb => :put)
|
|
356
|
+
subject[:method].should == method
|
|
357
|
+
end
|
|
358
|
+
end
|
|
359
|
+
|
|
360
|
+
context "with client error" do
|
|
361
|
+
before(:each) do
|
|
362
|
+
stub_request(:put, %r{test_resources/1/#{method}}).to_return(:status => 500)
|
|
363
|
+
end
|
|
364
|
+
|
|
365
|
+
it "doesn't raise without bang" do
|
|
366
|
+
silence_logger { subject.send("#{method}", :verb => :put).should be_false }
|
|
367
|
+
end
|
|
368
|
+
|
|
369
|
+
it "raises with bang" do
|
|
370
|
+
expect { silence_logger{ subject.send("#{method}!", :verb => :put) } }.to raise_error(ZendeskAPI::Error::ClientError)
|
|
371
|
+
end
|
|
372
|
+
end
|
|
373
|
+
end
|
|
374
|
+
end
|
|
375
|
+
|
|
308
376
|
%w{put post delete}.each do |verb|
|
|
309
377
|
context "on #{verb}" do
|
|
310
378
|
let(:method) { "test_#{verb}_method" }
|
|
@@ -323,17 +391,34 @@ describe ZendeskAPI::Resource do
|
|
|
323
391
|
context "instance method" do
|
|
324
392
|
subject { ZendeskAPI::TestResource.new(client, :id => 1) }
|
|
325
393
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
394
|
+
context "with an array response" do
|
|
395
|
+
before(:each) do
|
|
396
|
+
stub_json_request(verb.to_sym, %r{test_resources/1/#{method}}, json(:test_resources => [{ :id => 1, :method => method }]))
|
|
397
|
+
end
|
|
329
398
|
|
|
330
|
-
|
|
331
|
-
|
|
399
|
+
it "should return true" do
|
|
400
|
+
subject.send(method).should be_true
|
|
401
|
+
end
|
|
402
|
+
|
|
403
|
+
it "should update the attributes if they exist" do
|
|
404
|
+
subject.send(method)
|
|
405
|
+
subject[:method].should == method
|
|
406
|
+
end
|
|
332
407
|
end
|
|
333
408
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
409
|
+
context "with a resource response" do
|
|
410
|
+
before(:each) do
|
|
411
|
+
stub_json_request(verb.to_sym, %r{test_resources/1/#{method}}, json(:test_resource => { :id => 1, :method => method }))
|
|
412
|
+
end
|
|
413
|
+
|
|
414
|
+
it "should return true" do
|
|
415
|
+
subject.send(method).should be_true
|
|
416
|
+
end
|
|
417
|
+
|
|
418
|
+
it "should update the attributes if they exist" do
|
|
419
|
+
subject.send(method)
|
|
420
|
+
subject[:method].should == method
|
|
421
|
+
end
|
|
337
422
|
end
|
|
338
423
|
|
|
339
424
|
context "with client error" do
|
|
@@ -341,8 +426,12 @@ describe ZendeskAPI::Resource do
|
|
|
341
426
|
stub_request(verb.to_sym, %r{test_resources/1/#{method}}).to_return(:status => 500)
|
|
342
427
|
end
|
|
343
428
|
|
|
344
|
-
it "
|
|
345
|
-
|
|
429
|
+
it "doesn't raise without bang" do
|
|
430
|
+
silence_logger { subject.send("#{method}").should be_false }
|
|
431
|
+
end
|
|
432
|
+
|
|
433
|
+
it "raises with bang" do
|
|
434
|
+
expect { silence_logger{ subject.send("#{method}!") } }.to raise_error(ZendeskAPI::Error::ClientError)
|
|
346
435
|
end
|
|
347
436
|
end
|
|
348
437
|
end
|
data/spec/live/user_spec.rb
CHANGED
|
@@ -17,6 +17,16 @@ describe ZendeskAPI::User, :delete_after do
|
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
+
context "passwords", :vcr do
|
|
21
|
+
it "sets the password" do
|
|
22
|
+
agent.set_password!(:password => client.config.password)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "changes the password" do
|
|
26
|
+
current_user.change_password!(:previous_password => client.config.password, :password => client.config.password)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
20
30
|
context "side-loading" do
|
|
21
31
|
context "no permission set" do
|
|
22
32
|
subject do
|
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.1.
|
|
4
|
+
version: 1.1.3
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2013-
|
|
13
|
+
date: 2013-11-11 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: bump
|