desk 1.0.8 → 1.0.9
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.
- checksums.yaml +4 -4
- data/README.mkd +13 -0
- data/desk.gemspec +2 -1
- data/lib/desk/api.rb +1 -1
- data/lib/desk/authentication.rb +30 -0
- data/lib/desk/client/case.rb +1 -1
- data/lib/desk/client/insight.rb +2 -2
- data/lib/desk/configuration.rb +38 -0
- data/lib/desk/connection.rb +7 -1
- data/lib/desk/deash.rb +1 -2
- data/lib/desk/version.rb +1 -1
- data/spec/desk/api_spec.rb +4 -0
- data/spec/desk/client/customer_spec.rb +2 -1
- data/spec/desk_spec.rb +38 -2
- metadata +14 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf6cdb20333938ba846729b567cb0a18297354f6
|
4
|
+
data.tar.gz: 8a2b4d82b8e86a7fde28b53d6d9b56540c8469ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4df4acd8e57b70fccedbab77ff9f94a4e087c0775bfd88b3410bbd1791561365c1ca58fc7cab94d0f657cd841fcbaec3d71b50821680bd27d4023a7c43c24cc9
|
7
|
+
data.tar.gz: f55c90b816664f3d557a299e05e6934ce3b7b2a663a543b0f1593979889feb73a986c849937cac60fc7456e143c9f9af4df2f8814dc20bd4081be7583cf258b0
|
data/README.mkd
CHANGED
@@ -389,6 +389,19 @@ Usage Examples
|
|
389
389
|
# Show the daily system message
|
390
390
|
Desk.system_message
|
391
391
|
|
392
|
+
# Basic authentication with username and password; not recommended
|
393
|
+
|
394
|
+
Desk.configure do |config|
|
395
|
+
config.support_email = "help@example.com"
|
396
|
+
config.subdomain = YOUR_DESK_SUBDOMAIN
|
397
|
+
config.consumer_key = YOUR_CONSUMER_KEY
|
398
|
+
config.consumer_secret = YOUR_CONSUMER_SECRET
|
399
|
+
config.auth_method = Desk::Authentication::Methods:BASIC
|
400
|
+
config.basic_auth_username = YOUR_USERNAME
|
401
|
+
config.basic_auth_password = YOUR_PASSWORD
|
402
|
+
end
|
403
|
+
|
404
|
+
|
392
405
|
Contributing
|
393
406
|
------------
|
394
407
|
In the spirit of [free software](http://www.fsf.org/licensing/essays/free-sw.html), **everyone** is encouraged to help improve this project.
|
data/desk.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.add_development_dependency('webmock', '~> 1.6')
|
13
13
|
s.add_development_dependency('yard', '~> 0.6')
|
14
14
|
s.add_runtime_dependency('json', '~> 1.7') if RUBY_VERSION < '1.9'
|
15
|
-
s.add_runtime_dependency 'hashie', '3.4.
|
15
|
+
s.add_runtime_dependency 'hashie', '~> 3.4', '>= 3.4.2'
|
16
16
|
s.add_runtime_dependency('faraday', '~> 0.9.0')
|
17
17
|
s.add_runtime_dependency('faraday_middleware', '~> 0.9.0')
|
18
18
|
s.add_runtime_dependency('jruby-openssl', '~> 0.7.2') if RUBY_PLATFORM == 'java'
|
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
s.files = `git ls-files`.split("\n")
|
28
28
|
s.homepage = 'https://github.com/zencoder/desk'
|
29
29
|
s.name = 'desk'
|
30
|
+
s.license = 'MIT'
|
30
31
|
s.platform = Gem::Platform::RUBY
|
31
32
|
s.require_paths = ['lib']
|
32
33
|
s.required_rubygems_version = Gem::Requirement.new('>= 1.3.6') if s.respond_to? :required_rubygems_version=
|
data/lib/desk/api.rb
CHANGED
data/lib/desk/authentication.rb
CHANGED
@@ -1,12 +1,32 @@
|
|
1
1
|
module Desk
|
2
2
|
# @private
|
3
3
|
module Authentication
|
4
|
+
module Methods
|
5
|
+
OAUTH = "oauth"
|
6
|
+
BASIC = "basic"
|
7
|
+
ALL = [
|
8
|
+
OAUTH,
|
9
|
+
BASIC,
|
10
|
+
]
|
11
|
+
end
|
12
|
+
|
4
13
|
private
|
5
14
|
|
6
15
|
# Authentication hash
|
7
16
|
#
|
8
17
|
# @return [Hash]
|
9
18
|
def authentication
|
19
|
+
if auth_method == Methods::BASIC
|
20
|
+
basic_authentication
|
21
|
+
else
|
22
|
+
oauth_authentication
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Authentication hash for OAUTH connections
|
27
|
+
#
|
28
|
+
# @return [Hash]
|
29
|
+
def oauth_authentication
|
10
30
|
{
|
11
31
|
:consumer_key => consumer_key,
|
12
32
|
:consumer_secret => consumer_secret,
|
@@ -15,6 +35,16 @@ module Desk
|
|
15
35
|
}
|
16
36
|
end
|
17
37
|
|
38
|
+
# Authentication hash for Basic auth connections
|
39
|
+
#
|
40
|
+
# @return [Hash]
|
41
|
+
def basic_authentication
|
42
|
+
{
|
43
|
+
:username => basic_auth_username,
|
44
|
+
:password => basic_auth_password
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
18
48
|
# Check whether user is authenticated
|
19
49
|
#
|
20
50
|
# @return [Boolean]
|
data/lib/desk/client/case.rb
CHANGED
data/lib/desk/client/insight.rb
CHANGED
@@ -3,13 +3,13 @@ module Desk
|
|
3
3
|
module Insight
|
4
4
|
|
5
5
|
def show_insights_meta
|
6
|
-
get("
|
6
|
+
get("insights3/meta")
|
7
7
|
end
|
8
8
|
alias_method :insights_meta, :show_insights_meta
|
9
9
|
|
10
10
|
def create_insights_report(*args)
|
11
11
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
12
|
-
post("
|
12
|
+
post("insights3/reports", options)
|
13
13
|
end
|
14
14
|
|
15
15
|
end
|
data/lib/desk/configuration.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'faraday'
|
2
2
|
require 'desk/version'
|
3
|
+
require 'desk/authentication'
|
3
4
|
|
4
5
|
module Desk
|
5
6
|
# Defines constants and methods related to configuration
|
@@ -7,8 +8,12 @@ module Desk
|
|
7
8
|
# An array of valid keys in the options hash when configuring a {Twitter::API}
|
8
9
|
VALID_OPTIONS_KEYS = [
|
9
10
|
:adapter,
|
11
|
+
:auth_method,
|
12
|
+
:basic_auth_username,
|
13
|
+
:basic_auth_password,
|
10
14
|
:consumer_key,
|
11
15
|
:consumer_secret,
|
16
|
+
:domain,
|
12
17
|
:format,
|
13
18
|
:logger,
|
14
19
|
:max_requests,
|
@@ -32,6 +37,18 @@ module Desk
|
|
32
37
|
# @note The default faraday adapter is Net::HTTP.
|
33
38
|
DEFAULT_ADAPTER = Faraday.default_adapter
|
34
39
|
|
40
|
+
# By default, OAUTH is selected
|
41
|
+
DEFAULT_AUTH_METHOD = Desk::Authentication::Methods::OAUTH
|
42
|
+
|
43
|
+
# By default, don't set a username
|
44
|
+
DEFAULT_BASIC_AUTH_USERNAME = nil
|
45
|
+
|
46
|
+
# By default, don't set a password
|
47
|
+
DEFAULT_BASIC_AUTH_PASSWORD = nil
|
48
|
+
|
49
|
+
# By default, use the desk.com hosted domain
|
50
|
+
DEFAULT_DOMAIN = "desk.com"
|
51
|
+
|
35
52
|
# By default, don't set an application key
|
36
53
|
DEFAULT_CONSUMER_KEY = nil
|
37
54
|
|
@@ -75,6 +92,7 @@ module Desk
|
|
75
92
|
# By default, don't set a support email address
|
76
93
|
DEFAULT_SUPPORT_EMAIL = nil
|
77
94
|
|
95
|
+
attr_reader :DEFAULT_ADAPTER
|
78
96
|
# @private
|
79
97
|
attr_accessor *VALID_OPTIONS_KEYS
|
80
98
|
|
@@ -101,6 +119,14 @@ module Desk
|
|
101
119
|
Thread.current[:adapter] = val
|
102
120
|
end
|
103
121
|
|
122
|
+
def auth_method
|
123
|
+
Thread.current[:auth_method] ||= DEFAULT_ADAPTER
|
124
|
+
end
|
125
|
+
|
126
|
+
def auth_method=(val)
|
127
|
+
Thread.current[:auth_method] = val
|
128
|
+
end
|
129
|
+
|
104
130
|
def consumer_key
|
105
131
|
Thread.current[:consumer_key] ||= DEFAULT_CONSUMER_KEY
|
106
132
|
end
|
@@ -117,6 +143,14 @@ module Desk
|
|
117
143
|
Thread.current[:consumer_secret] = val
|
118
144
|
end
|
119
145
|
|
146
|
+
def domain
|
147
|
+
Thread.current[:domain] ||= DEFAULT_DOMAIN
|
148
|
+
end
|
149
|
+
|
150
|
+
def domain=(val)
|
151
|
+
Thread.current[:domain] = val
|
152
|
+
end
|
153
|
+
|
120
154
|
def format
|
121
155
|
Thread.current[:format] ||= DEFAULT_FORMAT
|
122
156
|
end
|
@@ -208,8 +242,12 @@ module Desk
|
|
208
242
|
# Reset all configuration options to defaults
|
209
243
|
def reset
|
210
244
|
self.adapter = DEFAULT_ADAPTER
|
245
|
+
self.auth_method = DEFAULT_AUTH_METHOD
|
246
|
+
self.basic_auth_username= DEFAULT_BASIC_AUTH_USERNAME
|
247
|
+
self.basic_auth_password= DEFAULT_BASIC_AUTH_PASSWORD
|
211
248
|
self.consumer_key = DEFAULT_CONSUMER_KEY
|
212
249
|
self.consumer_secret = DEFAULT_CONSUMER_SECRET
|
250
|
+
self.domain = DEFAULT_DOMAIN
|
213
251
|
self.format = DEFAULT_FORMAT
|
214
252
|
self.logger = DEFAULT_LOGGER
|
215
253
|
self.max_requests = DEFAULT_MAX_REQUESTS
|
data/lib/desk/connection.rb
CHANGED
@@ -19,7 +19,13 @@ module Desk
|
|
19
19
|
|
20
20
|
Faraday.new(options) do |builder|
|
21
21
|
builder.use Faraday::Request::MultipartWithFile
|
22
|
-
|
22
|
+
if authenticated?
|
23
|
+
if auth_method == Desk::Authentication::Methods::BASIC
|
24
|
+
builder.use Faraday::Request::BasicAuthentication,basic_auth_username, basic_auth_password
|
25
|
+
else
|
26
|
+
builder.use Faraday::Request::OAuth, authentication
|
27
|
+
end
|
28
|
+
end
|
23
29
|
builder.use Faraday::Request::Multipart
|
24
30
|
builder.use Faraday::Request::UrlEncoded
|
25
31
|
builder.use Faraday::Response::RaiseHttp4xx
|
data/lib/desk/deash.rb
CHANGED
data/lib/desk/version.rb
CHANGED
data/spec/desk/api_spec.rb
CHANGED
@@ -30,8 +30,12 @@ describe Desk::API do
|
|
30
30
|
|
31
31
|
before do
|
32
32
|
@configuration = {
|
33
|
+
:auth_method => Desk::Authentication::Methods::BASIC,
|
34
|
+
:basic_auth_username => 'UN',
|
35
|
+
:basic_auth_password => 'PW',
|
33
36
|
:consumer_key => 'CK',
|
34
37
|
:consumer_secret => 'CS',
|
38
|
+
:domain => 'example.com',
|
35
39
|
:oauth_token => 'OT',
|
36
40
|
:oauth_token_secret => 'OS',
|
37
41
|
:adapter => :typhoeus,
|
@@ -16,7 +16,8 @@ describe Desk::Client do
|
|
16
16
|
|
17
17
|
it_behaves_like "a create endpoint", {
|
18
18
|
:first_name => "John",
|
19
|
-
:last_name => "Doe"
|
19
|
+
:last_name => "Doe",
|
20
|
+
:emails => [{:type => "work", :value => "joe.user@example.org"}]
|
20
21
|
}
|
21
22
|
|
22
23
|
it_behaves_like "an update endpoint", { :first_name => "Johnny" } do
|
data/spec/desk_spec.rb
CHANGED
@@ -45,6 +45,42 @@ describe Desk do
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
+
describe ".auth_method" do
|
49
|
+
it "should return the default auth method" do
|
50
|
+
Desk.auth_method = Desk::Configuration::DEFAULT_AUTH_METHOD
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe ".auth_method=" do
|
55
|
+
it "should set the auth_method for all auth types" do
|
56
|
+
valid_methods = Desk::Authentication::Methods::ALL*5
|
57
|
+
valid_methods.each do |method|
|
58
|
+
Desk.auth_method = method
|
59
|
+
Desk.auth_method.should == method
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe ".domain" do
|
65
|
+
it "should return the default domain" do
|
66
|
+
Desk.domain.should == Desk::Configuration::DEFAULT_DOMAIN
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe ".domain=" do
|
71
|
+
before do
|
72
|
+
Desk.domain = "example.org"
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should set the domain" do
|
76
|
+
Desk.domain.should == "example.org"
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should change the endpoint" do
|
80
|
+
Desk.endpoint.should == "https://#{Desk::Configuration::DEFAULT_SUBDOMAIN}.example.org/api/#{Desk::Configuration::DEFAULT_VERSION}/"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
48
84
|
describe ".subdomain=" do
|
49
85
|
before do
|
50
86
|
Desk.subdomain = "zencoder"
|
@@ -55,7 +91,7 @@ describe Desk do
|
|
55
91
|
end
|
56
92
|
|
57
93
|
it "should change the endpoint" do
|
58
|
-
Desk.endpoint.should == "https://zencoder
|
94
|
+
Desk.endpoint.should == "https://zencoder.#{Desk::Configuration::DEFAULT_DOMAIN}/api/#{Desk::Configuration::DEFAULT_VERSION}/"
|
59
95
|
end
|
60
96
|
end
|
61
97
|
|
@@ -77,7 +113,7 @@ describe Desk do
|
|
77
113
|
Desk.version = "v4"
|
78
114
|
end
|
79
115
|
|
80
|
-
it "should set the
|
116
|
+
it "should set the version" do
|
81
117
|
Desk.version.should == "v4"
|
82
118
|
end
|
83
119
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: desk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Warren
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -132,16 +132,22 @@ dependencies:
|
|
132
132
|
name: hashie
|
133
133
|
requirement: !ruby/object:Gem::Requirement
|
134
134
|
requirements:
|
135
|
-
- -
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '3.4'
|
138
|
+
- - ">="
|
136
139
|
- !ruby/object:Gem::Version
|
137
|
-
version: 3.4.
|
140
|
+
version: 3.4.2
|
138
141
|
type: :runtime
|
139
142
|
prerelease: false
|
140
143
|
version_requirements: !ruby/object:Gem::Requirement
|
141
144
|
requirements:
|
142
|
-
- -
|
145
|
+
- - "~>"
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '3.4'
|
148
|
+
- - ">="
|
143
149
|
- !ruby/object:Gem::Version
|
144
|
-
version: 3.4.
|
150
|
+
version: 3.4.2
|
145
151
|
- !ruby/object:Gem::Dependency
|
146
152
|
name: faraday
|
147
153
|
requirement: !ruby/object:Gem::Requirement
|
@@ -405,7 +411,8 @@ files:
|
|
405
411
|
- spec/shared_context.rb
|
406
412
|
- spec/shared_examples.rb
|
407
413
|
homepage: https://github.com/zencoder/desk
|
408
|
-
licenses:
|
414
|
+
licenses:
|
415
|
+
- MIT
|
409
416
|
metadata: {}
|
410
417
|
post_install_message:
|
411
418
|
rdoc_options: []
|