zendesk_api 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/zendesk_api/collection.rb +7 -4
- data/lib/zendesk_api/middleware/response/raise_error.rb +7 -0
- data/lib/zendesk_api/resource.rb +2 -2
- data/lib/zendesk_api/version.rb +1 -1
- data/spec/core/collection_spec.rb +16 -0
- data/spec/core/middleware/response/raise_error_spec.rb +45 -22
- metadata +2 -2
data/Gemfile.lock
CHANGED
@@ -126,7 +126,7 @@ module ZendeskAPI
|
|
126
126
|
raise "this collection is for #{@resource_class}"
|
127
127
|
end
|
128
128
|
else
|
129
|
-
@resources << wrap_resource(item)
|
129
|
+
@resources << wrap_resource(item, true)
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
@@ -363,14 +363,17 @@ module ZendeskAPI
|
|
363
363
|
end
|
364
364
|
|
365
365
|
# Simplified Associations#wrap_resource
|
366
|
-
def wrap_resource(res)
|
366
|
+
def wrap_resource(res, with_association = @resource_class == Tag)
|
367
367
|
case res
|
368
368
|
when Array
|
369
369
|
wrap_resource(Hash[*res])
|
370
370
|
when Hash
|
371
|
-
|
371
|
+
res = res.merge(:association => @association) if with_association
|
372
|
+
@resource_class.new(@client, res)
|
372
373
|
else
|
373
|
-
|
374
|
+
res = { :id => res }
|
375
|
+
res.merge!(:association => @association) if with_association
|
376
|
+
@resource_class.new(@client, res)
|
374
377
|
end
|
375
378
|
end
|
376
379
|
|
@@ -4,6 +4,13 @@ module ZendeskAPI
|
|
4
4
|
module Middleware
|
5
5
|
module Response
|
6
6
|
class RaiseError < Faraday::Response::RaiseError
|
7
|
+
|
8
|
+
def call(env)
|
9
|
+
super
|
10
|
+
rescue Faraday::Error::TimeoutError, Faraday::Error::ConnectionFailed => e
|
11
|
+
raise Error::NetworkError.new(e)
|
12
|
+
end
|
13
|
+
|
7
14
|
def on_complete(env)
|
8
15
|
case env[:status]
|
9
16
|
when 404
|
data/lib/zendesk_api/resource.rb
CHANGED
@@ -92,8 +92,8 @@ module ZendeskAPI
|
|
92
92
|
end
|
93
93
|
|
94
94
|
# Returns the path to the resource
|
95
|
-
def path(
|
96
|
-
@association.generate_path(self,
|
95
|
+
def path(options = {})
|
96
|
+
@association.generate_path(self, options)
|
97
97
|
end
|
98
98
|
|
99
99
|
# Passes #to_json to the underlying attributes hash
|
data/lib/zendesk_api/version.rb
CHANGED
@@ -703,5 +703,21 @@ describe ZendeskAPI::Collection do
|
|
703
703
|
subject.create
|
704
704
|
end
|
705
705
|
end
|
706
|
+
|
707
|
+
context "resources" do
|
708
|
+
before(:each) do
|
709
|
+
stub_json_request(:get, %r{test_resources/active},
|
710
|
+
json(:test_resources => [{ :id => 1 }]))
|
711
|
+
|
712
|
+
subject.fetch
|
713
|
+
|
714
|
+
stub_json_request(:put, %r{test_resources/1})
|
715
|
+
end
|
716
|
+
|
717
|
+
it "should not save using the collection path" do
|
718
|
+
resource = subject.first
|
719
|
+
resource.save
|
720
|
+
end
|
721
|
+
end
|
706
722
|
end
|
707
723
|
end
|
@@ -1,40 +1,63 @@
|
|
1
1
|
require 'core/spec_helper'
|
2
2
|
|
3
3
|
describe ZendeskAPI::Middleware::Response::RaiseError do
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
context "with a failed connection" do
|
5
|
+
context "connection failed" do
|
6
|
+
before(:each) do
|
7
|
+
stub_request(:any, /.*/).to_raise(Faraday::Error::ConnectionFailed)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should raise NetworkError" do
|
11
|
+
expect { client.connection.get "/non_existent" }.to raise_error(ZendeskAPI::Error::NetworkError)
|
12
|
+
end
|
13
|
+
end
|
7
14
|
|
8
|
-
|
9
|
-
|
15
|
+
context "connection timeout" do
|
16
|
+
before(:each) do
|
17
|
+
stub_request(:any, /.*/).to_timeout
|
18
|
+
end
|
10
19
|
|
11
|
-
|
12
|
-
|
20
|
+
it "should raise NetworkError" do
|
21
|
+
expect { client.connection.get "/non_existent" }.to raise_error(ZendeskAPI::Error::NetworkError)
|
22
|
+
end
|
13
23
|
end
|
14
24
|
end
|
15
25
|
|
16
|
-
context "
|
17
|
-
|
26
|
+
context "status errors" do
|
27
|
+
before(:each) do
|
28
|
+
stub_request(:any, /.*/).to_return(:status => status)
|
29
|
+
end
|
18
30
|
|
19
|
-
|
20
|
-
|
31
|
+
context "with status = 404" do
|
32
|
+
let(:status) { 404 }
|
33
|
+
|
34
|
+
it "should raise RecordNotFound when status is 404" do
|
35
|
+
expect { client.connection.get "/non_existent" }.to raise_error(ZendeskAPI::Error::RecordNotFound)
|
36
|
+
end
|
21
37
|
end
|
22
|
-
end
|
23
38
|
|
24
|
-
|
25
|
-
|
39
|
+
context "with status in 400...600" do
|
40
|
+
let(:status) { 500 }
|
26
41
|
|
27
|
-
|
28
|
-
|
42
|
+
it "should raise NetworkError" do
|
43
|
+
expect { client.connection.get "/non_existent" }.to raise_error(ZendeskAPI::Error::NetworkError)
|
44
|
+
end
|
29
45
|
end
|
30
|
-
end
|
31
46
|
|
32
|
-
|
33
|
-
|
47
|
+
context "with status = 422" do
|
48
|
+
let(:status) { 422 }
|
34
49
|
|
35
|
-
|
36
|
-
|
50
|
+
it "should raise RecordInvalid" do
|
51
|
+
expect { client.connection.get "/non_existent" }.to raise_error(ZendeskAPI::Error::RecordInvalid)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "with status = 200" do
|
56
|
+
let(:status) { 200 }
|
57
|
+
|
58
|
+
it "should not raise" do
|
59
|
+
client.connection.get "/abcdef"
|
60
|
+
end
|
37
61
|
end
|
38
62
|
end
|
39
63
|
end
|
40
|
-
|
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.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-08-
|
13
|
+
date: 2013-08-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bump
|