zendesk_api 0.4.0.rc1 → 0.4.0.rc2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +31 -29
- data/Readme.md +232 -0
- data/lib/zendesk_api/actions.rb +8 -12
- data/lib/zendesk_api/client.rb +8 -4
- data/lib/zendesk_api/middleware/request/etag_cache.rb +7 -1
- data/lib/zendesk_api/resource.rb +6 -16
- data/lib/zendesk_api/resources.rb +12 -15
- data/lib/zendesk_api/version.rb +1 -1
- data/spec/core/client_spec.rb +5 -0
- data/spec/core/middleware/request/etag_cache_spec.rb +7 -6
- data/spec/core/resource_spec.rb +10 -0
- data/spec/core/spec_helper.rb +1 -1
- data/spec/live/activity_spec.rb +7 -0
- data/spec/live/ticket_spec.rb +2 -1
- data/spec/live/user_spec.rb +2 -0
- metadata +2 -4
- data/spec/live/crm_spec.rb +0 -11
data/Gemfile.lock
CHANGED
|
@@ -7,7 +7,7 @@ GIT
|
|
|
7
7
|
PATH
|
|
8
8
|
remote: .
|
|
9
9
|
specs:
|
|
10
|
-
zendesk_api (0.4.0.
|
|
10
|
+
zendesk_api (0.4.0.rc2)
|
|
11
11
|
faraday (>= 0.8.0)
|
|
12
12
|
faraday_middleware (>= 0.8.7)
|
|
13
13
|
hashie (>= 1.2)
|
|
@@ -25,15 +25,15 @@ GEM
|
|
|
25
25
|
activesupport (3.2.13)
|
|
26
26
|
i18n (= 0.6.1)
|
|
27
27
|
multi_json (~> 1.0)
|
|
28
|
-
addressable (2.3.
|
|
29
|
-
backports (3.
|
|
28
|
+
addressable (2.3.4)
|
|
29
|
+
backports (3.3.2)
|
|
30
30
|
bond (0.4.3)
|
|
31
31
|
bond (0.4.3-java)
|
|
32
|
-
bootstrap-sass (2.3.
|
|
32
|
+
bootstrap-sass (2.3.2.0)
|
|
33
33
|
sass (~> 3.2)
|
|
34
34
|
bouncy-castle-java (1.5.0147)
|
|
35
35
|
builder (3.0.4)
|
|
36
|
-
bump (0.4.
|
|
36
|
+
bump (0.4.2)
|
|
37
37
|
chunky_png (1.2.8)
|
|
38
38
|
coderay (1.0.9)
|
|
39
39
|
coderay_bash (1.0.5)
|
|
@@ -42,10 +42,11 @@ GEM
|
|
|
42
42
|
chunky_png (~> 1.2)
|
|
43
43
|
fssm (>= 0.2.7)
|
|
44
44
|
sass (~> 3.1)
|
|
45
|
-
crack (0.
|
|
45
|
+
crack (0.4.0)
|
|
46
|
+
safe_yaml (~> 0.9.0)
|
|
46
47
|
daemons (1.1.9)
|
|
47
|
-
database_cleaner (0.
|
|
48
|
-
diff-lcs (1.2.
|
|
48
|
+
database_cleaner (1.0.1)
|
|
49
|
+
diff-lcs (1.2.4)
|
|
49
50
|
eventmachine (1.0.3)
|
|
50
51
|
eventmachine (1.0.3-java)
|
|
51
52
|
faraday (0.8.7)
|
|
@@ -53,32 +54,32 @@ GEM
|
|
|
53
54
|
faraday_middleware (0.9.0)
|
|
54
55
|
faraday (>= 0.7.4, < 0.9)
|
|
55
56
|
fssm (0.2.10)
|
|
56
|
-
haml (4.0.
|
|
57
|
+
haml (4.0.3)
|
|
57
58
|
tilt
|
|
58
|
-
hashie (2.0.
|
|
59
|
+
hashie (2.0.5)
|
|
59
60
|
i18n (0.6.1)
|
|
60
61
|
inflection (1.0.0)
|
|
61
|
-
jruby-openssl (0.8.
|
|
62
|
+
jruby-openssl (0.8.8)
|
|
62
63
|
bouncy-castle-java (>= 1.5.0147)
|
|
63
64
|
json (1.8.0)
|
|
64
65
|
mime-types (1.23)
|
|
65
|
-
mongoid (3.1.
|
|
66
|
+
mongoid (3.1.4)
|
|
66
67
|
activemodel (~> 3.2)
|
|
67
|
-
moped (~> 1.4
|
|
68
|
+
moped (~> 1.4)
|
|
68
69
|
origin (~> 1.0)
|
|
69
70
|
tzinfo (~> 0.3.22)
|
|
70
|
-
moped (1.
|
|
71
|
-
multi_json (1.7.
|
|
72
|
-
newrelic_rpm (3.6.
|
|
73
|
-
origin (1.0
|
|
71
|
+
moped (1.5.0)
|
|
72
|
+
multi_json (1.7.7)
|
|
73
|
+
newrelic_rpm (3.6.4.122)
|
|
74
|
+
origin (1.1.0)
|
|
74
75
|
rack (1.5.2)
|
|
75
76
|
rack-protection (1.5.0)
|
|
76
77
|
rack
|
|
77
78
|
rack-ssl-enforcer (0.2.5)
|
|
78
79
|
rack-test (0.6.2)
|
|
79
80
|
rack (>= 1.0)
|
|
80
|
-
rake (10.0
|
|
81
|
-
redcarpet (2.
|
|
81
|
+
rake (10.1.0)
|
|
82
|
+
redcarpet (2.3.0)
|
|
82
83
|
ripl (0.7.0)
|
|
83
84
|
bond (~> 0.4.2)
|
|
84
85
|
rspec (2.13.0)
|
|
@@ -88,34 +89,35 @@ GEM
|
|
|
88
89
|
rspec-core (2.13.1)
|
|
89
90
|
rspec-expectations (2.13.0)
|
|
90
91
|
diff-lcs (>= 1.1.3, < 2.0)
|
|
91
|
-
rspec-mocks (2.13.
|
|
92
|
-
|
|
92
|
+
rspec-mocks (2.13.1)
|
|
93
|
+
safe_yaml (0.9.3)
|
|
94
|
+
sass (3.2.9)
|
|
93
95
|
simplecov (0.7.1)
|
|
94
96
|
multi_json (~> 1.0)
|
|
95
97
|
simplecov-html (~> 0.7.1)
|
|
96
98
|
simplecov-html (0.7.1)
|
|
97
|
-
sinatra (1.3
|
|
99
|
+
sinatra (1.4.3)
|
|
98
100
|
rack (~> 1.4)
|
|
99
|
-
rack-protection (~> 1.
|
|
100
|
-
tilt (~> 1.3, >= 1.3.
|
|
101
|
-
sinatra-contrib (1.
|
|
101
|
+
rack-protection (~> 1.4)
|
|
102
|
+
tilt (~> 1.3, >= 1.3.4)
|
|
103
|
+
sinatra-contrib (1.4.0)
|
|
102
104
|
backports (>= 2.0)
|
|
103
105
|
eventmachine
|
|
104
106
|
rack-protection
|
|
105
107
|
rack-test
|
|
106
|
-
sinatra (~> 1.
|
|
108
|
+
sinatra (~> 1.4.2)
|
|
107
109
|
tilt (~> 1.3)
|
|
108
110
|
thin (1.5.1)
|
|
109
111
|
daemons (>= 1.0.9)
|
|
110
112
|
eventmachine (>= 0.12.6)
|
|
111
113
|
rack (>= 1.0.0)
|
|
112
|
-
tilt (1.
|
|
114
|
+
tilt (1.4.1)
|
|
113
115
|
tzinfo (0.3.37)
|
|
114
|
-
vcr (2.
|
|
116
|
+
vcr (2.5.0)
|
|
115
117
|
webmock (1.9.3)
|
|
116
118
|
addressable (>= 2.2.7)
|
|
117
119
|
crack (>= 0.3.2)
|
|
118
|
-
yard (0.8.
|
|
120
|
+
yard (0.8.6.1)
|
|
119
121
|
|
|
120
122
|
PLATFORMS
|
|
121
123
|
java
|
data/Readme.md
CHANGED
|
@@ -13,6 +13,7 @@ Please check out the [wiki](https://github.com/zendesk/zendesk_api_client_rb/wik
|
|
|
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.
|
|
15
15
|
* Version 0.3.2 introduced a regression when side-loading roles on users. This was fixed in 0.3.4.
|
|
16
|
+
* Version 0.4.0rc1 changes the way errors are handled. Please see the [wiki page](https://github.com/zendesk/zendesk_api_client_rb/wiki/Errors) for more info.
|
|
16
17
|
|
|
17
18
|
## Installation
|
|
18
19
|
|
|
@@ -32,6 +33,237 @@ Add it to your Gemfile
|
|
|
32
33
|
|
|
33
34
|
and follow normal [Bundler](http://gembundler.com/) installation and execution procedures.
|
|
34
35
|
|
|
36
|
+
## Configuration
|
|
37
|
+
|
|
38
|
+
Configuration is done through a block returning an instance of ZendeskAPI::Client.
|
|
39
|
+
The block is mandatory and if not passed, an ArgumentError will be thrown.
|
|
40
|
+
|
|
41
|
+
```ruby
|
|
42
|
+
require 'zendesk_api'
|
|
43
|
+
|
|
44
|
+
client = ZendeskAPI::Client.new do |config|
|
|
45
|
+
# Mandatory:
|
|
46
|
+
|
|
47
|
+
config.url = "<- your-zendesk-url ->" # e.g. https://mydesk.zendesk.com/api/v2
|
|
48
|
+
|
|
49
|
+
config.username = "login.email@zendesk.com"
|
|
50
|
+
|
|
51
|
+
# Choose one of the following depending on your authentication choice
|
|
52
|
+
config.token = "your zendesk token"
|
|
53
|
+
config.password = "your zendesk password"
|
|
54
|
+
|
|
55
|
+
# Optional:
|
|
56
|
+
|
|
57
|
+
# Retry uses middleware to notify the user
|
|
58
|
+
# when hitting the rate limit, sleep automatically,
|
|
59
|
+
# then retry the request.
|
|
60
|
+
config.retry = true
|
|
61
|
+
|
|
62
|
+
# Logger prints to STDERR by default, to e.g. print to stdout:
|
|
63
|
+
require 'logger'
|
|
64
|
+
config.logger = Logger.new(STDOUT)
|
|
65
|
+
|
|
66
|
+
# Changes Faraday adapter
|
|
67
|
+
# config.adapter = :patron
|
|
68
|
+
|
|
69
|
+
# Merged with the default client options hash
|
|
70
|
+
# config.client_options = { :ssl => false }
|
|
71
|
+
|
|
72
|
+
# When getting the error 'hostname does not match the server certificate'
|
|
73
|
+
# use the API at https://yoursubdomain.zendesk.com/api/v2
|
|
74
|
+
end
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Note: This ZendeskAPI API client only supports basic authentication at the moment.
|
|
78
|
+
|
|
79
|
+
## Usage
|
|
80
|
+
|
|
81
|
+
The result of configuration is an instance of ZendeskAPI::Client which can then be used in two different methods.
|
|
82
|
+
|
|
83
|
+
One way to use the client is to pass it in as an argument to individual classes.
|
|
84
|
+
|
|
85
|
+
```ruby
|
|
86
|
+
ZendeskAPI::Ticket.new(client, :id => 1, :priority => "urgent") # doesn't actually send a request, must explicitly call #save
|
|
87
|
+
ZendeskAPI::Ticket.create(client, :subject => "Test Ticket", :comment => { :value => "This is a test" }, :submitter_id => client.current_user.id, :priority => "urgent")
|
|
88
|
+
ZendeskAPI::Ticket.find(client, :id => 1)
|
|
89
|
+
ZendeskAPI::Ticket.delete(client, :id => 1)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Another way is to use the instance methods under client.
|
|
93
|
+
|
|
94
|
+
```ruby
|
|
95
|
+
client.tickets.first
|
|
96
|
+
client.tickets.find(:id => 1)
|
|
97
|
+
client.tickets.create(:subject => "Test Ticket", :comment => { :value => "This is a test" }, :submitter_id => client.current_user.id, :priority => "urgent")
|
|
98
|
+
client.tickets.delete(:id => 1)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The methods under ZendeskAPI::Client (such as .tickets) return an instance of ZendeskAPI::Collection a lazy-loaded list of that resource.
|
|
102
|
+
Actual requests may not be sent until an explicit ZendeskAPI::Collection#fetch, ZendeskAPI::Collection#to_a, or an applicable methods such
|
|
103
|
+
as #each.
|
|
104
|
+
|
|
105
|
+
### Caveats
|
|
106
|
+
|
|
107
|
+
Resource updating is implemented by sending only the `changed?` attributes to the server (see `ZendeskAPI::TrackChanges`).
|
|
108
|
+
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.
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
zendesk_api_client_rb $ bundle console
|
|
112
|
+
> a = ZendeskAPI::Trackie.new(:tags => []).tap(&:clear_changes)
|
|
113
|
+
> a.changed?(:tags)
|
|
114
|
+
=> false
|
|
115
|
+
> a.tags << "my_new_tag"
|
|
116
|
+
=> ["my_new_tag"]
|
|
117
|
+
> a.changed?(:tags)
|
|
118
|
+
=> false
|
|
119
|
+
> a.tags += %w{my_other_tag}
|
|
120
|
+
=> ["my_new_tag", "my_other_tag"]
|
|
121
|
+
> a.changed?(:tags)
|
|
122
|
+
=> true
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Pagination
|
|
126
|
+
|
|
127
|
+
ZendeskAPI::Collections can be paginated:
|
|
128
|
+
|
|
129
|
+
```ruby
|
|
130
|
+
tickets = client.tickets.page(2).per_page(3)
|
|
131
|
+
next_page = tickets.next # => 3
|
|
132
|
+
tickets.fetch # GET /api/v2/tickets?page=3&per_page=3
|
|
133
|
+
previous_page = tickets.prev # => 2
|
|
134
|
+
tickets.fetch # GET /api/v2/tickets?page=2&per_page=3
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Iteration over all resources and pages is handled by Collection#all
|
|
138
|
+
|
|
139
|
+
```ruby
|
|
140
|
+
client.tickets.all do |resource|
|
|
141
|
+
# every resource, from all pages, will be yielded to this block
|
|
142
|
+
end
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
If given a block with two arguments, the page number is also passed in.
|
|
146
|
+
|
|
147
|
+
```ruby
|
|
148
|
+
client.tickets.all do |resource, page_number|
|
|
149
|
+
# all resources will be yielded along with the page number
|
|
150
|
+
end
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Callbacks
|
|
154
|
+
|
|
155
|
+
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.
|
|
156
|
+
|
|
157
|
+
```ruby
|
|
158
|
+
client.insert_callback do |env|
|
|
159
|
+
puts env[:response_headers]
|
|
160
|
+
end
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Resource management
|
|
164
|
+
|
|
165
|
+
Individual resources can be created, modified, saved, and destroyed.
|
|
166
|
+
|
|
167
|
+
```ruby
|
|
168
|
+
ticket = client.tickets[0] # ZendeskAPI::Ticket.find(client, :id => 1)
|
|
169
|
+
ticket.priority = "urgent"
|
|
170
|
+
ticket.attributes # => { "priority" => "urgent" }
|
|
171
|
+
ticket.save # Will PUT => true
|
|
172
|
+
ticket.destroy # => true
|
|
173
|
+
|
|
174
|
+
ZendeskAPI::Ticket.new(client, { :priority => "urgent" })
|
|
175
|
+
ticket.new_record? # => true
|
|
176
|
+
ticket.save # Will POST
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Side-loading
|
|
180
|
+
|
|
181
|
+
**Warning: this is an experimental feature. Abuse it and lose it.**
|
|
182
|
+
|
|
183
|
+
To facilitate a smaller number of requests and easier manipulation of associated data we allow "side-loading", or inclusion, of selected resources.
|
|
184
|
+
|
|
185
|
+
For example:
|
|
186
|
+
A ZendeskAPI::Ticket is associated with ZendeskAPI::User through the requester_id field.
|
|
187
|
+
API requests for that ticket return a structure similar to this:
|
|
188
|
+
```json
|
|
189
|
+
"ticket": {
|
|
190
|
+
"id": 1,
|
|
191
|
+
"url": "http.....",
|
|
192
|
+
"requester_id": 7,
|
|
193
|
+
...
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Calling ZendeskAPI::Ticket#requester automatically fetches and loads the user referenced above (`/api/v2/users/7`).
|
|
198
|
+
Using side-loading, however, the user can be partially loaded in the same request as the ticket.
|
|
199
|
+
|
|
200
|
+
```ruby
|
|
201
|
+
tickets = client.tickets.include(:users)
|
|
202
|
+
# Or client.tickets(include: :users)
|
|
203
|
+
# Does *NOT* make a request to the server since it is already loaded
|
|
204
|
+
tickets.first.requester # => #<ZendeskAPI::User id=...>
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
OR
|
|
208
|
+
|
|
209
|
+
```ruby
|
|
210
|
+
ticket = client.tickets.find(:id => 1, :include => :users)
|
|
211
|
+
ticket.requester # => #<ZendeskAPI::User id=...>
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Currently, this feature is limited to only a few resources and their associations.
|
|
215
|
+
They are documented on [developer.zendesk.com](http://developer.zendesk.com/documentation/rest_api/introduction.html#side-loading-\(beta\)).
|
|
216
|
+
|
|
217
|
+
### Search
|
|
218
|
+
|
|
219
|
+
Searching is done through the client. Returned is an instance of ZendeskAPI::Collection:
|
|
220
|
+
|
|
221
|
+
```ruby
|
|
222
|
+
client.search(:query => "my search query") # /api/v2/search.json?query=...
|
|
223
|
+
client.users.search(:query => "my new query") # /api/v2/users/search.json?query=...
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### Special case: Custom resources paths
|
|
227
|
+
|
|
228
|
+
API endpoints such as tickets/recent or topics/show_many can be accessed through chaining.
|
|
229
|
+
They will too return an instance of ZendeskAPI::Collection.
|
|
230
|
+
|
|
231
|
+
```ruby
|
|
232
|
+
client.tickets.recent
|
|
233
|
+
client.topics.show_many(:verb => :post, :ids => [1, 2, 3])
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Special Case: Current user
|
|
237
|
+
|
|
238
|
+
Use either of the following to obtain the current user instance:
|
|
239
|
+
|
|
240
|
+
```ruby
|
|
241
|
+
client.users.find(:id => 'me')
|
|
242
|
+
client.current_user
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### Special Case: Importing a ticket
|
|
246
|
+
|
|
247
|
+
Bulk importing tickets allows you to move large amounts of data into Zendesk.
|
|
248
|
+
|
|
249
|
+
```ruby
|
|
250
|
+
ticket = ZendeskAPI::Ticket.import(client, :subject => "Help", :comments => [{ :author_id => 19, :value => "This is a comment" }])
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
http://developer.zendesk.com/documentation/rest_api/ticket_import.html
|
|
254
|
+
|
|
255
|
+
### Attaching files
|
|
256
|
+
|
|
257
|
+
Files can be attached to ticket comments using either a path or the File class and will
|
|
258
|
+
be automatically uploaded and attached.
|
|
259
|
+
|
|
260
|
+
```ruby
|
|
261
|
+
ticket = ZendeskAPI::Ticket.new(client, :comment => { :value => "attachments" })
|
|
262
|
+
ticket.comment.uploads << "img.jpg"
|
|
263
|
+
ticket.comment.uploads << File.new("img.jpg")
|
|
264
|
+
ticket.save
|
|
265
|
+
```
|
|
266
|
+
|
|
35
267
|
## Note on Patches/Pull Requests
|
|
36
268
|
1. Fork the project.
|
|
37
269
|
2. Make your feature addition or bug fix.
|
data/lib/zendesk_api/actions.rb
CHANGED
|
@@ -4,10 +4,10 @@ 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
|
-
if new_record?
|
|
10
|
+
if new_record? && !options[:force_update]
|
|
11
11
|
method = :post
|
|
12
12
|
req_path = path
|
|
13
13
|
else
|
|
@@ -23,7 +23,10 @@ module ZendeskAPI
|
|
|
23
23
|
req.body = attributes_for_save.merge(@global_params)
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
@
|
|
26
|
+
if @response.body && @response.body[self.class.singular_resource_name]
|
|
27
|
+
@attributes.replace @attributes.deep_merge(@response.body[self.class.singular_resource_name] || {})
|
|
28
|
+
end
|
|
29
|
+
|
|
27
30
|
@attributes.clear_changes
|
|
28
31
|
clear_associations
|
|
29
32
|
true
|
|
@@ -92,6 +95,7 @@ module ZendeskAPI
|
|
|
92
95
|
|
|
93
96
|
new(client, response.body[singular_resource_name]).tap do |resource|
|
|
94
97
|
resource.set_includes(resource, includes, response.body)
|
|
98
|
+
resource.attributes.clear_changes
|
|
95
99
|
end
|
|
96
100
|
end
|
|
97
101
|
|
|
@@ -195,15 +199,7 @@ module ZendeskAPI
|
|
|
195
199
|
ZendeskAPI::Client.check_deprecated_namespace_usage attributes, singular_resource_name
|
|
196
200
|
resource = new(client, { :id => attributes.delete(:id), :global => attributes.delete(:global) })
|
|
197
201
|
resource.attributes.merge!(attributes)
|
|
198
|
-
resource.
|
|
199
|
-
end
|
|
200
|
-
|
|
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)
|
|
202
|
+
resource.save!(:force_update => resource.is_a?(SingularResource))
|
|
207
203
|
resource
|
|
208
204
|
end
|
|
209
205
|
end
|
data/lib/zendesk_api/client.rb
CHANGED
|
@@ -32,12 +32,13 @@ module ZendeskAPI
|
|
|
32
32
|
method = method.to_s
|
|
33
33
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
|
34
34
|
|
|
35
|
-
@resource_cache[method] ||= {}
|
|
35
|
+
@resource_cache[method] ||= { :class => nil, :cache => ZendeskAPI::LRUCache.new }
|
|
36
36
|
|
|
37
|
-
if !options.delete(:reload) && (cached = @resource_cache[method][options.hash
|
|
37
|
+
if !options.delete(:reload) && (cached = @resource_cache[method][:cache].read(options.hash))
|
|
38
38
|
cached
|
|
39
39
|
else
|
|
40
|
-
@resource_cache[method][
|
|
40
|
+
@resource_cache[method][:class] ||= ZendeskAPI.const_get(ZendeskAPI::Helpers.modulize_string(Inflection.singular(method)))
|
|
41
|
+
@resource_cache[method][:cache].write(options.hash, ZendeskAPI::Collection.new(self, @resource_cache[method][:class], options))
|
|
41
42
|
end
|
|
42
43
|
end
|
|
43
44
|
|
|
@@ -142,7 +143,10 @@ module ZendeskAPI
|
|
|
142
143
|
builder.use Faraday::Request::BasicAuthentication, config.username, config.password
|
|
143
144
|
end
|
|
144
145
|
|
|
145
|
-
|
|
146
|
+
if config.cache
|
|
147
|
+
builder.use ZendeskAPI::Middleware::Request::EtagCache, :cache => config.cache
|
|
148
|
+
end
|
|
149
|
+
|
|
146
150
|
builder.use ZendeskAPI::Middleware::Request::Upload
|
|
147
151
|
builder.request :multipart
|
|
148
152
|
builder.request :json
|
|
@@ -30,7 +30,13 @@ module ZendeskAPI
|
|
|
30
30
|
|
|
31
31
|
@app.call(env).on_complete do
|
|
32
32
|
if cached && env[:status] == 304 # not modified
|
|
33
|
-
env
|
|
33
|
+
env[:body] = cached[:body]
|
|
34
|
+
env[:response_headers].merge!(
|
|
35
|
+
:etag => cached[:response_headers][:etag],
|
|
36
|
+
:content_type => cached[:response_headers][:content_type],
|
|
37
|
+
:content_length => cached[:response_headers][:content_length],
|
|
38
|
+
:content_encoding => cached[:response_headers][:content_encoding]
|
|
39
|
+
)
|
|
34
40
|
elsif env[:status] == 200 && env[:response_headers]["Etag"] # modified and cacheable
|
|
35
41
|
@cache.write(cache_key(env), env)
|
|
36
42
|
end
|
data/lib/zendesk_api/resource.rb
CHANGED
|
@@ -35,16 +35,6 @@ module ZendeskAPI
|
|
|
35
35
|
|
|
36
36
|
alias :model_key :resource_name
|
|
37
37
|
|
|
38
|
-
# @private
|
|
39
|
-
def only_send_unnested_params
|
|
40
|
-
@unnested_params = true
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
# @private
|
|
44
|
-
def unnested_params
|
|
45
|
-
@unnested_params ||= false
|
|
46
|
-
end
|
|
47
|
-
|
|
48
38
|
def namespace(namespace)
|
|
49
39
|
@namespace = namespace
|
|
50
40
|
end
|
|
@@ -145,11 +135,7 @@ module ZendeskAPI
|
|
|
145
135
|
private
|
|
146
136
|
|
|
147
137
|
def attributes_for_save
|
|
148
|
-
|
|
149
|
-
attributes.changes
|
|
150
|
-
else
|
|
151
|
-
{ self.class.singular_resource_name.to_sym => attributes.changes }
|
|
152
|
-
end
|
|
138
|
+
{ self.class.singular_resource_name.to_sym => attributes.changes }
|
|
153
139
|
end
|
|
154
140
|
end
|
|
155
141
|
|
|
@@ -188,5 +174,9 @@ module ZendeskAPI
|
|
|
188
174
|
include Destroy
|
|
189
175
|
end
|
|
190
176
|
|
|
191
|
-
class SingularResource < Resource
|
|
177
|
+
class SingularResource < Resource
|
|
178
|
+
def attributes_for_save
|
|
179
|
+
{ self.class.resource_name.to_sym => attributes.changes }
|
|
180
|
+
end
|
|
181
|
+
end
|
|
192
182
|
end
|
|
@@ -11,13 +11,6 @@ module ZendeskAPI
|
|
|
11
11
|
|
|
12
12
|
class Locale < ReadResource; end
|
|
13
13
|
|
|
14
|
-
class CRMData < DataResource
|
|
15
|
-
class << self
|
|
16
|
-
alias :resource_name :singular_resource_name
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
class CRMDataStatus < DataResource; end
|
|
21
14
|
class CustomRole < DataResource; end
|
|
22
15
|
class Role < DataResource; end
|
|
23
16
|
class Topic < Resource; end
|
|
@@ -52,9 +45,13 @@ module ZendeskAPI
|
|
|
52
45
|
|
|
53
46
|
def id; token; end
|
|
54
47
|
|
|
55
|
-
only_send_unnested_params
|
|
56
|
-
|
|
57
48
|
has_many Attachment
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
def attributes_for_save
|
|
53
|
+
attributes.changes
|
|
54
|
+
end
|
|
58
55
|
end
|
|
59
56
|
|
|
60
57
|
class MobileDevice < Resource
|
|
@@ -71,7 +68,6 @@ module ZendeskAPI
|
|
|
71
68
|
end
|
|
72
69
|
|
|
73
70
|
class ForumSubscription < Resource
|
|
74
|
-
only_send_unnested_params
|
|
75
71
|
has Forum
|
|
76
72
|
has User
|
|
77
73
|
end
|
|
@@ -90,7 +86,6 @@ module ZendeskAPI
|
|
|
90
86
|
end
|
|
91
87
|
|
|
92
88
|
class TopicSubscription < Resource
|
|
93
|
-
only_send_unnested_params
|
|
94
89
|
has Topic
|
|
95
90
|
has User
|
|
96
91
|
end
|
|
@@ -111,9 +106,14 @@ module ZendeskAPI
|
|
|
111
106
|
end
|
|
112
107
|
|
|
113
108
|
class TopicVote < SingularResource
|
|
114
|
-
only_send_unnested_params
|
|
115
109
|
has Topic
|
|
116
110
|
has User
|
|
111
|
+
|
|
112
|
+
private
|
|
113
|
+
|
|
114
|
+
def attributes_for_save
|
|
115
|
+
attributes.changes
|
|
116
|
+
end
|
|
117
117
|
end
|
|
118
118
|
|
|
119
119
|
has Forum
|
|
@@ -394,9 +394,6 @@ module ZendeskAPI
|
|
|
394
394
|
has_many TopicSubscription
|
|
395
395
|
has_many :topic_comments, :class => TopicComment
|
|
396
396
|
has_many :topic_votes, :class => Topic::TopicVote
|
|
397
|
-
|
|
398
|
-
has CRMData
|
|
399
|
-
has CRMDataStatus, :path => 'crm_data/status'
|
|
400
397
|
end
|
|
401
398
|
|
|
402
399
|
class UserField < Resource; end
|
data/lib/zendesk_api/version.rb
CHANGED
data/spec/core/client_spec.rb
CHANGED
|
@@ -199,6 +199,11 @@ describe ZendeskAPI::Client do
|
|
|
199
199
|
subject.tickets.should be_instance_of(ZendeskAPI::Collection)
|
|
200
200
|
|
|
201
201
|
subject.instance_variable_get(:@resource_cache)["tickets"].should_not be_empty
|
|
202
|
+
subject.instance_variable_get(:@resource_cache)["tickets"][:class].should == ZendeskAPI::Ticket
|
|
203
|
+
subject.instance_variable_get(:@resource_cache)["tickets"][:cache].should be_instance_of(ZendeskAPI::LRUCache)
|
|
204
|
+
|
|
205
|
+
ZendeskAPI.should_not_receive(:const_get)
|
|
206
|
+
subject.tickets.should be_instance_of(ZendeskAPI::Collection)
|
|
202
207
|
end
|
|
203
208
|
|
|
204
209
|
it "should not cache calls with different options" do
|
|
@@ -5,16 +5,17 @@ describe ZendeskAPI::Middleware::Request::EtagCache do
|
|
|
5
5
|
client.config.cache.size = 1
|
|
6
6
|
|
|
7
7
|
stub_json_request(:get, %r{blergh}, '{"x":1}', :headers => {"Etag" => "x"})
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
headers = response.headers
|
|
8
|
+
first_response = client.connection.get("blergh")
|
|
9
|
+
first_response.status.should == 200
|
|
10
|
+
first_response.body.should == {"x"=>1}
|
|
13
11
|
|
|
14
12
|
stub_request(:get, %r{blergh}).to_return(:status => 304, :headers => {"Etag" => "x"})
|
|
15
13
|
response = client.connection.get("blergh")
|
|
16
14
|
response.status.should == 304
|
|
17
15
|
response.body.should == {"x"=>1}
|
|
18
|
-
|
|
16
|
+
|
|
17
|
+
%w{content_encoding content_type content_length etag}.each do |header|
|
|
18
|
+
response.headers[header].should == first_response.headers[header]
|
|
19
|
+
end
|
|
19
20
|
end
|
|
20
21
|
end
|
data/spec/core/resource_spec.rb
CHANGED
|
@@ -413,6 +413,16 @@ describe ZendeskAPI::Resource do
|
|
|
413
413
|
end.to_not raise_error(ArgumentError)
|
|
414
414
|
end
|
|
415
415
|
end
|
|
416
|
+
|
|
417
|
+
context "#update" do
|
|
418
|
+
before do
|
|
419
|
+
stub_json_request(:put, %r{/singular_test_resource})
|
|
420
|
+
end
|
|
421
|
+
|
|
422
|
+
it "should always PUT" do
|
|
423
|
+
ZendeskAPI::SingularTestResource.update(client, :test => :test)
|
|
424
|
+
end
|
|
425
|
+
end
|
|
416
426
|
end
|
|
417
427
|
|
|
418
428
|
context "Ticket#assignee" do
|
data/spec/core/spec_helper.rb
CHANGED
|
@@ -73,7 +73,7 @@ module TestHelper
|
|
|
73
73
|
|
|
74
74
|
def stub_json_request(verb, path_matcher, body = json, options = {})
|
|
75
75
|
stub_request(verb, path_matcher).to_return(Hashie::Mash.new(
|
|
76
|
-
:body => body, :headers => { :content_type => "application/json" }
|
|
76
|
+
:body => body, :headers => { :content_type => "application/json", :content_length => body.size }
|
|
77
77
|
).deep_merge(options))
|
|
78
78
|
end
|
|
79
79
|
end
|
data/spec/live/activity_spec.rb
CHANGED
data/spec/live/ticket_spec.rb
CHANGED
data/spec/live/user_spec.rb
CHANGED
|
@@ -25,6 +25,7 @@ describe ZendeskAPI::User, :delete_after do
|
|
|
25
25
|
|
|
26
26
|
it "should include role" do
|
|
27
27
|
if subject
|
|
28
|
+
subject.changes.key?(:role_id).should be_false
|
|
28
29
|
subject.role.should_not be_nil
|
|
29
30
|
subject.role.id.should be_nil
|
|
30
31
|
subject.role.name.should == "admin"
|
|
@@ -42,6 +43,7 @@ describe ZendeskAPI::User, :delete_after do
|
|
|
42
43
|
|
|
43
44
|
it "should include role" do
|
|
44
45
|
if subject
|
|
46
|
+
subject.changes.key?(:role_id).should be_false
|
|
45
47
|
subject.role.should_not be_nil
|
|
46
48
|
subject.role.id.should be_nil
|
|
47
49
|
subject.role.name.should == "agent"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: zendesk_api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.4.0.
|
|
4
|
+
version: 0.4.0.rc2
|
|
5
5
|
prerelease: 6
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2013-
|
|
13
|
+
date: 2013-06-20 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: bump
|
|
@@ -475,7 +475,6 @@ files:
|
|
|
475
475
|
- spec/live/bookmark_spec.rb
|
|
476
476
|
- spec/live/category_spec.rb
|
|
477
477
|
- spec/live/collection_spec.rb
|
|
478
|
-
- spec/live/crm_spec.rb
|
|
479
478
|
- spec/live/custom_role_spec.rb
|
|
480
479
|
- spec/live/forum_spec.rb
|
|
481
480
|
- spec/live/forum_subscription_spec.rb
|
|
@@ -571,7 +570,6 @@ test_files:
|
|
|
571
570
|
- spec/live/bookmark_spec.rb
|
|
572
571
|
- spec/live/category_spec.rb
|
|
573
572
|
- spec/live/collection_spec.rb
|
|
574
|
-
- spec/live/crm_spec.rb
|
|
575
573
|
- spec/live/custom_role_spec.rb
|
|
576
574
|
- spec/live/forum_spec.rb
|
|
577
575
|
- spec/live/forum_subscription_spec.rb
|
data/spec/live/crm_spec.rb
DELETED