zendesk_api 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/.gitignore +7 -0
  2. data/.rspec +2 -0
  3. data/.travis.yml +5 -0
  4. data/.yardopts +1 -0
  5. data/Gemfile +6 -0
  6. data/Gemfile.lock +59 -0
  7. data/LICENSE +19 -0
  8. data/Rakefile +49 -0
  9. data/Readme.md +178 -0
  10. data/lib/zendesk_api.rb +10 -0
  11. data/lib/zendesk_api/actions.rb +176 -0
  12. data/lib/zendesk_api/association.rb +267 -0
  13. data/lib/zendesk_api/client.rb +150 -0
  14. data/lib/zendesk_api/collection.rb +233 -0
  15. data/lib/zendesk_api/configuration.rb +52 -0
  16. data/lib/zendesk_api/core_ext/inflection.rb +13 -0
  17. data/lib/zendesk_api/core_ext/modulize.rb +10 -0
  18. data/lib/zendesk_api/core_ext/snakecase.rb +12 -0
  19. data/lib/zendesk_api/lru_cache.rb +38 -0
  20. data/lib/zendesk_api/middleware/request/etag_cache.rb +38 -0
  21. data/lib/zendesk_api/middleware/request/retry.rb +39 -0
  22. data/lib/zendesk_api/middleware/request/upload.rb +32 -0
  23. data/lib/zendesk_api/middleware/response/callback.rb +19 -0
  24. data/lib/zendesk_api/middleware/response/deflate.rb +18 -0
  25. data/lib/zendesk_api/middleware/response/gzip.rb +18 -0
  26. data/lib/zendesk_api/middleware/response/parse_iso_dates.rb +29 -0
  27. data/lib/zendesk_api/rescue.rb +44 -0
  28. data/lib/zendesk_api/resource.rb +133 -0
  29. data/lib/zendesk_api/resources/forum.rb +51 -0
  30. data/lib/zendesk_api/resources/misc.rb +66 -0
  31. data/lib/zendesk_api/resources/playlist.rb +64 -0
  32. data/lib/zendesk_api/resources/ticket.rb +76 -0
  33. data/lib/zendesk_api/resources/user.rb +44 -0
  34. data/lib/zendesk_api/track_changes.rb +72 -0
  35. data/lib/zendesk_api/trackie.rb +8 -0
  36. data/lib/zendesk_api/verbs.rb +43 -0
  37. data/lib/zendesk_api/version.rb +3 -0
  38. data/live/Readme.md +4 -0
  39. data/live/activity_spec.rb +5 -0
  40. data/live/audit_spec.rb +5 -0
  41. data/live/bookmark_spec.rb +11 -0
  42. data/live/category_spec.rb +12 -0
  43. data/live/collection_spec.rb +68 -0
  44. data/live/crm_spec.rb +11 -0
  45. data/live/custom_role_spec.rb +5 -0
  46. data/live/forum_spec.rb +14 -0
  47. data/live/forum_subscription_spec.rb +12 -0
  48. data/live/group_membership_spec.rb +18 -0
  49. data/live/group_spec.rb +14 -0
  50. data/live/identity_spec.rb +14 -0
  51. data/live/locale_spec.rb +11 -0
  52. data/live/macro_spec.rb +5 -0
  53. data/live/mobile_device_spec.rb +11 -0
  54. data/live/organization_spec.rb +12 -0
  55. data/live/satisfaction_rating_spec.rb +6 -0
  56. data/live/setting_spec.rb +5 -0
  57. data/live/suspended_ticket_spec.rb +8 -0
  58. data/live/ticket_field_spec.rb +12 -0
  59. data/live/ticket_metrics_spec.rb +6 -0
  60. data/live/ticket_spec.rb +88 -0
  61. data/live/topic_comment_spec.rb +13 -0
  62. data/live/topic_spec.rb +18 -0
  63. data/live/topic_subscription_spec.rb +12 -0
  64. data/live/topic_vote_spec.rb +13 -0
  65. data/live/upload_spec.rb +9 -0
  66. data/live/user_spec.rb +13 -0
  67. data/live/view_spec.rb +6 -0
  68. data/spec/association_spec.rb +210 -0
  69. data/spec/client_spec.rb +149 -0
  70. data/spec/collection_spec.rb +302 -0
  71. data/spec/configuration_spec.rb +24 -0
  72. data/spec/create_resource_spec.rb +39 -0
  73. data/spec/data_resource_spec.rb +229 -0
  74. data/spec/fixtures/Argentina.gif +0 -0
  75. data/spec/fixtures/Argentina2.gif +0 -0
  76. data/spec/fixtures/credentials.yml.example +3 -0
  77. data/spec/fixtures/test_resources.rb +8 -0
  78. data/spec/fixtures/zendesk.rb +88 -0
  79. data/spec/lru_cache_spec.rb +26 -0
  80. data/spec/macros/resource_macros.rb +157 -0
  81. data/spec/middleware/request/etag_cache_spec.rb +17 -0
  82. data/spec/middleware/request/retry_spec.rb +47 -0
  83. data/spec/middleware/request/test.jpg +0 -0
  84. data/spec/middleware/request/upload_spec.rb +74 -0
  85. data/spec/middleware/response/callback_spec.rb +17 -0
  86. data/spec/middleware/response/deflate_spec.rb +15 -0
  87. data/spec/middleware/response/gzip_spec.rb +19 -0
  88. data/spec/middleware/response/parse_iso_dates_spec.rb +44 -0
  89. data/spec/playlist_spec.rb +95 -0
  90. data/spec/read_resource_spec.rb +37 -0
  91. data/spec/rescue_spec.rb +94 -0
  92. data/spec/resource_spec.rb +332 -0
  93. data/spec/spec_helper.rb +120 -0
  94. data/spec/string_spec.rb +7 -0
  95. data/spec/trackie_spec.rb +39 -0
  96. data/zendesk_api.gemspec +38 -0
  97. metadata +364 -0
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZendeskAPI::Ticket::Audit do
4
+ it_should_be_readable ticket, :audits
5
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZendeskAPI::Bookmark, :not_findable, :delete_after do
4
+ def valid_attributes
5
+ { :ticket_id => ticket.id }
6
+ end
7
+
8
+ it_should_be_creatable
9
+ it_should_be_deletable
10
+ it_should_be_readable :bookmarks, :create => true
11
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZendeskAPI::Category, :delete_after do
4
+ def valid_attributes
5
+ { :name => "My Category" }
6
+ end
7
+
8
+ it_should_be_creatable
9
+ it_should_be_updatable :name
10
+ it_should_be_deletable
11
+ it_should_be_readable :categories, :create => true
12
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZendeskAPI::Collection do
4
+ subject do
5
+ ZendeskAPI::Collection.new(client, ZendeskAPI::TestResource)
6
+ end
7
+
8
+ context "with real data" do
9
+ subject do
10
+ ZendeskAPI::Collection.new(client, ZendeskAPI::User)
11
+ end
12
+
13
+ before(:all) do
14
+ VCR.use_cassette('collection_fetch_users') do
15
+ subject.per_page(1).page(2)
16
+ subject.fetch(true)
17
+ end
18
+ end
19
+
20
+ context "pagination with no options" do
21
+ use_vcr_cassette
22
+
23
+ before(:each) { subject.per_page(nil).page(nil) }
24
+
25
+ it "should find the next page by calling fetch" do
26
+ current = subject.to_a.dup
27
+ nxt = subject.next
28
+
29
+ nxt.size.should == 1
30
+ nxt.should_not == current
31
+ end
32
+
33
+ it "should find the prev page by calling fetch" do
34
+ current = subject.to_a.dup
35
+ prev = subject.prev
36
+
37
+ prev.size.should == 1
38
+ prev.should_not == current
39
+ end
40
+ end
41
+
42
+ context "pagination with options" do
43
+ use_vcr_cassette
44
+
45
+ before(:each) { subject.per_page(1).page(2) }
46
+
47
+ it "should increase page option and not call fetch" do
48
+ subject.next.should == 3
49
+ end
50
+
51
+ it "should decrease page option and not call fetch" do
52
+ subject.prev.should == 1
53
+ end
54
+
55
+ context "with page == 1" do
56
+ before do
57
+ subject.page(1)
58
+ subject.clear_cache
59
+ subject.should_not_receive(:fetch)
60
+ end
61
+
62
+ it "should do nothing on #prev" do
63
+ subject.prev.should == []
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZendeskAPI::CRMData do
4
+ # TODO
5
+ # it_should_be_readable user, :crm_data
6
+ end
7
+
8
+ describe ZendeskAPI::CRMDataStatus do
9
+ # TODO
10
+ # it_should_be_readable user, :crm_data_status
11
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZendeskAPI::CustomRole do
4
+ it_should_be_readable :custom_roles
5
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZendeskAPI::Forum, :delete_after do
4
+ def valid_attributes
5
+ { :name => "My Forum", :forum_type => "articles", :access => "logged-in users", :category_id => category.id }
6
+ end
7
+
8
+ it_should_be_creatable
9
+ it_should_be_updatable :name
10
+ # Forum delete jobs are queued, so don't look for it
11
+ it_should_be_deletable :find => false
12
+ it_should_be_readable :forums, :create => true
13
+ it_should_be_readable category, :forums, :create => true
14
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZendeskAPI::ForumSubscription, :delete_after do
4
+ def valid_attributes
5
+ { :forum_id => forum.id, :user_id => agent.id }
6
+ end
7
+
8
+ it_should_be_creatable
9
+ it_should_be_deletable
10
+ it_should_be_readable forum, :subscriptions, :create => true
11
+ it_should_be_readable agent, :forum_subscriptions, :create => true
12
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZendeskAPI::GroupMembership, :delete_after do
4
+ before :all do
5
+ VCR.use_cassette("delete_existing_group_memberships_create") do
6
+ agent.group_memberships.each(&:destroy)
7
+ end
8
+ end
9
+
10
+ def valid_attributes
11
+ { :group_id => group.id, :user_id => agent.id }
12
+ end
13
+
14
+ it_should_be_creatable
15
+ it_should_be_deletable
16
+ it_should_be_readable :group_memberships
17
+ it_should_be_readable agent, :group_memberships, :create => true
18
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZendeskAPI::Group do
4
+ def valid_attributes
5
+ { :name => "My Group" }
6
+ end
7
+
8
+ it_should_be_creatable
9
+ it_should_be_updatable :name
10
+ it_should_be_deletable :find => [:deleted?, true]
11
+ it_should_be_readable :groups
12
+ it_should_be_readable :groups, :assignable
13
+ it_should_be_readable agent, :groups
14
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZendeskAPI::User::Identity, :delete_after do
4
+ def valid_attributes
5
+ { :type => "email", :value => "abcdef@example.com" }
6
+ end
7
+
8
+ under current_user do
9
+ it_should_be_creatable
10
+ it_should_be_updatable :verified, true
11
+ it_should_be_deletable
12
+ it_should_be_readable current_user, :identities, :create => true
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZendeskAPI::Locale do
4
+ use_vcr_cassette
5
+
6
+ specify "client#current_locale" do
7
+ client.current_locale.should be_instance_of(described_class)
8
+ end
9
+
10
+ it_should_be_readable :locales
11
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZendeskAPI::Macro do
4
+ it_should_be_readable :macros, :active
5
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZendeskAPI::MobileDevice do
4
+ def valid_attributes
5
+ { :device_type => "iPhone", :token => "5D41402ABC4B2A76B9719D911017C592" }
6
+ end
7
+
8
+ it_should_be_creatable
9
+ it_should_be_deletable
10
+ it_should_be_readable :mobile_devices, :create => true
11
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZendeskAPI::Organization, :delete_after do
4
+ def valid_attributes
5
+ { :name => "Awesome-O" }
6
+ end
7
+
8
+ it_should_be_creatable
9
+ it_should_be_updatable :name
10
+ it_should_be_deletable
11
+ it_should_be_readable :organizations, :create => true
12
+ end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZendeskAPI::SatisfactionRating do
4
+ it_should_be_readable :satisfaction_ratings
5
+ it_should_be_readable :satisfaction_ratings, :received
6
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZendeskAPI::Setting do
4
+ it_should_be_readable :settings, :path => 'account/settings'
5
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZendeskAPI::SuspendedTicket do
4
+ it_should_be_readable :suspended_tickets
5
+ it_should_be_deletable :object => suspended_ticket
6
+
7
+ # Test #recover
8
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZendeskAPI::TicketField do
4
+ def valid_attributes
5
+ { :type => "text", :title => "Age" }
6
+ end
7
+
8
+ it_should_be_creatable
9
+ it_should_be_updatable :title
10
+ it_should_be_deletable
11
+ it_should_be_readable :ticket_fields
12
+ end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZendeskAPI::TicketMetric do
4
+ it_should_be_readable :ticket_metrics
5
+ it_should_be_readable ticket, :metrics
6
+ end
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZendeskAPI::Ticket do
4
+ def valid_attributes
5
+ {
6
+ :type => "question",
7
+ :subject => "This is a question?",
8
+ :description => "Indeed it is!",
9
+ :priority => "normal",
10
+ :requester_id => user.id,
11
+ :submitter_id => user.id
12
+ }
13
+ end
14
+
15
+ it_should_be_creatable
16
+ it_should_be_updatable :subject
17
+ it_should_be_deletable
18
+ it_should_be_readable :tickets
19
+ it_should_be_readable :tickets, :recent
20
+ it_should_be_readable user, :requested_tickets
21
+ it_should_be_readable user, :ccd_tickets
22
+ it_should_be_readable organization, :tickets
23
+
24
+ describe ".incremental_export" do
25
+ let(:results){ ZendeskAPI::Ticket.incremental_export(client, Time.at(1023059503)) } # ~ 10 years ago
26
+
27
+ around do |example|
28
+ # 1 request every 5 minutes allowed <-> you can only test 1 call ...
29
+ VCR.use_cassette("incremental_export") do
30
+ Timeout.timeout(5) do # fail if we get rate-limited
31
+ example.call
32
+ end
33
+ end
34
+ end
35
+
36
+ it "finds tickets after a old date" do
37
+ results.to_a.first.should be_an_instance_of ZendeskAPI::Ticket
38
+ end
39
+
40
+ it "is able to do next" do
41
+ first = results.to_a.first
42
+ recent_url = "api/v2/exports/tickets.json?start_time=#{Time.now.to_i.to_s[0..5]}"
43
+ stub_json_request(:get, /#{recent_url}/, json(:results => []))
44
+
45
+ results.next
46
+ results.first.should_not == first
47
+ end
48
+ end
49
+
50
+ describe ".import" do
51
+ it "can import" do
52
+ VCR.use_cassette("ticket_import_can_import") do
53
+ old = Time.now - 5*365*24*60*60
54
+ ticket = ZendeskAPI::Ticket.import(client, valid_attributes.merge(:created_at => old))
55
+ ZendeskAPI::Ticket.find(client, ticket).created_at.year.should == old.year
56
+ end
57
+ end
58
+
59
+ it "returns nothing if import fails" do
60
+ VCR.use_cassette("ticket_import_cannot_import") do
61
+ silence_logger { ZendeskAPI::Ticket.import(client, {}).should == nil }
62
+ end
63
+ end
64
+ end
65
+
66
+ it "can upload while creating" do
67
+ VCR.use_cassette("ticket_inline_uploads") do
68
+ ticket = ZendeskAPI::Ticket.new(client, valid_attributes.merge(default_options))
69
+ ticket.uploads << "spec/fixtures/Argentina.gif"
70
+ #ticket.uploads << File.new("spec/fixtures/Argentina.gif") # TODO ZendeskAPI bug: you can only upload 1 picture at a time
71
+
72
+ ticket.save!
73
+ ticket.changes.should == {} # uploads where set before save
74
+ ticket.attributes[:uploads].map(&:class).should == [String] # upload was sent as tokens
75
+ end
76
+ end
77
+
78
+ it "can comment while creating" do
79
+ VCR.use_cassette("ticket_inline_comments") do
80
+ ticket = ZendeskAPI::Ticket.new(client, valid_attributes.merge(default_options))
81
+ ticket.comment = ZendeskAPI::TicketComment.new(client, :value => "My comment", :public => false)
82
+ ticket.save!
83
+
84
+ ticket.changes.should == {} # comment was set before save
85
+ ticket.attributes[:comment].should == {"value" => "My comment", "public" => false}
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZendeskAPI::Topic::TopicComment, :not_findable do
4
+ def valid_attributes
5
+ { :body => "Texty-text, text.", :topic_id => topic.id }
6
+ end
7
+
8
+ it_should_be_creatable
9
+ it_should_be_updatable :body
10
+ it_should_be_deletable
11
+ it_should_be_readable topic, :comments
12
+ it_should_be_readable current_user, :topic_comments
13
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZendeskAPI::Topic do
4
+ def valid_attributes
5
+ {
6
+ :forum_id => forum.id, :title => "My Topic",
7
+ :body => "The mayan calendar ends December 31st. Coincidence? I think not."
8
+ }
9
+ end
10
+
11
+ it_should_be_creatable
12
+ it_should_be_updatable :title
13
+ it_should_be_deletable :create => true
14
+ it_should_be_readable :topics
15
+ it_should_be_readable current_user, :topics
16
+ it_should_be_readable forum, :topics
17
+ #it_should_be_readable :topics, :show_many, :verb => :post, :ids =>
18
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZendeskAPI::TopicSubscription, :delete_after do
4
+ def valid_attributes
5
+ { :topic_id => topic.id, :user_id => user.id }
6
+ end
7
+
8
+ it_should_be_creatable
9
+ it_should_be_deletable
10
+ it_should_be_readable topic, :subscriptions, :create => true
11
+ it_should_be_readable user, :topic_subscriptions, :create => true
12
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZendeskAPI::Topic::TopicVote, :delete_after do
4
+ def valid_attributes
5
+ { :topic_id => topic.id }
6
+ end
7
+
8
+ under topic do
9
+ it_should_be_creatable
10
+ it_should_be_deletable
11
+ it_should_be_readable topic, :votes, :create => true
12
+ end
13
+ end