| 1 |
|
| package WebService::Desk; |
| 2 |
|
| |
| 3 |
|
| use 5.010; |
| 4 |
|
| use Mouse; |
| 5 |
|
| |
| 6 |
|
| # ABSTRACT: WebService::Desk - an interface to desk.com's RESTful Web API using Web::API |
| 7 |
|
| |
| 8 |
|
| our $VERSION = '0.6'; # VERSION |
| 9 |
|
| |
| 10 |
|
| with 'Web::API'; |
| 11 |
|
| |
| 12 |
|
| |
| 13 |
|
| has 'commands' => ( |
| 14 |
|
| is => 'rw', |
| 15 |
|
| default => sub { |
| 16 |
|
| { |
| 17 |
|
| # articles |
| 18 |
|
| articles => {}, |
| 19 |
|
| article => { path => 'articles/:id' }, |
| 20 |
|
| create_article => { path => 'articles', method => 'POST' }, |
| 21 |
|
| update_article => { |
| 22 |
|
| path => 'articles/:id', |
| 23 |
|
| method => 'POST', |
| 24 |
|
| headers => { 'X-HTTP-Method-Override' => 'PATCH' }, |
| 25 |
|
| }, |
| 26 |
|
| delete_article => { path => 'articles/:id', method => 'DELETE' }, |
| 27 |
|
| search_article => { |
| 28 |
|
| path => 'articles/search', |
| 29 |
|
| mandatory => ['text'], |
| 30 |
|
| optional => ['topic_ids'] |
| 31 |
|
| }, |
| 32 |
|
| article_translations => { path => 'articles/:id/translations' }, |
| 33 |
|
| article_translation => |
| 34 |
|
| { path => 'articles/:id/translations/:locale' }, |
| 35 |
|
| create_article_translation => { |
| 36 |
|
| path => 'articles/:id/translations', |
| 37 |
|
| method => 'POST', |
| 38 |
|
| mandatory => [ 'locale', 'subject' ] |
| 39 |
|
| }, |
| 40 |
|
| update_article_translation => { |
| 41 |
|
| path => 'articles/:id/translations/:locale', |
| 42 |
|
| method => 'POST', |
| 43 |
|
| headers => { 'X-HTTP-Method-Override' => 'PATCH' }, |
| 44 |
|
| }, |
| 45 |
|
| |
| 46 |
|
| # cases |
| 47 |
|
| cases => {}, |
| 48 |
|
| case => { path => 'cases/:id' }, |
| 49 |
|
| search_case => { path => 'cases/search' }, |
| 50 |
|
| create_case => |
| 51 |
|
| { path => 'cases', method => 'POST', mandatory => ['message'] }, |
| 52 |
|
| update_case => { |
| 53 |
|
| path => 'cases/:id', |
| 54 |
|
| method => 'POST', |
| 55 |
|
| headers => { 'X-HTTP-Method-Override' => 'PATCH' }, |
| 56 |
|
| }, |
| 57 |
|
| history => { path => 'cases/:id/history' }, |
| 58 |
|
| message => { path => 'cases/:id/message' }, |
| 59 |
|
| replies => { path => 'cases/:id/replies' }, |
| 60 |
|
| reply => { path => 'cases/:case_id/replies/:id' }, |
| 61 |
|
| create_reply => { |
| 62 |
|
| path => 'cases/:case_id/replies', |
| 63 |
|
| method => 'POST', |
| 64 |
|
| mandatory => ['body'], |
| 65 |
|
| }, |
| 66 |
|
| update_reply => { |
| 67 |
|
| path => 'cases/:case_id/replies/:id', |
| 68 |
|
| method => 'POST', |
| 69 |
|
| headers => { 'X-HTTP-Method-Override' => 'PATCH' }, |
| 70 |
|
| }, |
| 71 |
|
| notes => { path => 'cases/:case_id/notes' }, |
| 72 |
|
| note => { path => 'cases/:case_id/notes/:id' }, |
| 73 |
|
| create_note => { |
| 74 |
|
| path => 'cases/:case_id/notes', |
| 75 |
|
| method => 'POST', |
| 76 |
|
| mandatory => ['body'], |
| 77 |
|
| }, |
| 78 |
|
| attachments => { path => 'cases/:case_id/attachments' }, |
| 79 |
|
| message_attachments => |
| 80 |
|
| { path => 'cases/:case_id/message/attachments' }, |
| 81 |
|
| reply_attachments => |
| 82 |
|
| { path => 'cases/:case_id/replies/:id/attachments' }, |
| 83 |
|
| attachment => { path => 'cases/:case_id/attachments/:id' }, |
| 84 |
|
| message_attachment => |
| 85 |
|
| { path => 'cases/:case_id/message/attachments/:id' }, |
| 86 |
|
| reply_attachment => |
| 87 |
|
| { path => 'cases/:case_id/replies/:reply_id/attachments/:id' }, |
| 88 |
|
| create_attachment => |
| 89 |
|
| { path => 'cases/:case_id/attachments', method => 'POST' }, |
| 90 |
|
| create_message_attachment => { |
| 91 |
|
| path => 'cases/:case_id/message/attachments', |
| 92 |
|
| method => 'POST', |
| 93 |
|
| }, |
| 94 |
|
| create_reply_attachment => { |
| 95 |
|
| path => 'cases/:case_id/replies/:reply_id/attachments', |
| 96 |
|
| method => 'POST', |
| 97 |
|
| }, |
| 98 |
|
| delete_attachment => { |
| 99 |
|
| path => 'cases/:case_id/attachments/:id', |
| 100 |
|
| method => 'DELETE', |
| 101 |
|
| }, |
| 102 |
|
| delete_message_attachment => { |
| 103 |
|
| path => 'cases/:case_id/message/attachments/:id', |
| 104 |
|
| method => 'DELETE', |
| 105 |
|
| }, |
| 106 |
|
| delete_reply_attachment => { |
| 107 |
|
| path => 'cases/:case_id/replies/:reply_id/attachments/:id', |
| 108 |
|
| method => 'DELETE', |
| 109 |
|
| }, |
| 110 |
|
| |
| 111 |
|
| # companies |
| 112 |
|
| companies => {}, |
| 113 |
|
| company => { path => 'companies/:id' }, |
| 114 |
|
| create_company => { |
| 115 |
|
| path => 'companies', |
| 116 |
|
| method => 'POST', |
| 117 |
|
| mandatory => ['name'] |
| 118 |
|
| }, |
| 119 |
|
| update_company => { |
| 120 |
|
| path => 'companies/:id', |
| 121 |
|
| method => 'POST', |
| 122 |
|
| headers => { 'X-HTTP-Method-Override' => 'PATCH' }, |
| 123 |
|
| }, |
| 124 |
|
| |
| 125 |
|
| # custom fields |
| 126 |
|
| custom_fields => {}, |
| 127 |
|
| custom_field => { path => 'custom_fields/:id' }, |
| 128 |
|
| |
| 129 |
|
| # customers |
| 130 |
|
| customers => {}, |
| 131 |
|
| customer => { path => 'customers/:id' }, |
| 132 |
|
| search_customer => { path => 'customers/search' }, |
| 133 |
|
| create_customer => { path => 'customers', method => 'POST' }, |
| 134 |
|
| update_customer => { |
| 135 |
|
| path => 'customers/:id', |
| 136 |
|
| method => 'POST', |
| 137 |
|
| headers => { 'X-HTTP-Method-Override' => 'PATCH' }, |
| 138 |
|
| }, |
| 139 |
|
| |
| 140 |
|
| # filters |
| 141 |
|
| filters => {}, |
| 142 |
|
| filter => { path => 'filters/:id' }, |
| 143 |
|
| filter_cases => { path => 'filters/:id/cases' }, |
| 144 |
|
| |
| 145 |
|
| # groups |
| 146 |
|
| groups => {}, |
| 147 |
|
| group => { path => 'groups/:id' }, |
| 148 |
|
| group_filters => { path => 'groups/:id/filters' }, |
| 149 |
|
| group_users => { path => 'groups/:id/users' }, |
| 150 |
|
| |
| 151 |
|
| # inbound mailboxes |
| 152 |
|
| mailboxes => { path => 'mailboxes/inbound' }, |
| 153 |
|
| mailbox => { path => 'mailboxes/inbound/:id' }, |
| 154 |
|
| |
| 155 |
|
| # insights |
| 156 |
|
| insight_meta => { path => 'insights/meta' }, |
| 157 |
|
| create_report => { path => 'insights/report', method => 'POST' }, |
| 158 |
|
| |
| 159 |
|
| # integration URLS |
| 160 |
|
| integration_urls => {}, |
| 161 |
|
| integration_url => { path => 'integration_urls/:id' }, |
| 162 |
|
| create_integration_url => |
| 163 |
|
| { path => 'integration_urls', method => 'POST' }, |
| 164 |
|
| update_integration_url => { |
| 165 |
|
| path => 'integration_urls/:id', |
| 166 |
|
| method => 'POST', |
| 167 |
|
| headers => { 'X-HTTP-Method-Override' => 'PATCH' }, |
| 168 |
|
| }, |
| 169 |
|
| delete_integration_url => |
| 170 |
|
| { path => 'integration_urls/:id', method => 'DELETE' }, |
| 171 |
|
| |
| 172 |
|
| # jobs |
| 173 |
|
| jobs => {}, |
| 174 |
|
| job => { path => 'jobs/:id' }, |
| 175 |
|
| create_job => { path => 'jobs', method => 'POST' }, |
| 176 |
|
| |
| 177 |
|
| # labels |
| 178 |
|
| labels => {}, |
| 179 |
|
| label => { path => 'labels/:id' }, |
| 180 |
|
| create_label => |
| 181 |
|
| { path => 'labels', method => 'POST', mandatory => ['name'] }, |
| 182 |
|
| update_label => { path => 'labels/:id' }, |
| 183 |
|
| delete_label => { |
| 184 |
|
| path => 'labels/:id', |
| 185 |
|
| method => 'POST', |
| 186 |
|
| headers => { 'X-HTTP-Method-Override' => 'PATCH' }, |
| 187 |
|
| }, |
| 188 |
|
| |
| 189 |
|
| # macros |
| 190 |
|
| macros => {}, |
| 191 |
|
| macro => { path => 'macros/:id' }, |
| 192 |
|
| create_macro => { path => 'macros', method => 'POST' }, |
| 193 |
|
| update_macro => { |
| 194 |
|
| path => 'macros/:id', |
| 195 |
|
| method => 'POST', |
| 196 |
|
| headers => { 'X-HTTP-Method-Override' => 'PATCH' }, |
| 197 |
|
| }, |
| 198 |
|
| delete_macro => { path => 'macros/:id', method => 'DELETE' }, |
| 199 |
|
| actions => { path => 'macros/:macro_id/actions' }, |
| 200 |
|
| action => { path => 'macros/:macro_id/actions/:id' }, |
| 201 |
|
| update_action => { |
| 202 |
|
| path => 'macros/:macro_id/actions/:id', |
| 203 |
|
| method => 'POST', |
| 204 |
|
| headers => { 'X-HTTP-Method-Override' => 'PATCH' }, |
| 205 |
|
| }, |
| 206 |
|
| |
| 207 |
|
| # rules |
| 208 |
|
| rules => {}, |
| 209 |
|
| rule => { path => 'rules/:id' }, |
| 210 |
|
| |
| 211 |
|
| # site settings |
| 212 |
|
| site_settings => {}, |
| 213 |
|
| site_setting => { path => 'site_settings/:id' }, |
| 214 |
|
| |
| 215 |
|
| # system message |
| 216 |
|
| system_message => {}, |
| 217 |
|
| |
| 218 |
|
| # topics |
| 219 |
|
| topics => {}, |
| 220 |
|
| topic => { path => 'topics/:id' }, |
| 221 |
|
| create_topic => |
| 222 |
|
| { path => 'topics', method => 'POST', mandatory => ['name'] }, |
| 223 |
|
| update_topic => { |
| 224 |
|
| path => 'topics/:id', |
| 225 |
|
| method => 'POST', |
| 226 |
|
| headers => { 'X-HTTP-Method-Override' => 'PATCH' }, |
| 227 |
|
| }, |
| 228 |
|
| delete_topic => { path => 'topics/:id', method => 'DELETE' }, |
| 229 |
|
| topic_translations => { path => 'topics/:id/translations' }, |
| 230 |
|
| topic_translation => { path => 'topics/:id/translations/:locale' }, |
| 231 |
|
| create_topic_translation => { |
| 232 |
|
| path => 'topics/:id/translations', |
| 233 |
|
| method => 'POST', |
| 234 |
|
| mandatory => ['locale'] |
| 235 |
|
| }, |
| 236 |
|
| update_topic_translation => { |
| 237 |
|
| path => 'topics/:id/translations/:locale', |
| 238 |
|
| method => 'POST', |
| 239 |
|
| headers => { 'X-HTTP-Method-Override' => 'PATCH' }, |
| 240 |
|
| }, |
| 241 |
|
| delete_topic_translation => { |
| 242 |
|
| path => 'topics/:id/translations/:locale', |
| 243 |
|
| method => 'DELETE' |
| 244 |
|
| }, |
| 245 |
|
| |
| 246 |
|
| # twitter |
| 247 |
|
| twitter_accounts => {}, |
| 248 |
|
| twitter_account => { path => 'twitter_accounts/:id' }, |
| 249 |
|
| tweets => { path => 'twitter_accounts/:id/tweets' }, |
| 250 |
|
| tweet => { path => 'twitter_accounts/:account_id/tweets/:id' }, |
| 251 |
|
| create_tweet => { |
| 252 |
|
| path => 'twitter_accounts/:id/tweets', |
| 253 |
|
| method => 'POST', |
| 254 |
|
| mandatory => ['body'] |
| 255 |
|
| }, |
| 256 |
|
| |
| 257 |
|
| # users |
| 258 |
|
| users => {}, |
| 259 |
|
| user => { path => 'users/:id' }, |
| 260 |
|
| user_preferences => { path => 'users/:id/preferences' }, |
| 261 |
|
| user_preference => { path => 'users/:user_id/preferences/:id' }, |
| 262 |
|
| update_user_preference => { |
| 263 |
|
| path => 'users/:user_id/preferences/:id', |
| 264 |
|
| method => 'POST', |
| 265 |
|
| headers => { 'X-HTTP-Method-Override' => 'PATCH' }, |
| 266 |
|
| }, |
| 267 |
|
| }; |
| 268 |
|
| }, |
| 269 |
|
| ); |
| 270 |
|
| |
| 271 |
|
| |
| 272 |
|
| sub commands { |
| 273 |
|
| my ($self) = @_; |
| 274 |
|
| return $self->commands; |
| 275 |
|
| } |
| 276 |
|
| |
| 277 |
|
| |
| 278 |
|
| sub BUILD { |
| 279 |
|
| my ($self) = @_; |
| 280 |
|
| |
| 281 |
|
| $self->user_agent(__PACKAGE__ . ' ' . $WebService::Desk::VERSION); |
| 282 |
|
| $self->content_type('application/json'); |
| 283 |
|
| $self->base_url('https://' . $self->user . '.desk.com/api/v2'); |
| 284 |
|
| $self->auth_type('oauth_header'); |
| 285 |
|
| $self->oauth_post_body(0); |
| 286 |
|
| $self->error_keys(['message']); |
| 287 |
|
| |
| 288 |
|
| return $self; |
| 289 |
|
| } |
| 290 |
|
| |
| 291 |
|
| |
| 292 |
|
| 1; # End of WebService::Desk |
| 293 |
|
| |
| 294 |
|
| __END__ |