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
@@ -0,0 +1,133 @@
1
+ Desk.com API v1 to v2 transition guide
2
+ ======================================
3
+
4
+ The API v2 endpoints and responses are both highly standardized and
5
+ significantly different compared to v1 of the API. As a result the Desk.com Ruby
6
+ gem was almost entirely rewritten to take advantage of the changes. An
7
+ unfortunate side effect is that likely all projects upgrading from v1 to v2 will
8
+ need to be rewritten to some extent.
9
+
10
+ Below are some ideas and tips for utilizing the new features as well as
11
+ transition guides for the original endpoints.
12
+
13
+ General Pagination
14
+ ------------------
15
+
16
+ Previously, to paginate through results (like all cases) you would need to do
17
+ something similar to the following:
18
+
19
+ page = 1
20
+ while page > 0 do
21
+ results = Desk.cases(:count => 10, :page => page)
22
+ # Do something with results
23
+ if page*10 >= results.total
24
+ page = 0
25
+ else
26
+ page += 1
27
+ end
28
+ end
29
+
30
+ Now, utilizing the new "\_links" callbacks (see the main README for more
31
+ information), pagination can be done like:
32
+
33
+ results = Desk.list_cases
34
+ while results
35
+ # Do something with results
36
+ results = results.next
37
+ end
38
+
39
+ Result objects
40
+ --------------
41
+
42
+ Previously, the raw results from the API were returned as a Hashie object. This
43
+ required your code to dig down like:
44
+
45
+ r = Desk.cases(:count => 5)
46
+ r.results.each do |c|
47
+ theActualCaseObject = c.case
48
+ # Do something with theActualCaseObject
49
+ end
50
+
51
+ r = Desk.case(12345)
52
+ theActualCaseObject = r.case
53
+ # Do soemthing with theActualCaseObject
54
+
55
+ Now, the object returned (an extended Hashie object of type Deash) gives root
56
+ level access to the endpoint fields. This allows for:
57
+
58
+ Desk.cases(:per_page => 5).each do |theCase|
59
+ # Do something with theCase
60
+ end
61
+
62
+ theCase = Desk.case(12345)
63
+ # Do soemthing with theCase
64
+
65
+ For more information see the specific endpoint examples below.
66
+
67
+ Cases & Interaction endpoint examples
68
+ -------------------------------------
69
+
70
+ Previously cases and interactions were seperate endpoints. Additionally all
71
+ interactions were returned with no direct access to a specific interaction, the
72
+ original message or notes. Just to get, for example, the original interaction
73
+ for all cases assigned to a user your code likely looked something like this:
74
+
75
+ r = Desk.cases(:assigned_user => "joe")
76
+ r.results.each do |c|
77
+ in = Desk.interactions(:case_id => c.case.case_id)
78
+ in.results.each do |i|
79
+ if( i.interaction.basis == "original" )
80
+ i.interaction.interactionable.each do |interaction_type, interaction|
81
+ case interaction_type
82
+ when "email"
83
+ puts "Message: #{interaction.body}
84
+ when "tweet"
85
+ puts "Message: #{interaction.subject}"
86
+ when "chat"
87
+ puts "Message: #{interaction.messages.first.message.text}"
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+ Now, because of standardized fields and responses along with the _links
95
+ callbacks, the above can be simplified to:
96
+
97
+ Desk.cases(:assigned_user => "joe").each do |c|
98
+ puts "Message: #{c.message.body}"
99
+ end
100
+
101
+ For more information on accessing case messages, replies, notes, attachments and
102
+ history site the README and http://dev.desk.com/API/cases/
103
+
104
+ Customer endpoint examples
105
+ --------------------------
106
+
107
+ The redundancy for customers is gone as well. Email addresses, phone numbers and
108
+ addresses are no longer burried and are all accessible in a uniform way. So, with
109
+ API v1, what looked like:
110
+
111
+ customers = Desk.customers(:since_created_at => 1279139906)
112
+ customers.results.each do |customer|
113
+ puts "#{customer.customer.first_name} #{customer.customer.last_name}"
114
+ customer.customer.addresses.each do |address|
115
+ puts address.address.location
116
+ end
117
+ customer.customer.phones.each do |phone|
118
+ # seriously, this is correct, but it feels a bit excessive
119
+ puts phone.phone.phone
120
+ end
121
+ customer.customer.twitters.each do |twitter|
122
+ puts twitter.twitter.login
123
+ end
124
+ end
125
+
126
+ using the API v2 looks like:
127
+
128
+ Desk.customers(:since_created_at => 1279139906).each do |customer|
129
+ puts "#{customer.first_name} #{customer.last_name}"
130
+ customer.addresses.each { |address| puts address.value }
131
+ customer.phone_numbers.each { |phone| puts phone.value }
132
+ puts customer.twitter_user.handle
133
+ end
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.add_runtime_dependency('multi_json', '~> 1.6')
20
20
  s.add_runtime_dependency('multi_xml', '~> 0.5')
