zendesk_api 0.3.14 → 0.4.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. data/.yardopts +6 -2
  2. data/Gemfile +3 -2
  3. data/Gemfile.lock +4 -4
  4. data/Readme.md +3 -268
  5. data/lib/zendesk_api/actions.rb +51 -46
  6. data/lib/zendesk_api/association.rb +1 -1
  7. data/lib/zendesk_api/associations.rb +2 -6
  8. data/lib/zendesk_api/client.rb +8 -9
  9. data/lib/zendesk_api/collection.rb +84 -50
  10. data/lib/zendesk_api/configuration.rb +4 -0
  11. data/lib/zendesk_api/error.rb +22 -0
  12. data/lib/zendesk_api/middleware/request/etag_cache.rb +1 -7
  13. data/lib/zendesk_api/middleware/request/upload.rb +1 -2
  14. data/lib/zendesk_api/middleware/response/raise_error.rb +20 -0
  15. data/lib/zendesk_api/resource.rb +33 -5
  16. data/lib/zendesk_api/resources.rb +36 -11
  17. data/lib/zendesk_api/server/base.rb +1 -1
  18. data/lib/zendesk_api/server/helper.rb +3 -3
  19. data/lib/zendesk_api/server/models/zlib_json.rb +1 -1
  20. data/lib/zendesk_api/server/public/doc/ZendeskAPI.html +7 -7
  21. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Ability.html +415 -13
  22. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Activity.html +414 -51
  23. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Attachment.html +321 -25
  24. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Automation.html +413 -46
  25. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Bookmark.html +389 -26
  26. data/lib/zendesk_api/server/public/doc/ZendeskAPI/CRMData.html +415 -13
  27. data/lib/zendesk_api/server/public/doc/ZendeskAPI/CRMDataStatus.html +415 -13
  28. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Category.html +410 -47
  29. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Client.html +98 -362
  30. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Collection.html +457 -676
  31. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Configuration.html +110 -20
  32. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Create.html +264 -6
  33. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Create/ClassMethods.html +43 -82
  34. data/lib/zendesk_api/server/public/doc/ZendeskAPI/CreateResource.html +671 -15
  35. data/lib/zendesk_api/server/public/doc/ZendeskAPI/CustomRole.html +415 -13
  36. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Data.html +207 -233
  37. data/lib/zendesk_api/server/public/doc/ZendeskAPI/DataResource.html +499 -24
  38. data/lib/zendesk_api/server/public/doc/ZendeskAPI/DeleteResource.html +614 -15
  39. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Destroy.html +73 -23
  40. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Destroy/ClassMethod.html +68 -18
  41. data/lib/zendesk_api/server/public/doc/ZendeskAPI/{FormatError.html → Error.html} +19 -27
  42. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Error/ClientError.html +127 -0
  43. data/lib/zendesk_api/server/public/doc/ZendeskAPI/{Server/UserRequest.html → Error/NetworkError.html} +18 -16
  44. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Error/RecordInvalid.html +371 -0
  45. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Error/RecordNotFound.html +127 -0
  46. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Forum.html +426 -63
  47. data/lib/zendesk_api/server/public/doc/ZendeskAPI/ForumSubscription.html +414 -51
  48. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Group.html +389 -26
  49. data/lib/zendesk_api/server/public/doc/ZendeskAPI/GroupMembership.html +414 -51
  50. data/lib/zendesk_api/server/public/doc/ZendeskAPI/JobStatus.html +405 -16
  51. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Locale.html +405 -16
  52. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Macro.html +413 -46
  53. data/lib/zendesk_api/server/public/doc/ZendeskAPI/MobileDevice.html +404 -41
  54. data/lib/zendesk_api/server/public/doc/ZendeskAPI/OAuthClient.html +606 -0
  55. data/lib/zendesk_api/server/public/doc/ZendeskAPI/OAuthToken.html +810 -0
  56. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Organization.html +422 -59
  57. data/lib/zendesk_api/server/public/doc/ZendeskAPI/OrganizationField.html +606 -0
  58. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Read.html +75 -12
  59. data/lib/zendesk_api/server/public/doc/ZendeskAPI/ReadResource.html +593 -16
  60. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Request.html +418 -55
  61. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Request/Comment.html +420 -31
  62. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Resource.html +1025 -20
  63. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Role.html +415 -13
  64. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Rule.html +610 -0
  65. data/lib/zendesk_api/server/public/doc/ZendeskAPI/RuleExecution.html +317 -21
  66. data/lib/zendesk_api/server/public/doc/ZendeskAPI/SatisfactionRating.html +428 -39
  67. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Save.html +63 -79
  68. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Search.html +34 -26
  69. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Search/Result.html +305 -9
  70. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Setting.html +433 -41
  71. data/lib/zendesk_api/server/public/doc/ZendeskAPI/SharingAgreement.html +405 -16
  72. data/lib/zendesk_api/server/public/doc/ZendeskAPI/SingularResource.html +389 -26
  73. data/lib/zendesk_api/server/public/doc/ZendeskAPI/SuspendedTicket.html +600 -31
  74. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Ticket.html +464 -101
  75. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Ticket/Audit.html +427 -25
  76. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Ticket/Comment.html +435 -32
  77. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Ticket/Tag.html +389 -26
  78. data/lib/zendesk_api/server/public/doc/ZendeskAPI/TicketField.html +389 -26
  79. data/lib/zendesk_api/server/public/doc/ZendeskAPI/TicketMetric.html +592 -15
  80. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Topic.html +427 -64
  81. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Topic/TopicComment.html +907 -17
  82. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Topic/TopicVote.html +414 -55
  83. data/lib/zendesk_api/server/public/doc/ZendeskAPI/TopicComment.html +325 -29
  84. data/lib/zendesk_api/server/public/doc/ZendeskAPI/TopicSubscription.html +414 -51
  85. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Trigger.html +413 -46
  86. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Update.html +258 -6
  87. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Update/ClassMethod.html +62 -12
  88. data/lib/zendesk_api/server/public/doc/ZendeskAPI/UpdateResource.html +671 -15
  89. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Upload.html +800 -28
  90. data/lib/zendesk_api/server/public/doc/ZendeskAPI/User.html +505 -142
  91. data/lib/zendesk_api/server/public/doc/ZendeskAPI/User/Identity.html +412 -49
  92. data/lib/zendesk_api/server/public/doc/ZendeskAPI/User/TopicComment.html +475 -13
  93. data/lib/zendesk_api/server/public/doc/ZendeskAPI/UserField.html +606 -0
  94. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Verbs.html +9 -15
  95. data/lib/zendesk_api/server/public/doc/ZendeskAPI/View.html +433 -66
  96. data/lib/zendesk_api/server/public/doc/ZendeskAPI/ViewCount.html +415 -13
  97. data/lib/zendesk_api/server/public/doc/ZendeskAPI/ViewRow.html +451 -49
  98. data/lib/zendesk_api/server/public/doc/_index.html +72 -72
  99. data/lib/zendesk_api/server/public/doc/class_list.html +1 -1
  100. data/lib/zendesk_api/server/public/doc/css/style.css +10 -0
  101. data/lib/zendesk_api/server/public/doc/file.Readme.html +20 -260
  102. data/lib/zendesk_api/server/public/doc/file_list.html +1 -1
  103. data/lib/zendesk_api/server/public/doc/frames.html +1 -1
  104. data/lib/zendesk_api/server/public/doc/index.html +20 -260
  105. data/lib/zendesk_api/server/public/doc/method_list.html +309 -517
  106. data/lib/zendesk_api/server/public/doc/top-level-namespace.html +3 -35
  107. data/lib/zendesk_api/verbs.rb +0 -4
  108. data/lib/zendesk_api/version.rb +1 -1
  109. data/spec/core/client_spec.rb +53 -13
  110. data/spec/core/collection_spec.rb +32 -4
  111. data/spec/core/create_resource_spec.rb +1 -1
  112. data/spec/core/data_resource_spec.rb +2 -2
  113. data/spec/core/middleware/request/etag_cache_spec.rb +6 -7
  114. data/spec/core/middleware/request/upload_spec.rb +2 -10
  115. data/spec/core/middleware/response/callback_spec.rb +1 -1
  116. data/spec/core/middleware/response/raise_error_spec.rb +40 -0
  117. data/spec/core/read_resource_spec.rb +0 -2
  118. data/spec/core/resource_spec.rb +13 -5
  119. data/spec/core/search_spec.rb +1 -1
  120. data/spec/core/spec_helper.rb +3 -3
  121. data/spec/live/automation_spec.rb +23 -0
  122. data/spec/live/organization_field_spec.rb +12 -0
  123. data/spec/live/ticket_spec.rb +8 -2
  124. data/spec/live/trigger_spec.rb +23 -0
  125. data/spec/live/user_field_spec.rb +12 -0
  126. data/spec/live/user_spec.rb +0 -2
  127. data/spec/live/view_spec.rb +17 -1
  128. data/spec/server/spec_helper.rb +2 -2
  129. data/zendesk_api.gemspec +1 -1
  130. metadata +88 -51
  131. checksums.yaml +0 -7
  132. data/lib/zendesk_api/rescue.rb +0 -63
  133. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Console.html +0 -860
  134. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Console/Eval.html +0 -190
  135. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Server.html +0 -131
  136. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Server/App.html +0 -523
  137. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Server/Helper.html +0 -684
  138. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Server/HtmlRenderer.html +0 -303
  139. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Server/HtmlRenderer/RedcarpetRenderer.html +0 -508
  140. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Server/ZlibJSON.html +0 -244
  141. data/spec/core/rescue_spec.rb +0 -151
