zendesk_api 1.4.0 → 1.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1d07ce370fb28464897785ae66e33e426fc65b1f
4
- data.tar.gz: df2e6e5fed6d5bb977b0707b7f46e7396a3c8c70
3
+ metadata.gz: 9c3a7d321889f60c5c4d0f0c2c4170351b271c6b
4
+ data.tar.gz: 2de81c86986e49e8f925fb52ee77eee475bf18e7
5
5
  SHA512:
6
- metadata.gz: 789311dcc288abb846bd53a6301df3f1c60988aefec37949272d260e58a85d2fa3faca796f50814578fc377acf813b159fccbe67328a334405b81f596f58fbd6
7
- data.tar.gz: 19fc5162ac0a2956a4d6a70cfe082d39dcfdc87d56f81e3c5a53c11442882a507485e5a61529f350700ffbc9d0b32da38f6fb825111b72c6212ba3f1aaf756c6
6
+ metadata.gz: 7127ae993715fe0b818ba71e55f0287847d671bd08d0920a2188e58211dac67643a1b09b5647790cca95e225c35f75bd7f0d030dcb72cff98a27d1f37358d9dd
7
+ data.tar.gz: fdf856dbb4229b36059b96cce96bc1db1037482ced53b33eed92f161ed7ed6dc9e18aad7abd6da880ca196b4c60c95e7c581723699f4b9aca43f14bf8131a958
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zendesk_api (1.4.0)
4
+ zendesk_api (1.4.2)
5
5
  faraday (~> 0.9)
6
6
  hashie (>= 1.2)
7
7
  inflection