21
21
  s.add_runtime_dependency('rash', '~> 0.3.1')
22
- s.add_runtime_dependency('simple_oauth', '~> 0.1.4')
22
+ s.add_runtime_dependency('simple_oauth', '~> 0.2.0')
23
23
  s.add_runtime_dependency('pony', '~> 1.1')
24
24
  s.authors = ["Chris Warren"]
25
25
  s.description = %q{A Ruby wrapper for the Desk.com REST API}
@@ -11,7 +11,7 @@ module Desk
11
11
 
12
12
  class << self
13
13
  attr_accessor :counter, :minute
14
-
14
+
15
15
  # Alias for Desk::Client.new
16
16
  #
17
17
  # @return [Desk::Client]
@@ -18,7 +18,11 @@ module Desk
18
18
  end
19
19
 
20
20
  def endpoint
21
- "https://#{self.subdomain}.desk.com/api/#{self.version}/"
21
+ "https://#{self.subdomain}.desk.com"+api_path
22
+ end
23
+
24
+ def api_path
25
+ "/api/#{self.version}/"
22
26
  end
23
27
 
24
28
  include Connection
@@ -7,24 +7,198 @@ module Desk
7
7
  # Require client method modules after initializing the Client class in
8
8
  # order to avoid a superclass mismatch error, allowing those modules to be
9
9
  # Client-namespaced.
10
- require 'desk/client/user'
11
- require 'desk/client/group'
12
- require 'desk/client/interaction'
10
+ require 'desk/client/article'
11
+ require 'desk/client/brand'
13
12
  require 'desk/client/case'
13
+ require 'desk/client/company'
14
+ require 'desk/client/custom_field'
14
15
  require 'desk/client/customer'
15
- require 'desk/client/topic'
16
- require 'desk/client/article'
16
+ require 'desk/client/facebook_user'
17
+ require 'desk/client/filter'
18
+ require 'desk/client/group'
19
+ require 'desk/client/insight'
20
+ require 'desk/client/integration_url'
21
+ require 'desk/client/job'
22
+ require 'desk/client/label'
17
23
  require 'desk/client/macro'
24
+ require 'desk/client/mailbox'
25
+ require 'desk/client/rule'
26
+ require 'desk/client/site_setting'
27
+ require 'desk/client/system_message'
28
+ require 'desk/client/topic'
29
+ require 'desk/client/twitter_account'
30
+ require 'desk/client/twitter_user'
31
+ require 'desk/client/user'
18
32
 
19
33
  alias :api_endpoint :endpoint
20
34
 
21
- include Desk::Client::User
22
- include Desk::Client::Group
23
- include Desk::Client::Interaction
35
+ include Desk::Client::Article
36
+ include Desk::Client::Brand
24
37
  include Desk::Client::Case
38
+ include Desk::Client::Company
39
+ include Desk::Client::CustomField
25
40
  include Desk::Client::Customer
26
- include Desk::Client::Topic
27
- include Desk::Client::Article
41
+ include Desk::Client::FacebookUser
42
+ include Desk::Client::Filter
43
+ include Desk::Client::Group
44
+ include Desk::Client::Insight
45
+ include Desk::Client::IntegrationUrl
46
+ include Desk::Client::Job
47
+ include Desk::Client::Label
28
48
  include Desk::Client::Macro
