desk 0.3.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. checksums.yaml +7 -0
  2. data/README.mkd +305 -106
  3. data/TRANSITION.mkd +133 -0
  4. data/desk.gemspec +1 -1
  5. data/lib/desk.rb +1 -1
  6. data/lib/desk/api.rb +5 -1
  7. data/lib/desk/client.rb +184 -10
  8. data/lib/desk/client/article.rb +4 -83
  9. data/lib/desk/client/brand.rb +11 -0
  10. data/lib/desk/client/case.rb +59 -42
  11. data/lib/desk/client/company.rb +11 -0
  12. data/lib/desk/client/custom_field.rb +10 -0
  13. data/lib/desk/client/customer.rb +26 -124
  14. data/lib/desk/client/facebook_user.rb +11 -0
  15. data/lib/desk/client/filter.rb +11 -0
  16. data/lib/desk/client/group.rb +3 -29
  17. data/lib/desk/client/insight.rb +17 -0
  18. data/lib/desk/client/integration_url.rb +11 -0
  19. data/lib/desk/client/job.rb +11 -0
  20. data/lib/desk/client/label.rb +11 -0
  21. data/lib/desk/client/macro.rb +3 -133
  22. data/lib/desk/client/mailbox.rb +26 -0
  23. data/lib/desk/client/rule.rb +14 -0
  24. data/lib/desk/client/site_setting.rb +11 -0
  25. data/lib/desk/client/system_message.rb +16 -0
  26. data/lib/desk/client/topic.rb +4 -81
  27. data/lib/desk/client/twitter_account.rb +11 -0
  28. data/lib/desk/client/twitter_user.rb +11 -0
  29. data/lib/desk/client/user.rb +3 -30
  30. data/lib/desk/configuration.rb +1 -1
  31. data/lib/desk/connection.rb +2 -1
  32. data/lib/desk/deash.rb +100 -0
  33. data/lib/desk/request.rb +33 -20
  34. data/lib/desk/version.rb +1 -1
  35. data/lib/faraday/request/oauth.rb +6 -3
  36. data/lib/faraday/response/deashify.rb +23 -0
  37. data/spec/desk/client/article_spec.rb +62 -117
  38. data/spec/desk/client/brand_spec.rb +18 -0
  39. data/spec/desk/client/case_spec.rb +182 -66
  40. data/spec/desk/client/companies_spec.rb +26 -0
  41. data/spec/desk/client/custom_fields_spec.rb +18 -0
  42. data/spec/desk/client/customer_spec.rb +16 -145
  43. data/spec/desk/client/facebook_users_spec.rb +17 -0
  44. data/spec/desk/client/filter_spec.rb +28 -0
  45. data/spec/desk/client/group_spec.rb +32 -49
  46. data/spec/desk/client/inbound_mailboxes_spec.rb +70 -0
  47. data/spec/desk/client/integration_url_spec.rb +28 -0
  48. data/spec/desk/client/job_spec.rb +32 -0
  49. data/spec/desk/client/label_spec.rb +31 -0
  50. data/spec/desk/client/macro_spec.rb +22 -185
  51. data/spec/desk/client/rule_spec.rb +18 -0
  52. data/spec/desk/client/site_setting_spec.rb +18 -0
  53. data/spec/desk/client/system_message_spec.rb +42 -0
  54. data/spec/desk/client/topic_spec.rb +31 -112
  55. data/spec/desk/client/twitter_account_spec.rb +32 -0
  56. data/spec/desk/client/twitter_user_spec.rb +27 -0
  57. data/spec/desk/client/user_spec.rb +19 -42
  58. data/spec/desk_spec.rb +2 -2
  59. data/spec/faraday/response_spec.rb +3 -6
  60. data/spec/fixtures/article +50 -0
  61. data/spec/fixtures/article_create +50 -0
  62. data/spec/fixtures/article_translation +29 -0
  63. data/spec/fixtures/article_translation_create +29 -0
  64. data/spec/fixtures/article_translation_update +29 -0
  65. data/spec/fixtures/article_translations +81 -0
  66. data/spec/fixtures/article_update +50 -0
  67. data/spec/fixtures/articles +123 -0
  68. data/spec/fixtures/articles_search +124 -0
  69. data/spec/fixtures/brand +11 -0
  70. data/spec/fixtures/brands +45 -0
  71. data/spec/fixtures/case +44 -0
  72. data/spec/fixtures/case_attachment +19 -0
  73. data/spec/fixtures/case_attachment_create +19 -0
  74. data/spec/fixtures/case_attachments +61 -0
  75. data/spec/fixtures/case_create +51 -0
  76. data/spec/fixtures/case_message +26 -0
  77. data/spec/fixtures/case_note +21 -0
  78. data/spec/fixtures/case_note_create +26 -0
  79. data/spec/fixtures/case_notes +65 -0
  80. data/spec/fixtures/case_replies +75 -0
  81. data/spec/fixtures/case_reply +26 -0
  82. data/spec/fixtures/case_reply_create +26 -0
  83. data/spec/fixtures/case_reply_update +26 -0
  84. data/spec/fixtures/case_update +49 -0
  85. data/spec/fixtures/cases +111 -0
  86. data/spec/fixtures/cases_search +113 -0
  87. data/spec/fixtures/companies +75 -0
  88. data/spec/fixtures/companies_search +76 -0
  89. data/spec/fixtures/company +26 -0
  90. data/spec/fixtures/company_create +26 -0
  91. data/spec/fixtures/company_search +76 -0
  92. data/spec/fixtures/company_update +27 -0
  93. data/spec/fixtures/custom_field +15 -0
  94. data/spec/fixtures/custom_fields +58 -0
  95. data/spec/fixtures/customer +60 -0
  96. data/spec/fixtures/customer_create +54 -0
  97. data/spec/fixtures/customer_update +60 -0
  98. data/spec/fixtures/customers +143 -0
  99. data/spec/fixtures/customers_search +143 -0
  100. data/spec/fixtures/facebook_user +16 -0
  101. data/spec/fixtures/facebook_users +55 -0
  102. data/spec/fixtures/filter +16 -0
  103. data/spec/fixtures/filter_cases +111 -0
  104. data/spec/fixtures/filters +55 -0
  105. data/spec/fixtures/group +9 -0
  106. data/spec/fixtures/group_filters +55 -0
  107. data/spec/fixtures/group_users +63 -0
  108. data/spec/fixtures/groups +42 -0
  109. data/spec/fixtures/inbound_mailbox +32 -0
  110. data/spec/fixtures/inbound_mailboxes +87 -0
  111. data/spec/fixtures/integration_url +15 -0
  112. data/spec/fixtures/integration_url_create +15 -0
  113. data/spec/fixtures/integration_url_update +15 -0
  114. data/spec/fixtures/integration_urls +54 -0
  115. data/spec/fixtures/job +17 -0
  116. data/spec/fixtures/job_create +17 -0
  117. data/spec/fixtures/jobs +57 -0
  118. data/spec/fixtures/label +17 -0
  119. data/spec/fixtures/label_create +17 -0
  120. data/spec/fixtures/label_update +17 -0
  121. data/spec/fixtures/labels +57 -0
  122. data/spec/fixtures/macro +20 -0
  123. data/spec/fixtures/macro_action +17 -0
  124. data/spec/fixtures/macro_action_update +17 -0
  125. data/spec/fixtures/macro_actions +57 -0
  126. data/spec/fixtures/macro_create +20 -0
  127. data/spec/fixtures/macro_update +20 -0
  128. data/spec/fixtures/macros +63 -0
  129. data/spec/fixtures/rule +13 -0
  130. data/spec/fixtures/rules +49 -0
  131. data/spec/fixtures/site_setting +10 -0
  132. data/spec/fixtures/site_settings +43 -0
  133. data/spec/fixtures/system_message +4 -0
  134. data/spec/fixtures/topic +23 -0
  135. data/spec/fixtures/topic_create +23 -0
  136. data/spec/fixtures/topic_translation +12 -0
  137. data/spec/fixtures/topic_translation_create +12 -0
  138. data/spec/fixtures/topic_translation_update +12 -0
  139. data/spec/fixtures/topic_translations +47 -0
  140. data/spec/fixtures/topic_update +23 -0
  141. data/spec/fixtures/topics +69 -0
  142. data/spec/fixtures/twitter_account +14 -0
  143. data/spec/fixtures/twitter_account_tweet +20 -0
  144. data/spec/fixtures/twitter_account_tweet_create +20 -0
  145. data/spec/fixtures/twitter_account_tweets +63 -0
  146. data/spec/fixtures/twitter_accounts +51 -0
  147. data/spec/fixtures/twitter_user +18 -0
  148. data/spec/fixtures/twitter_user_create +18 -0
  149. data/spec/fixtures/twitter_users +59 -0
  150. data/spec/fixtures/user +20 -0
  151. data/spec/fixtures/user_preference +18 -0
  152. data/spec/fixtures/user_preference_update +14 -0
  153. data/spec/fixtures/user_preferences +223 -0
  154. data/spec/fixtures/users +63 -0
  155. data/spec/helper.rb +12 -0
  156. data/spec/shared_context.rb +16 -0
  157. data/spec/shared_examples.rb +312 -0
  158. metadata +247 -181
  159. data/lib/desk/client/interaction.rb +0 -75
  160. data/spec/desk/client/interaction_spec.rb +0 -191
  161. data/spec/fixtures/article.json +0 -50
  162. data/spec/fixtures/article_create.json +0 -54
  163. data/spec/fixtures/article_destroy.json +0 -3
  164. data/spec/fixtures/article_update.json +0 -54
  165. data/spec/fixtures/articles.json +0 -58
  166. data/spec/fixtures/case.json +0 -59
  167. data/spec/fixtures/case_update.json +0 -59
  168. data/spec/fixtures/cases.json +0 -182
  169. data/spec/fixtures/customer.json +0 -58
  170. data/spec/fixtures/customer_create.json +0 -56
  171. data/spec/fixtures/customer_create_email.json +0 -15
  172. data/spec/fixtures/customer_update.json +0 -47
  173. data/spec/fixtures/customer_update_email.json +0 -15
  174. data/spec/fixtures/customers.json +0 -98
  175. data/spec/fixtures/group.json +0 -8
  176. data/spec/fixtures/groups.json +0 -23
  177. data/spec/fixtures/interaction_create.json +0 -126
  178. data/spec/fixtures/interactions.json +0 -139
  179. data/spec/fixtures/macro.json +0 -8
  180. data/spec/fixtures/macro_action.json +0 -9
  181. data/spec/fixtures/macro_action_update.json +0 -12
  182. data/spec/fixtures/macro_actions.json +0 -69
  183. data/spec/fixtures/macro_create.json +0 -13
  184. data/spec/fixtures/macro_destroy.json +0 -3
  185. data/spec/fixtures/macro_update.json +0 -13
  186. data/spec/fixtures/macros.json +0 -24
  187. data/spec/fixtures/topic.json +0 -9
  188. data/spec/fixtures/topic_create.json +0 -14
  189. data/spec/fixtures/topic_destroy.json +0 -3
  190. data/spec/fixtures/topic_update.json +0 -14
  191. data/spec/fixtures/topics.json +0 -35
  192. data/spec/fixtures/user.json +0 -15
  193. data/spec/fixtures/users.json +0 -24
