zendesk_api 1.9.1 → 1.9.2
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.
- checksums.yaml +4 -4
- data/lib/zendesk_api/actions.rb +4 -4
- data/lib/zendesk_api/collection.rb +17 -1
- data/lib/zendesk_api/version.rb +1 -1
- data/spec/core/collection_spec.rb +20 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c0668873d6863859d423460120ad1f26f5fcbbf
|
4
|
+
data.tar.gz: ed41d94e6c305a99128c0f168b9bdf94c45fe16d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ade3e680e0f974e0661ccca4838eedd48b500a2042120b7847739b817845047ff1c478c114c07a08913e0f2c8851e1b50196e65b017da1ca976a4bf779b0cffc
|
7
|
+
data.tar.gz: 32d63c8526860913545c2e22bbae5792da1a4fd5b0b40d3d6fb9f7af4303b073dda993fb5f79f56d4a5b503c0d6908c30d2bf67feba055b2a3080c3962349173
|
data/lib/zendesk_api/actions.rb
CHANGED
@@ -160,8 +160,8 @@ module ZendeskAPI
|
|
160
160
|
end
|
161
161
|
|
162
162
|
module CreateMany
|
163
|
-
def create_many!(client, attributes_array)
|
164
|
-
response = client.connection.post("#{
|
163
|
+
def create_many!(client, attributes_array, association = Association.new(:class => self))
|
164
|
+
response = client.connection.post("#{association.generate_path}/create_many") do |req|
|
165
165
|
req.body = { resource_name => attributes_array }
|
166
166
|
|
167
167
|
yield req if block_given?
|
@@ -218,8 +218,8 @@ module ZendeskAPI
|
|
218
218
|
end
|
219
219
|
|
220
220
|
module DestroyMany
|
221
|
-
def destroy_many!(client, ids)
|
222
|
-
response = client.connection.delete("#{
|
221
|
+
def destroy_many!(client, ids, association = Association.new(:class => self))
|
222
|
+
response = client.connection.delete("#{association.generate_path}/destroy_many") do |req|
|
223
223
|
req.params = { :ids => ids }
|
224
224
|
|
225
225
|
yield req if block_given?
|
@@ -46,9 +46,9 @@ module ZendeskAPI
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
+
# Methods that take a Hash argument
|
49
50
|
methods = %w{create find update destroy}
|
50
51
|
methods += methods.map {|method| method + "!"}
|
51
|
-
methods += %w{create_many! destroy_many!}
|
52
52
|
methods.each do |deferrable|
|
53
53
|
# Passes arguments and the proper path to the resource class method.
|
54
54
|
# @param [Hash] options Options or attributes to pass
|
@@ -64,6 +64,22 @@ module ZendeskAPI
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
+
# Methods that take an Array argument
|
68
|
+
methods = %w{create_many! destroy_many!}
|
69
|
+
methods.each do |deferrable|
|
70
|
+
# Passes arguments and the proper path to the resource class method.
|
71
|
+
# @param [Array] array arguments
|
72
|
+
define_method deferrable do |*args|
|
73
|
+
unless @resource_class.respond_to?(deferrable)
|
74
|
+
raise NoMethodError.new("undefined method \"#{deferrable}\" for #{@resource_class}", deferrable, args)
|
75
|
+
end
|
76
|
+
|
77
|
+
array = args.last.is_a?(Array) ? args.pop : []
|
78
|
+
|
79
|
+
@resource_class.send(deferrable, @client, array, @association)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
67
83
|
# Convenience method to build a new resource and
|
68
84
|
# add it to the collection. Fetches the collection as well.
|
69
85
|
# @param [Hash] options Options or attributes to pass
|
data/lib/zendesk_api/version.rb
CHANGED
@@ -24,23 +24,41 @@ describe ZendeskAPI::Collection do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
context "deferral" do
|
27
|
-
|
28
|
-
|
27
|
+
it "should defer #create_many! to the resource class" do
|
28
|
+
collection = ZendeskAPI::Collection.new(client, ZendeskAPI::BulkTestResource)
|
29
|
+
stub_json_request(:post, %r{bulk_test_resources/create_many$}, json(:job_status => {}))
|
30
|
+
collection.create_many!([{:name => 'Mick'}, {:name => 'Steven'}])
|
31
|
+
assert_requested(:post, %r{bulk_test_resources/create_many$},
|
32
|
+
:body => {
|
33
|
+
:bulk_test_resources => [{:name => 'Mick'}, {:name => 'Steven'}]
|
34
|
+
}
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should defer #destroy_many! to the resource class" do
|
39
|
+
collection = ZendeskAPI::Collection.new(client, ZendeskAPI::BulkTestResource)
|
40
|
+
stub_json_request(:delete, %r{bulk_test_resources/destroy_many\?}, json(:job_status => {}))
|
41
|
+
collection.destroy_many!([1,2,3])
|
42
|
+
assert_requested(:delete, %r{bulk_test_resources/destroy_many\?ids%5B%5D=1&ids%5B%5D=2&ids%5B%5D=3$})
|
29
43
|
end
|
30
44
|
|
31
45
|
it "should defer #create to the resource class" do
|
46
|
+
stub_json_request(:post, %r{test_resources$}, json(:test_resource => {}))
|
32
47
|
subject.create
|
33
48
|
end
|
34
49
|
|
35
50
|
it "should defer #find to the resource class" do
|
51
|
+
stub_json_request(:get, %r{test_resources/1$}, json(:test_resource => {}))
|
36
52
|
subject.find(:id => 1)
|
37
53
|
end
|
38
54
|
|
39
55
|
it "should defer #destroy to the resource class" do
|
56
|
+
stub_json_request(:delete, %r{test_resources/1$}, json(:test_resource => {}))
|
40
57
|
subject.destroy(:id => 1)
|
41
58
|
end
|
42
59
|
|
43
60
|
it "should defer #update to the resource class" do
|
61
|
+
stub_json_request(:put, %r{test_resources/1$}, json(:test_resource => {}))
|
44
62
|
subject.update(:id => 1)
|
45
63
|
end
|
46
64
|
|
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: 1.9.
|
4
|
+
version: 1.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Davidovitz
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-06-
|
12
|
+
date: 2015-06-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bump
|