zendesk2 1.7.2 → 1.7.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -2
- data/lib/zendesk2/client/mock.rb +63 -61
- data/lib/zendesk2/client/models/ticket_audit.rb +3 -1
- data/lib/zendesk2/client/real.rb +52 -54
- data/lib/zendesk2/version.rb +1 -1
- data/spec/client_spec.rb +12 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16ff1793762e3e79b861085c3c15546dcc0972ed
|
4
|
+
data.tar.gz: 1b221889fcadd78477031cf1b84cffffac37bf90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af82a3dfd968173f87118ce99a099b26ac9741d94057953abe1ffb5839512a14599010cd1fb397e94035017af99c38056c51a7cb7ec35efa2d75b814b1226ca4
|
7
|
+
data.tar.gz: cf4674bc02e4cf6215e8e9c3fb8768b71c71a78ca0839e1e36726d2a5bbac02b1936e98df9c7dfe43e5706a631d9676f42b43587ee076091f4a26e0e453f1db9
|
data/.travis.yml
CHANGED
data/lib/zendesk2/client/mock.rb
CHANGED
@@ -1,74 +1,76 @@
|
|
1
|
-
class Zendesk2::Client
|
2
|
-
|
1
|
+
class Zendesk2::Client::Mock
|
2
|
+
attr_reader :username, :url, :token, :jwt_token
|
3
|
+
attr_accessor :last_request
|
3
4
|
|
4
|
-
|
5
|
-
|
5
|
+
def self.data
|
6
|
+
@data ||= Hash.new { |h,k| h[k] = {
|
7
|
+
:categories => {},
|
8
|
+
:forums => {},
|
9
|
+
:groups => {},
|
10
|
+
:help_center_articles => {},
|
11
|
+
:help_center_categories => {},
|
12
|
+
:help_center_sections => {},
|
13
|
+
:identities => {},
|
14
|
+
:memberships => {},
|
15
|
+
:organizations => {},
|
16
|
+
:ticket_audits => {},
|
17
|
+
:ticket_comments => {},
|
18
|
+
:ticket_fields => {},
|
19
|
+
:ticket_metrics => {},
|
20
|
+
:tickets => {},
|
21
|
+
:topic_comments => {},
|
22
|
+
:topics => {},
|
23
|
+
:user_fields => {},
|
24
|
+
:users => {},
|
25
|
+
:views => {},
|
26
|
+
}
|
27
|
+
}
|
28
|
+
end
|
6
29
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
:help_center_articles => {},
|
13
|
-
:help_center_categories => {},
|
14
|
-
:help_center_sections => {},
|
15
|
-
:identities => {},
|
16
|
-
:memberships => {},
|
17
|
-
:organizations => {},
|
18
|
-
:ticket_audits => {},
|
19
|
-
:ticket_comments => {},
|
20
|
-
:ticket_fields => {},
|
21
|
-
:ticket_metrics => {},
|
22
|
-
:tickets => {},
|
23
|
-
:topic_comments => {},
|
24
|
-
:topics => {},
|
25
|
-
:user_fields => {},
|
26
|
-
:users => {},
|
27
|
-
:views => {},
|
28
|
-
}
|
29
|
-
}
|
30
|
-
end
|
30
|
+
def self.serial_id
|
31
|
+
@current_id ||= 0
|
32
|
+
@current_id += 1
|
33
|
+
@current_id
|
34
|
+
end
|
31
35
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
@current_id
|
36
|
-
end
|
36
|
+
def data
|
37
|
+
self.class.data[@url]
|
38
|
+
end
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
40
|
+
def reset
|
41
|
+
data.clear
|
42
|
+
end
|
41
43
|
|
42
|
-
|
43
|
-
|
44
|
-
|
44
|
+
def self.reset
|
45
|
+
data.clear
|
46
|
+
end
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
48
|
+
def serial_id
|
49
|
+
self.class.serial_id
|
50
|
+
end
|
49
51
|
|
50
|
-
|
51
|
-
|
52
|
-
|
52
|
+
def initialize(options={})
|
53
|
+
@url = options[:url]
|
54
|
+
@path = URI.parse(url).path
|
55
|
+
@username, @password = options[:username], options[:password]
|
56
|
+
@token = options[:token]
|
57
|
+
@jwt_token = options[:jwt_token]
|
53
58
|
|
54
|
-
|
55
|
-
@
|
56
|
-
|
57
|
-
@username,
|
58
|
-
|
59
|
-
@jwt_token = options[:jwt_token]
|
59
|
+
@current_user ||= self.data[:users].values.find { |u|
|
60
|
+
@username == u["name"]
|
61
|
+
} || self.create_user(
|
62
|
+
"user" => {"email" => @username, "name" => @username}
|
63
|
+
).body["user"]
|
60
64
|
|
61
|
-
|
62
|
-
|
63
|
-
end
|
65
|
+
@current_user_identity ||= self.data[:identities].values.first
|
66
|
+
end
|
64
67
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
68
|
+
# Lazily re-seeds data after reset
|
69
|
+
# @return [Hash] current user response
|
70
|
+
def current_user
|
71
|
+
self.data[:users][@current_user["id"]] ||= @current_user
|
72
|
+
self.data[:identities][@current_user_identity["id"]] ||= @current_user_identity
|
70
73
|
|
71
|
-
|
72
|
-
end
|
74
|
+
@current_user
|
73
75
|
end
|
74
76
|
end
|
@@ -23,6 +23,8 @@ class Zendesk2::Client::TicketAudit < Zendesk2::Client::Model
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def events
|
26
|
-
(self.attributes[:events] || []).map{|ae|
|
26
|
+
(self.attributes[:events] || []).map { |ae|
|
27
|
+
Zendesk2::Client::AuditEvent.for(ae.merge(ticket_audit: self, service: self.service))
|
28
|
+
}
|
27
29
|
end
|
28
30
|
end
|
data/lib/zendesk2/client/real.rb
CHANGED
@@ -1,71 +1,69 @@
|
|
1
|
-
class Zendesk2::Client
|
2
|
-
class Real
|
1
|
+
class Zendesk2::Client::Real
|
3
2
|
|
4
|
-
|
3
|
+
attr_accessor :username, :url, :token, :logger, :jwt_token, :last_request
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
def initialize(options={})
|
6
|
+
@url = if url = options[:url] || Zendesk2.defaults[:url]
|
7
|
+
URI.parse(url).to_s
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
@logger = options[:logger] || Logger.new(nil)
|
11
|
+
adapter = options[:adapter] || Faraday.default_adapter
|
12
|
+
@username = options[:username] || Zendesk2.defaults[:username]
|
13
|
+
@token = options.fetch(:token, Zendesk2.defaults[:token])
|
14
|
+
password = options[:password] || Zendesk2.defaults[:password]
|
16
15
|
|
17
|
-
|
16
|
+
service_options = options[:service_options] || {}
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
@auth_token = password || @token
|
19
|
+
@username += "/token" if @auth_token == @token
|
20
|
+
@jwt_token = options[:jwt_token]
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
raise "Missing required options: :url" unless @url
|
23
|
+
raise "Missing required options: :username" unless @username
|
24
|
+
raise "Missing required options: :password or :token" unless password || @token
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
@service = Faraday.new({url: @url}.merge(service_options)) do |connection|
|
27
|
+
# response
|
28
|
+
connection.use Faraday::Request::BasicAuthentication, @username, @auth_token
|
29
|
+
connection.use Faraday::Response::RaiseError
|
30
|
+
connection.response :json, content_type: /\bjson/
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
# request
|
33
|
+
connection.request :multipart
|
34
|
+
connection.request :json
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
36
|
+
# idempotency
|
37
|
+
connection.request :retry,
|
38
|
+
:max => 30,
|
39
|
+
:interval => 1,
|
40
|
+
:interval_randomness => 0.2,
|
41
|
+
:backoff_factor => 2
|
43
42
|
|
44
|
-
|
45
|
-
|
43
|
+
# rate limit
|
44
|
+
connection.use Zendesk2::RateLimit, logger: @logger
|
46
45
|
|
47
|
-
|
48
|
-
|
49
|
-
end
|
46
|
+
connection.use Zendesk2::Logger, @logger
|
47
|
+
connection.adapter(*adapter)
|
50
48
|
end
|
49
|
+
end
|
51
50
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
51
|
+
def request(options={})
|
52
|
+
method = options[:method] || :get
|
53
|
+
url = options[:url] || File.join(@url, "/api/v2", options[:path])
|
54
|
+
params = options[:params] || {}
|
55
|
+
body = options[:body]
|
56
|
+
headers = {"User-Agent" => Zendesk2::Client::USER_AGENT}.merge(options[:headers] || {})
|
58
57
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
end
|
65
|
-
rescue Faraday::ConnectionFailed
|
66
|
-
raise
|
67
|
-
rescue Faraday::Error::ClientError => e
|
68
|
-
raise Zendesk2::Error.new(e)
|
58
|
+
@service.send(method) do |req|
|
59
|
+
req.url(url)
|
60
|
+
req.headers.merge!(headers)
|
61
|
+
req.params.merge!(params)
|
62
|
+
req.body = @last_request = body
|
69
63
|
end
|
64
|
+
rescue Faraday::ConnectionFailed
|
65
|
+
raise
|
66
|
+
rescue Faraday::Error::ClientError => e
|
67
|
+
raise Zendesk2::Error.new(e)
|
70
68
|
end
|
71
69
|
end
|
data/lib/zendesk2/version.rb
CHANGED
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Zendesk2 do
|
5
|
+
context "when mocking", mock_only: true do
|
6
|
+
# this used to cause user creation conflicts
|
7
|
+
it "allows the client to be intialized more than once" do
|
8
|
+
Zendesk2::Client.new(username: "steve@example.org", url: "http://example.org")
|
9
|
+
Zendesk2::Client.new(username: "steve@example.org", url: "http://example.org")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zendesk2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.
|
4
|
+
version: 1.7.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Lane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10
|
11
|
+
date: 2015-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cistern
|
@@ -246,6 +246,7 @@ files:
|
|
246
246
|
- lib/zendesk2/searchable.rb
|
247
247
|
- lib/zendesk2/version.rb
|
248
248
|
- spec/categories_spec.rb
|
249
|
+
- spec/client_spec.rb
|
249
250
|
- spec/forums_spec.rb
|
250
251
|
- spec/groups_spec.rb
|
251
252
|
- spec/help_center/articles_spec.rb
|
@@ -294,6 +295,7 @@ specification_version: 4
|
|
294
295
|
summary: Zendesk V2 API client
|
295
296
|
test_files:
|
296
297
|
- spec/categories_spec.rb
|
298
|
+
- spec/client_spec.rb
|
297
299
|
- spec/forums_spec.rb
|
298
300
|
- spec/groups_spec.rb
|
299
301
|
- spec/help_center/articles_spec.rb
|