workarea-zendesk 1.0.0
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 +7 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
- data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.github/workflows/ci.yml +54 -0
- data/.gitignore +22 -0
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +13 -0
- data/Gemfile +15 -0
- data/LICENSE +52 -0
- data/README.md +73 -0
- data/Rakefile +57 -0
- data/app/assets/images/zendesk/.keep +0 -0
- data/app/assets/javascripts/zendesk/.keep +0 -0
- data/app/assets/stylesheets/zendesk/.keep +0 -0
- data/app/controllers/.keep +0 -0
- data/app/helpers/.keep +0 -0
- data/app/lib/workarea/zendesk/bogus_gateway.rb +57 -0
- data/app/lib/workarea/zendesk/gateway.rb +53 -0
- data/app/lib/workarea/zendesk/response.rb +27 -0
- data/app/mailers/.keep +0 -0
- data/app/models/.keep +0 -0
- data/app/views/workarea/storefront/_zendesk_web_widget.html.haml +2 -0
- data/app/workers/zendesk/create_inquiry_request.rb +46 -0
- data/bin/rails +25 -0
- data/config/initializers/append_points.rb +4 -0
- data/config/initializers/workarea.rb +8 -0
- data/config/routes.rb +2 -0
- data/lib/workarea/zendesk.rb +38 -0
- data/lib/workarea/zendesk/engine.rb +10 -0
- data/lib/workarea/zendesk/version.rb +5 -0
- data/test/dummy/.ruby-version +1 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/config/manifest.js +3 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/javascripts/application.js +14 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +2 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/jobs/application_job.rb +2 -0
- data/test/dummy/app/mailers/application_mailer.rb +4 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +15 -0
- data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +25 -0
- data/test/dummy/bin/update +25 -0
- data/test/dummy/config.ru +5 -0
- data/test/dummy/config/application.rb +34 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +52 -0
- data/test/dummy/config/environments/production.rb +83 -0
- data/test/dummy/config/environments/test.rb +45 -0
- data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/test/dummy/config/initializers/assets.rb +12 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/content_security_policy.rb +25 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/workarea.rb +5 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
- data/test/dummy/config/locales/en.yml +33 -0
- data/test/dummy/config/puma.rb +34 -0
- data/test/dummy/config/routes.rb +5 -0
- data/test/dummy/config/spring.rb +6 -0
- data/test/dummy/db/seeds.rb +2 -0
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/dummy/log/.keep +0 -0
- data/test/integration/workarea/storefront/zendesk_integration_test.rb +24 -0
- data/test/lib/workarea/zendesk/gateway_test.rb +64 -0
- data/test/support/workarea/zendesk_api_config.rb +19 -0
- data/test/teaspoon_env.rb +6 -0
- data/test/test_helper.rb +10 -0
- data/test/vcr_cassettes/zendesk/create_request.yml +87 -0
- data/test/vcr_cassettes/zendesk/create_request_error.yml +81 -0
- data/workarea-zendesk.gemspec +20 -0
- metadata +139 -0
@@ -0,0 +1,53 @@
|
|
1
|
+
module Workarea
|
2
|
+
module Zendesk
|
3
|
+
class Gateway
|
4
|
+
attr_reader :options
|
5
|
+
|
6
|
+
def initialize(options = {})
|
7
|
+
@options = options
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_request(request)
|
11
|
+
resp = connection.post('api/v2/requests.json') do |req|
|
12
|
+
req.body = request.to_json
|
13
|
+
end
|
14
|
+
|
15
|
+
Response.new(resp)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def encoded_basic_auth
|
21
|
+
"Basic #{Base64.encode64(auth_string)}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def connection
|
25
|
+
headers = { 'Content-Type' => 'application/json', 'Authorization' => encoded_basic_auth }
|
26
|
+
|
27
|
+
request_timeouts = {
|
28
|
+
timeout: Workarea.config.zendesk[:api_timeout],
|
29
|
+
open_timeout: Workarea.config.zendesk[:open_timeout]
|
30
|
+
}
|
31
|
+
|
32
|
+
conn = Faraday.new(url: rest_endpoint, headers: headers, request: request_timeouts)
|
33
|
+
conn
|
34
|
+
end
|
35
|
+
|
36
|
+
def api_user_name
|
37
|
+
options[:api_user_name]
|
38
|
+
end
|
39
|
+
|
40
|
+
def api_token
|
41
|
+
options[:api_token]
|
42
|
+
end
|
43
|
+
|
44
|
+
def auth_string
|
45
|
+
"#{api_user_name}/token:#{api_token}"
|
46
|
+
end
|
47
|
+
|
48
|
+
def rest_endpoint
|
49
|
+
options[:rest_endpoint]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Workarea
|
2
|
+
module Zendesk
|
3
|
+
class Response
|
4
|
+
attr_reader :response
|
5
|
+
|
6
|
+
def initialize(response = {})
|
7
|
+
@response = response
|
8
|
+
end
|
9
|
+
|
10
|
+
def success?
|
11
|
+
@response.status.to_s =~ /^2/
|
12
|
+
end
|
13
|
+
|
14
|
+
def body
|
15
|
+
return {} unless @response.body.present?
|
16
|
+
JSON.parse(@response.body)
|
17
|
+
end
|
18
|
+
|
19
|
+
def error_details
|
20
|
+
return unless body.present?
|
21
|
+
return unless body["error"].present?
|
22
|
+
|
23
|
+
body["details"].to_s
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/app/mailers/.keep
ADDED
File without changes
|
data/app/models/.keep
ADDED
File without changes
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Workarea
|
2
|
+
module Zendesk
|
3
|
+
class CreateInquiryRequest
|
4
|
+
class ZendeskTicketError < StandardError; end
|
5
|
+
|
6
|
+
include Sidekiq::Worker
|
7
|
+
include Sidekiq::CallbacksWorker
|
8
|
+
|
9
|
+
sidekiq_options(
|
10
|
+
enqueue_on: { Workarea::Inquiry => [:create] }
|
11
|
+
)
|
12
|
+
|
13
|
+
def perform(id)
|
14
|
+
inquiry = Workarea::Inquiry.find(id)
|
15
|
+
response = Workarea::Zendesk.gateway.create_request(zendesk_request(inquiry))
|
16
|
+
|
17
|
+
raise ZendeskTicketError, response.error_details unless response.success?
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def test_prefix
|
23
|
+
!Rails.env.production? ? "** IGNORE * TEST * IGNORE ** " : ""
|
24
|
+
end
|
25
|
+
|
26
|
+
def zendesk_request(inquiry)
|
27
|
+
{
|
28
|
+
request: {
|
29
|
+
requester: {
|
30
|
+
name: inquiry.name,
|
31
|
+
email: inquiry.email
|
32
|
+
},
|
33
|
+
subject: test_prefix + inquiry.full_subject,
|
34
|
+
comment: {
|
35
|
+
body: comment_body(inquiry)
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def comment_body(inquiry)
|
42
|
+
"Name: #{inquiry.name}\nEmail: #{inquiry.email}\nSubject: #{inquiry.full_subject}\nOrder Id: #{inquiry.order_id || ""}\nMessage: #{inquiry.message}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/bin/rails
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails gems
|
3
|
+
# installed from the root of your application.
|
4
|
+
|
5
|
+
ENGINE_ROOT = File.expand_path('..', __dir__)
|
6
|
+
ENGINE_PATH = File.expand_path('../lib/workarea/zendesk/engine', __dir__)
|
7
|
+
APP_PATH = File.expand_path('../test/dummy/config/application', __dir__)
|
8
|
+
|
9
|
+
# Set up gems listed in the Gemfile.
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
11
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
12
|
+
|
13
|
+
require "rails"
|
14
|
+
# Pick the frameworks you want:
|
15
|
+
require "active_model/railtie"
|
16
|
+
require "active_job/railtie"
|
17
|
+
# require "active_record/railtie"
|
18
|
+
# require "active_storage/engine"
|
19
|
+
require "action_controller/railtie"
|
20
|
+
require "action_mailer/railtie"
|
21
|
+
require "action_view/railtie"
|
22
|
+
# require "action_cable/engine"
|
23
|
+
require "sprockets/railtie"
|
24
|
+
require "rails/test_unit/railtie"
|
25
|
+
require 'rails/engine/commands'
|
data/config/routes.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'workarea'
|
2
|
+
require 'workarea/storefront'
|
3
|
+
require 'workarea/admin'
|
4
|
+
|
5
|
+
require 'workarea/zendesk/engine'
|
6
|
+
require 'workarea/zendesk/version'
|
7
|
+
|
8
|
+
module Workarea
|
9
|
+
module Zendesk
|
10
|
+
def self.config
|
11
|
+
Workarea.config.zendesk
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.credentials
|
15
|
+
(Rails.application.secrets.zendesk || '')
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.rest_endpoint
|
19
|
+
config.rest_endpoint
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.api_user_name
|
23
|
+
credentials[:api_user_name]
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.api_token
|
27
|
+
credentials[:api_token]
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.gateway
|
31
|
+
if credentials.present?
|
32
|
+
Zendesk::Gateway.new(rest_endpoint: rest_endpoint, api_user_name: api_user_name, api_token: api_token)
|
33
|
+
else
|
34
|
+
Zendesk::BogusGateway.new
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
2.4.2
|
data/test/dummy/Rakefile
ADDED
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require rails-ujs
|
14
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
File without changes
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<%= csrf_meta_tags %>
|
6
|
+
<%= csp_meta_tag %>
|
7
|
+
|
8
|
+
<%= stylesheet_link_tag 'application', media: 'all' %>
|
9
|
+
<%= javascript_include_tag 'application' %>
|
10
|
+
</head>
|
11
|
+
|
12
|
+
<body>
|
13
|
+
<%= yield %>
|
14
|
+
</body>
|
15
|
+
</html>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= yield %>
|
data/test/dummy/bin/rake
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'fileutils'
|
3
|
+
include FileUtils
|
4
|
+
|
5
|
+
# path to your application root.
|
6
|
+
APP_ROOT = File.expand_path('..', __dir__)
|
7
|
+
|
8
|
+
def system!(*args)
|
9
|
+
system(*args) || abort("\n== Command #{args} failed ==")
|
10
|
+
end
|
11
|
+
|
12
|
+
chdir APP_ROOT do
|
13
|
+
# This script is a starting point to setup your application.
|
14
|
+
# Add necessary setup steps to this file.
|
15
|
+
|
16
|
+
puts '== Installing dependencies =='
|
17
|
+
system! 'gem install bundler --conservative'
|
18
|
+
system('bundle check') || system!('bundle install')
|
19
|
+
|
20
|
+
puts "\n== Removing old logs and tempfiles =="
|
21
|
+
system! 'bin/rails log:clear tmp:clear'
|
22
|
+
|
23
|
+
puts "\n== Restarting application server =="
|
24
|
+
system! 'bin/rails restart'
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'fileutils'
|
3
|
+
include FileUtils
|
4
|
+
|
5
|
+
# path to your application root.
|
6
|
+
APP_ROOT = File.expand_path('..', __dir__)
|
7
|
+
|
8
|
+
def system!(*args)
|
9
|
+
system(*args) || abort("\n== Command #{args} failed ==")
|
10
|
+
end
|
11
|
+
|
12
|
+
chdir APP_ROOT do
|
13
|
+
# This script is a way to update your development environment automatically.
|
14
|
+
# Add necessary update steps to this file.
|
15
|
+
|
16
|
+
puts '== Installing dependencies =='
|
17
|
+
system! 'gem install bundler --conservative'
|
18
|
+
system('bundle check') || system!('bundle install')
|
19
|
+
|
20
|
+
puts "\n== Removing old logs and tempfiles =="
|
21
|
+
system! 'bin/rails log:clear tmp:clear'
|
22
|
+
|
23
|
+
puts "\n== Restarting application server =="
|
24
|
+
system! 'bin/rails restart'
|
25
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative 'boot'
|
2
|
+
|
3
|
+
require "rails"
|
4
|
+
# Pick the frameworks you want:
|
5
|
+
require "active_model/railtie"
|
6
|
+
require "active_job/railtie"
|
7
|
+
# require "active_record/railtie"
|
8
|
+
# require "active_storage/engine"
|
9
|
+
require "action_controller/railtie"
|
10
|
+
require "action_mailer/railtie"
|
11
|
+
require "action_view/railtie"
|
12
|
+
# require "action_cable/engine"
|
13
|
+
require "sprockets/railtie"
|
14
|
+
require "rails/test_unit/railtie"
|
15
|
+
|
16
|
+
# Workarea must be required before other gems to ensure control over Rails.env
|
17
|
+
# for running tests
|
18
|
+
require 'workarea/core'
|
19
|
+
require 'workarea/admin'
|
20
|
+
require 'workarea/storefront'
|
21
|
+
Bundler.require(*Rails.groups)
|
22
|
+
require "workarea/zendesk"
|
23
|
+
|
24
|
+
module Dummy
|
25
|
+
class Application < Rails::Application
|
26
|
+
# Initialize configuration defaults for originally generated Rails version.
|
27
|
+
config.load_defaults 5.2
|
28
|
+
|
29
|
+
# Settings in config/environments/* take precedence over those specified here.
|
30
|
+
# Application configuration can go into files in config/initializers
|
31
|
+
# -- all .rb files in that directory are automatically loaded after loading
|
32
|
+
# the framework and any gems in your application.
|
33
|
+
end
|
34
|
+
end
|