zendesk_api 1.8.0 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zendesk_api/actions.rb +61 -27
- data/lib/zendesk_api/resource.rb +10 -2
- data/lib/zendesk_api/resources.rb +3 -0
- data/lib/zendesk_api/version.rb +1 -1
- data/spec/core/bulk_actions_spec.rb +45 -0
- data/spec/core/read_resource_spec.rb +20 -0
- data/spec/fixtures/test_resources.rb +5 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7ceae5c77434c64d5c127b60223bf116aea9886
|
4
|
+
data.tar.gz: fda68db40b3a1433387b9d5493f2a82afef0c56e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13e01aca05908e6046cfe6da59ef99f9f5bb83db4287de96596ccbf6365ba8055b6cec8df5f5ad1b55a425afcb7291fdd37920ffe52408b3b163f42e58c7433b
|
7
|
+
data.tar.gz: 272d233f0a6e56cd4985ad3fee74d93d1c5557a7b479e31286dc78cf78a67fe3890724b725a21ba5329c54018ff6845391f7a4134b133a0f7162e00beb9908ec
|
data/lib/zendesk_api/actions.rb
CHANGED
@@ -83,42 +83,52 @@ module ZendeskAPI
|
|
83
83
|
end
|
84
84
|
|
85
85
|
module Read
|
86
|
-
|
87
|
-
|
88
|
-
|
86
|
+
include ResponseHandler
|
87
|
+
include ZendeskAPI::Sideloading
|
88
|
+
|
89
|
+
def self.included(base)
|
90
|
+
base.extend(ClassMethods)
|
91
|
+
end
|
92
|
+
|
93
|
+
def reload!
|
94
|
+
response = client.connection.get(path) do |req|
|
95
|
+
yield req if block_given?
|
96
|
+
end
|
97
|
+
|
98
|
+
handle_response(response)
|
99
|
+
attributes.clear_changes
|
100
|
+
self
|
89
101
|
end
|
90
102
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
103
|
+
module ClassMethods
|
104
|
+
# Finds a resource by an id and any options passed in.
|
105
|
+
# A custom path to search at can be passed into opts. It defaults to the {Data.resource_name} of the class.
|
106
|
+
# @param [Client] client The {Client} object to be used
|
107
|
+
# @param [Hash] options Any additional GET parameters to be added
|
108
|
+
def find!(client, options = {})
|
109
|
+
@client = client # so we can use client.logger in rescue
|
97
110
|
|
98
|
-
|
99
|
-
|
111
|
+
raise ArgumentError, "No :id given" unless options[:id] || options["id"] || ancestors.include?(SingularResource)
|
112
|
+
association = options.delete(:association) || Association.new(:class => self)
|
100
113
|
|
101
|
-
|
102
|
-
|
114
|
+
includes = Array(options[:include])
|
115
|
+
options[:include] = includes.join(",") if includes.any?
|
103
116
|
|
104
|
-
|
105
|
-
|
117
|
+
response = client.connection.get(association.generate_path(options)) do |req|
|
118
|
+
req.params = options
|
106
119
|
|
107
|
-
|
108
|
-
|
120
|
+
yield req if block_given?
|
121
|
+
end
|
109
122
|
|
110
|
-
|
111
|
-
resource.handle_response(response)
|
112
|
-
resource.set_includes(resource, includes, response.body)
|
113
|
-
resource.attributes.clear_changes
|
123
|
+
new_from_response(client, response, includes)
|
114
124
|
end
|
115
|
-
end
|
116
125
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
126
|
+
# Finds, returning nil if it fails
|
127
|
+
def find(client, options = {}, &block)
|
128
|
+
find!(client, options, &block)
|
129
|
+
rescue ZendeskAPI::Error::ClientError => e
|
130
|
+
nil
|
131
|
+
end
|
122
132
|
end
|
123
133
|
end
|
124
134
|
|
@@ -149,6 +159,18 @@ module ZendeskAPI
|
|
149
159
|
end
|
150
160
|
end
|
151
161
|
|
162
|
+
module CreateMany
|
163
|
+
def create_many!(client, attributes_array)
|
164
|
+
response = client.connection.post("#{resource_path}/create_many") do |req|
|
165
|
+
req.body = { resource_name => attributes_array }
|
166
|
+
|
167
|
+
yield req if block_given?
|
168
|
+
end
|
169
|
+
|
170
|
+
JobStatus.new_from_response(client, response)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
152
174
|
module Destroy
|
153
175
|
def self.included(klass)
|
154
176
|
klass.extend(ClassMethod)
|
@@ -195,6 +217,18 @@ module ZendeskAPI
|
|
195
217
|
end
|
196
218
|
end
|
197
219
|
|
220
|
+
module DestroyMany
|
221
|
+
def destroy_many!(client, ids)
|
222
|
+
response = client.connection.delete("#{resource_path}/destroy_many") do |req|
|
223
|
+
req.params = { :ids => ids }
|
224
|
+
|
225
|
+
yield req if block_given?
|
226
|
+
end
|
227
|
+
|
228
|
+
JobStatus.new_from_response(client, response)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
198
232
|
module Update
|
199
233
|
include Save
|
200
234
|
|
data/lib/zendesk_api/resource.rb
CHANGED
@@ -66,6 +66,14 @@ module ZendeskAPI
|
|
66
66
|
@attributes.clear_changes unless new_record?
|
67
67
|
end
|
68
68
|
|
69
|
+
def self.new_from_response(client, response, includes = nil)
|
70
|
+
new(client).tap do |resource|
|
71
|
+
resource.handle_response(response)
|
72
|
+
resource.set_includes(resource, includes, response.body) if includes
|
73
|
+
resource.attributes.clear_changes
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
69
77
|
# Passes the method onto the attributes hash.
|
70
78
|
# If the attributes are nested (e.g. { :tickets => { :id => 1 } }), passes the method onto the nested hash.
|
71
79
|
def method_missing(*args, &block)
|
@@ -147,7 +155,7 @@ module ZendeskAPI
|
|
147
155
|
|
148
156
|
# Represents a resource that can only GET
|
149
157
|
class ReadResource < DataResource
|
150
|
-
|
158
|
+
include Read
|
151
159
|
end
|
152
160
|
|
153
161
|
# Represents a resource that can only POST
|
@@ -167,7 +175,7 @@ module ZendeskAPI
|
|
167
175
|
|
168
176
|
# Represents a resource that can CRUD (create, read, update, delete).
|
169
177
|
class Resource < DataResource
|
170
|
-
|
178
|
+
include Read
|
171
179
|
include Create
|
172
180
|
|
173
181
|
include Update
|
data/lib/zendesk_api/version.rb
CHANGED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'core/spec_helper'
|
2
|
+
|
3
|
+
describe ZendeskAPI::DestroyMany do
|
4
|
+
subject { ZendeskAPI::BulkTestResource }
|
5
|
+
|
6
|
+
context "destroy_many!" do
|
7
|
+
before(:each) do
|
8
|
+
stub_json_request(:delete, %r{bulk_test_resources/destroy_many}, json(:job_status => {:id => 'abc'}))
|
9
|
+
@response = subject.destroy_many!(client, [1,2,3])
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'calls the destroy_many endpoint' do
|
13
|
+
assert_requested(:delete, %r{bulk_test_resources/destroy_many\?ids%5B%5D=1&ids%5B%5D=2&ids%5B%5D=3})
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'returns a JobStatus' do
|
17
|
+
expect(@response).to be_instance_of(ZendeskAPI::JobStatus)
|
18
|
+
expect(@response.id).to eq('abc')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe ZendeskAPI::CreateMany do
|
24
|
+
subject { ZendeskAPI::BulkTestResource }
|
25
|
+
|
26
|
+
context "create_many!" do
|
27
|
+
let(:attributes) { [{:name => 'A'}, {:name => 'B'}] }
|
28
|
+
|
29
|
+
before(:each) do
|
30
|
+
stub_json_request(:post, %r{bulk_test_resources/create_many}, json(:job_status => {:id => 'def'}))
|
31
|
+
@response = subject.create_many!(client, attributes)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'calls the create_many endpoint' do
|
35
|
+
assert_requested(:post, %r{bulk_test_resources/create_many},
|
36
|
+
:body => json(:bulk_test_resources => attributes)
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'returns a JobStatus' do
|
41
|
+
expect(@response).to be_instance_of(ZendeskAPI::JobStatus)
|
42
|
+
expect(@response.id).to eq('def')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -73,5 +73,25 @@ describe ZendeskAPI::ReadResource do
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
end
|
76
|
+
|
77
|
+
context "#reload!" do
|
78
|
+
let(:id) { 2 }
|
79
|
+
|
80
|
+
subject { ZendeskAPI::TestResource.new(client, :id => id, :name => 'Old Name') }
|
81
|
+
|
82
|
+
before(:each) do
|
83
|
+
stub_json_request(:get, %r{test_resources/#{id}}, json("test_resource" => {:id => id, :name => "New Name" }))
|
84
|
+
end
|
85
|
+
|
86
|
+
it "reloads the data" do
|
87
|
+
expect(subject.name).to eq('Old Name')
|
88
|
+
assert_not_requested(:get, %r{test_resources/#{id}})
|
89
|
+
|
90
|
+
subject.reload!
|
91
|
+
|
92
|
+
assert_requested(:get, %r{test_resources/#{id}})
|
93
|
+
expect(subject.name).to eq('New Name')
|
94
|
+
end
|
95
|
+
end
|
76
96
|
end
|
77
97
|
|
@@ -7,6 +7,11 @@ class ZendeskAPI::TestResource < ZendeskAPI::Resource
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
+
class ZendeskAPI::BulkTestResource < ZendeskAPI::DataResource
|
11
|
+
extend ZendeskAPI::CreateMany
|
12
|
+
extend ZendeskAPI::DestroyMany
|
13
|
+
end
|
14
|
+
|
10
15
|
class ZendeskAPI::NilResource < ZendeskAPI::Data; end
|
11
16
|
class ZendeskAPI::NilDataResource < ZendeskAPI::DataResource; end
|
12
17
|
class ZendeskAPI::SingularTestResource < ZendeskAPI::SingularResource; end
|
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.
|
4
|
+
version: 1.9.0
|
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-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bump
|
@@ -239,6 +239,7 @@ files:
|
|
239
239
|
- lib/zendesk_api/verbs.rb
|
240
240
|
- lib/zendesk_api/version.rb
|
241
241
|
- spec/core/association_spec.rb
|
242
|
+
- spec/core/bulk_actions_spec.rb
|
242
243
|
- spec/core/client_spec.rb
|
243
244
|
- spec/core/collection_spec.rb
|
244
245
|
- spec/core/configuration_spec.rb
|
@@ -351,12 +352,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
351
352
|
version: 1.3.6
|
352
353
|
requirements: []
|
353
354
|
rubyforge_project:
|
354
|
-
rubygems_version: 2.
|
355
|
+
rubygems_version: 2.2.2
|
355
356
|
signing_key:
|
356
357
|
specification_version: 4
|
357
358
|
summary: Zendesk REST API Client
|
358
359
|
test_files:
|
359
360
|
- spec/core/association_spec.rb
|
361
|
+
- spec/core/bulk_actions_spec.rb
|
360
362
|
- spec/core/client_spec.rb
|
361
363
|
- spec/core/collection_spec.rb
|
362
364
|
- spec/core/configuration_spec.rb
|