@@ -1,4 +1,4 @@
1
1
  module Desk
2
2
  # The version of the gem
3
- VERSION = '0.3.3'.freeze unless defined?(::Desk::VERSION)
3
+ VERSION = '1.0.0'.freeze unless defined?(::Desk::VERSION)
4
4
  end
@@ -6,11 +6,14 @@ module Faraday
6
6
 
7
7
  def call(env)
8
8
  params = env[:body] || {}
9
-
9
+ break
10
10
  signature_params = params.reject{ |k,v| v.respond_to?(:content_type) || (env[:method] == :put) }
11
11
 
12
- header = SimpleOAuth::Header.new(env[:method], env[:url], signature_params, @options)
13
-
12
+ #header = SimpleOAuth::Header.new(env[:method], env[:url], signature_params, @options)
13
+ # Runscope Support
14
+ realURL = env[:url].sub(/-desk-com-(\w)+.runscope.net/, ".desk.com")
15
+ header = SimpleOAuth::Header.new(env[:method], realURL, signature_params, @options)
16
+ env[:request_headers]['theURL'] = realURL
14
17
  env[:request_headers]['Authorization'] = header.to_s
15
18
 
16
19
  @app.call(env)
@@ -0,0 +1,23 @@
1
+ require 'faraday_middleware/response/mashify'
2
+
3
+ module FaradayMiddleware
4
+ # Public: Converts parsed response bodies to a Hashie::Rash if they were of
5
+ # Hash or Array type.
6
+ class Deashify < Mashify
7
+ dependency do
8
+ require 'desk/deash'
9
+ self.mash_class = ::Hashie::Deash
10
+ end
11
+
12
+ def parse(body)
13
+ case body
14
+ when Hash
15
+ raw = mash_class.new({:raw => body})
16
+ when Array
17
+ raw = body.map { |item| parse(item) }
18
+ else
19
+ raw = body
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,132 +1,77 @@
1
1
  require 'helper'