data/.yardopts CHANGED
@@ -1,8 +1,12 @@
1
1
  --tag internal
2
2
  --hide-tag internal
3
3
  --no-private
4
- --protected lib/**/*.rb
4
+ --protected
5
+ --embed-mixins
5
6
  --load ./util/resource_handler.rb
6
7
  --load ./util/verb_handler.rb
8
+ --exclude lib/zendesk_api/console
9
+ --exclude lib/zendesk_api/server
10
+ -r Readme.md
11
+ lib/**/*.rb
7
12
  -
8
- Readme.md
data/Gemfile CHANGED
@@ -3,10 +3,9 @@ source 'https://rubygems.org'
3
3
  # gem "bundler", "~> 1.2.0"
4
4
  # ruby "1.9.3"
5
5
 
6
- gem "simplecov", :platforms => :ruby_19, :group => :development
6
+ gem "simplecov", :platforms => :ruby_19, :group => :test
7
7
  gem "jruby-openssl", :platforms => :jruby
8
8
  gem "multipart-post", :git => "https://github.com/steved555/multipart-post.git"
9
- gem "multi_json", :group => :test
10
9
 
11
10
  group :server do
12
11
  gem "thin"
@@ -36,4 +35,6 @@ group :console do
36
35
  gem "ripl"
