zendesk_api 0.3.0 → 0.3.1
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 +3 -3
- data/lib/zendesk_api/actions.rb +1 -1
- data/lib/zendesk_api/associations.rb +1 -1
- data/lib/zendesk_api/collection.rb +2 -2
- data/lib/zendesk_api/resources.rb +4 -8
- data/lib/zendesk_api/track_changes.rb +6 -2
- data/lib/zendesk_api/trackie.rb +5 -0
- data/lib/zendesk_api/version.rb +1 -1
- data/spec/core/collection_spec.rb +71 -34
- data/spec/core/data_resource_spec.rb +23 -0
- data/spec/core/resource_spec.rb +9 -1
- data/spec/core/trackie_spec.rb +29 -1
- data/spec/fixtures/test_resources.rb +1 -1
- data/spec/live/upload_spec.rb +2 -1
- data/spec/macros/resource_macros.rb +1 -1
- metadata +3 -3
data/Gemfile.lock
CHANGED
@@ -13,7 +13,7 @@ GIT
|
|
13
13
|
PATH
|
14
14
|
remote: .
|
15
15
|
specs:
|
16
|
-
zendesk_api (0.3.
|
16
|
+
zendesk_api (0.3.1)
|
17
17
|
faraday (>= 0.8.0)
|
18
18
|
faraday_middleware (>= 0.8.7)
|
19
19
|
hashie
|
@@ -54,7 +54,7 @@ GEM
|
|
54
54
|
diff-lcs (1.1.3)
|
55
55
|
eventmachine (1.0.0)
|
56
56
|
eventmachine (1.0.0-java)
|
57
|
-
faraday (0.8.
|
57
|
+
faraday (0.8.6)
|
58
58
|
multipart-post (~> 1.1)
|
59
59
|
faraday_middleware (0.9.0)
|
60
60
|
faraday (>= 0.7.4, < 0.9)
|
@@ -75,7 +75,7 @@ GEM
|
|
75
75
|
multi_json (1.5.0)
|
76
76
|
newrelic_rpm (3.5.3.25)
|
77
77
|
origin (1.0.11)
|
78
|
-
rack (1.5.
|
78
|
+
rack (1.5.2)
|
79
79
|
rack-protection (1.3.2)
|
80
80
|
rack
|
81
81
|
rack-ssl-enforcer (0.2.5)
|
data/lib/zendesk_api/actions.rb
CHANGED
@@ -61,7 +61,7 @@ module ZendeskAPI
|
|
61
61
|
self.send("#{association_name}=", association) # set id/ids columns
|
62
62
|
end
|
63
63
|
|
64
|
-
if association_data[:inline] == true || inline_creation
|
64
|
+
if (association_data[:inline] == true || inline_creation) && association.changed?
|
65
65
|
attributes[association_name] = (association.is_a?(Collection) ? association.map(&:to_param) : association.to_param)
|
66
66
|
end
|
67
67
|
end
|
@@ -111,7 +111,7 @@ module ZendeskAPI
|
|
111
111
|
klass.find(@client, :id => resource_id, :association => instance_association)
|
112
112
|
elsif found = method_missing(association[:name].to_sym)
|
113
113
|
wrap_resource(found, association)
|
114
|
-
elsif klass.superclass == DataResource
|
114
|
+
elsif klass.superclass == DataResource && !association[:inline]
|
115
115
|
rescue_client_error do
|
116
116
|
response = @client.connection.get(instance_association.generate_path(:with_parent => true))
|
117
117
|
klass.new(@client, response.body[klass.singular_resource_name].merge(:association => instance_association))
|
@@ -169,8 +169,8 @@ module ZendeskAPI
|
|
169
169
|
|
170
170
|
# Calls #each on every page with the passed in block
|
171
171
|
# @param [Block] block Passed to #each
|
172
|
-
def each_page(&block)
|
173
|
-
page(
|
172
|
+
def each_page(start_page = @options["page"], &block)
|
173
|
+
page(start_page)
|
174
174
|
clear_cache
|
175
175
|
|
176
176
|
while !empty?
|
@@ -48,6 +48,9 @@ module ZendeskAPI
|
|
48
48
|
|
49
49
|
class Upload < Data
|
50
50
|
include Create
|
51
|
+
include Destroy
|
52
|
+
|
53
|
+
def id; token; end
|
51
54
|
|
52
55
|
only_send_unnested_params
|
53
56
|
|
@@ -328,16 +331,9 @@ module ZendeskAPI
|
|
328
331
|
put :request_verification
|
329
332
|
end
|
330
333
|
|
331
|
-
def initialize(*)
|
332
|
-
super
|
333
|
-
|
334
|
-
# Needed for side-loading to work
|
335
|
-
self.role_id = role.id if self.key?(:role)
|
336
|
-
end
|
337
|
-
|
338
334
|
has Organization
|
339
335
|
|
340
|
-
has CustomRole, :include => :roles
|
336
|
+
has CustomRole, :inline => true, :include => :roles
|
341
337
|
has Role, :inline => true, :include_key => :name
|
342
338
|
has Ability, :inline => true
|
343
339
|
|
@@ -41,8 +41,12 @@ module ZendeskAPI
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def regular_writer(key, value)
|
44
|
-
|
45
|
-
|
44
|
+
if self.has_key?(key) && self[key] == value
|
45
|
+
value
|
46
|
+
else
|
47
|
+
changes[key] = value
|
48
|
+
defined?(_store) ? _store(key, value) : super(key, value)
|
49
|
+
end
|
46
50
|
end
|
47
51
|
|
48
52
|
def delete(key)
|
data/lib/zendesk_api/trackie.rb
CHANGED
data/lib/zendesk_api/version.rb
CHANGED
@@ -166,49 +166,86 @@ describe ZendeskAPI::Collection do
|
|
166
166
|
end
|
167
167
|
|
168
168
|
context "each_page" do
|
169
|
-
|
170
|
-
|
171
|
-
:
|
172
|
-
|
173
|
-
|
169
|
+
context "Faraday errors" do
|
170
|
+
before(:each) do
|
171
|
+
stub_json_request(:get, %r{test_resources$}, json(
|
172
|
+
:test_resources => [{:id => 1}], :next_page => "/test_resources?page=2"
|
173
|
+
))
|
174
174
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
))
|
175
|
+
stub_request(:get, %r{test_resources\?page=2}).to_return(:status => 500).then.to_return(
|
176
|
+
:headers => { :content_type => "application/json" }, :status => 200,
|
177
|
+
:body => json(:test_resources => [{:id => 2}], :next_page => "/test_resources?page=3"))
|
179
178
|
|
180
|
-
|
181
|
-
|
179
|
+
stub_request(:get, %r{test_resources\?page=3}).to_return(:status => 404)
|
180
|
+
end
|
182
181
|
|
183
|
-
|
184
|
-
|
185
|
-
# Needed to make sure the arity == 1
|
186
|
-
block.instance_eval do
|
187
|
-
def to_proc
|
188
|
-
@used = true
|
182
|
+
it "should retry from the same page" do
|
183
|
+
class SearchError < Exception; end
|
189
184
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
185
|
+
expect do |b|
|
186
|
+
client.insert_callback do |env|
|
187
|
+
if env[:status] == 500 && env[:url].request_uri =~ /test_resources/
|
188
|
+
raise SearchError
|
194
189
|
end
|
195
190
|
end
|
196
|
-
end
|
197
191
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
192
|
+
begin
|
193
|
+
silence_logger { subject.each_page(&b) }
|
194
|
+
rescue SearchError
|
195
|
+
retry
|
196
|
+
end
|
197
|
+
end.to yield_successive_args(
|
198
|
+
[ZendeskAPI::TestResource.new(client, :id => 1), 1],
|
199
|
+
[ZendeskAPI::TestResource.new(client, :id => 2), 2]
|
200
|
+
)
|
201
|
+
end
|
203
202
|
end
|
204
203
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
204
|
+
context "successful requests" do
|
205
|
+
before(:each) do
|
206
|
+
stub_json_request(:get, %r{test_resources$}, json(
|
207
|
+
:test_resources => [{:id => 1}],
|
208
|
+
:next_page => "/test_resources?page=2"
|
209
|
+
))
|
210
|
+
|
211
|
+
stub_json_request(:get, %r{test_resources\?page=2}, json(
|
212
|
+
:test_resources => [{:id => 2}],
|
213
|
+
:next_page => "/test_resources?page=3"
|
214
|
+
))
|
215
|
+
|
216
|
+
stub_request(:get, %r{test_resources\?page=3}).to_return(:status => 404)
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should yield resource if arity == 1" do
|
220
|
+
expect do |block|
|
221
|
+
# Needed to make sure the arity == 1
|
222
|
+
block.instance_eval do
|
223
|
+
def to_proc
|
224
|
+
@used = true
|
225
|
+
|
226
|
+
probe = self
|
227
|
+
Proc.new do |arg|
|
228
|
+
probe.num_yields += 1
|
229
|
+
probe.yielded_args << [arg]
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
silence_logger { subject.each_page(&block) }
|
235
|
+
end.to yield_successive_args(
|
236
|
+
ZendeskAPI::TestResource.new(client, :id => 1),
|
237
|
+
ZendeskAPI::TestResource.new(client, :id => 2)
|
238
|
+
)
|
239
|
+
end
|
240
|
+
|
241
|
+
it "should yield resource and page" do
|
242
|
+
expect do |b|
|
243
|
+
silence_logger { subject.each_page(&b) }
|
244
|
+
end.to yield_successive_args(
|
245
|
+
[ZendeskAPI::TestResource.new(client, :id => 1), 1],
|
246
|
+
[ZendeskAPI::TestResource.new(client, :id => 2), 2]
|
247
|
+
)
|
248
|
+
end
|
212
249
|
end
|
213
250
|
end
|
214
251
|
|
@@ -12,6 +12,29 @@ describe ZendeskAPI::DataResource do
|
|
12
12
|
ZendeskAPI::Category.resource_name.should == "categories"
|
13
13
|
end
|
14
14
|
|
15
|
+
context "association" do
|
16
|
+
subject { ZendeskAPI::TestResource.new(client, :id => 1) }
|
17
|
+
let(:options) {{}}
|
18
|
+
|
19
|
+
before(:each) do
|
20
|
+
ZendeskAPI::TestResource.has :nil, options.merge(:class => ZendeskAPI::NilDataResource)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should try and find non-existant object" do
|
24
|
+
stub_json_request(:get, %r{test_resources/1/nil}, json(:nil_data_resource => {}))
|
25
|
+
|
26
|
+
subject.nil.should be_instance_of(ZendeskAPI::NilDataResource)
|
27
|
+
end
|
28
|
+
|
29
|
+
context "inline => true" do
|
30
|
+
let(:options) {{ :inline => true }}
|
31
|
+
|
32
|
+
it "should not try and find non-existant object" do
|
33
|
+
subject.nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
15
38
|
context "user" do
|
16
39
|
context "with first order attributes" do
|
17
40
|
subject { ZendeskAPI::TestResource.new(client) }
|
data/spec/core/resource_spec.rb
CHANGED
@@ -239,12 +239,20 @@ describe ZendeskAPI::Resource do
|
|
239
239
|
ZendeskAPI::TestResource.has :nil, :class => ZendeskAPI::NilResource, :inline => true
|
240
240
|
|
241
241
|
subject.nil = { :abc => :def }
|
242
|
-
subject.save_associations
|
243
242
|
end
|
244
243
|
|
245
244
|
it "should save param data" do
|
245
|
+
subject.save_associations
|
246
|
+
|
246
247
|
subject.attributes[:nil].should == "TESTDATA"
|
247
248
|
end
|
249
|
+
|
250
|
+
it "should not save param data when unchanged" do
|
251
|
+
subject.nil.clear_changes
|
252
|
+
subject.save_associations
|
253
|
+
|
254
|
+
subject.attributes[:nil].should be_nil
|
255
|
+
end
|
248
256
|
end
|
249
257
|
|
250
258
|
context "create" do
|
data/spec/core/trackie_spec.rb
CHANGED
@@ -9,7 +9,7 @@ describe ZendeskAPI::Trackie do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
context "adding keys" do
|
12
|
-
before(:each) { subject[:key] = true }
|
12
|
+
before(:each) { subject[:key] = true }
|
13
13
|
|
14
14
|
it "should include key in changes" do
|
15
15
|
subject.changes[:key].should be_true
|
@@ -21,6 +21,24 @@ describe ZendeskAPI::Trackie do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
context "adding identical keys" do
|
25
|
+
before(:each) do
|
26
|
+
subject[:key] = "foo"
|
27
|
+
subject.clear_changes
|
28
|
+
|
29
|
+
subject[:key] = "foo"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should not include key in changes" do
|
33
|
+
subject.changes[:key].should be_false
|
34
|
+
end
|
35
|
+
|
36
|
+
specify "key should not be changed" do
|
37
|
+
subject.changed?(:key).should be_false
|
38
|
+
subject.changed?.should be_false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
24
42
|
context "nested hashes" do
|
25
43
|
before(:each) do
|
26
44
|
subject[:key] = ZendeskAPI::Trackie.new
|
@@ -36,4 +54,14 @@ describe ZendeskAPI::Trackie do
|
|
36
54
|
subject.changed?.should be_true
|
37
55
|
end
|
38
56
|
end
|
57
|
+
|
58
|
+
describe "#size" do
|
59
|
+
before do
|
60
|
+
subject[:size] = 42
|
61
|
+
end
|
62
|
+
|
63
|
+
it "returns the value corresponding to the :size key" do
|
64
|
+
subject.size.should == 42
|
65
|
+
end
|
66
|
+
end
|
39
67
|
end
|
data/spec/live/upload_spec.rb
CHANGED
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.3.
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
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-03-05 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bump
|
@@ -527,7 +527,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
527
527
|
version: 1.3.6
|
528
528
|
requirements: []
|
529
529
|
rubyforge_project:
|
530
|
-
rubygems_version: 1.8.
|
530
|
+
rubygems_version: 1.8.25
|
531
531
|
signing_key:
|
532
532
|
specification_version: 3
|
533
533
|
summary: Zendesk REST API Client
|