zendesk_api 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/.yardopts +1 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +59 -0
- data/LICENSE +19 -0
- data/Rakefile +49 -0
- data/Readme.md +178 -0
- data/lib/zendesk_api.rb +10 -0
- data/lib/zendesk_api/actions.rb +176 -0
- data/lib/zendesk_api/association.rb +267 -0
- data/lib/zendesk_api/client.rb +150 -0
- data/lib/zendesk_api/collection.rb +233 -0
- data/lib/zendesk_api/configuration.rb +52 -0
- data/lib/zendesk_api/core_ext/inflection.rb +13 -0
- data/lib/zendesk_api/core_ext/modulize.rb +10 -0
- data/lib/zendesk_api/core_ext/snakecase.rb +12 -0
- data/lib/zendesk_api/lru_cache.rb +38 -0
- data/lib/zendesk_api/middleware/request/etag_cache.rb +38 -0
- data/lib/zendesk_api/middleware/request/retry.rb +39 -0
- data/lib/zendesk_api/middleware/request/upload.rb +32 -0
- data/lib/zendesk_api/middleware/response/callback.rb +19 -0
- data/lib/zendesk_api/middleware/response/deflate.rb +18 -0
- data/lib/zendesk_api/middleware/response/gzip.rb +18 -0
- data/lib/zendesk_api/middleware/response/parse_iso_dates.rb +29 -0
- data/lib/zendesk_api/rescue.rb +44 -0
- data/lib/zendesk_api/resource.rb +133 -0
- data/lib/zendesk_api/resources/forum.rb +51 -0
- data/lib/zendesk_api/resources/misc.rb +66 -0
- data/lib/zendesk_api/resources/playlist.rb +64 -0
- data/lib/zendesk_api/resources/ticket.rb +76 -0
- data/lib/zendesk_api/resources/user.rb +44 -0
- data/lib/zendesk_api/track_changes.rb +72 -0
- data/lib/zendesk_api/trackie.rb +8 -0
- data/lib/zendesk_api/verbs.rb +43 -0
- data/lib/zendesk_api/version.rb +3 -0
- data/live/Readme.md +4 -0
- data/live/activity_spec.rb +5 -0
- data/live/audit_spec.rb +5 -0
- data/live/bookmark_spec.rb +11 -0
- data/live/category_spec.rb +12 -0
- data/live/collection_spec.rb +68 -0
- data/live/crm_spec.rb +11 -0
- data/live/custom_role_spec.rb +5 -0
- data/live/forum_spec.rb +14 -0
- data/live/forum_subscription_spec.rb +12 -0
- data/live/group_membership_spec.rb +18 -0
- data/live/group_spec.rb +14 -0
- data/live/identity_spec.rb +14 -0
- data/live/locale_spec.rb +11 -0
- data/live/macro_spec.rb +5 -0
- data/live/mobile_device_spec.rb +11 -0
- data/live/organization_spec.rb +12 -0
- data/live/satisfaction_rating_spec.rb +6 -0
- data/live/setting_spec.rb +5 -0
- data/live/suspended_ticket_spec.rb +8 -0
- data/live/ticket_field_spec.rb +12 -0
- data/live/ticket_metrics_spec.rb +6 -0
- data/live/ticket_spec.rb +88 -0
- data/live/topic_comment_spec.rb +13 -0
- data/live/topic_spec.rb +18 -0
- data/live/topic_subscription_spec.rb +12 -0
- data/live/topic_vote_spec.rb +13 -0
- data/live/upload_spec.rb +9 -0
- data/live/user_spec.rb +13 -0
- data/live/view_spec.rb +6 -0
- data/spec/association_spec.rb +210 -0
- data/spec/client_spec.rb +149 -0
- data/spec/collection_spec.rb +302 -0
- data/spec/configuration_spec.rb +24 -0
- data/spec/create_resource_spec.rb +39 -0
- data/spec/data_resource_spec.rb +229 -0
- data/spec/fixtures/Argentina.gif +0 -0
- data/spec/fixtures/Argentina2.gif +0 -0
- data/spec/fixtures/credentials.yml.example +3 -0
- data/spec/fixtures/test_resources.rb +8 -0
- data/spec/fixtures/zendesk.rb +88 -0
- data/spec/lru_cache_spec.rb +26 -0
- data/spec/macros/resource_macros.rb +157 -0
- data/spec/middleware/request/etag_cache_spec.rb +17 -0
- data/spec/middleware/request/retry_spec.rb +47 -0
- data/spec/middleware/request/test.jpg +0 -0
- data/spec/middleware/request/upload_spec.rb +74 -0
- data/spec/middleware/response/callback_spec.rb +17 -0
- data/spec/middleware/response/deflate_spec.rb +15 -0
- data/spec/middleware/response/gzip_spec.rb +19 -0
- data/spec/middleware/response/parse_iso_dates_spec.rb +44 -0
- data/spec/playlist_spec.rb +95 -0
- data/spec/read_resource_spec.rb +37 -0
- data/spec/rescue_spec.rb +94 -0
- data/spec/resource_spec.rb +332 -0
- data/spec/spec_helper.rb +120 -0
- data/spec/string_spec.rb +7 -0
- data/spec/trackie_spec.rb +39 -0
- data/zendesk_api.gemspec +38 -0
- metadata +364 -0
data/live/audit_spec.rb
ADDED
@@ -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
|
data/live/crm_spec.rb
ADDED
data/live/forum_spec.rb
ADDED
@@ -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
|
data/live/group_spec.rb
ADDED
@@ -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
|
data/live/locale_spec.rb
ADDED
data/live/macro_spec.rb
ADDED
@@ -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,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
|
data/live/ticket_spec.rb
ADDED
@@ -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
|
data/live/topic_spec.rb
ADDED
@@ -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
|