zendesk2 0.0.17 → 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,6 @@
1
1
  class Zendesk2::Client::Organization < Cistern::Model
2
2
  PARAMS = %w[id details domain_names external_id group_id shared_comments shared_tickets tags name notes]
3
+
3
4
  identity :id, type: :integer
4
5
  attribute :url, type: :string
5
6
  attribute :created_at, type: :time
@@ -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(
@@ -177,7 +177,7 @@ class Zendesk2::Client < Cistern::Service
177
177
  end
178
178
 
179
179
  def url_for(path)
180
- File.join(@url, "/api/v2", path)
180
+ File.join(@url, "/api/v2", path.to_s)
181
181
  end
182
182
 
183
183
  def page(params, collection, path, collection_root, options={})
@@ -1,14 +1,15 @@
1
1
  class Zendesk2::Error < StandardError
2
2
 
3
- attr_reader :message, :wrapped_exception
3
+ attr_reader :wrapped_exception
4
4
  def initialize(wrapped_exception)
5
5
  @wrapped_exception = wrapped_exception
6
- @message = if wrapped_exception.is_a?(Faraday::Error::ParsingError)
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
@@ -1,3 +1,3 @@
1
1
  module Zendesk2
2
- VERSION = "0.0.17"
2
+ VERSION = "0.0.18"
3
3
  end
@@ -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, organization_id: organization.id)
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, organization_id: organization.id)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zendesk2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 0.0.18
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: