zendesk2 0.0.18 → 0.0.19
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.
- data/lib/zendesk2/client/models/categories.rb +1 -1
- data/lib/zendesk2/client/models/category.rb +2 -2
- data/lib/zendesk2/client/models/forum.rb +2 -2
- data/lib/zendesk2/client/models/forums.rb +1 -1
- data/lib/zendesk2/client/models/organization.rb +2 -2
- data/lib/zendesk2/client/models/organizations.rb +1 -1
- data/lib/zendesk2/client/models/ticket.rb +2 -2
- data/lib/zendesk2/client/models/tickets.rb +1 -1
- data/lib/zendesk2/client/models/topic.rb +2 -2
- data/lib/zendesk2/client/models/topic_comment.rb +2 -2
- data/lib/zendesk2/client/models/topic_comments.rb +1 -1
- data/lib/zendesk2/client/models/topics.rb +1 -1
- data/lib/zendesk2/client/models/user.rb +3 -2
- data/lib/zendesk2/client/models/users.rb +1 -1
- data/lib/zendesk2/client/requests/create_user.rb +6 -5
- data/lib/zendesk2/collection.rb +6 -0
- data/lib/zendesk2/error.rb +2 -1
- data/lib/zendesk2/model.rb +11 -0
- data/lib/zendesk2/version.rb +1 -1
- data/lib/zendesk2.rb +3 -1
- data/spec/organizations_spec.rb +4 -2
- data/spec/users_spec.rb +14 -4
- metadata +4 -2
@@ -1,4 +1,4 @@
|
|
1
|
-
class Zendesk2::Client::Category <
|
1
|
+
class Zendesk2::Client::Category < Zendesk2::Model
|
2
2
|
PARAMS = %w[id name description position]
|
3
3
|
|
4
4
|
identity :id, type: :integer # ro[yes] mandatory[no] Automatically assigned during creation
|
@@ -19,7 +19,7 @@ class Zendesk2::Client::Category < Cistern::Model
|
|
19
19
|
!self.reload
|
20
20
|
end
|
21
21
|
|
22
|
-
def save
|
22
|
+
def save!
|
23
23
|
data = if new_record?
|
24
24
|
requires :name
|
25
25
|
connection.create_category(params).body["category"]
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Zendesk2::Client::Forum <
|
1
|
+
class Zendesk2::Client::Forum < Zendesk2::Model
|
2
2
|
extend Zendesk2::Attributes
|
3
3
|
|
4
4
|
PARAMS = %w[id name description category_id organization_id locale_id locked position forum_type access]
|
@@ -31,7 +31,7 @@ class Zendesk2::Client::Forum < Cistern::Model
|
|
31
31
|
!self.reload
|
32
32
|
end
|
33
33
|
|
34
|
-
def save
|
34
|
+
def save!
|
35
35
|
data = if new_record?
|
36
36
|
requires :name
|
37
37
|
connection.create_forum(params).body["forum"]
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Zendesk2::Client::Organization <
|
1
|
+
class Zendesk2::Client::Organization < Zendesk2::Model
|
2
2
|
PARAMS = %w[id details domain_names external_id group_id shared_comments shared_tickets tags name notes]
|
3
3
|
|
4
4
|
identity :id, type: :integer
|
@@ -31,7 +31,7 @@ class Zendesk2::Client::Organization < Cistern::Model
|
|
31
31
|
!self.reload
|
32
32
|
end
|
33
33
|
|
34
|
-
def save
|
34
|
+
def save!
|
35
35
|
data = if new_record?
|
36
36
|
requires :name
|
37
37
|
connection.create_organization(params).body["organization"]
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Zendesk2::Client::Ticket <
|
1
|
+
class Zendesk2::Client::Ticket < Zendesk2::Model
|
2
2
|
extend Zendesk2::Attributes
|
3
3
|
|
4
4
|
PARAMS = %w[external_id via requester_id submitter_id assignee_id organization_id subject description fields recipient status collaborator_ids]
|
@@ -31,7 +31,7 @@ class Zendesk2::Client::Ticket < Cistern::Model
|
|
31
31
|
assoc_accessor :requester, collection: :users
|
32
32
|
assoc_reader :submitter, collection: :users
|
33
33
|
|
34
|
-
def save
|
34
|
+
def save!
|
35
35
|
if new_record?
|
36
36
|
requires :subject, :description
|
37
37
|
data = connection.create_ticket(params).body["ticket"]
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Zendesk2::Client::Topic <
|
1
|
+
class Zendesk2::Client::Topic < Zendesk2::Model
|
2
2
|
extend Zendesk2::Attributes
|
3
3
|
|
4
4
|
PARAMS = %w[id title body submitter_id updater_id forum_id locked pinned highlighted position tags]
|
@@ -34,7 +34,7 @@ class Zendesk2::Client::Topic < Cistern::Model
|
|
34
34
|
!self.reload
|
35
35
|
end
|
36
36
|
|
37
|
-
def save
|
37
|
+
def save!
|
38
38
|
data = if new_record?
|
39
39
|
requires :title, :body
|
40
40
|
connection.create_topic(params).body["topic"]
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Zendesk2::Client::TopicComment <
|
1
|
+
class Zendesk2::Client::TopicComment < Zendesk2::Model
|
2
2
|
extend Zendesk2::Attributes
|
3
3
|
|
4
4
|
PARAMS = %w[id topic_id user_id body informative]
|
@@ -26,7 +26,7 @@ class Zendesk2::Client::TopicComment < Cistern::Model
|
|
26
26
|
!self.reload
|
27
27
|
end
|
28
28
|
|
29
|
-
def save
|
29
|
+
def save!
|
30
30
|
data = if new_record?
|
31
31
|
requires :topic_id, :user_id, :body
|
32
32
|
connection.create_topic_comment(params).body["topic_comment"]
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Zendesk2::Client::User <
|
1
|
+
class Zendesk2::Client::User < Zendesk2::Model
|
2
2
|
extend Zendesk2::Attributes
|
3
3
|
|
4
4
|
PARAMS = %w[name email organization_id external_id alias verified locate_id time_zone phone signature details notes role custom_role_id moderator ticket_restriction only_private_comments]
|
@@ -33,9 +33,10 @@ class Zendesk2::Client::User < Cistern::Model
|
|
33
33
|
attribute :photo
|
34
34
|
attribute :authenticity_token
|
35
35
|
|
36
|
+
attr_accessor :errors
|
36
37
|
assoc_accessor :organization
|
37
38
|
|
38
|
-
def save
|
39
|
+
def save!
|
39
40
|
if new_record?
|
40
41
|
requires :name, :email
|
41
42
|
data = connection.create_user(params).body["user"]
|
@@ -22,17 +22,18 @@ class Zendesk2::Client
|
|
22
22
|
}.merge(params)
|
23
23
|
|
24
24
|
path = "/users.json"
|
25
|
-
if record["email"] && self.data[:users].find{|k,u| u["email"] ==
|
25
|
+
if (email = record["email"]) && self.data[:users].find{|k,u| u["email"] == email && k != identity}
|
26
26
|
response(
|
27
27
|
:method => :put,
|
28
28
|
:path => path,
|
29
29
|
:status => 422,
|
30
30
|
:body => {
|
31
31
|
"error" => "RecordInvalid",
|
32
|
-
"description" => "Record validation errors",
|
33
|
-
|
34
|
-
|
35
|
-
"
|
32
|
+
"description" => "Record validation errors",
|
33
|
+
"details" => {
|
34
|
+
"email" => [ {
|
35
|
+
"type" => "#{email} is already being used by another user",
|
36
|
+
"description" => "Email: #{email} is already being used by another user"
|
36
37
|
} ]
|
37
38
|
}
|
38
39
|
}
|
data/lib/zendesk2/error.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
class Zendesk2::Error < StandardError
|
2
2
|
|
3
|
-
attr_reader :wrapped_exception
|
3
|
+
attr_reader :wrapped_exception, :response
|
4
4
|
def initialize(wrapped_exception)
|
5
5
|
@wrapped_exception = wrapped_exception
|
6
|
+
@response = wrapped_exception.response
|
6
7
|
message = if wrapped_exception.is_a?(Faraday::Error::ParsingError)
|
7
8
|
wrapped_exception.message
|
8
9
|
elsif wrapped_exception.is_a?(Faraday::Error::ClientError)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class Zendesk2::Model < Cistern::Model
|
2
|
+
|
3
|
+
attr_accessor :errors
|
4
|
+
|
5
|
+
def save
|
6
|
+
save!
|
7
|
+
rescue Zendesk2::Error => e
|
8
|
+
self.errors= e.response[:body]["details"].inject({}){|r,(k,v)| r.merge(k => v.map{|e| e["type"] || e["description"]})} rescue nil
|
9
|
+
self
|
10
|
+
end
|
11
|
+
end
|
data/lib/zendesk2/version.rb
CHANGED
data/lib/zendesk2.rb
CHANGED
@@ -17,6 +17,8 @@ module Zendesk2
|
|
17
17
|
autoload :PagedCollection, 'zendesk2/paged_collection'
|
18
18
|
autoload :Searchable, 'zendesk2/searchable'
|
19
19
|
autoload :Logger, 'zendesk2/logger'
|
20
|
+
autoload :Model, 'zendesk2/model'
|
21
|
+
autoload :Collection, 'zendesk2/collection'
|
20
22
|
|
21
23
|
def self.defaults
|
22
24
|
@defaults ||= if File.exists?(File.expand_path("~/.zendesk2"))
|
@@ -44,6 +46,6 @@ module Zendesk2
|
|
44
46
|
end
|
45
47
|
|
46
48
|
def self.blank?(string)
|
47
|
-
|
49
|
+
!string || string == ""
|
48
50
|
end
|
49
51
|
end
|
data/spec/organizations_spec.rb
CHANGED
@@ -20,8 +20,10 @@ describe "organizations" do
|
|
20
20
|
organization.tickets.should include ticket
|
21
21
|
end
|
22
22
|
|
23
|
-
it "should
|
24
|
-
lambda { client.organizations.create(name: organization.name) }.should raise_exception(Zendesk2::Error)
|
23
|
+
it "should hate non-unique names" do
|
24
|
+
lambda { client.organizations.create!(name: organization.name) }.should raise_exception(Zendesk2::Error)
|
25
|
+
model = client.organizations.create(name: organization.name)
|
26
|
+
model.errors.should == {"name" => ["Name: has already been taken"]}
|
25
27
|
end
|
26
28
|
end
|
27
29
|
end
|
data/spec/users_spec.rb
CHANGED
@@ -14,8 +14,11 @@ describe "users" do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
describe do
|
17
|
-
|
18
|
-
|
17
|
+
before(:each) do
|
18
|
+
@user = client.users.create(email: "zendesk2+#{Zendesk2.uuid}@example.org", name: Zendesk2.uuid)
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:user) { @user }
|
19
22
|
|
20
23
|
it "should update organization" do
|
21
24
|
organization = client.organizations.create(name: Zendesk2.uuid)
|
@@ -47,9 +50,16 @@ describe "users" do
|
|
47
50
|
it "should hate non-unique emails" do
|
48
51
|
email = "zendesk2+#{Zendesk2.uuid}@example.org"
|
49
52
|
client.users.create(email: email, name: Zendesk2.uuid)
|
50
|
-
lambda { client.users.create(email: email, name: Zendesk2.uuid) }.should raise_exception(Zendesk2::Error)
|
53
|
+
lambda { client.users.create!(email: email, name: Zendesk2.uuid) }.should raise_exception(Zendesk2::Error)
|
54
|
+
user = client.users.create(email: email, name: Zendesk2.uuid)
|
55
|
+
user.identity.should be_false
|
56
|
+
user.errors.should == {"email" => ["#{email} is already being used by another user"]}
|
51
57
|
end
|
52
58
|
|
53
|
-
it "should form login url"
|
59
|
+
it "should form login url" do
|
60
|
+
return_to = "http://engineyard.com"
|
61
|
+
uri = Addressable::URI.parse(user.login_url(Time.now.to_s, return_to: return_to))
|
62
|
+
uri.query_values["return_to"].should == return_to
|
63
|
+
end
|
54
64
|
end
|
55
65
|
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.
|
4
|
+
version: 0.0.19
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cistern
|
@@ -147,8 +147,10 @@ files:
|
|
147
147
|
- lib/zendesk2/client/requests/update_topic.rb
|
148
148
|
- lib/zendesk2/client/requests/update_topic_comment.rb
|
149
149
|
- lib/zendesk2/client/requests/update_user.rb
|
150
|
+
- lib/zendesk2/collection.rb
|
150
151
|
- lib/zendesk2/error.rb
|
151
152
|
- lib/zendesk2/logger.rb
|
153
|
+
- lib/zendesk2/model.rb
|
152
154
|
- lib/zendesk2/paged_collection.rb
|
153
155
|
- lib/zendesk2/searchable.rb
|
154
156
|
- lib/zendesk2/version.rb
|