37
36
  end
38
37
 
38
+ gem "json", :group => :test, :platform => :ruby_18
39
+
39
40
  gemspec
data/Gemfile.lock CHANGED
@@ -7,13 +7,13 @@ GIT
7
7
  PATH
8
8
  remote: .
9
9
  specs:
10
- zendesk_api (0.3.14)
10
+ zendesk_api (0.4.0.rc1)
11
11
  faraday (>= 0.8.0)
12
12
  faraday_middleware (>= 0.8.7)
13
13
  hashie (>= 1.2)
14
14
  inflection
15
- json
16
15
  mime-types
16
+ multi_json
17
17
  multipart-post
18
18
 
19
19
  GEM
@@ -55,7 +55,7 @@ GEM
55
55
  fssm (0.2.10)
56
56
  haml (4.0.1)
57
57
  tilt
58
- hashie (2.0.5)
58
+ hashie (2.0.4)
59
59
  i18n (0.6.1)
60
60
  inflection (1.0.0)
61
61
  jruby-openssl (0.8.7)
@@ -130,8 +130,8 @@ DEPENDENCIES
130
130
  database_cleaner
131
131
  haml
132
132
  jruby-openssl
133
+ json
133
134
  mongoid
134
- multi_json
135
135
  multipart-post!
136
136
  newrelic_rpm