49
+ include Desk::Client::Mailbox
50
+ include Desk::Client::Rule
51
+ include Desk::Client::SiteSetting
52
+ include Desk::Client::SystemMessage
53
+ include Desk::Client::Topic
54
+ include Desk::Client::TwitterAccount
55
+ include Desk::Client::TwitterUser
56
+ include Desk::Client::User
57
+
58
+
59
+ def initialize(options={})
60
+ if !self.respond_to? :endpoints_setup
61
+ self.class.included_modules.each do |m|
62
+ if r = m.name.match(/Desk::Client::([a-zA-z]+)/)
63
+ base = r[1].gsub(/(.)([A-Z])/, '\1_\2').downcase
64
+ if self.respond_to? "#{base}_endpoints"
65
+ endpoints_list = send("#{base}_endpoints")
66
+ setup_functions(base, endpoints_list)
67
+ end
68
+ end
69
+ end
70
+ self.class.send(:define_method, :endpoints_setup) {}
71
+ end
72
+ super(options)
73
+ end
74
+
75
+ def plural(singular)
76
+ if singular[-1, 1] == "y"
77
+ singular[0..-2]+"ies"
78
+ elsif singular[-1, 1] == "x"
79
+ singular+"es"
80
+ else
81
+ singular+"s"
82
+ end
83
+ end
84
+
85
+ def create_link(type, class_or_hash, id = nil, sub_class = nil, sub_id = nil)
86
+ if class_or_hash.class == Hashie::Deash
87
+ {type.to_sym => {
88
+ :class => class_or_hash._links.self['class'],
89
+ :href => class_or_hash._links.self['href']
90
+ }}
91
+ elsif class_or_hash.class == String
92
+ href = Desk.api_path+plural(class_or_hash)+"/#{id}"
93
+ href += "/"+plural(sub_class)+"/#{sub_id}" if sub_class != nil
94
+ {type.to_sym => { :class => class_or_hash, :href => href }}
95
+ else
96
+ nil
97
+ end
98
+ end
99
+
100
+ private
101
+
102
+ def setup_functions(base, endpoints_list)
103
+ endpoints_list.each do |endpoint|
104
+ eps = endpoint.to_s.split("_")
105
+ endpoint = eps[0]
106
+ bases = plural(base)
107
+ sub_ep = eps[1]
108
+ sub_eps = plural(sub_ep) if sub_ep
109
+
110
+ case endpoint
111
+ when "list"
112
+ if sub_ep
113
+ method_name = "list_#{base}_#{sub_ep}"
114
+ alias_names = ["#{base}_#{sub_ep}"]
115
+ block = lambda{ |id, *args|
116
+ options = args.last.is_a?(Hash) ? args.pop : {}
117
+ get("#{bases}/#{id}/#{sub_ep}", options)
118
+ }
119
+ else
120
+ method_name = "list_#{bases}"
121
+ alias_names = [bases]
122
+ block = lambda{ |*args|
123
+ options = args.last.is_a?(Hash) ? args.pop : {}
124
+ searchOptions = options.keys - [:page, :per_page]
125
+ if (!self.respond_to? "search_#{bases}") || searchOptions.empty?
126
+ get(bases, options)
127
+ else
128
+ send("search_#{bases}", options)
129
+ end
130
+ }
131
+ end
132
+ when "search"
133
+ method_name = "search_#{bases}"
134
+ alias_names = []
135
+ block = lambda{ |*args|
136
+ options = args.last.is_a?(Hash) ? args.pop : {}
137
+ get("#{bases}/search", options)
138
+ }
139
+ when "show"
140
+ if sub_ep
141
+ method_name = "show_#{base}_#{sub_ep}"
142
+ alias_names = ["#{base}_#{sub_ep}"]
143
+ block = lambda{ |id, sub_id|
144
+ get("#{bases}/#{id}/#{sub_eps}/#{sub_id}")
145
+ }
146
+ else
147
+ method_name = "show_#{base}"
148
+ alias_names = [base]
149
+ block = lambda{ |id| get("#{bases}/#{id}") }
150
+ end
151
+ when "create"
152
+ if sub_ep
153
+ method_name = "create_#{base}_#{sub_ep}"
154
+ alias_names = []
155
+ block = lambda{ |id, *args|
156
+ options = args.last.is_a?(Hash) ? args.pop : {}
157
+ post("#{bases}/#{id}/#{sub_eps}", options)
158
+ }
159
+ else
160
+ method_name = "create_#{base}"
161
+ alias_names = []
162
+ block = lambda{ |*args|
163
+ options = args.last.is_a?(Hash) ? args.pop : {}
164
+ post("#{bases}", options)
165
+ }
166
+ end
167
+ when "update"
168
+ if sub_ep
169
+ method_name = "update_#{base}_#{sub_ep}"
170
+ alias_names = []
171
+ block = lambda{ |id, sub_id, *args|
172
+ options = args.last.is_a?(Hash) ? args.pop : {}
173
+ patch("#{bases}/#{id}/#{sub_eps}/#{sub_id}", options)
174
+ }
175
+ else
176
+ method_name = "update_#{base}"
177
+ alias_names = []
178
+ block = lambda{ |id, *args|
179
+ options = args.last.is_a?(Hash) ? args.pop : {}
180
+ patch("#{bases}/#{id}", options)
181
+ }
182
+ end
183
+ when "delete"
184
+ if sub_ep
185
+ method_name = "delete_#{base}_#{sub_ep}"
186
+ alias_names = []
187
+ block = lambda{ |id, sub_id|
188
+ delete("#{bases}/#{id}/#{sub_eps}/#{sub_id}")
189
+ }
190
+ else
191
+ method_name = "delete_#{base}"
192
+ alias_names = []
193
+ block = lambda{ |id| delete("#{bases}/#{id}") }
194
+ end
195
+ end
196
+ self.class.send(:define_method, method_name, block)
197
+ alias_names.each do |alias_name|
198
+ self.class.send(:alias_method, alias_name, method_name)
199
+ end
200
+ end
201
+ end
202
+
29
203
  end
