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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c3a7d321889f60c5c4d0f0c2c4170351b271c6b
4
- data.tar.gz: 2de81c86986e49e8f925fb52ee77eee475bf18e7
3
+ metadata.gz: 558412300c43c0e2ce45a0c149261bd0a6d60568
4
+ data.tar.gz: e64f115c5aa31ada40ff8084bbf2059ac6d53d2b
5
5
  SHA512:
6
- metadata.gz: 7127ae993715fe0b818ba71e55f0287847d671bd08d0920a2188e58211dac67643a1b09b5647790cca95e225c35f75bd7f0d030dcb72cff98a27d1f37358d9dd
7
- data.tar.gz: fdf856dbb4229b36059b96cce96bc1db1037482ced53b33eed92f161ed7ed6dc9e18aad7abd6da880ca196b4c60c95e7c581723699f4b9aca43f14bf8131a958
6
+ metadata.gz: f4476bfb5fd72707b5e14a62114d60b30f70e585b59cbc9b695512a666834c55ed3f60367067a0ab39cac12153c88053e53cea913b54a79804279ed9bee3c664
7
+ data.tar.gz: 7af9a7e1816ad64d83d525e29a5893cc2b0551bb588fb48953412ab41d461af1a3ed648841317d6a767d0d5c8b4bf7948d79e44d2b6f515de7c0571f5ff9bc16
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zendesk_api (1.4.2)
4
+ zendesk_api (1.4.3)
5
5
  faraday (~> 0.9)
6
- hashie (>= 1.2)
6
+ hashie (>= 1.2, < 4.0)
7
7
  inflection
8
8
  mime-types (~> 1.0)
9
9
  multi_json
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, :upload_id => upload.id)
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
- %w(ZendeskAPI Voice).each { |ns| namespace.delete(ns) }
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)
@@ -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
- klass_as_const = ZendeskAPI::Helpers.modulize_string(Inflection.singular(method))
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(klass_as_const)
173
- [ZendeskAPI, ZendeskAPI::Voice].each do |ns|
174
- if ns.const_defined?(klass_as_const)
175
- return ns.const_get(klass_as_const)
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://"
@@ -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
@@ -604,6 +604,7 @@ module ZendeskAPI
604
604
  class Target < Resource; end
605
605
 
606
606
  module Voice
607
+ include DataNamespace
607
608
  class PhoneNumber < Resource
608
609
  namespace "channels/voice"
609
610
  end
@@ -1,3 +1,3 @@
1
1
  module ZendeskAPI
2
- VERSION = "1.4.2"
2
+ VERSION = "1.4.3"
3
3
  end
@@ -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
+
@@ -55,7 +55,7 @@ module ZendeskAPI
55
55
 
56
56
  def ticket
57
57
  VCR.use_cassette('valid_ticket') do
58
- @ticket ||= client.tickets.first
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.2
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-08-15 00:00:00.000000000 Z
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