137
137
  rack-ssl-enforcer
data/Readme.md CHANGED
@@ -4,11 +4,11 @@
4
4
 
5
5
  This client **only** supports Zendesk's v2 API. Please see our [API documentation](http://developer.zendesk.com) for more information.
6
6
 
7
- ## Additional Documentation
7
+ ## Documentation
8
8
 
9
- Additional documentation can be found on our [documentation site](https://zendesk-api.herokuapp.com/doc/index.html) and [wiki](https://github.com/zendesk/zendesk_api_client_rb/wiki).
9
+ Please check out the [wiki](https://github.com/zendesk/zendesk_api_client_rb/wiki), [class documentation](https://zendesk-api.herokuapp.com/doc/index.html), and [issues](https://github.com/zendesk/zendesk_api_client_rb/issues) before reporting a bug or asking for help.
10
10
 
11
- ## Important Notice
11
+ ## Important Notices
12
12
 
13
13
  * Version 0.0.5 brings with it a change to the top-level namespace. All references to Zendesk should now use ZendeskAPI.
14
14
  * Version 0.3.0 changed the license from MIT to Apache Version 2.
@@ -32,271 +32,6 @@ Add it to your Gemfile
32
32
 
33
33
  and follow normal [Bundler](http://gembundler.com/) installation and execution procedures.
34
34
 
35
- ## Configuration
36
-
37
- Configuration is done through a block returning an instance of ZendeskAPI::Client.
38
- The block is mandatory and if not passed, an ArgumentError will be thrown.
39
-
40
- ```ruby
41
- require 'zendesk_api'
42
-
43
- client = ZendeskAPI::Client.new do |config|
44
- # Mandatory:
45
-
46
- config.url = "<- your-zendesk-url ->" # e.g. https://mydesk.zendesk.com/api/v2
47
-
48
- config.username = "login.email@zendesk.com"
49
-
50
- # Choose one of the following depending on your authentication choice
51
- config.token = "your zendesk token"
52
- config.password = "your zendesk password"
53
-
54
- # Optional:
55
-
56
- # Retry uses middleware to notify the user
57
- # when hitting the rate limit, sleep automatically,
58
- # then retry the request.
59
- config.retry = true
60
-
61
- # Logger prints to STDERR by default, to e.g. print to stdout:
62
- require 'logger'
63
- config.logger = Logger.new(STDOUT)
64
-
65
- # Changes Faraday adapter
66
- # config.adapter = :patron
67
-
68
- # Merged with the default client options hash
69
- # config.client_options = { :ssl => false }
70
-
71
- # When getting the error 'hostname does not match the server certificate'
72
- # use the API at https://yoursubdomain.zendesk.com/api/v2
73
- end
74
- ```
75
-
76
- Note: This ZendeskAPI API client only supports basic authentication at the moment.
77
-
78
- ## Usage
79
-
80
- The result of configuration is an instance of ZendeskAPI::Client which can then be used in two different methods.
81
-
82
- One way to use the client is to pass it in as an argument to individual classes.
83
-
84
- ```ruby
85
- ZendeskAPI::Ticket.new(client, :id => 1, :priority => "urgent") # doesn't actually send a request, must explicitly call #save
86
- ZendeskAPI::Ticket.create(client, :subject => "Test Ticket", :comment => { :value => "This is a test" }, :submitter_id => client.current_user.id, :priority => "urgent")
87
- ZendeskAPI::Ticket.find(client, :id => 1)
88
- ZendeskAPI::Ticket.delete(client, :id => 1)
89
- ```
90
-
91
- Another way is to use the instance methods under client.
92
-
93
- ```ruby
94
- client.tickets.first
95
- client.tickets.find(:id => 1)
96
- client.tickets.create(:subject => "Test Ticket", :comment => { :value => "This is a test" }, :submitter_id => client.current_user.id, :priority => "urgent")
97
- client.tickets.delete(:id => 1)
98
- ```
99
-
100
- The methods under ZendeskAPI::Client (such as .tickets) return an instance of ZendeskAPI::Collection a lazy-loaded list of that resource.
101
- Actual requests may not be sent until an explicit ZendeskAPI::Collection#fetch, ZendeskAPI::Collection#to_a, or an applicable methods such
102
- as #each.
103
-
104
- ### Caveats
105
-
106
- Resource updating is implemented by sending only the `changed?` attributes to the server (see `ZendeskAPI::TrackChanges`).
107
- Unfortunately, this module only hooks into `Hash` meaning any changes to an `Array`not resulting in a new instance will not be tracked and sent.
108
-
109
- ```
110
- zendesk_api_client_rb $ bundle console
111
- > a = ZendeskAPI::Trackie.new(:tags => []).tap(&:clear_changes)
112
- > a.changed?(:tags)
113
- => false
114
- > a.tags << "my_new_tag"
115
- => ["my_new_tag"]
116
- > a.changed?(:tags)
117
- => false
118
- > a.tags += %w{my_other_tag}
119
- => ["my_new_tag", "my_other_tag"]
120
- > a.changed?(:tags)
121
- => true
122
- ```
123
-
124
- ### Pagination
125
-
126
- ZendeskAPI::Collections can be paginated:
127
-
128
- ```ruby
129
- tickets = client.tickets.page(2).per_page(3)
130
- next_page = tickets.next
131
- previous_page = tickets.prev
132
- ```
133
-
134
- Iteration over all resources and pages is handled by Collection#each_page
135
-
136
- ```ruby
137
- client.tickets.each_page do |resource|
138
- # all resources will be yielded
139
- end
140
- ```
141
-
142
- If given a block with two arguments, the page is also passed in.
143
-
144
- ```ruby
145
- client.tickets.each_page do |resource, page|
146
- # all resources will be yielded along with the page
147
- end
148
- ```
149
-
150
- ### Callbacks
151
-
152
- Callbacks can be added to the ZendeskAPI::Client instance and will be called (with the response env) after all response middleware on a successful request.
153
-
154
- ```ruby
155
- client.insert_callback do |env|
156
- puts env[:response_headers]
157
- end
158
- ```
159
-
160
- ### Resource management
161
-
162
- Individual resources can be created, modified, saved, and destroyed.
163
-
164
- ```ruby
165
- ticket = client.tickets[0] # ZendeskAPI::Ticket.find(client, :id => 1)
166
- ticket.priority = "urgent"
167
- ticket.attributes # => { "priority" => "urgent" }
168
- ticket.save # Will PUT => true
169
- ticket.destroy # => true
170
-
171
- ZendeskAPI::Ticket.new(client, { :priority => "urgent" })
172
- ticket.new_record? # => true
173
- ticket.save # Will POST
174
- ```
175
-
176
- ### Side-loading
177
-
178
- **Warning: this is an experimental feature. Abuse it and lose it.**
179
-
180
- To facilitate a smaller number of requests and easier manipulation of associated data we allow "side-loading", or inclusion, of selected resources.
181
-
182
- For example:
183
- A ZendeskAPI::Ticket is associated with ZendeskAPI::User through the requester_id field.
184
- API requests for that ticket return a structure similar to this:
185
- ```json
186
- "ticket": {
187
- "id": 1,
188
- "url": "http.....",
189
- "requester_id": 7,
190
- ...
191
- }
192
- ```
193
-
194
- Calling ZendeskAPI::Ticket#requester automatically fetches and loads the user referenced above (`/api/v2/users/7`).
195
- Using side-loading, however, the user can be partially loaded in the same request as the ticket.
196
-
197
- ```ruby
198
- tickets = client.tickets.include(:users)
199
- # Or client.tickets(include: :users)
200
- # Does *NOT* make a request to the server since it is already loaded
201
- tickets.first.requester # => #<ZendeskAPI::User id=...>
202
- ```
203
-
204
- OR
205
-
206
- ```ruby
207
- ticket = client.tickets.find(:id => 1, :include => :users)
208
- ticket.requester # => #<ZendeskAPI::User id=...>
209
- ```
210
-
211
- Currently, this feature is limited to only a few resources and their associations.
212
- They are documented on [developer.zendesk.com](http://developer.zendesk.com/documentation/rest_api/introduction.html#side-loading-\(beta\)).
213
-
214
- ### Search
215
-
216
- Searching is done through the client. Returned is an instance of ZendeskAPI::Collection:
217
-
218
- ```ruby
219
- client.search(:query => "my search query") # /api/v2/search.json?query=...
220
- client.users.search(:query => "my new query") # /api/v2/users/search.json?query=...
221
- ```
222
-
223
- ### Special case: Custom resources paths
224
-
225
- API endpoints such as tickets/recent or topics/show_many can be accessed through chaining.
226
- They will too return an instance of ZendeskAPI::Collection.
227
-
228
- ```ruby
229
- client.tickets.recent
230
- client.topics.show_many(:verb => :post, :ids => [1, 2, 3])
231
- ```
232
-
233
- ### Special Case: Current user
234
-
235
- Use either of the following to obtain the current user instance:
236
-
237
- ```ruby
238
- client.users.find(:id => 'me')
239
- client.current_user
240
- ```
241
-
242
- ### Special Case: Importing a ticket
243
-
244
- Bulk importing tickets allows you to move large amounts of data into Zendesk.
245
-
246
- ```ruby
247
- ticket = ZendeskAPI::Ticket.import(client, :subject => "Help", :comments => [{ :author_id => 19, :value => "This is a comment" }])
248
- ```
249
-
250
- http://developer.zendesk.com/documentation/rest_api/ticket_import.html
251
-
252
- ### Attaching files
253
-
254
- Files can be attached to ticket comments using either a path or the File class and will
255
- be automatically uploaded and attached.
256
-
257
- ```ruby
258
- ticket = ZendeskAPI::Ticket.new(client, :comment => { :value => "attachments" })
259
- ticket.comment.uploads << "img.jpg"
260
- ticket.comment.uploads << File.new("img.jpg")
261
- ticket.save
262
- ```
263
-
264
- ## Extras
265
-
266
- The following projects are still works in progress and require checking out the repository,
267
- using ruby 1.9.3, and running `bundle install`.
268
-
269
- ### Zendesk API Test Server
270
-
271
- Included in this repository is the code for the [Zendesk API Tester](https://zendesk-api.herokuapp.com/) website.
272
-
273
- ```sh
274
- bin/zendesk server --help
275
- ```
276
-
277
- Additional Dependencies:
278
-
279
- * sinatra
280
- * sinatra-contrib
281
- * haml
282
- * compass
283
- * coderay
284
- * coderay_bash
285
- * redcarpet
286
- * mongoid (and a working MongoDB instance)
287
-
288
- ### Zendesk Console
289
-
290
- WIP
291
-
292
- ```sh
293
- bin/zendesk console --help
294
- ```
295
-
296
- Additional Dependencies:
297
-
298
- * ripl
299
-
300
35
  ## Note on Patches/Pull Requests
301
36
  1. Fork the project.
302
37
  2. Make your feature addition or bug fix.
@@ -4,7 +4,7 @@ module ZendeskAPI
4
4
  # Executes a POST if it is a {Data#new_record?}, otherwise a PUT.
5
5
  # Merges returned attributes on success.
6
6
  # @return [Boolean] Success?
7
- def save(options={})
7
+ def save!(options={})
8
8
  return false if respond_to?(:destroyed?) && destroyed?
9
9
 
10
10
  if new_record?
@@ -20,13 +20,7 @@ module ZendeskAPI
20
20
  save_associations
21
21
 
22
22
  @response = @client.connection.send(method, req_path) do |req|
23
- req.body = if self.class.unnested_params
24
- attributes.changes
25
- else
26
- {self.class.singular_resource_name.to_sym => attributes.changes}
27
- end
28
-
29
- req.body.merge!(@global_params)
23
+ req.body = attributes_for_save.merge(@global_params)
30
24
  end
31
25
 
32
26
  @attributes.replace @attributes.deep_merge(@response.body[self.class.singular_resource_name] || {})
@@ -35,10 +29,14 @@ module ZendeskAPI
35
29
  true
36
30
  end
37
31
 
38
- # Saves, raising an Argument error if it fails
39
- # @raise [ArgumentError] if saving failed
40
- def save!(options={})
41
- save(options) || raise("Save failed")
32
+ # Saves, returning false if it fails and attaching the errors
33
+ def save(options={})
34
+ save!(options)
35
+ rescue ZendeskAPI::Error::RecordInvalid => e
36
+ @errors = e.errors
37
+ false
38
+ rescue ZendeskAPI::Error::ClientError
39
+ false
42
40
  end
43
41
 
44
42
  # Removes all cached associations
@@ -71,8 +69,6 @@ module ZendeskAPI
71
69
  end
72
70
 
73
71
  module Read
74
- include Rescue
75
-
76
72
  def self.extended(klass)
77
73
  klass.send(:include, ZendeskAPI::Sideloading)
78
74
  end
@@ -81,7 +77,7 @@ module ZendeskAPI
81
77
  # A custom path to search at can be passed into opts. It defaults to the {Data.resource_name} of the class.
82
78
  # @param [Client] client The {Client} object to be used
83
79
  # @param [Hash] options Any additional GET parameters to be added
84
- def find(client, options = {})
80
+ def find!(client, options = {})
85
81
  @client = client # so we can use client.logger in rescue
86
82
 
87
83
  raise ArgumentError, "No :id given" unless options[:id] || options["id"] || ancestors.include?(SingularResource)
@@ -96,11 +92,15 @@ module ZendeskAPI
96
92
 
97
93
  new(client, response.body[singular_resource_name]).tap do |resource|
98
94
  resource.set_includes(resource, includes, response.body)
99
- resource.attributes.clear_changes
100
95
  end
101
96
  end
102
97
 
103
- rescue_client_error :find
98
+ # Finds, returning nil if it fails
99
+ def find(client, options = {})
100
+ find!(client, options)
101
+ rescue ZendeskAPI::Error::ClientError => e
102
+ nil
103
+ end
104
104
  end
105
105
 
106
106
  module Create
@@ -111,32 +111,23 @@ module ZendeskAPI
111
111
  end
112
112
 
113
113
  module ClassMethods
114
- include Rescue
115
-
116
114
  # Create a resource given the attributes passed in.
117
115
  # @param [Client] client The {Client} object to be used
118
116
  # @param [Hash] attributes The attributes to create.
119
- def create(client, attributes = {})
117
+ def create!(client, attributes = {})
120
118
  ZendeskAPI::Client.check_deprecated_namespace_usage attributes, singular_resource_name
121
- resource = new(client, attributes)
122
- return unless resource.save
123
- resource
119
+ new(client, attributes).tap(&:save!)
124
120
  end
125
121
 
126
- # Creates the resource, raising an ArgumentError if it fails
127
- # @raise [ArgumentError] if the creation fails
128
- def create!(client, attributes={})
129
- c = create(client, attributes)
130
- c || raise("Create failed #{self} #{attributes}")
122
+ def create(client, attributes = {})
123
+ create!(client, attributes)
124
+ rescue ZendeskAPI::Error::ClientError
125
+ nil
131
126
  end
132
-
133
- rescue_client_error :create
134
127
  end
135
128
  end
136
129
 
137
130
  module Destroy
138
- include Rescue
139
-
140
131
  def self.included(klass)
141
132
  klass.extend(ClassMethod)
142
133
  end
@@ -148,21 +139,23 @@ module ZendeskAPI
148
139
 
149
140
  # If this resource hasn't already been deleted, then do so.
150
141
  # @return [Boolean] Successful?
151
- def destroy
142
+ def destroy!
152
143
  return false if destroyed? || new_record?
153
144
  @client.connection.delete(url || path)
154
145
  @destroyed = true
155
146
  end
156
147
 
157
- rescue_client_error :destroy, :with => false
148
+ def destroy
149
+ destroy!
150
+ rescue ZendeskAPI::Error::ClientError
151
+ false
152
+ end
158
153
 
159
154
  module ClassMethod
160
- include Rescue
161
-
162
155
  # Deletes a resource given the id passed in.
163
156
  # @param [Client] client The {Client} object to be used
164
157
  # @param [Hash] opts The optional parameters to pass. Defaults to {}
165
- def destroy(client, opts = {})
158
+ def destroy!(client, opts = {})
166
159
  @client = client # so we can use client.logger in rescue
167
160
  association = opts.delete(:association) || Association.new(:class => self)
168
161
 
@@ -173,34 +166,46 @@ module ZendeskAPI
173
166
  true
174
167
  end
175
168
 
176
- rescue_client_error :destroy, :with => false
169
+ def destroy(client, attributes = {})
170
+ destroy!(client, attributes)
171
+ rescue ZendeskAPI::Error::ClientError
172
+ false
173
+ end
177
174
  end
178
175
  end
179
176
 
180
177
  module Update
181
- include Rescue
182
178
  include Save
183
179
 
184
180
  def self.included(klass)
185
181
  klass.extend(ClassMethod)
186
182
  end
187
183
 
188
- rescue_client_error :save, :with => false
189
-
190
184
  module ClassMethod
191
- include Rescue
192
-
193
185
  # Updates a resource given the id passed in.
194
186
  # @param [Client] client The {Client} object to be used
195
187
  # @param [Hash] attributes The attributes to update. Default to {}
196
188
  def update(client, attributes = {})
189
+ update!(client, attributes)
190
+ rescue ZendeskAPI::Error::ClientError
191
+ false
192
+ end
193
+
194
+ def update!(client, attributes = {})
197
195
  ZendeskAPI::Client.check_deprecated_namespace_usage attributes, singular_resource_name
198
- resource = new(client, {:id => attributes.delete(:id), :global => attributes.delete(:global)})
196
+ resource = new(client, { :id => attributes.delete(:id), :global => attributes.delete(:global) })
199
197
  resource.attributes.merge!(attributes)
200
- resource.save
198
+ resource.tap(&:save!)
201
199
  end
202
200
 
203
- rescue_client_error :update, :with => false
201
+ private
202
+
203
+ def _update(client, attributes = {})
204
+ ZendeskAPI::Client.check_deprecated_namespace_usage attributes, singular_resource_name
205
+ resource = new(client, { :id => attributes.delete(:id), :global => attributes.delete(:global) })
206
+ resource.attributes.merge!(attributes)
207
+ resource
208
+ end
204
209
  end
205
210
  end
206
211
  end