zendesk_api 1.0.7 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -7,7 +7,7 @@ GIT
7
7
  PATH
8
8
  remote: .
9
9
  specs:
10
- zendesk_api (1.0.7)
10
+ zendesk_api (1.1.0)
11
11
  faraday (>= 0.8.0)
12
12
  faraday_middleware (>= 0.8.7)
13
13
  hashie (>= 1.2)
@@ -269,6 +269,111 @@ ticket.comment.uploads << File.new("img.jpg")
269
269
  ticket.save
270
270
  ```
271
271
 
272
+ ### Apps API
273
+
274
+ v1.1.0 introduces support for the Zendesk [Apps API](http://developer.zendesk.com/documentation/apps/reference/api.html)
275
+
276
+ #### Creating Apps
277
+
278
+ ```ruby
279
+ upload = client.apps.uploads.create!(:file => "path/to/app.zip")
280
+ client.apps.create!(:name => "test", :short_description => "My test app", :upload_id => upload.id)
281
+
282
+ # Or
283
+
284
+ app = ZendeskAPI::App.new(client, :name => "test", :short_description => "My test app")
285
+ app.upload = "path/to/app.zip"
286
+ app.save!
287
+
288
+ # Or
289
+
290
+ upload = ZendeskAPI::App::Upload.new(client, :file => "path/to/app.zip")
291
+ upload.save!
292
+
293
+ app = ZendeskAPI::App.new(client, :name => "test")
294
+ app.short_description = "My test app"
295
+ app.upload_id = upload.id
296
+ app.save!
297
+
298
+ # Not supported!
299
+ client.apps.create!(:name => "test", :short_description => "My test app", :upload => "app.zip")
300
+ ```
301
+
302
+ *Note: job statuses are currently not supported, so you must manually poll the job status API for app creation.*
303
+ ```ruby
304
+ body = {}
305
+ until %w{failed completed}.include?(body["status"])
306
+ response = client.connection.get(app.response.headers["Location"])
307
+ body = response.body
308
+
309
+ sleep(body["retry_in"])
310
+ end
311
+ ```
312
+
313
+ #### Updating Apps
314
+
315
+ ```ruby
316
+ client.apps.update!(:id => 123, :short_description => "New Description")
317
+
318
+ app = ZendeskAPI::App.new(client, :id => 123, :short_description => "New Description")
319
+ app.save!
320
+
321
+ ZendeskAPI::App.update!(client, :id => 123, :short_description => "New Description")
322
+ ```
323
+
324
+ #### Deleting Apps
325
+
326
+ ```ruby
327
+ client.apps.destroy!(:id => 123)
328
+
329
+ app = ZendeskAPI::App.new(client, :id => 123)
330
+ app.destroy!
331
+
332
+ ZendeskAPI::App.destroy!(client, :id => 123)
333
+ ```
334
+
335
+ #### Installing an App
336
+
337
+ ```ruby
338
+ install = ZendeskAPI::App::Installation.new(client, :app_id => 123)
339
+ install.save!
340
+
341
+ client.apps.installations.create!(:app_id => 123)
342
+
343
+ ZendeskAPI::App::Installation.create!(client, :app_id => 123)
344
+ ```
345
+
346
+ #### List Installations
347
+
348
+ ```ruby
349
+ apps = client.app.installations
350
+ apps.fetch!
351
+ ```
352
+
353
+ #### Update Installation
354
+
355
+ ```ruby
356
+ client.app.installations.update!(:id => 123, :settings => { :title => "My New Name" })
357
+
358
+ install = ZendeskAPI::App::Installation.new(client, :id => 123)
359
+ install.settings = { :title => "My New Name" }
360
+ install.save!
361
+
362
+ ZendeskAPI::App::Installation.update!(client, :id => 123, :settings => { :title => "My New Name" })
363
+ ```
364
+
365
+ #### Delete Installation
366
+
367
+ ```ruby
368
+ client.app.installations.destroy!(:id => 123)
369
+
370
+ install = ZendeskAPI::App::Installation.new(client, :id => 123)
371
+ install.destroy!
372
+
373
+ ZendeskAPI::App::Installation.destroy!(client, :id => 123)
374
+ ```
375
+
376
+
272
377
  ## Note on Patches/Pull Requests
273
378
  1. Fork the project.
274
379
  2. Make your feature addition or bug fix.
@@ -25,9 +25,7 @@ module ZendeskAPI
25
25
  yield req if block_given?
26
26
  end
27
27
 
28
- if @response.body && @response.body[self.class.singular_resource_name]
29
- @attributes.replace @attributes.deep_merge(@response.body[self.class.singular_resource_name] || {})
30
- end
28
+ handle_response
31
29
 
32
30
  @attributes.clear_changes
33
31
  clear_associations
@@ -71,6 +69,12 @@ module ZendeskAPI
71
69
  end
72
70
  end
73
71
  end
72
+
73
+ def handle_response
74
+ if @response.body && @response.body[self.class.singular_resource_name]
75
+ @attributes.replace @attributes.deep_merge(@response.body[self.class.singular_resource_name] || {})
76
+ end
77
+ end
74
78
  end
75
79
 
76
80
  module Read
@@ -32,6 +32,8 @@ module ZendeskAPI
32
32
  instance = args.first
33
33
 
34
34
  namespace = @options[:class].to_s.split("::")
35
+ namespace[-1] = @options[:class].resource_path
36
+
35
37
  %w(ZendeskAPI Voice).each { |ns| namespace.delete(ns) }
36
38
  has_parent = namespace.size > 1 || (options[:with_parent] && @options.parent)
37
39
 
@@ -118,7 +120,7 @@ module ZendeskAPI
118
120
  return unless association_on_parent = parent_class.associations.detect {|a| a[:class] == @options[:class] }
119
121
  [
120
122
  extract_parent_id(parent_class, instance, options, original_options),
121
- @options.path || association_on_parent[:name].to_s
123
+ @options.path || association_on_parent[:path] || association_on_parent[:name].to_s
122
124
  ]
123
125
  end
124
126
 
@@ -263,8 +263,14 @@ module ZendeskAPI
263
263
 
264
264
  class Ticket < Resource
265
265
  class Audit < DataResource
266
+ class Event < Data
267
+ has :author, :class => User
268
+ end
269
+
266
270
  # need this to support SideLoading
267
271
  has :author, :class => User
272
+
273
+ has_many Event
268
274
  end
269
275
 
270
276
  class Comment < Data
@@ -451,6 +457,8 @@ module ZendeskAPI
451
457
  has_many TopicSubscription
452
458
  has_many :topic_comments, :class => TopicComment
453
459
  has_many :topic_votes, :class => Topic::TopicVote
460
+
461
+ has_many Setting
454
462
  end
455
463
 
456
464
  class UserField < Resource; end
@@ -485,4 +493,79 @@ module ZendeskAPI
485
493
  # TODO
486
494
  # post :clone
487
495
  end
496
+
497
+ class App < DataResource
498
+ include Create
499
+ include Update
500
+ include Destroy
501
+
502
+ def initialize(client, attributes = {})
503
+ attributes[:upload_id] ||= nil
504
+
505
+ super
506
+ end
507
+
508
+ class Upload < Data
509
+ class << self
510
+ def resource_path
511
+ "uploads"
512
+ end
513
+ end
514
+
515
+ include Create
516
+
517
+ def initialize(client, attributes)
518
+ attributes[:file] ||= attributes.delete(:id)
519
+
520
+ super
521
+ end
522
+
523
+ # Not nested under :upload, just returns :id
524
+ def save!(*)
525
+ super.tap do
526
+ attributes.id = @response.body["id"]
527
+ end
528
+ end
529
+
530
+ # Always save
531
+ def changed?
532
+ true
533
+ end
534
+
535
+ # Don't nest attributes
536
+ def attributes_for_save
537
+ attributes
538
+ end
539
+ end
540
+
541
+ class Installation < Resource
542
+ # Don't nest attributes
543
+ def attributes_for_save
544
+ attributes.changes
545
+ end
546
+
547
+ def handle_response
548
+ @attributes.replace(@response.body) if @response.body
549
+ end
550
+ end
551
+
552
+ def self.uploads(client, *args, &block)
553
+ ZendeskAPI::Collection.new(client, Upload, *args, &block)
554
+ end
555
+
556
+ def self.installations(client, *args, &block)
557
+ ZendeskAPI::Collection.new(client, Installation, *args, &block)
558
+ end
559
+
560
+ has Upload, :path => "uploads"
561
+
562
+ # Don't nest attributes
563
+ def attributes_for_save
564
+ attributes.changes
565
+ end
566
+
567
+ def handle_response
568
+ @attributes.replace(@response.body) if @response.body
569
+ end
570
+ end
488
571
  end
@@ -44,10 +44,6 @@ module ZendeskAPI
44
44
  keys.each{|key| delete key}
45
45
  end
46
46
 
47
- def [](key)
48
- super(key)
49
- end
50
-
51
47
  def regular_writer(key, value)
52
48
  if self.has_key?(key) && self[key] == value
53
49
  value
@@ -58,8 +54,9 @@ module ZendeskAPI
58
54
  end
59
55
 
60
56
  def delete(key)
61
- self[key] = nil
62
- super
57
+ super.tap do |value|
58
+ changes[key] = nil
59
+ end
63
60
  end
64
61
 
65
62
  def changes
@@ -1,3 +1,3 @@
1
1
  module ZendeskAPI
2
- VERSION = "1.0.7"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -180,6 +180,27 @@ describe ZendeskAPI::Association do
180
180
  subject.generate_path.should == "test_resources/1/blergh"
181
181
  end
182
182
  end
183
+
184
+ context "with a path on the association" do
185
+ before(:each) do
186
+ association = ZendeskAPI::TestResource.associations.detect {|a| a[:name] == :children}
187
+ association[:path] = "blergh"
188
+ end
189
+
190
+ it "should generate nested resource path" do
191
+ subject.generate_path.should == "test_resources/1/blergh"
192
+ end
193
+ end
194
+
195
+ context "with no association" do
196
+ before(:each) do
197
+ ZendeskAPI::TestResource.associations.clear
198
+ end
199
+
200
+ it "should generate nested resource path" do
201
+ subject.generate_path.should == "test_resources/test_children"
202
+ end
203
+ end
183
204
  end
184
205
 
185
206
  context "class with a parent id" do
@@ -21,6 +21,24 @@ describe ZendeskAPI::Trackie do
21
21
  end
22
22
  end
23
23
 
24
+ context "deleting keys" do
25
+ before(:each) do
26
+ subject[:key] = true
27
+ end
28
+
29
+ it "returns key on deletion" do
30
+ subject.delete(:key).should be_true
31
+ end
32
+
33
+ context "after deletion" do
34
+ before(:each) { subject.delete(:key) }
35
+
36
+ it "keeps the changes" do
37
+ subject.changed?(:key).should be_true
38
+ end
39
+ end
40
+ end
41
+
24
42
  context "adding identical keys" do
25
43
  before(:each) do
26
44
  subject[:key] = "foo"
Binary file
@@ -0,0 +1,40 @@
1
+ require 'core/spec_helper'
2
+
3
+ describe ZendeskAPI::App do
4
+ it "should work "do
5
+ upload = VCR.use_cassette("app_upload_create") do
6
+ ZendeskAPI::App::Upload.new(client, :id => "spec/fixtures/sample_app.zip").tap(&:save!)
7
+ end
8
+
9
+ attributes = { :upload_id => upload.id, :name => "My App", :short_description => "Testing" }
10
+
11
+ app = ZendeskAPI::App.new(client, attributes)
12
+
13
+ VCR.use_cassette("app_create") { app.save! }
14
+
15
+ body = {}
16
+
17
+ VCR.use_cassette("app_create_job_status") do
18
+ until %w{failed completed}.include?(body["status"])
19
+ response = client.connection.get(app.response.headers["Location"])
20
+ body = response.body
21
+
22
+ sleep(3)
23
+ end
24
+ end
25
+
26
+ if body["status"] == "failed"
27
+ fail "Could not create app: #{body.inspect}"
28
+ end
29
+
30
+ app.id = body["app_id"]
31
+ app.short_description = "My Test App"
32
+
33
+ VCR.use_cassette("app_save") { app.save! }
34
+
35
+ app.short_description.should == "My Test App"
36
+ app.author_name.should == "Skip Moore"
37
+
38
+ VCR.use_cassette("app_destroy") { app.destroy! }
39
+ end
40
+ end
@@ -2,4 +2,14 @@ require 'core/spec_helper'
2
2
 
3
3
  describe ZendeskAPI::Ticket::Audit do
4
4
  it_should_be_readable ticket, :audits
5
+
6
+ describe ZendeskAPI::Ticket::Audit::Event, :vcr do
7
+ it "should side-load events" do
8
+ audit = ticket.audits(include: :users).first
9
+ event = audit.events.first
10
+
11
+ event.should be_instance_of(ZendeskAPI::Ticket::Audit::Event)
12
+ event.author.should be_instance_of(ZendeskAPI::User)
13
+ end
14
+ end
5
15
  end
@@ -0,0 +1,57 @@
1
+ require 'core/spec_helper'
2
+
3
+ describe ZendeskAPI::App::Installation do
4
+ it "should work "do
5
+ upload = VCR.use_cassette("app_installations_upload_create") do
6
+ ZendeskAPI::App::Upload.new(client, :id => "spec/fixtures/sample_app.zip").tap(&:save!)
7
+ end
8
+
9
+ attributes = { :upload_id => upload.id, :name => "My App", :short_description => "Testing" }
10
+
11
+ app = ZendeskAPI::App.new(client, attributes)
12
+
13
+ VCR.use_cassette("app_installations_create") { app.save! }
14
+
15
+ body = {}
16
+
17
+ VCR.use_cassette("app_installations_create_job_status") do
18
+ until %w{failed completed}.include?(body["status"])
19
+ response = client.connection.get(app.response.headers["Location"])
20
+ body = response.body
21
+
22
+ sleep(3)
23
+ end
24
+ end
25
+
26
+ if body["status"] == "failed"
27
+ fail "Could not create app: #{body.inspect}"
28
+ end
29
+
30
+ app.id = body["app_id"]
31
+
32
+ attributes = { :app_id => app.id, :settings => {
33
+ :name => "My App",
34
+ "Custom_Field_ID" => "123",
35
+ "Custom_Field_Default" => "Default"
36
+ }
37
+ }
38
+
39
+ install = ZendeskAPI::App::Installation.new(client, attributes)
40
+
41
+ VCR.use_cassette("app_install_create") { install.save! }
42
+
43
+ installations = client.app.installations
44
+ VCR.use_cassette("app_install_fetch") { installations.fetch! }
45
+
46
+ installations.should include(install)
47
+
48
+ install.settings.name = "My New Name"
49
+ VCR.use_cassette("app_install_update") { install.save! }
50
+
51
+ install.settings.title.should == "My New Name"
52
+
53
+ VCR.use_cassette("app_install_destroy") { install.destroy! }
54
+
55
+ VCR.use_cassette("app_installations_destroy") { app.destroy! }
56
+ end
57
+ 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.0.7
4
+ version: 1.1.0
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-10-02 00:00:00.000000000 Z
13
+ date: 2013-10-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bump
@@ -236,8 +236,8 @@ files:
236
236
  - Gemfile.lock
237
237
  - LICENSE
238
238
  - Procfile
239
+ - README.md
239
240
  - Rakefile
240
- - Readme.md
241
241
  - bin/zendesk
242
242
  - config.ru
243
243
  - config/mongoid.yml
@@ -477,10 +477,12 @@ files:
477
477
  - spec/fixtures/cassettes/ZendeskAPI_Voice_PhoneNumber_update_create.json
478
478
  - spec/fixtures/cassettes/ZendeskAPI_Voice_PhoneNumber_update_delete.json
479
479
  - spec/fixtures/credentials.yml.example
480
+ - spec/fixtures/sample_app.zip
480
481
  - spec/fixtures/test_resources.rb
481
482
  - spec/fixtures/zendesk.rb
482
483
  - spec/live/Readme.md
483
484
  - spec/live/activity_spec.rb
485
+ - spec/live/app_spec.rb
484
486
  - spec/live/audit_spec.rb
485
487
  - spec/live/automation_spec.rb
486
488
  - spec/live/bookmark_spec.rb
@@ -492,6 +494,7 @@ files:
492
494
  - spec/live/group_membership_spec.rb
493
495
  - spec/live/group_spec.rb
494
496
  - spec/live/identity_spec.rb
497
+ - spec/live/installation_spec.rb
495
498
  - spec/live/locale_spec.rb
496
499
  - spec/live/macro_spec.rb
497
500
  - spec/live/mobile_device_spec.rb
@@ -586,10 +589,12 @@ test_files:
586
589
  - spec/fixtures/cassettes/ZendeskAPI_Voice_PhoneNumber_update_create.json
587
590
  - spec/fixtures/cassettes/ZendeskAPI_Voice_PhoneNumber_update_delete.json
588
591
  - spec/fixtures/credentials.yml.example
592
+ - spec/fixtures/sample_app.zip
589
593
  - spec/fixtures/test_resources.rb
590
594
  - spec/fixtures/zendesk.rb
591
595
  - spec/live/Readme.md
592
596
  - spec/live/activity_spec.rb
597
+ - spec/live/app_spec.rb
593
598
  - spec/live/audit_spec.rb
594
599
  - spec/live/automation_spec.rb
595
600
  - spec/live/bookmark_spec.rb
@@ -601,6 +606,7 @@ test_files:
601
606
  - spec/live/group_membership_spec.rb
602
607
  - spec/live/group_spec.rb
603
608
  - spec/live/identity_spec.rb
609
+ - spec/live/installation_spec.rb
604
610
  - spec/live/locale_spec.rb
605
611
  - spec/live/macro_spec.rb
606
612
  - spec/live/mobile_device_spec.rb