desk 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.yardopts +9 -0
- data/Gemfile +12 -0
- data/HISTORY.mkd +44 -0
- data/LICENSE.mkd +20 -0
- data/README.mkd +267 -0
- data/Rakefile +23 -0
- data/desk.gemspec +44 -0
- data/lib/desk.rb +26 -0
- data/lib/desk/api.rb +28 -0
- data/lib/desk/authentication.rb +25 -0
- data/lib/desk/client.rb +28 -0
- data/lib/desk/client/article.rb +92 -0
- data/lib/desk/client/case.rb +55 -0
- data/lib/desk/client/customer.rb +146 -0
- data/lib/desk/client/interaction.rb +75 -0
- data/lib/desk/client/macro.rb +142 -0
- data/lib/desk/client/topic.rb +90 -0
- data/lib/desk/client/user.rb +38 -0
- data/lib/desk/configuration.rb +98 -0
- data/lib/desk/connection.rb +39 -0
- data/lib/desk/error.rb +67 -0
- data/lib/desk/request.rb +44 -0
- data/lib/desk/version.rb +4 -0
- data/lib/faraday/request/multipart_with_file.rb +30 -0
- data/lib/faraday/request/oauth.rb +23 -0
- data/lib/faraday/response/raise_http_4xx.rb +45 -0
- data/lib/faraday/response/raise_http_5xx.rb +24 -0
- data/spec/desk/api_spec.rb +70 -0
- data/spec/desk/client/article_spec.rb +134 -0
- data/spec/desk/client/case_spec.rb +99 -0
- data/spec/desk/client/customer_spec.rb +158 -0
- data/spec/desk/client/interaction_spec.rb +191 -0
- data/spec/desk/client/macro_spec.rb +204 -0
- data/spec/desk/client/topic_spec.rb +135 -0
- data/spec/desk/client/user_spec.rb +58 -0
- data/spec/desk/client_spec.rb +10 -0
- data/spec/desk_spec.rb +127 -0
- data/spec/faraday/response_spec.rb +34 -0
- data/spec/fixtures/article.json +50 -0
- data/spec/fixtures/article_create.json +54 -0
- data/spec/fixtures/article_destroy.json +3 -0
- data/spec/fixtures/article_update.json +54 -0
- data/spec/fixtures/articles.json +58 -0
- data/spec/fixtures/case.json +59 -0
- data/spec/fixtures/case_update.json +59 -0
- data/spec/fixtures/cases.json +182 -0
- data/spec/fixtures/customer.json +58 -0
- data/spec/fixtures/customer_create.json +56 -0
- data/spec/fixtures/customer_create_email.json +15 -0
- data/spec/fixtures/customer_update.json +47 -0
- data/spec/fixtures/customer_update_email.json +15 -0
- data/spec/fixtures/customers.json +98 -0
- data/spec/fixtures/interaction_create.json +126 -0
- data/spec/fixtures/interactions.json +139 -0
- data/spec/fixtures/macro.json +8 -0
- data/spec/fixtures/macro_action.json +9 -0
- data/spec/fixtures/macro_action_update.json +12 -0
- data/spec/fixtures/macro_actions.json +69 -0
- data/spec/fixtures/macro_create.json +13 -0
- data/spec/fixtures/macro_destroy.json +3 -0
- data/spec/fixtures/macro_update.json +13 -0
- data/spec/fixtures/macros.json +24 -0
- data/spec/fixtures/topic.json +9 -0
- data/spec/fixtures/topic_create.json +14 -0
- data/spec/fixtures/topic_destroy.json +3 -0
- data/spec/fixtures/topic_update.json +14 -0
- data/spec/fixtures/topics.json +35 -0
- data/spec/fixtures/user.json +15 -0
- data/spec/fixtures/users.json +24 -0
- data/spec/helper.rb +55 -0
- metadata +464 -0
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Desk::Client do
|
4
|
+
Desk::Configuration::VALID_FORMATS.each do |format|
|
5
|
+
context ".new(:format => '#{format}')" do
|
6
|
+
before do
|
7
|
+
@client = Desk::Client.new(:subdomain => "example", :format => format, :consumer_key => 'CK', :consumer_secret => 'CS', :oauth_token => 'OT', :oauth_token_secret => 'OS')
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ".topics" do
|
11
|
+
|
12
|
+
context "lookup" do
|
13
|
+
|
14
|
+
before do
|
15
|
+
stub_get("topics.#{format}").
|
16
|
+
to_return(:body => fixture("topics.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should get the correct resource" do
|
20
|
+
@client.topics
|
21
|
+
a_get("topics.#{format}").
|
22
|
+
should have_been_made
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return up to 100 topics worth of extended information" do
|
26
|
+
topics = @client.topics
|
27
|
+
|
28
|
+
topics.results.should be_a Array
|
29
|
+
topics.results.first.topic.id.should == 1
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe ".topic" do
|
36
|
+
|
37
|
+
context "lookup" do
|
38
|
+
|
39
|
+
before do
|
40
|
+
stub_get("topics/1.#{format}").
|
41
|
+
to_return(:body => fixture("topic.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should get the correct resource" do
|
45
|
+
@client.topic(1)
|
46
|
+
a_get("topics/1.#{format}").
|
47
|
+
should have_been_made
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should return up to 100 cases worth of extended information" do
|
51
|
+
topic = @client.topic(1)
|
52
|
+
|
53
|
+
topic.id.should == 1
|
54
|
+
topic.name.should == "General"
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe ".create_topic" do
|
61
|
+
|
62
|
+
context "create" do
|
63
|
+
|
64
|
+
before do
|
65
|
+
stub_post("topics.#{format}").
|
66
|
+
to_return(:body => fixture("topic_create.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should post to the correct resource" do
|
70
|
+
@client.create_topic("General", :description => "Everything belongs here")
|
71
|
+
a_post("topics.#{format}").
|
72
|
+
should have_been_made
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should return the new topic" do
|
76
|
+
topic = @client.create_topic("General", :description => "Everything belongs here")
|
77
|
+
|
78
|
+
topic.id.should == 9
|
79
|
+
topic.name.should == "General"
|
80
|
+
topic.description.should == "Everything belongs here"
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe ".update_topic" do
|
87
|
+
|
88
|
+
context "update" do
|
89
|
+
|
90
|
+
before do
|
91
|
+
stub_put("topics/1.#{format}").
|
92
|
+
to_return(:body => fixture("topic_update.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should post to the correct resource" do
|
96
|
+
@client.update_topic(1, :name => "Updated", :description => "Updated Description")
|
97
|
+
a_put("topics/1.#{format}").
|
98
|
+
should have_been_made
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should return the new topic" do
|
102
|
+
topic = @client.update_topic(1, :name => "Updated", :description => "Updated Description")
|
103
|
+
|
104
|
+
topic.name.should == "Updated"
|
105
|
+
topic.description.should == "Updated Description"
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe ".delete_topic" do
|
112
|
+
|
113
|
+
context "delete" do
|
114
|
+
|
115
|
+
before do
|
116
|
+
stub_delete("topics/1.#{format}").
|
117
|
+
to_return(:body => fixture("topic_destroy.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should post to the correct resource" do
|
121
|
+
@client.delete_topic(1)
|
122
|
+
a_delete("topics/1.#{format}").
|
123
|
+
should have_been_made
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should return a successful response" do
|
127
|
+
topic = @client.delete_topic(1)
|
128
|
+
topic.success.should == true
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Desk::Client do
|
4
|
+
Desk::Configuration::VALID_FORMATS.each do |format|
|
5
|
+
context ".new(:format => '#{format}')" do
|
6
|
+
before do
|
7
|
+
@client = Desk::Client.new(:subdomain => "example", :format => format, :consumer_key => 'CK', :consumer_secret => 'CS', :oauth_token => 'OT', :oauth_token_secret => 'OS')
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ".user" do
|
11
|
+
|
12
|
+
context "with id passed" do
|
13
|
+
|
14
|
+
before do
|
15
|
+
stub_get("users/1.#{format}").
|
16
|
+
to_return(:body => fixture("user.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should get the correct resource" do
|
20
|
+
@client.user(1)
|
21
|
+
a_get("users/1.#{format}").
|
22
|
+
should have_been_made
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return extended information of a given user" do
|
26
|
+
user = @client.user(1)
|
27
|
+
user.name.should == "Chris Warren"
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe ".users" do
|
34
|
+
|
35
|
+
context "lookup" do
|
36
|
+
|
37
|
+
before do
|
38
|
+
stub_get("users.#{format}").
|
39
|
+
to_return(:body => fixture("users.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should get the correct resource" do
|
43
|
+
@client.users
|
44
|
+
a_get("users.#{format}").
|
45
|
+
should have_been_made
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should return up to 100 users worth of extended information" do
|
49
|
+
users = @client.users
|
50
|
+
users.results.should be_a Array
|
51
|
+
users.results.first.user.name.should == "Test User"
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Desk::Client do
|
4
|
+
it "should connect using the endpoint configuration" do
|
5
|
+
client = Desk::Client.new
|
6
|
+
endpoint = URI.parse(client.api_endpoint)
|
7
|
+
connection = client.send(:connection).build_url("./").to_s.strip
|
8
|
+
connection.should == endpoint.to_s
|
9
|
+
end
|
10
|
+
end
|
data/spec/desk_spec.rb
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Desk do
|
4
|
+
after do
|
5
|
+
Desk.reset
|
6
|
+
end
|
7
|
+
|
8
|
+
# context "when delegating to a client" do
|
9
|
+
#
|
10
|
+
# before do
|
11
|
+
# stub_get("statuses/user_timeline.json").
|
12
|
+
# with(:query => {:screen_name => "sferik"}).
|
13
|
+
# to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# it "should get the correct resource" do
|
17
|
+
# Twitter.user_timeline('sferik')
|
18
|
+
# a_get("statuses/user_timeline.json").
|
19
|
+
# with(:query => {:screen_name => "sferik"}).
|
20
|
+
# should have_been_made
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# it "should return the same results as a client" do
|
24
|
+
# Desk.user_timeline('sferik').should == Twitter::Client.new.user_timeline('sferik')
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# end
|
28
|
+
|
29
|
+
describe ".client" do
|
30
|
+
it "should be an Desk::Client" do
|
31
|
+
Desk.client.should be_a Desk::Client
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe ".adapter" do
|
36
|
+
it "should return the default adapter" do
|
37
|
+
Desk.adapter.should == Desk::Configuration::DEFAULT_ADAPTER
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe ".adapter=" do
|
42
|
+
it "should set the adapter" do
|
43
|
+
Desk.adapter = :typhoeus
|
44
|
+
Desk.adapter.should == :typhoeus
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe ".subdomain=" do
|
49
|
+
before do
|
50
|
+
Desk.subdomain = "zencoder"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should set the subdomain" do
|
54
|
+
Desk.subdomain.should == "zencoder"
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should change the endpoint" do
|
58
|
+
Desk.endpoint.should == "https://zencoder.desk.com/api/#{Desk::Configuration::DEFAULT_VERSION}/"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe ".support_email" do
|
63
|
+
it "should return the default support_email" do
|
64
|
+
Desk.support_email.should == Desk::Configuration::DEFAULT_SUPPORT_EMAIL
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe ".support_email=" do
|
69
|
+
it "should set the support_email" do
|
70
|
+
Desk.support_email = "help@example.com"
|
71
|
+
Desk.support_email.should == "help@example.com"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe ".version=" do
|
76
|
+
before do
|
77
|
+
Desk.version = "v4"
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should set the subdomain" do
|
81
|
+
Desk.version.should == "v4"
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should change the endpoint" do
|
85
|
+
Desk.endpoint.should == "https://#{Desk::Configuration::DEFAULT_SUBDOMAIN}.desk.com/api/v4/"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe ".format" do
|
90
|
+
it "should return the default format" do
|
91
|
+
Desk.format.should == Desk::Configuration::DEFAULT_FORMAT
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe ".format=" do
|
96
|
+
it "should set the format" do
|
97
|
+
Desk.format = 'xml'
|
98
|
+
Desk.format.should == 'xml'
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe ".user_agent" do
|
103
|
+
it "should return the default user agent" do
|
104
|
+
Desk.user_agent.should == Desk::Configuration::DEFAULT_USER_AGENT
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe ".user_agent=" do
|
109
|
+
it "should set the user_agent" do
|
110
|
+
Desk.user_agent = 'Custom User Agent'
|
111
|
+
Desk.user_agent.should == 'Custom User Agent'
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe ".configure" do
|
116
|
+
|
117
|
+
Desk::Configuration::VALID_OPTIONS_KEYS.each do |key|
|
118
|
+
|
119
|
+
it "should set the #{key}" do
|
120
|
+
Desk.configure do |config|
|
121
|
+
config.send("#{key}=", key)
|
122
|
+
Desk.send(key).should == key
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Faraday::Response do
|
4
|
+
before do
|
5
|
+
@client = Desk::Client.new
|
6
|
+
end
|
7
|
+
|
8
|
+
{
|
9
|
+
400 => Desk::BadRequest,
|
10
|
+
401 => Desk::Unauthorized,
|
11
|
+
403 => Desk::Forbidden,
|
12
|
+
404 => Desk::NotFound,
|
13
|
+
406 => Desk::NotAcceptable,
|
14
|
+
420 => Desk::EnhanceYourCalm,
|
15
|
+
500 => Desk::InternalServerError,
|
16
|
+
502 => Desk::BadGateway,
|
17
|
+
503 => Desk::ServiceUnavailable,
|
18
|
+
}.each do |status, exception|
|
19
|
+
context "when HTTP status is #{status}" do
|
20
|
+
|
21
|
+
before do
|
22
|
+
stub_get('users/1.json').
|
23
|
+
with(:headers => {'Accept'=>'application/json', 'User-Agent'=>Desk::Configuration::DEFAULT_USER_AGENT}).
|
24
|
+
to_return(:status => status)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should raise #{exception.name} error" do
|
28
|
+
lambda do
|
29
|
+
@client.user(1)
|
30
|
+
end.should raise_error(exception)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
{
|
2
|
+
"article":
|
3
|
+
{
|
4
|
+
"id":13,
|
5
|
+
"subject":"API Tips",
|
6
|
+
"show_in_portal":true,
|
7
|
+
"main_content":"Tips on using our API",
|
8
|
+
"agent_content":null,
|
9
|
+
"email":"Tips on using our API",
|
10
|
+
"chat":"Tips on using our API",
|
11
|
+
"twitter":"Tips on using our API",
|
12
|
+
"question_answer":"Tips on using our API",
|
13
|
+
"phone":"Tips on using our API",
|
14
|
+
"quickcode":null,
|
15
|
+
"created_by":
|
16
|
+
{
|
17
|
+
"user":
|
18
|
+
{
|
19
|
+
"id":1,
|
20
|
+
"name":"API User",
|
21
|
+
"name_public":"API User",
|
22
|
+
"email":"apiuser@yoursite.com",
|
23
|
+
"created_at":"2011-01-13T22:41:42Z",
|
24
|
+
"updated_at":"2011-01-19T22:04:33Z",
|
25
|
+
"user_level":"admin",
|
26
|
+
"login_count":9,
|
27
|
+
"time_zone":"Pacific Time (US & Canada)",
|
28
|
+
"last_login_at":"2011-01-19T18:21:52Z",
|
29
|
+
"current_login_at":"2011-01-19T22:04:33Z"
|
30
|
+
}
|
31
|
+
},
|
32
|
+
"updated_by":
|
33
|
+
{
|
34
|
+
"user":
|
35
|
+
{
|
36
|
+
"id":1,
|
37
|
+
"name":"API User",
|
38
|
+
"name_public":"API User",
|
39
|
+
"email":"apiuser@yoursite.com",
|
40
|
+
"created_at":"2011-01-13T22:41:42Z",
|
41
|
+
"updated_at":"2011-01-19T22:04:33Z",
|
42
|
+
"user_level":"admin",
|
43
|
+
"login_count":9,
|
44
|
+
"time_zone":"Pacific Time (US & Canada)",
|
45
|
+
"last_login_at":"2011-01-19T18:21:52Z",
|
46
|
+
"current_login_at":"2011-01-19T22:04:33Z"
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
{
|
2
|
+
"success":true,
|
3
|
+
"results":
|
4
|
+
{
|
5
|
+
"article":
|
6
|
+
{
|
7
|
+
"id":13,
|
8
|
+
"subject":"API Tips",
|
9
|
+
"show_in_portal":true,
|
10
|
+
"main_content":"Tips on using our API",
|
11
|
+
"agent_content":null,
|
12
|
+
"email":"Tips on using our API",
|
13
|
+
"chat":"Tips on using our API",
|
14
|
+
"twitter":"Tips on using our API",
|
15
|
+
"question_answer":"Tips on using our API",
|
16
|
+
"phone":"Tips on using our API",
|
17
|
+
"quickcode":null,
|
18
|
+
"created_by":
|
19
|
+
{
|
20
|
+
"user":
|
21
|
+
{
|
22
|
+
"id":1,
|
23
|
+
"name":"API User",
|
24
|
+
"name_public":"API User",
|
25
|
+
"email":"apiuser@yoursite.com",
|
26
|
+
"created_at":"2011-01-13T22:41:42Z",
|
27
|
+
"updated_at":"2011-01-19T22:04:33Z",
|
28
|
+
"user_level":"admin",
|
29
|
+
"login_count":9,
|
30
|
+
"time_zone":"Pacific Time (US & Canada)",
|
31
|
+
"last_login_at":"2011-01-19T18:21:52Z",
|
32
|
+
"current_login_at":"2011-01-19T22:04:33Z"
|
33
|
+
}
|
34
|
+
},
|
35
|
+
"updated_by":
|
36
|
+
{
|
37
|
+
"user":
|
38
|
+
{
|
39
|
+
"id":1,
|
40
|
+
"name":"API User",
|
41
|
+
"name_public":"API User",
|
42
|
+
"email":"apiuser@yoursite.com",
|
43
|
+
"created_at":"2011-01-13T22:41:42Z",
|
44
|
+
"updated_at":"2011-01-19T22:04:33Z",
|
45
|
+
"user_level":"admin",
|
46
|
+
"login_count":9,
|
47
|
+
"time_zone":"Pacific Time (US & Canada)",
|
48
|
+
"last_login_at":"2011-01-19T18:21:52Z",
|
49
|
+
"current_login_at":"2011-01-19T22:04:33Z"
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}
|