zendesk2 0.0.17 → 0.0.18
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.
@@ -20,6 +20,47 @@ class Zendesk2::Client
|
|
20
20
|
"updated_at" => Time.now.iso8601,
|
21
21
|
}.merge(params)
|
22
22
|
|
23
|
+
unless record["name"]
|
24
|
+
response(
|
25
|
+
:status => 422,
|
26
|
+
:headers => {
|
27
|
+
"status" => "422 Unprocessable Entity",
|
28
|
+
},
|
29
|
+
:body => {
|
30
|
+
"error" => "RecordInvalid",
|
31
|
+
"description" => "Record validation errors",
|
32
|
+
"details" => {
|
33
|
+
"name" => [
|
34
|
+
{
|
35
|
+
"description" => "Name: cannot be blank"
|
36
|
+
}
|
37
|
+
]
|
38
|
+
}
|
39
|
+
}
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
if self.data[:organizations].values.find{|o| o["name"] == record["name"]}
|
44
|
+
response(
|
45
|
+
:status => 422,
|
46
|
+
:headers => {
|
47
|
+
"status" => "422 Unprocessable Entity",
|
48
|
+
},
|
49
|
+
:body => {
|
50
|
+
"error" => "RecordInvalid",
|
51
|
+
"description" => "Record validation errors",
|
52
|
+
"details" => {
|
53
|
+
"name" => [
|
54
|
+
{
|
55
|
+
"description" => "Name: has already been taken"
|
56
|
+
}
|
57
|
+
]
|
58
|
+
}
|
59
|
+
}
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
|
23
64
|
self.data[:organizations][identity]= record
|
24
65
|
|
25
66
|
response(
|
data/lib/zendesk2/client.rb
CHANGED
data/lib/zendesk2/error.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
class Zendesk2::Error < StandardError
|
2
2
|
|
3
|
-
attr_reader :
|
3
|
+
attr_reader :wrapped_exception
|
4
4
|
def initialize(wrapped_exception)
|
5
5
|
@wrapped_exception = wrapped_exception
|
6
|
-
|
6
|
+
message = if wrapped_exception.is_a?(Faraday::Error::ParsingError)
|
7
7
|
wrapped_exception.message
|
8
8
|
elsif wrapped_exception.is_a?(Faraday::Error::ClientError)
|
9
9
|
wrapped_exception.response.inspect
|
10
10
|
else
|
11
11
|
wrapped_exception.instance_variable_get(:@wrapped_exception).inspect
|
12
12
|
end
|
13
|
+
super(message)
|
13
14
|
end
|
14
15
|
end
|
data/lib/zendesk2/version.rb
CHANGED
data/spec/organizations_spec.rb
CHANGED
@@ -7,17 +7,21 @@ describe "organizations" do
|
|
7
7
|
lambda { {name: Zendesk2.uuid} },
|
8
8
|
lambda { {name: Zendesk2.uuid} }
|
9
9
|
|
10
|
-
describe do
|
10
|
+
describe "with an organization" do
|
11
11
|
let(:organization) { client.organizations.create(name: Zendesk2.uuid) }
|
12
12
|
it "should get #users" do
|
13
|
-
user = client.users.create(email: "#{Zendesk2.uuid}@example.org", name: Zendesk2.uuid,
|
13
|
+
user = client.users.create(email: "#{Zendesk2.uuid}@example.org", name: Zendesk2.uuid, organization: organization)
|
14
14
|
organization.users.should include user
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should get #tickets" do
|
18
|
-
user = client.users.create(email: "#{Zendesk2.uuid}@example.org", name: Zendesk2.uuid,
|
18
|
+
user = client.users.create(email: "#{Zendesk2.uuid}@example.org", name: Zendesk2.uuid, organization: organization)
|
19
19
|
ticket = client.tickets.create(subject: "#{Zendesk2.uuid}@example.org", description: Zendesk2.uuid, requester: user)
|
20
20
|
organization.tickets.should include ticket
|
21
21
|
end
|
22
|
+
|
23
|
+
it "should raise on name conflict" do
|
24
|
+
lambda { client.organizations.create(name: organization.name) }.should raise_exception(Zendesk2::Error)
|
25
|
+
end
|
22
26
|
end
|
23
27
|
end
|