data/README.md CHANGED
@@ -16,6 +16,7 @@ Please check out the [wiki](https://github.com/zendesk/zendesk_api_client_rb/wik
16
16
  * Version 1.0.0 changes the way errors are handled. Please see the [wiki page](https://github.com/zendesk/zendesk_api_client_rb/wiki/Errors) for more info.
17
17
  * Version 1.3.0 updates the Faraday dependency to 0.9. Since Faraday did not bump a major version we have not either, but there is no guarantee >= 1.3.0 works with Faraday < 0.9
18
18
  * Version 1.3.8 had a bug where attachments were created, but the response was not handled properly
19
+ * Version >= 1.0 and < 1.4.2 had a bug where non application/json response bodies were discarded
19
20
 
20
21
  ## Installation
21
22
 
@@ -1,7 +1,7 @@
1
1
  module ZendeskAPI
2
2
  module ResponseHandler
3
3
  def handle_response(response)
4
- if response.body && response.body[self.class.singular_resource_name]
4
+ if response.body.is_a?(Hash) && response.body[self.class.singular_resource_name]
5
5
  @attributes.replace(@attributes.deep_merge(response.body[self.class.singular_resource_name]))
6
6
  end
7
7
  end
@@ -387,7 +387,7 @@ module ZendeskAPI
387
387
  end
388
388
 
389
389
  def handle_response(response_body)
390
- unless response_body
390
+ unless response_body.is_a?(Hash)
391
391
  raise ZendeskAPI::Error::NetworkError, @response.env
392
392
  end
393
393
 
@@ -7,7 +7,7 @@ module ZendeskAPI
7
7
  # @private
8
8
  class Deflate < Faraday::Response::Middleware
9
9
  def on_complete(env)
10
- if env.body.respond_to?(:to_str) && !env.body.strip.empty? && env[:response_headers]['content-encoding'] == "deflate"
10
+ if !env.body.strip.empty? && env[:response_headers]['content-encoding'] == "deflate"
11
11
  env.body = Zlib::Inflate.inflate(env.body)
12
12
  end
13
13
  end
@@ -9,7 +9,7 @@ module ZendeskAPI
9
9
  # Faraday middleware to handle content-encoding = gzip
10
10
  class Gzip < Faraday::Response::Middleware
11
11
  def on_complete(env)
12
- if env[:body].respond_to?(:to_str) && !env[:body].strip.empty? && env[:response_headers]['content-encoding'] == "gzip"
12
+ if !env[:body].strip.empty? && env[:response_headers]['content-encoding'] == "gzip"
13
13
  env[:body] = Zlib::GzipReader.new(StringIO.new(env[:body])).read
14
14
  end
15
15
  end
@@ -12,10 +12,10 @@ module ZendeskAPI
12
12
  type = type.split(';', 2).first if type.index(';')
13
13
  type
14
14
 
15
- if type == 'application/json' && env[:body].respond_to?(:to_str) && !env[:body].strip.empty?
15
+ return unless type == 'application/json'
16
+
17
+ unless env[:body].strip.empty?
16
18
  env[:body] = JSON.parse(env[:body])
17
- else
18
- env[:body] = nil
19
19
  end
20
20
  end
21
21
  end
@@ -118,6 +118,12 @@ module ZendeskAPI
118
118
  end
119
119
 
120
120
  class Brand < Resource
121
+ def destroy!
122
+ self.active = false
123
+ save!
124
+
125
+ super
126
+ end
121
127
  end
122
128
 
123
129
  class ForumSubscription < Resource
@@ -511,13 +517,6 @@ module ZendeskAPI
511
517
  put :request_verification
512
518
  end
513
519
 
514
- def initialize(*)
515
- super
516
-
517
- # Needed for proper Role sideloading
518
- self.role_id = role.name if key?(:role)
519
- end
520
-
521
520
  any :password
522
521
 
523
522
  # Set a user's password
@@ -573,6 +572,13 @@ module ZendeskAPI
573
572
 
574
573
  { self.class.singular_resource_name => attrs }
575
574
  end
575
+
576
+ def handle_response(*)
577
+ super
578
+
579
+ # Needed for proper Role sideloading
580
+ self.role_id = role.name if key?(:role)
581
+ end
576
582
  end
577
583
 
578
584
  class UserField < Resource; end
@@ -1,3 +1,3 @@
1
1
  module ZendeskAPI
2
- VERSION = "1.4.0"
2
+ VERSION = "1.4.2"
3
3
  end
@@ -29,7 +29,7 @@ describe ZendeskAPI::Middleware::Response::ParseIsoDates do
29
29
  end
30
30
 
31
31
  it "should not blow up on empty body" do
32
- expect(fake_response('').body).to eq(nil)
32
+ expect(fake_response('').body).to eq('')
33
33
  end
34
34
 
35
35
  it "should leave arrays with ids alone" do
@@ -11,8 +11,8 @@ describe ZendeskAPI::Middleware::Response::ParseJson do
11
11
  )
12
12
  end
13
13
 
14
- it "should return nil body" do
15
- expect(client.connection.get("blergh").body).to be_nil
14
+ it "should not return nil body" do
15
+ expect(client.connection.get("blergh").body).to eql('<nope></nope>')
16
16
  end
17
17
  end
18
18
 
@@ -29,16 +29,16 @@ describe ZendeskAPI::Middleware::Response::ParseJson do
29
29
  context "with a nil body" do
30
30
  let(:body) { nil }
31
31
 
32
- it "should return nil body" do
33
- expect(client.connection.get("blergh").body).to be_nil
32
+ it "should return empty body" do
33
+ expect(client.connection.get("blergh").body).to eql('')
34
34
  end
35
35
  end
36
36
 
37
37
  context "with a empty body" do
38
38
  let(:body) { '' }
39
39
 
40
- it "should return nil body" do
41
- expect(client.connection.get("blergh").body).to be_nil
40
+ it "should return empty body" do
41
+ expect(client.connection.get("blergh").body).to eql('')
42
42
  end
43
43
  end
44
44
 
@@ -85,7 +85,9 @@ module ZendeskAPI
85
85
 
86
86
  def brand
87
87
  VCR.use_cassette('valid_brand') do
88
- @brand ||= current_user.brand
88
+ @brand ||= client.brands.detect do |brand|
89
+ client.config.url.start_with?(brand.brand_url)
90
+ end
89
91
  end
90
92
  end
91
93
  end
@@ -2,11 +2,13 @@ require 'core/spec_helper'
2
2
 
3
3
  describe ZendeskAPI::Brand, :delete_after do
4
4
  def valid_attributes
5
- { :name => "Awesome-O" }
5
+ { :name => "awesomesauce", :subdomain => "zendeskapi#{SecureRandom.hex(3)}" }
6
6
  end
7
7
 
8
8
  it_should_be_creatable
9
9
  it_should_be_updatable :name
10
- it_should_be_deletable
11
- it_should_be_readable :brands, :create => true
10
+ it_should_be_readable :brands
11
+
12
+ # Deleted brands are still findable by id, but in the index action
13
+ it_should_be_deletable :find => nil
12
14
  end
@@ -13,15 +13,17 @@ describe ZendeskAPI::Macro, :delete_after do
13
13
  it_should_be_deletable
14
14
 
15
15
  describe "application", :vcr do
16
- subject do
16
+ subject { @object }
17
+
18
+ before :all do
17
19
  VCR.use_cassette("#{described_class.to_s}_application_create") do
18
- described_class.create(client, valid_attributes.merge(default_options))
20
+ @object = described_class.create(client, valid_attributes.merge(default_options))
19
21
  end
20
22
  end
21
23
 
22
24
  after :all do
23
25
  VCR.use_cassette("#{described_class.to_s}_application_delete") do
24
- subject.destroy
26
+ @object.destroy
25
27
  end
26
28
  end
27
29
 
@@ -21,7 +21,6 @@ describe ZendeskAPI::Ticket do
21
21
  it_should_be_readable user, :requested_tickets
22
22
  it_should_be_readable agent, :ccd_tickets
23
23
  it_should_be_readable organization, :tickets
24
- it_should_be_readable brand, :tickets
25
24
 
26
25
  context "recent tickets" do
27
26
  before(:all) do
@@ -96,14 +96,14 @@ module ResourceMacros
96
96
  end
97
97
  end
98
98
 
99
- it "should be destroyable" do
99
+ it "should be destroyable" do |example|
100
100
  expect(@object.destroy).to be(true)
101
101
  expect(@object.destroyed?).to be(true)
102
102
 
103
103
  if (!options.key?(:find) || options[:find]) && !example.metadata[:not_findable]
104
104
  opts = default_options
105
105
  opts.merge!(:id => @object.id) unless described_class.ancestors.include?(ZendeskAPI::SingularResource)
106
- obj = silence_logger{ described_class.find(client, opts) }
106
+ obj = described_class.find(client, opts)
107
107
 
108
108
  if options[:find]
109
109
  expect(obj.send(options[:find].first)).to eq(options[:find].last)
@@ -134,14 +134,23 @@ module ResourceMacros
134
134
  end
135
135
  end if create
136
136
 
137
- it "should be findable" do
137
+ it "should be findable" do |example|
138
138
  result = klass
139
139
  args.each {|a| result = result.send(a, options) }
140
140
 
141
141
  if result.is_a?(ZendeskAPI::Collection)
142
- expect(result.fetch(true)).to_not be_empty
143
- expect(result.fetch).to include(@object) if create
144
- object = result.first
142
+ if create
143
+ object = nil
144
+
145
+ result.all do |o|
146
+ object = o if @object == o
147
+ end
148
+
149
+ expect(object).to_not be_nil
150
+ else
151
+ expect(result.fetch(true)).to_not be_empty
152
+ object = result.first
153
+ end
145
154
  else
146
155
  expect(result).to_not be_nil
147
156
  expect(result).to eq(@object) if create
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.0
4
+ version: 1.4.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: 2014-07-18 00:00:00.000000000 Z
12
+ date: 2014-08-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bump