2
2
 
3
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 ".articles" do
11
-
12
- context "lookup" do
13
-
14
- before do
15
- stub_get("topics/1/articles.#{format}").
16
- to_return(:body => fixture("articles.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
17
- end
18
-
19
- it "should post to the correct resource" do
20
- @client.articles(1)
21
- a_get("topics/1/articles.#{format}").
22
- should have_been_made
23
- end
24
-
25
- it "should return the articles" do
26
- articles = @client.articles(1)
27
-
28
- articles.results.should be_a Array
29
- articles.results.first.article.id.should == 13
30
- end
31
-
32
- end
33
- end
34
-
35
- describe ".article" do
36
-
37
- context "lookup" do
38
-
39
- before do
40
- stub_get("articles/13.#{format}").
41
- to_return(:body => fixture("article.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
42
- end
43
-
44
- it "should get the correct resource" do
45
- @client.article(13)
46
- a_get("articles/13.#{format}").
47
- should have_been_made
48
- end
49
-
50
- it "should return up to 100 cases worth of extended information" do
51
- article = @client.article(13)
52
-
53
- article.id.should == 13
54
- article.subject.should == "API Tips"
55
- end
56
-
57
- end
58
- end
59
-
60
- describe ".create_article" do
61
-
62
- context "create" do
63
-
64
- before do
65
- stub_post("topics/1/articles.#{format}").
66
- to_return(:body => fixture("article_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_article(1, :subject => "API Tips", :main_content => "Tips on using our API")
71
- a_post("topics/1/articles.#{format}").
72
- should have_been_made
73
- end
74
-
75
- it "should return the articles" do
76
- article = @client.create_article(1, :subject => "API Tips", :main_content => "Tips on using our API")
77
-
78
- article.id.should == 13
79
- end
80
-
81
- end
82
- end
4
+ context "Article" do
5
+
6
+ let(:endpoint) { "article" }
7
+ let(:id) { 1 }
8
+ let(:check_key) { "subject" }
9
+ let(:check_value) { "Awesome Subject" }
10
+
11
+ include_context "basic configuration"
12
+
13
+ it_behaves_like "a list endpoint"
14
+
15
+ it_behaves_like "a show endpoint"
16
+
17
+ it_behaves_like "a create endpoint", {
18
+ :subject => "Awesome Subject",
19
+ :body => "Simply post here",
20
+ :_links => {
21
+ :topic => {
22
+ :href => "/api/v2/topics/1",
23
+ :class => "topic"
24
+ }
25
+ }
26
+ }
27
+
28
+ it_behaves_like "an update endpoint", {
29
+ :subject => "How to make your customers happy",
30
+ :body => "<strong>Use Desk.com</strong>",
31
+ :body_email => "Custom email body for article",
32
+ :body_email_auto => false,
33
+ :_links => {
34
+ :topic => {
35
+ :href => "/api/v2/topics/1",
36
+ :class => "topic"
37
+ }
38
+ }
39
+ } do
40
+ let(:check_value) { "How to make your customers happy" }
41
+ end
83
42
 
84
- describe ".update_article" do
43
+ it_behaves_like "a delete endpoint"
85
44
 
86
- context "update" do
45
+ it_behaves_like "a search endpoint", {
46
+ :text => "happy",
47
+ :topic_ids => "1,2,4"
48
+ }
87
49
 
88
- before do
89
- stub_put("articles/1.#{format}").
90
- to_return(:body => fixture("article_update.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
91
- end
50
+ context "Translation" do
92
51
 
93
- it "should post to the correct resource" do
94
- @client.update_article(1, :subject => "API Tips", :main_content => "Tips on using our API")
95
- a_put("articles/1.#{format}").
96
- should have_been_made
97
- end
52
+ let(:sub_endpoint) { "translation" }
53
+ let(:sub_id) { "en" }
54
+ let(:check_key) { "subject" }
55
+ let(:check_value) { "Awesome Subject" }
98
56
 
99
- it "should return the new topic" do
100
- topic = @client.update_article(1, :subject => "API Tips", :main_content => "Tips on using our API")
57
+ it_behaves_like "a sub list endpoint"
101
58
 
102
- topic.subject.should == "API Tips"
103
- topic.main_content.should == "Tips on using our API"
104
- end
59
+ it_behaves_like "a sub show endpoint"
105
60
 
106
- end
61
+ it_behaves_like "a sub create endpoint", {
62
+ :locale => "es",
63
+ :subject => "Spanish Translation",
64
+ :body => "Traducción español aquí"
65
+ } do
66
+ let(:sub_id) { "es" }
67
+ let(:check_value) { "Spanish Translation" }
107
68
  end
108
69
 
109
- describe ".delete_article" do
110
-
111
- context "delete" do
112
-
113
- before do
114
- stub_delete("articles/1.#{format}").
115
- to_return(:body => fixture("article_destroy.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
116
- end
117
-
118
- it "should post to the correct resource" do
119
- @client.delete_article(1)
120
- a_delete("articles/1.#{format}").
121
- should have_been_made
122
- end
123
-
124
- it "should return a successful response" do
125
- topic = @client.delete_article(1)
126
- topic.success.should == true
127
- end
128
-
129
- end
70
+ it_behaves_like "a sub update endpoint", {
71
+ :subject => "Updated Spanish Translation"
72
+ } do
73
+ let(:sub_id) { "es" }
74
+ let(:check_value) { "Updated Spanish Translation" }
130
75
  end
131
76
 
132
77
  end
@@ -0,0 +1,18 @@
1
+ require 'helper'
2
+
3
+ describe Desk::Client do
4
+ context "Brand" do
5
+
6
+ let(:endpoint) { "brand" }
7
+ let(:id) { 1 }
8
+ let(:check_key) { "name" }
9
+ let(:check_value) { "Desk.com" }
10
+
11
+ include_context "basic configuration"
12
+
13
+ it_behaves_like "a list endpoint"
14
+
15
+ it_behaves_like "a show endpoint"
16
+
17
+ end
18
+ end
@@ -1,99 +1,215 @@
1
1
  require 'helper'
2
2
 
3
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
4
+ context "Case" do
5
+
6
+ let(:endpoint) { "case" }
7
+ let(:id) { 1 }
8
+ let(:check_key) { "subject" }
9
+ let(:check_value) { "Welcome" }
10
+
11
+ include_context "basic configuration"
12
+
13
+ it_behaves_like "a list endpoint"
14
+
15
+ it_behaves_like "a search endpoint", {
16
+ :subject => "please help",
17
+ :name => "jimmy"
18
+ }
19
+
20
+ it_behaves_like "a show endpoint"
21
+
22
+ it_behaves_like "a create endpoint", {
23
+ :type => "email",
24
+ :subject => "Creating a case via the API",
25
+ :priority => 4,
26
+ :status => "open",
27
+ :labels => [ "Spam", "Ignore" ],
28
+ :created_at => "2012-05-01T21:38:48Z",
29
+ :_links => {
30
+ :customer => {
31
+ :href => "/api/v2/customers/1",
32
+ :class => "customer"
33
+ },
34
+ :assigned_user => {
35
+ :href => "/api/v2/users/1",
36
+ :class => "user"
37
+ },
38
+ :assigned_group => {
39
+ :href => "/api/v2/groups/1",
40
+ :class => "group"
41
+ },
42
+ :locked_by => {
43
+ :href => "/api/v2/users/1",
44
+ :class => "user"
45
+ }
46
+ },
47
+ :message => {
48
+ :direction => "out",
49
+ :status => "pending",
50
+ :to => "someone@desk.com",
51
+ :from => "someone-else@desk.com",
52
+ :cc => "alpha@desk.com",
53
+ :bcc => "beta@desk.com",
54
+ :subject => "Creating a case via the API",
55
+ :body => "Please assist me with this case",
56
+ :created_at => "2012-05-02T21:38:48Z"
57
+ }
58
+ } do
59
+ let(:check_value) { "Creating a case via the API" }
60
+ end
9
61
 
10
- describe ".cases" do
62
+ it_behaves_like "an update endpoint", {
63
+ :subject => "Updated",
64
+ :status => "pending",
65
+ :labels => [ "Spam", "Test" ],
66
+ :label_action => "replace",
67
+ :custom_fields => { :level => "super" },
68
+ :_links => {
69
+ :assigned_group => {
70
+ :href => "/api/v2/groups/1",
71
+ :rel => "group"
72
+ }
73
+ }
74
+ } do
75
+ let(:check_value) { "Updated" }
76
+ end
11
77
 
12
- context "lookup" do
78
+ context "Message" do
13
79
 
14
- before do
15
- stub_get("cases.#{format}").
16
- to_return(:body => fixture("cases.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
17
- end
80
+ let(:sub_endpoint) { "message" }
81
+ let(:check_value) { "Please help" }
18
82
 
19
- it "should get the correct resource" do
20
- @client.cases
21
- a_get("cases.#{format}").
22
- should have_been_made
23
- end
83
+ include_context "plural endpoint"
24
84
 
25
- it "should return up to 100 cases worth of extended information" do
26
- cases = @client.cases
85
+ subject { client.send("show_#{endpoint}_#{sub_endpoint}", id) }
27
86
 
28
- cases.results.should be_a Array
29
- cases.results.first.case.id.should == 1
30
- cases.results.first.case.user.name.should == "Jeremy Suriel"
31
- end
87
+ before do
88
+ stub_get("#{endpoints}/#{id}/#{sub_endpoint}").
89
+ to_return(:body => fixture("#{endpoint}_#{sub_endpoint}"))
90
+ end
32
91
 
33
- end
92
+ it "gets the correct resource" do
93
+ subject
94
+ expect(a_get("#{endpoints}/#{id}/#{sub_endpoint}")).
95
+ to have_been_made
34
96
  end
35
97
 
36
- describe ".case" do
98
+ it { expect(subject).to be_a Hashie::Deash }
99
+
100
+ it "has a valid entry" do
101
+ expect(subject.parent_id).to eq(id)
102
+ expect(subject.send(check_key)).to eq(check_value)
103
+ end
37
104
 
38
- context "lookup" do
105
+ it "allows raw access" do
106
+ expect(subject.raw).to be_a Hashie::Deash
107
+ end
39
108
 
40
- before do
41
- stub_get("cases/1.#{format}").
42
- to_return(:body => fixture("case.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
43
- end
109
+ end
44
110
 
45
- it "should get the correct resource" do
46
- @client.case(1)
47
- a_get("cases/1.#{format}").
48
- should have_been_made
49
- end
111
+ context "Reply" do
50
112
 
51
- it "should return up to 100 cases worth of extended information" do
52
- a_case = @client.case(1)
113
+ let(:sub_endpoint) { "reply" }
114
+ let(:sub_id) { 1 }
115
+ let(:check_key) { "subject" }
116
+ let(:check_value) { "Re: Please help" }
53
117
 
54
- a_case.id.should == 1
55
- a_case.external_id.should == "123"
56
- a_case.subject.should == "Welcome to Desk.com"
57
- end
118
+ it_behaves_like "a sub list endpoint" do
119
+ let(:check_value) { "Please help" }
120
+ end
58
121
 
59
- end
122
+ it_behaves_like "a sub show endpoint" do
123
+ let(:sub_id) { 2 }
60
124
  end
61
125
 
62
- describe ".update_case" do
126
+ it_behaves_like "a sub create endpoint", {
127
+ :body => "My Reply",
128
+ :direction => "out"
129
+ }
130
+
131
+ it_behaves_like "a sub update endpoint", {
132
+ :body => "Updated reply body",
133
+ :cc => "new.email@example.com"
134
+ }
63
135
 
64
- context "update" do
136
+ end
65
137
 
66
- before do
67
- stub_put("cases/1.#{format}").
68
- to_return(:body => fixture("case_update.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
69
- end
138
+ context "Note" do
70
139
 
71
- it "should get the correct resource" do
72
- @client.update_case(1, :subject => "Welcome to Desk")
73
- a_put("cases/1.#{format}").
74
- should have_been_made
75
- end
140
+ let(:sub_endpoint) { "note" }
141
+ let(:sub_id) { 1 }
142
+ let(:check_key) { "body" }
143
+ let(:check_value) { "Please assist me with this case" }
76
144
 
77
- it "should return up to 100 cases worth of extended information" do
78
- a_case = @client.update_case(1, :subject => "Welcome to Desk.com")
145
+ it_behaves_like "a sub list endpoint"
79
146
 
80
- a_case.id.should == 1
81
- a_case.subject.should == "Welcome to Desk.com"
82
- end
147
+ it_behaves_like "a sub show endpoint"
83
148
 
84
- end
149
+ it_behaves_like "a sub create endpoint", {
150
+ :body => "Help me with my issue!"
151
+ } do
152
+ let(:check_value) { "Help me with my issue!" }
85
153
  end
86
154
 
87
- describe ".case_url" do
88
-
89
- context "generating a case url" do
155
+ end
90
156
 
91
- it "should make a correct url for the case" do
92
- @client.case_url(123).should == "https://example.desk.com/agent/case/123"
93
- end
157
+ context "Attachment" do
158
+
159
+ let(:sub_endpoint) { "attachment" }
160
+ let(:sub_id) { 1 }
161
+ let(:check_key) { "file_name" }
162
+ let(:check_value) { "awesome_pic.png" }
163
+
164
+ it_behaves_like "a sub list endpoint"
165
+
166
+ it_behaves_like "a sub show endpoint"
167
+
168
+ it_behaves_like "a sub create endpoint", {
169
+ :file_name => "awesome_pic.png",
170
+ :content_type => "image/png",
171
+ :content => "iVBORw0KGgoAAAANSUhEUgAAABsAAAAXCAIAAAB1dKN5AAAAGXRFWHRTb2Z0
172
+ d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9i
173
+ ZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2Vo
174
+ aUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6
175
+ bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2
176
+ LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpS
177
+ REYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJk
178
+ Zi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIg
179
+ eG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxu
180
+ czp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1s
181
+ bnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9S
182
+ ZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9w
183
+ IENTNiAoTWFjaW50b3NoKSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDo0
184
+ NkEyOEM5RUE2REUxMUUyODc1NUM1OUZGMTlFMjEwNyIgeG1wTU06RG9jdW1l
185
+ bnRJRD0ieG1wLmRpZDo0NkEyOEM5RkE2REUxMUUyODc1NUM1OUZGMTlFMjEw
186
+ NyI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAu
187
+ aWlkOjg5ODY1RDg5QTZENzExRTI4NzU1QzU5RkYxOUUyMTA3IiBzdFJlZjpk
188
+ b2N1bWVudElEPSJ4bXAuZGlkOjg5ODY1RDhBQTZENzExRTI4NzU1QzU5RkYx
189
+ OUUyMTA3Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4
190
+ bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+I+v80gAAAwJJREFUeNqklUtr
191
+ U0EUx2fuvb1pmvSVmvpA2021tMXWoiLiY6MoFHQhgvYTFBTpZ+jChXHjwo3g
192
+ Uhe6EAuCoC1uRKVRulBbUFNSWvrC2rTN475mjmdmkkuSpg/t5SaczNzzu//z
193
+ PzMTAwDI/14MCAficrAYyTHIepBlRNsVjhCPEw/E7XLiyu9/IELhZjITWTmb
194
+ x98l3jwdtxk4HFxJN3YCUhcWCFIXBgiNj/x89ehTOpVrO3moh4HFiS1kgrET
195
+ HOcCxGTABA5QS+LbAuJU+TkmcEqmsVWN0nglylMgUSyIqmXhvqG5Ag7HjLLS
196
+ FEWNqOokDqT3IkeaBaobvhsWEyOUkN5G3YANHimWVCdEKWmO9KhAVM0BXyPO
197
+ Npq0q14L6tRAa0B5BPmK8tIIMC7GJU5ALZf/WVh3HFYdCRkh09doauR4RI+Y
198
+ VP00vAJLvdwtgjIJxcHV5Wz82fjU+4SbczFH02hL1z5S2Bp1VdTHCaLLQNns
199
+ 5G0SjqiqUSAS5yYXR2Mj9rrl53AOya/zm7XUwH2DFEcSHSaaiMaxgptrS+nR
200
+ 2Ft73d75RkAioEwb3ZVondKATlecPPTLk7iPO3el4/zVzpqw+X1sZvhxPLPJ
201
+ awzc3o7soFgcQDrrtWiAIiuD2z7tvPg8rZ67dLPn2sApFSO3tT1679ZLziuc
202
+ MlpGHBvE4oCLfk9A4HAUP2GDppLLzBPrmFJ6ub+nOA2JHScOVtaoFifW2Byg
203
+ KLB4LpdxVBAIGqG66rLMyN5wHmHqJRptJpbB4bDW3aDT0pzahqAKrKz7e36t
204
+ jDibWFZBYzRUQmyr1c5GjdZQhWOtpT0aDJkqfv7wI2fcn8K2JCeXVHzk2IHi
205
+ LP3B3aFybf7bNJpOWVMTixgvzqxOxGex/Uuzqx9e//BwfQBZmE5FmsM3Bs/g
206
+ k34W3fpfwco6sdvDc8mVyq/UtcH7fe29JRq3OcOra8w7sT7sbKWpqoGhi2W4
207
+ 7TXmtx3jWOnY6C/shmt7Tftru0+3Xrh+tL6pZuPDdDf/hRWvvwIMAJE9J8AO
208
+ RSMOAAAAAElFTkSuQmCC"
209
+ }
210
+
211
+ it_behaves_like "a sub delete endpoint"
94
212
 
95
- end
96
- end
97
213
  end
98
214
  end
99
215
  end