zendesk_api 1.4.2 → 1.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +2 -1
- data/lib/zendesk_api/association.rb +7 -1
- data/lib/zendesk_api/client.rb +27 -8
- data/lib/zendesk_api/resource.rb +13 -0
- data/lib/zendesk_api/resources.rb +1 -0
- data/lib/zendesk_api/version.rb +1 -1
- data/spec/core/client_spec.rb +27 -0
- data/spec/core/data_namespace_spec.rb +15 -0
- data/spec/fixtures/test_resources.rb +4 -0
- data/spec/fixtures/zendesk.rb +1 -1
- data/zendesk_api.gemspec +1 -1
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 558412300c43c0e2ce45a0c149261bd0a6d60568
|
4
|
+
data.tar.gz: e64f115c5aa31ada40ff8084bbf2059ac6d53d2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4476bfb5fd72707b5e14a62114d60b30f70e585b59cbc9b695512a666834c55ed3f60367067a0ab39cac12153c88053e53cea913b54a79804279ed9bee3c664
|
7
|
+
data.tar.gz: 7af9a7e1816ad64d83d525e29a5893cc2b0551bb588fb48953412ab41d461af1a3ed648841317d6a767d0d5c8b4bf7948d79e44d2b6f515de7c0571f5ff9bc16
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -324,7 +324,8 @@ client.apps.update!(:id => 123, :upload_id => upload.id)
|
|
324
324
|
|
325
325
|
# Or
|
326
326
|
|
327
|
-
app = ZendeskAPI::App.new(client, :id => 123
|
327
|
+
app = ZendeskAPI::App.new(client, :id => 123)
|
328
|
+
app.upload_id = upload.id
|
328
329
|
app.save!
|
329
330
|
|
330
331
|
# Or
|
@@ -34,7 +34,8 @@ module ZendeskAPI
|
|
34
34
|
namespace = @options[:class].to_s.split("::")
|
35
35
|
namespace[-1] = @options[:class].resource_path
|
36
36
|
|
37
|
-
|
37
|
+
# Remove components without path information
|
38
|
+
ignorable_namespace_strings.each { |ns| namespace.delete(ns) }
|
38
39
|
has_parent = namespace.size > 1 || (options[:with_parent] && @options.parent)
|
39
40
|
|
40
41
|
if has_parent
|
@@ -71,6 +72,11 @@ module ZendeskAPI
|
|
71
72
|
|
72
73
|
private
|
73
74
|
|
75
|
+
# @return [Array<String>] ['ZendeskAPI', 'Voice', etc.. ]
|
76
|
+
def ignorable_namespace_strings
|
77
|
+
ZendeskAPI::DataNamespace.descendants.map { |klass| klass.to_s.split('::') }.flatten.uniq
|
78
|
+
end
|
79
|
+
|
74
80
|
def _side_load(resource, side_loads)
|
75
81
|
side_loads.map! do |side_load|
|
76
82
|
resource.send(:wrap_resource, side_load, options)
|
data/lib/zendesk_api/client.rb
CHANGED
@@ -39,14 +39,15 @@ module ZendeskAPI
|
|
39
39
|
if !options.delete(:reload) && (cached = @resource_cache[method][:cache].read(options.hash))
|
40
40
|
cached
|
41
41
|
else
|
42
|
-
|
43
|
-
klass = class_from_namespace(klass_as_const)
|
44
|
-
|
45
|
-
@resource_cache[method][:class] ||= klass
|
42
|
+
@resource_cache[method][:class] ||= method_as_class(method)
|
46
43
|
@resource_cache[method][:cache].write(options.hash, ZendeskAPI::Collection.new(self, @resource_cache[method][:class], options))
|
47
44
|
end
|
48
45
|
end
|
49
46
|
|
47
|
+
def respond_to?(method, *args)
|
48
|
+
((cache = @resource_cache[method]) && cache[:class]) || !method_as_class(method).nil? || super
|
49
|
+
end
|
50
|
+
|
50
51
|
# Returns the current user (aka me)
|
51
52
|
# @return [ZendeskAPI::User] Current user or nil
|
52
53
|
def current_user(reload = false)
|
@@ -169,16 +170,34 @@ module ZendeskAPI
|
|
169
170
|
|
170
171
|
private
|
171
172
|
|
172
|
-
def class_from_namespace(
|
173
|
-
|
174
|
-
if
|
175
|
-
return ns.const_get(
|
173
|
+
def class_from_namespace(klass_as_string)
|
174
|
+
namespaces.each do |ns|
|
175
|
+
if module_defines_class?(ns, klass_as_string)
|
176
|
+
return ns.const_get(klass_as_string)
|
176
177
|
end
|
177
178
|
end
|
178
179
|
|
179
180
|
nil
|
180
181
|
end
|
181
182
|
|
183
|
+
# 1.9+ changed default to search ancestors, added flag to disable behavior.
|
184
|
+
def module_defines_class?(mod, klass_as_string)
|
185
|
+
if RUBY_VERSION < '1.9'
|
186
|
+
mod.const_defined?(klass_as_string)
|
187
|
+
else
|
188
|
+
mod.const_defined?(klass_as_string, false)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def namespaces
|
193
|
+
[ZendeskAPI] + ZendeskAPI::DataNamespace.descendants
|
194
|
+
end
|
195
|
+
|
196
|
+
def method_as_class(method)
|
197
|
+
klass_as_string = ZendeskAPI::Helpers.modulize_string(Inflection.singular(method.to_s))
|
198
|
+
class_from_namespace(klass_as_string)
|
199
|
+
end
|
200
|
+
|
182
201
|
def check_url
|
183
202
|
if !config.allow_http && config.url !~ /^https/
|
184
203
|
raise ArgumentError, "zendesk_api is ssl only; url must begin with https://"
|
data/lib/zendesk_api/resource.rb
CHANGED
@@ -179,4 +179,17 @@ module ZendeskAPI
|
|
179
179
|
{ self.class.resource_name.to_sym => attributes.changes }
|
180
180
|
end
|
181
181
|
end
|
182
|
+
|
183
|
+
# Namespace parent class for Data/Resource classes
|
184
|
+
module DataNamespace
|
185
|
+
class << self
|
186
|
+
def included(base)
|
187
|
+
@descendants ||= []
|
188
|
+
@descendants << base
|
189
|
+
end
|
190
|
+
def descendants
|
191
|
+
@descendants || []
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
182
195
|
end
|
data/lib/zendesk_api/version.rb
CHANGED
data/spec/core/client_spec.rb
CHANGED
@@ -222,6 +222,33 @@ describe ZendeskAPI::Client do
|
|
222
222
|
it "should cache calls with the same options" do
|
223
223
|
expect(subject.search(:query => 'abc')).to eq(subject.search(:query => 'abc'))
|
224
224
|
end
|
225
|
+
|
226
|
+
it "should respond_to? for valid resources" do
|
227
|
+
expect(subject.respond_to?(:tickets)).to eq(true)
|
228
|
+
end
|
229
|
+
|
230
|
+
it "should respond_to? for valid cached resources" do
|
231
|
+
subject.tickets
|
232
|
+
|
233
|
+
expect(subject.respond_to?(:tickets)).to eq(true)
|
234
|
+
end
|
235
|
+
|
236
|
+
it "should respond_to? for actual instance methods" do
|
237
|
+
expect(subject.respond_to?(:set_default_logger, true)).to eq(true)
|
238
|
+
expect(subject.respond_to?(:set_default_logger)).to eq(false)
|
239
|
+
end
|
240
|
+
|
241
|
+
it "should not respond_to? invalid resources" do
|
242
|
+
expect(subject.respond_to?(:nope)).to eq(false)
|
243
|
+
end
|
244
|
+
|
245
|
+
it "delegates voice correctly" do
|
246
|
+
expect(subject.voice.greetings).to be_instance_of(ZendeskAPI::Collection)
|
247
|
+
end
|
248
|
+
|
249
|
+
it "looks in the appropriate namespaces" do
|
250
|
+
expect(subject.greetings.association.options['class']).to eq(ZendeskAPI::Voice::Greeting)
|
251
|
+
end
|
225
252
|
end
|
226
253
|
|
227
254
|
it "can be subclassed" do
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'core/spec_helper'
|
2
|
+
|
3
|
+
class ZendeskAPI::DataNamespaceTest; end
|
4
|
+
|
5
|
+
describe ZendeskAPI::DataNamespace do
|
6
|
+
describe "descendants" do
|
7
|
+
let(:target_klass) { ZendeskAPI::DataNamespaceTest }
|
8
|
+
it "adds class to its descendants list when included" do
|
9
|
+
expect(ZendeskAPI::DataNamespace.descendants).not_to include(target_klass)
|
10
|
+
expect { target_klass.send(:include, ZendeskAPI::DataNamespace) }.
|
11
|
+
to change { ZendeskAPI::DataNamespace.descendants.count }.by(1)
|
12
|
+
expect(ZendeskAPI::DataNamespace.descendants).to include(target_klass)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -10,3 +10,7 @@ end
|
|
10
10
|
class ZendeskAPI::NilResource < ZendeskAPI::Data; end
|
11
11
|
class ZendeskAPI::NilDataResource < ZendeskAPI::DataResource; end
|
12
12
|
class ZendeskAPI::SingularTestResource < ZendeskAPI::SingularResource; end
|
13
|
+
|
14
|
+
# `client.greetings` should ignore this class, as it's not in the right namespace
|
15
|
+
class Greeting; end
|
16
|
+
|
data/spec/fixtures/zendesk.rb
CHANGED
@@ -55,7 +55,7 @@ module ZendeskAPI
|
|
55
55
|
|
56
56
|
def ticket
|
57
57
|
VCR.use_cassette('valid_ticket') do
|
58
|
-
@ticket ||= client.tickets.
|
58
|
+
@ticket ||= client.tickets.detect {|t| t.status != 'closed'}
|
59
59
|
@ticket ||= client.tickets.create(
|
60
60
|
:subject => "Test Ticket",
|
61
61
|
:description => "This is a test of the emergency alert system.",
|
data/zendesk_api.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.add_development_dependency "yard"
|
27
27
|
|
28
28
|
s.add_runtime_dependency "faraday", "~> 0.9"
|
29
|
-
s.add_runtime_dependency "hashie", ">= 1.2"
|
29
|
+
s.add_runtime_dependency "hashie", ">= 1.2", "< 4.0"
|
30
30
|
s.add_runtime_dependency "inflection"
|
31
31
|
s.add_runtime_dependency "multi_json"
|
32
32
|
s.add_runtime_dependency "mime-types", "~> 1.0"
|
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.
|
4
|
+
version: 1.4.3
|
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: 2014-
|
12
|
+
date: 2014-09-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bump
|
@@ -116,6 +116,9 @@ dependencies:
|
|
116
116
|
- - ">="
|
117
117
|
- !ruby/object:Gem::Version
|
118
118
|
version: '1.2'
|
119
|
+
- - "<"
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '4.0'
|
119
122
|
type: :runtime
|
120
123
|
prerelease: false
|
121
124
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -123,6 +126,9 @@ dependencies:
|
|
123
126
|
- - ">="
|
124
127
|
- !ruby/object:Gem::Version
|
125
128
|
version: '1.2'
|
129
|
+
- - "<"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '4.0'
|
126
132
|
- !ruby/object:Gem::Dependency
|
127
133
|
name: inflection
|
128
134
|
requirement: !ruby/object:Gem::Requirement
|
@@ -232,6 +238,7 @@ files:
|
|
232
238
|
- spec/core/collection_spec.rb
|
233
239
|
- spec/core/configuration_spec.rb
|
234
240
|
- spec/core/create_resource_spec.rb
|
241
|
+
- spec/core/data_namespace_spec.rb
|
235
242
|
- spec/core/data_resource_spec.rb
|
236
243
|
- spec/core/inflection_spec.rb
|
237
244
|
- spec/core/lru_cache_spec.rb
|
@@ -343,6 +350,7 @@ test_files:
|
|
343
350
|
- spec/core/collection_spec.rb
|
344
351
|
- spec/core/configuration_spec.rb
|
345
352
|
- spec/core/create_resource_spec.rb
|
353
|
+
- spec/core/data_namespace_spec.rb
|
346
354
|
- spec/core/data_resource_spec.rb
|
347
355
|
- spec/core/inflection_spec.rb
|
348
356
|
- spec/core/lru_cache_spec.rb
|