zendesk2 0.0.5 → 0.0.6
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.rb +1 -0
- data/lib/zendesk2/client.rb +25 -17
- data/lib/zendesk2/{models → client/models}/organization.rb +31 -25
- data/lib/zendesk2/{models → client/models}/organizations.rb +2 -2
- data/lib/zendesk2/{models → client/models}/ticket.rb +17 -8
- data/lib/zendesk2/{models → client/models}/tickets.rb +0 -0
- data/lib/zendesk2/{models → client/models}/user.rb +34 -11
- data/lib/zendesk2/{models → client/models}/users.rb +0 -0
- data/lib/zendesk2/{requests → client/requests}/create_organization.rb +0 -0
- data/lib/zendesk2/{requests → client/requests}/create_ticket.rb +6 -5
- data/lib/zendesk2/{requests → client/requests}/create_user.rb +5 -4
- data/lib/zendesk2/{requests → client/requests}/destroy_organization.rb +0 -0
- data/lib/zendesk2/{requests → client/requests}/destroy_ticket.rb +0 -0
- data/lib/zendesk2/client/requests/destroy_user.rb +47 -0
- data/lib/zendesk2/client/requests/get_ccd_tickets.rb +22 -0
- data/lib/zendesk2/{requests → client/requests}/get_current_user.rb +0 -0
- data/lib/zendesk2/{requests → client/requests}/get_organization.rb +1 -2
- data/lib/zendesk2/{requests → client/requests}/get_organization_tickets.rb +0 -0
- data/lib/zendesk2/{requests → client/requests}/get_organization_users.rb +0 -0
- data/lib/zendesk2/{requests → client/requests}/get_organizations.rb +0 -0
- data/lib/zendesk2/client/requests/get_requested_tickets.rb +22 -0
- data/lib/zendesk2/{requests → client/requests}/get_ticket.rb +8 -7
- data/lib/zendesk2/{requests → client/requests}/get_tickets.rb +0 -0
- data/lib/zendesk2/{requests → client/requests}/get_user.rb +0 -0
- data/lib/zendesk2/{requests → client/requests}/get_users.rb +0 -0
- data/lib/zendesk2/client/requests/search.rb +26 -0
- data/lib/zendesk2/{requests → client/requests}/update_organization.rb +0 -0
- data/lib/zendesk2/{requests → client/requests}/update_ticket.rb +0 -0
- data/lib/zendesk2/{requests → client/requests}/update_user.rb +0 -2
- data/lib/zendesk2/error.rb +13 -0
- data/lib/zendesk2/errors.rb +8 -0
- data/lib/zendesk2/paged_collection.rb +3 -0
- data/lib/zendesk2/version.rb +1 -1
- data/spec/shared/resource.rb +2 -0
- data/spec/users_spec.rb +24 -0
- metadata +30 -26
- data/lib/zendesk2/requests/destroy_user.rb +0 -27
data/lib/zendesk2.rb
CHANGED
data/lib/zendesk2/client.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
class Zendesk2::Client < Cistern::Service
|
2
2
|
|
3
|
-
model_path "zendesk2/models"
|
4
|
-
request_path "zendesk2/requests"
|
3
|
+
model_path "zendesk2/client/models"
|
4
|
+
request_path "zendesk2/client/requests"
|
5
5
|
|
6
6
|
model :organization
|
7
7
|
collection :organizations
|
@@ -23,8 +23,11 @@ class Zendesk2::Client < Cistern::Service
|
|
23
23
|
request :get_ticket
|
24
24
|
request :get_user
|
25
25
|
request :get_organizations
|
26
|
+
request :get_requested_tickets
|
27
|
+
request :get_ccd_tickets
|
26
28
|
request :get_tickets
|
27
29
|
request :get_users
|
30
|
+
request :search
|
28
31
|
request :update_organization
|
29
32
|
request :update_ticket
|
30
33
|
request :update_user
|
@@ -55,15 +58,15 @@ class Zendesk2::Client < Cistern::Service
|
|
55
58
|
logger = options[:logger]
|
56
59
|
adapter = options[:adapter] || :net_http
|
57
60
|
connection_options = options[:connection_options] || {ssl: {verify: false}}
|
58
|
-
username
|
61
|
+
@username = options[:username] || Zendesk2.defaults[:username]
|
59
62
|
password = options[:password] || Zendesk2.defaults[:password]
|
60
63
|
@token = options[:token]
|
61
64
|
|
62
|
-
raise "Missing required options: [:username, :password]" unless username && password
|
65
|
+
raise "Missing required options: [:username, :password]" unless @username && password
|
63
66
|
|
64
67
|
@connection = Faraday.new({url: @url}.merge(connection_options)) do |builder|
|
65
68
|
# response
|
66
|
-
builder.use Faraday::Request::BasicAuthentication, username, password
|
69
|
+
builder.use Faraday::Request::BasicAuthentication, @username, password
|
67
70
|
builder.use Faraday::Response::RaiseError
|
68
71
|
builder.use Faraday::Response::Logger, logger if logger
|
69
72
|
builder.response :json
|
@@ -89,14 +92,15 @@ class Zendesk2::Client < Cistern::Service
|
|
89
92
|
req.params.merge!(params)
|
90
93
|
req.body= body
|
91
94
|
end
|
95
|
+
rescue Faraday::Error::ClientError => e
|
96
|
+
raise Zendesk2::Error.new(e)
|
92
97
|
end
|
93
|
-
|
94
98
|
end
|
95
99
|
|
96
100
|
class Mock
|
97
101
|
include Zendesk2::Errors
|
98
102
|
|
99
|
-
attr_reader :username, :url
|
103
|
+
attr_reader :username, :url, :token
|
100
104
|
|
101
105
|
def self.data
|
102
106
|
@data ||= {
|
@@ -135,6 +139,7 @@ class Zendesk2::Client < Cistern::Service
|
|
135
139
|
@url = url
|
136
140
|
@path = URI.parse(url).path
|
137
141
|
@username, @password = options[:username], options[:password]
|
142
|
+
@token = options[:token]
|
138
143
|
|
139
144
|
@current_user_id = self.class.new_id
|
140
145
|
|
@@ -178,8 +183,8 @@ class Zendesk2::Client < Cistern::Service
|
|
178
183
|
}
|
179
184
|
|
180
185
|
response(
|
181
|
-
body
|
182
|
-
path
|
186
|
+
:body => body,
|
187
|
+
:path => path
|
183
188
|
)
|
184
189
|
end
|
185
190
|
|
@@ -191,15 +196,18 @@ class Zendesk2::Client < Cistern::Service
|
|
191
196
|
|
192
197
|
url = options[:url] || url_for(path)
|
193
198
|
|
194
|
-
|
195
|
-
:method
|
196
|
-
:status
|
197
|
-
:url
|
198
|
-
:body
|
199
|
-
:
|
200
|
-
"Content-Type"
|
199
|
+
env = {
|
200
|
+
:method => method,
|
201
|
+
:status => status,
|
202
|
+
:url => url,
|
203
|
+
:body => body,
|
204
|
+
:response_headers => {
|
205
|
+
"Content-Type" => "application/json; charset=utf-8"
|
201
206
|
},
|
202
|
-
|
207
|
+
}
|
208
|
+
Faraday::Response::RaiseError.new.on_complete(env) || Faraday::Response.new(env)
|
209
|
+
rescue Faraday::Error::ClientError => e
|
210
|
+
raise Zendesk2::Error.new(e)
|
203
211
|
end
|
204
212
|
end
|
205
213
|
end
|
@@ -1,49 +1,49 @@
|
|
1
1
|
class Zendesk2::Client::Organization < Cistern::Model
|
2
2
|
include Zendesk2::Errors
|
3
3
|
identity :id, type: :integer
|
4
|
-
attribute :
|
5
|
-
attribute :
|
6
|
-
attribute :tags
|
4
|
+
attribute :created_at, type: :time
|
5
|
+
attribute :details, type: :string
|
7
6
|
attribute :domain_names, type: :array
|
8
|
-
attribute :group_id, type: :integer
|
9
7
|
attribute :external_id, type: :integer
|
10
|
-
attribute :
|
11
|
-
attribute :
|
12
|
-
attribute :details
|
8
|
+
attribute :group_id, type: :integer
|
9
|
+
attribute :shared_comments, type: :boolean
|
13
10
|
attribute :shared_tickets, type: :boolean
|
11
|
+
attribute :tags, type: :array
|
12
|
+
attribute :name, type: :string
|
13
|
+
attribute :notes, type: :array
|
14
14
|
attribute :updated_at, type: :time
|
15
15
|
|
16
|
-
def destroy
|
16
|
+
def destroy!
|
17
17
|
requires :identity
|
18
18
|
|
19
|
-
|
19
|
+
connection.destroy_organization("id" => self.identity)
|
20
|
+
end
|
21
|
+
|
22
|
+
def destroy
|
23
|
+
destroy!
|
24
|
+
rescue Zendesk2::Error
|
25
|
+
false
|
20
26
|
end
|
21
27
|
|
22
28
|
def destroyed?
|
23
|
-
self.reload
|
24
|
-
rescue not_found
|
25
|
-
true
|
29
|
+
!self.reload
|
26
30
|
end
|
27
31
|
|
28
32
|
def save
|
29
|
-
if new_record?
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
"name" => self.name,
|
38
|
-
}
|
39
|
-
data = connection.update_organization(params).body["organization"]
|
40
|
-
merge_attributes(data)
|
41
|
-
end
|
33
|
+
data = if new_record?
|
34
|
+
requires :name
|
35
|
+
connection.create_organization(params).body["organization"]
|
36
|
+
else
|
37
|
+
requires :identity
|
38
|
+
connection.update_organization(params).body["organization"]
|
39
|
+
end
|
40
|
+
merge_attributes(data)
|
42
41
|
end
|
43
42
|
|
44
43
|
def users
|
45
44
|
requires :identity
|
46
45
|
data = connection.get_organization_users("id" => self.identity).body["users"]
|
46
|
+
|
47
47
|
connection.users.load(data)
|
48
48
|
end
|
49
49
|
|
@@ -53,4 +53,10 @@ class Zendesk2::Client::Organization < Cistern::Model
|
|
53
53
|
|
54
54
|
connection.tickets.load(data)
|
55
55
|
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def params
|
60
|
+
Cistern::Hash.slice(Zendesk2.stringify_keys(attributes), "id", "details", "domain_names", "external_id", "group_id", "shared_comments", "shared_tickets", "tags", "name", "notes")
|
61
|
+
end
|
56
62
|
end
|
@@ -12,8 +12,8 @@ class Zendesk2::Client::Organizations < Cistern::Collection
|
|
12
12
|
new(connection.get_current_organization.body["organization"])
|
13
13
|
end
|
14
14
|
|
15
|
-
def search(
|
16
|
-
body = connection.
|
15
|
+
def search(parameters)
|
16
|
+
body = connection.search(parameters.merge("type" => "organization")).body
|
17
17
|
if data = body.delete("results")
|
18
18
|
load(data)
|
19
19
|
end
|
@@ -42,18 +42,16 @@ class Zendesk2::Client::Ticket < Cistern::Model
|
|
42
42
|
connection.destroy_ticket("id" => self.identity)
|
43
43
|
end
|
44
44
|
|
45
|
-
def
|
46
|
-
self.
|
47
|
-
rescue not_found
|
48
|
-
true
|
45
|
+
def collaborators
|
46
|
+
self.collaborator_ids.map{|cid| self.connection.users.get(cid)}
|
49
47
|
end
|
50
48
|
|
51
|
-
def
|
52
|
-
|
49
|
+
def collaborators=(collaborators)
|
50
|
+
self.collaborator_ids= collaborators.map(&:identity)
|
53
51
|
end
|
54
52
|
|
55
|
-
def
|
56
|
-
self.
|
53
|
+
def destroyed?
|
54
|
+
!self.reload
|
57
55
|
end
|
58
56
|
|
59
57
|
def requester=(requester)
|
@@ -63,4 +61,15 @@ class Zendesk2::Client::Ticket < Cistern::Model
|
|
63
61
|
def requester
|
64
62
|
self.connection.users.get(self.requester_id)
|
65
63
|
end
|
64
|
+
|
65
|
+
def submitter
|
66
|
+
self.connection.users.get(submitter_id)
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def params
|
72
|
+
Cistern::Hash.slice(Zendesk2.stringify_keys(attributes), "external_id", "via", "requester_id", "submitter_id", "assignee_id", "organization_id", "subject", "description", "fields", "recipient", "status", "collaborator_ids")
|
73
|
+
end
|
74
|
+
|
66
75
|
end
|
File without changes
|
@@ -1,4 +1,5 @@
|
|
1
1
|
class Zendesk2::Client::User < Cistern::Model
|
2
|
+
include Zendesk2::Errors
|
2
3
|
identity :id, type: :id
|
3
4
|
attribute :url
|
4
5
|
attribute :external_id
|
@@ -16,7 +17,7 @@ class Zendesk2::Client::User < Cistern::Model
|
|
16
17
|
attribute :email
|
17
18
|
attribute :phone
|
18
19
|
attribute :signature
|
19
|
-
attribute :details
|
20
|
+
attribute :details, type: :string
|
20
21
|
attribute :notes
|
21
22
|
attribute :organization_id, type: :integer
|
22
23
|
attribute :role
|
@@ -41,7 +42,7 @@ class Zendesk2::Client::User < Cistern::Model
|
|
41
42
|
end
|
42
43
|
end
|
43
44
|
|
44
|
-
def destroy
|
45
|
+
def destroy!
|
45
46
|
requires :identity
|
46
47
|
raise "don't nuke yourself" if self.email == connection.username
|
47
48
|
|
@@ -49,23 +50,21 @@ class Zendesk2::Client::User < Cistern::Model
|
|
49
50
|
merge_attributes(data)
|
50
51
|
end
|
51
52
|
|
52
|
-
def
|
53
|
-
!
|
54
|
-
|
55
|
-
|
56
|
-
def organization=(organization)
|
57
|
-
self.organization_id= organization.id
|
53
|
+
def destroy
|
54
|
+
destroy!
|
55
|
+
rescue Zendesk2::Error => e
|
56
|
+
false
|
58
57
|
end
|
59
58
|
|
60
|
-
def
|
61
|
-
self.
|
59
|
+
def destroyed?
|
60
|
+
!reload || !self.active
|
62
61
|
end
|
63
62
|
|
64
63
|
def login_url(timestamp, options={})
|
65
64
|
requires :name, :email
|
66
65
|
|
67
66
|
return_to = options[:return_to]
|
68
|
-
token = self.token || options[:token]
|
67
|
+
token = self.connection.token || options[:token]
|
69
68
|
|
70
69
|
uri = Addressable::URI.parse(self.connection.url)
|
71
70
|
uri.path = "/access/remote"
|
@@ -87,6 +86,30 @@ class Zendesk2::Client::User < Cistern::Model
|
|
87
86
|
uri.to_s
|
88
87
|
end
|
89
88
|
|
89
|
+
def requested_tickets
|
90
|
+
requires :identity
|
91
|
+
|
92
|
+
data = connection.get_requested_tickets("id" => self.identity).body["tickets"]
|
93
|
+
|
94
|
+
connection.tickets.load(data)
|
95
|
+
end
|
96
|
+
|
97
|
+
def ccd_tickets
|
98
|
+
requires :identity
|
99
|
+
|
100
|
+
data = connection.get_ccd_tickets("id" => self.identity).body["tickets"]
|
101
|
+
|
102
|
+
connection.tickets.load(data)
|
103
|
+
end
|
104
|
+
|
105
|
+
def organization=(organization)
|
106
|
+
self.organization_id= organization.id
|
107
|
+
end
|
108
|
+
|
109
|
+
def organization
|
110
|
+
self.connection.organizations.get(self.organization_id)
|
111
|
+
end
|
112
|
+
|
90
113
|
private
|
91
114
|
|
92
115
|
def params
|
File without changes
|
File without changes
|
@@ -14,10 +14,11 @@ class Zendesk2::Client
|
|
14
14
|
identity = self.class.new_id
|
15
15
|
|
16
16
|
record = {
|
17
|
-
"id"
|
18
|
-
"url"
|
19
|
-
"created_at"
|
20
|
-
"updated_at"
|
17
|
+
"id" => identity,
|
18
|
+
"url" => url_for("/tickets/#{identity}.json"),
|
19
|
+
"created_at" => Time.now.iso8601,
|
20
|
+
"updated_at" => Time.now.iso8601,
|
21
|
+
"collaborator_ids" => [],
|
21
22
|
}.merge(params)
|
22
23
|
|
23
24
|
record["requester_id"] ||= @current_user_id
|
@@ -34,4 +35,4 @@ class Zendesk2::Client
|
|
34
35
|
)
|
35
36
|
end
|
36
37
|
end # Mock
|
37
|
-
end
|
38
|
+
end # Zendesk2::Client
|
@@ -14,10 +14,11 @@ class Zendesk2::Client
|
|
14
14
|
identity = self.class.new_id
|
15
15
|
|
16
16
|
record = {
|
17
|
-
"id"
|
18
|
-
"url"
|
19
|
-
"created_at"
|
20
|
-
"updated_at"
|
17
|
+
"id" => identity,
|
18
|
+
"url" => url_for("/users/#{identity}.json"),
|
19
|
+
"created_at" => Time.now.iso8601,
|
20
|
+
"updated_at" => Time.now.iso8601,
|
21
|
+
"active" => true,
|
21
22
|
}.merge(params)
|
22
23
|
|
23
24
|
self.data[:users][identity]= record
|
File without changes
|
File without changes
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class Zendesk2::Client
|
2
|
+
class Real
|
3
|
+
def destroy_user(params={})
|
4
|
+
id = params["id"]
|
5
|
+
|
6
|
+
request(
|
7
|
+
:method => :delete,
|
8
|
+
:path => "/users/#{id}.json"
|
9
|
+
)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Mock
|
14
|
+
def destroy_user(params={})
|
15
|
+
id = params["id"]
|
16
|
+
path = "/users/#{id}.json"
|
17
|
+
|
18
|
+
tickets = self.data[:tickets].values.select{|t| t["requester_id"] == id}.size
|
19
|
+
if tickets < 1
|
20
|
+
body = self.data[:users].delete(id)
|
21
|
+
response(
|
22
|
+
:method => :delete,
|
23
|
+
:path => path,
|
24
|
+
:body => {
|
25
|
+
"user" => body,
|
26
|
+
},
|
27
|
+
)
|
28
|
+
else
|
29
|
+
response(
|
30
|
+
:method => :delete,
|
31
|
+
:path => path,
|
32
|
+
:status => 422,
|
33
|
+
:body => {
|
34
|
+
"error" => "RecordInvalid",
|
35
|
+
"description" => "Record validation errors",
|
36
|
+
"details" => {
|
37
|
+
"base" => [{
|
38
|
+
"type" => "User is requester on #{tickets} ticket(s) that are not closed.",
|
39
|
+
"description" => "Base User is requester on #{tickets} ticket(s) that are not closed."
|
40
|
+
}]
|
41
|
+
}
|
42
|
+
}
|
43
|
+
)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class Zendesk2::Client
|
2
|
+
class Real
|
3
|
+
def get_ccd_tickets(params={})
|
4
|
+
id = params["id"]
|
5
|
+
page_params = Zendesk2.paging_parameters(params)
|
6
|
+
|
7
|
+
request(
|
8
|
+
:params => page_params,
|
9
|
+
:method => :get,
|
10
|
+
:path => "/users/#{id}/tickets/ccd.json",
|
11
|
+
)
|
12
|
+
end
|
13
|
+
end # Real
|
14
|
+
|
15
|
+
class Mock
|
16
|
+
def get_ccd_tickets(params={})
|
17
|
+
id = params["id"]
|
18
|
+
|
19
|
+
page(params, :tickets, "/ccds/#{id}/tickets.json", "tickets", filter: lambda{|c| c.select{|u| u["collaborator_ids"].include?(id)}})
|
20
|
+
end
|
21
|
+
end # Mock
|
22
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class Zendesk2::Client
|
2
|
+
class Real
|
3
|
+
def get_requested_tickets(params={})
|
4
|
+
id = params["id"]
|
5
|
+
page_params = Zendesk2.paging_parameters(params)
|
6
|
+
|
7
|
+
request(
|
8
|
+
:params => page_params,
|
9
|
+
:method => :get,
|
10
|
+
:path => "/users/#{id}/tickets/requested.json",
|
11
|
+
)
|
12
|
+
end
|
13
|
+
end # Real
|
14
|
+
|
15
|
+
class Mock
|
16
|
+
def get_requested_tickets(params={})
|
17
|
+
id = params["id"]
|
18
|
+
|
19
|
+
page(params, :tickets, "/requesteds/#{id}/tickets.json", "tickets", filter: lambda{|c| c.select{|u| u["requester_id"] == id}})
|
20
|
+
end
|
21
|
+
end # Mock
|
22
|
+
end
|
@@ -13,20 +13,21 @@ class Zendesk2::Client
|
|
13
13
|
class Mock
|
14
14
|
def get_ticket(params={})
|
15
15
|
id = params["id"]
|
16
|
-
|
16
|
+
path = "/tickets/#{id}.json"
|
17
17
|
|
18
|
+
if body = self.data[:tickets][id]
|
18
19
|
response(
|
19
|
-
:path
|
20
|
-
:body
|
20
|
+
:path => path,
|
21
|
+
:body => {
|
21
22
|
"ticket" => body
|
22
23
|
},
|
23
24
|
)
|
24
25
|
else
|
25
|
-
|
26
|
-
:path =>
|
27
|
-
:status => 404
|
26
|
+
response(
|
27
|
+
:path => path,
|
28
|
+
:status => 404,
|
29
|
+
:body => {"error" => "RecordNotFound", "description" => "Not found"},
|
28
30
|
)
|
29
|
-
raise not_found!(nil, r)
|
30
31
|
end
|
31
32
|
end
|
32
33
|
end # Mock
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Zendesk2::Client
|
2
|
+
class Real
|
3
|
+
def search(query)
|
4
|
+
term = query.map{|k,v| "#{k}:#{v}"}.join(" ")
|
5
|
+
request(
|
6
|
+
:method => :get,
|
7
|
+
:params => {query: term},
|
8
|
+
:path => "/search.json",
|
9
|
+
)
|
10
|
+
end
|
11
|
+
end # Real
|
12
|
+
|
13
|
+
class Mock
|
14
|
+
def search(query)
|
15
|
+
type = query.delete("type")
|
16
|
+
collection = type.nil? ? self.data.values : self.data["#{type}s".to_sym]
|
17
|
+
|
18
|
+
results = collection.select{|k,v| query.all?{|term, condition| v[term.to_s] == condition}}.values
|
19
|
+
|
20
|
+
response(
|
21
|
+
:path => "/search.json",
|
22
|
+
:body => {"results" => results},
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end # Mock
|
26
|
+
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class Zendesk2::Error < StandardError
|
2
|
+
|
3
|
+
attr_reader :message
|
4
|
+
def initialize(exception)
|
5
|
+
@exception = exception
|
6
|
+
message = if exception.response
|
7
|
+
"#{exception.response[:status]} #{exception.response[:body]}"
|
8
|
+
else
|
9
|
+
exception.message
|
10
|
+
end
|
11
|
+
super(message)
|
12
|
+
end
|
13
|
+
end
|
data/lib/zendesk2/errors.rb
CHANGED
@@ -3,6 +3,7 @@ module Zendesk2::PagedCollection
|
|
3
3
|
klass.send(:attribute, :count)
|
4
4
|
klass.send(:attribute, :next_page_link, {:aliases => "next_page"})
|
5
5
|
klass.send(:attribute, :previous_page_link, {:aliases => "previous_page"})
|
6
|
+
klass.send(:include, Zendesk2::Errors)
|
6
7
|
klass.send(:extend, Zendesk2::PagedCollection::Attributes)
|
7
8
|
end
|
8
9
|
|
@@ -23,6 +24,8 @@ module Zendesk2::PagedCollection
|
|
23
24
|
if data = self.connection.send(model_method, {"id" => id}).body[self.model_root]
|
24
25
|
new(data)
|
25
26
|
end
|
27
|
+
rescue Zendesk2::Error
|
28
|
+
nil
|
26
29
|
end
|
27
30
|
|
28
31
|
def next_page
|
data/lib/zendesk2/version.rb
CHANGED
data/spec/shared/resource.rb
CHANGED
data/spec/users_spec.rb
CHANGED
@@ -12,4 +12,28 @@ describe "users" do
|
|
12
12
|
current_user.should be_a(Zendesk2::Client::User)
|
13
13
|
current_user.email.should == client.username
|
14
14
|
end
|
15
|
+
|
16
|
+
describe do
|
17
|
+
let(:user) { client.users.create(email: "zendesk2+#{Zendesk2.uuid}@example.org", name: Zendesk2.uuid) }
|
18
|
+
|
19
|
+
it "should get requested tickets" do
|
20
|
+
ticket = client.tickets.create(requester: user, subject: Zendesk2.uuid, description: Zendesk2.uuid)
|
21
|
+
|
22
|
+
user.requested_tickets.should include ticket
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should get ccd tickets" do
|
26
|
+
ticket = client.tickets.create(collaborators: [user], subject: Zendesk2.uuid, description: Zendesk2.uuid)
|
27
|
+
|
28
|
+
user.ccd_tickets.should include ticket
|
29
|
+
end
|
30
|
+
|
31
|
+
it "cannot destroy a user with a ticket" do
|
32
|
+
ticket = client.tickets.create(requester: user, subject: Zendesk2.uuid, description: Zendesk2.uuid)
|
33
|
+
|
34
|
+
user.destroy.should be_false
|
35
|
+
|
36
|
+
user.should_not be_destroyed
|
37
|
+
end
|
38
|
+
end
|
15
39
|
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.6
|
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-07-
|
12
|
+
date: 2012-07-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cistern
|
@@ -108,32 +108,36 @@ files:
|
|
108
108
|
- Rakefile
|
109
109
|
- lib/zendesk2.rb
|
110
110
|
- lib/zendesk2/client.rb
|
111
|
+
- lib/zendesk2/client/models/organization.rb
|
112
|
+
- lib/zendesk2/client/models/organizations.rb
|
113
|
+
- lib/zendesk2/client/models/ticket.rb
|
114
|
+
- lib/zendesk2/client/models/tickets.rb
|
115
|
+
- lib/zendesk2/client/models/user.rb
|
116
|
+
- lib/zendesk2/client/models/users.rb
|
117
|
+
- lib/zendesk2/client/requests/create_organization.rb
|
118
|
+
- lib/zendesk2/client/requests/create_ticket.rb
|
119
|
+
- lib/zendesk2/client/requests/create_user.rb
|
120
|
+
- lib/zendesk2/client/requests/destroy_organization.rb
|
121
|
+
- lib/zendesk2/client/requests/destroy_ticket.rb
|
122
|
+
- lib/zendesk2/client/requests/destroy_user.rb
|
123
|
+
- lib/zendesk2/client/requests/get_ccd_tickets.rb
|
124
|
+
- lib/zendesk2/client/requests/get_current_user.rb
|
125
|
+
- lib/zendesk2/client/requests/get_organization.rb
|
126
|
+
- lib/zendesk2/client/requests/get_organization_tickets.rb
|
127
|
+
- lib/zendesk2/client/requests/get_organization_users.rb
|
128
|
+
- lib/zendesk2/client/requests/get_organizations.rb
|
129
|
+
- lib/zendesk2/client/requests/get_requested_tickets.rb
|
130
|
+
- lib/zendesk2/client/requests/get_ticket.rb
|
131
|
+
- lib/zendesk2/client/requests/get_tickets.rb
|
132
|
+
- lib/zendesk2/client/requests/get_user.rb
|
133
|
+
- lib/zendesk2/client/requests/get_users.rb
|
134
|
+
- lib/zendesk2/client/requests/search.rb
|
135
|
+
- lib/zendesk2/client/requests/update_organization.rb
|
136
|
+
- lib/zendesk2/client/requests/update_ticket.rb
|
137
|
+
- lib/zendesk2/client/requests/update_user.rb
|
138
|
+
- lib/zendesk2/error.rb
|
111
139
|
- lib/zendesk2/errors.rb
|
112
|
-
- lib/zendesk2/models/organization.rb
|
113
|
-
- lib/zendesk2/models/organizations.rb
|
114
|
-
- lib/zendesk2/models/ticket.rb
|
115
|
-
- lib/zendesk2/models/tickets.rb
|
116
|
-
- lib/zendesk2/models/user.rb
|
117
|
-
- lib/zendesk2/models/users.rb
|
118
140
|
- lib/zendesk2/paged_collection.rb
|
119
|
-
- lib/zendesk2/requests/create_organization.rb
|
120
|
-
- lib/zendesk2/requests/create_ticket.rb
|
121
|
-
- lib/zendesk2/requests/create_user.rb
|
122
|
-
- lib/zendesk2/requests/destroy_organization.rb
|
123
|
-
- lib/zendesk2/requests/destroy_ticket.rb
|
124
|
-
- lib/zendesk2/requests/destroy_user.rb
|
125
|
-
- lib/zendesk2/requests/get_current_user.rb
|
126
|
-
- lib/zendesk2/requests/get_organization.rb
|
127
|
-
- lib/zendesk2/requests/get_organization_tickets.rb
|
128
|
-
- lib/zendesk2/requests/get_organization_users.rb
|
129
|
-
- lib/zendesk2/requests/get_organizations.rb
|
130
|
-
- lib/zendesk2/requests/get_ticket.rb
|
131
|
-
- lib/zendesk2/requests/get_tickets.rb
|
132
|
-
- lib/zendesk2/requests/get_user.rb
|
133
|
-
- lib/zendesk2/requests/get_users.rb
|
134
|
-
- lib/zendesk2/requests/update_organization.rb
|
135
|
-
- lib/zendesk2/requests/update_ticket.rb
|
136
|
-
- lib/zendesk2/requests/update_user.rb
|
137
141
|
- lib/zendesk2/version.rb
|
138
142
|
- spec/organizations_spec.rb
|
139
143
|
- spec/shared/resource.rb
|
@@ -1,27 +0,0 @@
|
|
1
|
-
class Zendesk2::Client
|
2
|
-
class Real
|
3
|
-
def destroy_user(params={})
|
4
|
-
id = params["id"]
|
5
|
-
|
6
|
-
request(
|
7
|
-
:method => :delete,
|
8
|
-
:path => "/users/#{id}.json"
|
9
|
-
)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
class Mock
|
14
|
-
def destroy_user(params={})
|
15
|
-
id = params["id"]
|
16
|
-
body = self.data[:users].delete(id)
|
17
|
-
|
18
|
-
response(
|
19
|
-
:method => :delete,
|
20
|
-
:path => "/users/#{id}.json",
|
21
|
-
:body => {
|
22
|
-
"user" => body,
|
23
|
-
},
|
24
|
-
)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|