30
204
  end
@@ -1,92 +1,13 @@
1
1
  module Desk
2
2
  class Client
3
- # Defines methods related to articles
4
3
  module Article
5
- # Returns extended information of articles for a topic
6
- #
7
- # @param id [Integer] a article ID
8
- # @option options [Boolean, String, Integer]
9
- # @example Return extended information for 12345
10
- # Desk.articles
11
- # Desk.articles(:count => 5)
12
- # Desk.articles(:count => 5, :page => 3)
13
- # @format :json
14
- # @authenticated true
15
- # @see http://dev.desk.com/docs/api/topics/articles
16
- def articles(id, *args)
17
- options = args.last.is_a?(Hash) ? args.pop : {}
18
- response = get("topics/#{id}/articles",options)
19
- response
20
- end
21
-
22
- # Returns extended information on a single article
23
- #
24
- # @param id [Integer] a article ID
25
- # @option options [Hash]
26
- # @example Return extended information for 12345
27
- # Desk.article(12345)
28
- # Desk.article(12345, :by => "external_id")
29
- # @format :json
30
- # @authenticated true
31
- # @see http://dev.desk.com/docs/api/articles/show
32
- def article(id, *args)
33
- options = args.last.is_a?(Hash) ? args.pop : {}
34
- response = get("articles/#{id}",options)
35
- response.article
36
- end
37
4
 
38
- # Creates a new article
39
- #
40
- # @param id [Integer] a article ID
41
- # @param id [Integer] a article ID
42
- # @param id [Integer] a article ID
43
- # @option options [Hash]
44
- # @example Creates a new article
45
- # Desk.create_article(1, :subject => "API Tips", :main_content => "Tips on using our API")
46
- # @format :json
47
- # @authenticated true
48
- # @see http://dev.desk.com/docs/api/articles/create
49
- def create_article(topic_id, *args)
50
- options = args.last.is_a?(Hash) ? args.pop : {}
51
- response = post("topics/#{topic_id}/articles",options)
52
- if response['success']
53
- return response['results']['article']
54
- else
55
- return response
56
- end
5
+ def article_endpoints
6
+ [ :list, :show, :create, :update, :delete, :search,
7
+ :list_translations, :show_translation, :create_translation,
8
+ :update_translation, :delete_translation ]
57
9
  end
58
10
 
59
- # Updates a single article
60
- #
61
- # @param id [Integer] a article ID
62
- # @option options [String]
63
- # @example Updates information for article 12345
64
- # Desk.update_article(12345, :subject => "New Subject")
65
- # @format :json
66
- # @authenticated true
67
- # @see http://dev.desk.com/docs/api/articles/update
68
- def update_article(id, *args)
69
- options = args.last.is_a?(Hash) ? args.pop : {}
70
- response = put("articles/#{id}",options)
71
- if response['success']
72
- return response['results']['article']
73
- else
74
- return response
75
- end
76
- end
77
-
78
- # Deletes a single article
79
- #
80
- # @param id [Integer] a article ID
81
- # @example Deletes article 12345
82
- # Desk.update_article(12345, :subject => "New Subject")
83
- # @format :json
84
- # @authenticated true
85
- # @see http://dev.desk.com/docs/api/articles/update
86
- def delete_article(id)
87
- response = delete("articles/#{id}")
88
- response
89
- end
90
11
  end
91
12
  end
92
13
  end