zendesk_apps_tools 2.12.0 → 2.12.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 96bae990144484c85c9a51b4008e1aed20c55cf45fc912ddb32321a297e548e8
4
- data.tar.gz: f5c245e354a317b97b93de231dbfed59a1bd9f91d49ecb2933a7d85d99983144
2
+ SHA1:
3
+ metadata.gz: 1ee308e4dfdc555c1b6c864fa7516d08cafe7f0f
4
+ data.tar.gz: 8fc3c41e0d56a395891f402b478944436ff9c806
5
5
  SHA512:
6
- metadata.gz: 2081cc4b5c7754b20d3cb3b644c133656c9ef6cf9014a705c01449ed1e7200e1dbebfe3b3a4fb2f62dd83460531526db3440586db304dd0858a1d01583fdf20b
7
- data.tar.gz: 5031f40fb8f8b667fb2593f9b2b9cd6e781eeea414e7a6bcbb8750e09dd08164d01bae4d70b2661475ecbfcf500734531079a6856392c13e2d0d95c47b4e3722
6
+ metadata.gz: adb8c79e5bd5a625e9914c9bff76ed0a0cf37a209662e76aef57f9a445568890b90ee9847ee197587cfc328ed7c350dc3b70f5f58687fe065ed0862b1e28ed65
7
+ data.tar.gz: 60b4dba4543aef673189ced75f7b643047e4e1c87973fe576ffbfca09d591765c98f196872229c700d009a3670457ba3f6bec60913e1004bf40d8c72213ea952
data/README.md CHANGED
@@ -18,10 +18,16 @@ For information on using the tools, see [Zendesk App Tools](https://developer.z
18
18
  ## Work on ZAT
19
19
  If you want to help **develop** this tool, clone this repo and run `bundle install`.
20
20
 
21
- ZAT uses a gem called [ZAS](https://github.com/zendesk/zendesk_apps_support/). If you're developing ZAT, you'll probably want to edit code in ZAS too. To do so, you need to clone the ZAS repo and change the `Gemfile` in the ZAT project to say:
21
+ ZAT uses a gem called [ZAS](https://github.com/zendesk/zendesk_apps_support/). If you're developing ZAT, you'll probably want to edit code in ZAS too. To do so, you need to clone the ZAS repo and add the following line at the end of `Gemfile` in the ZAT project:
22
22
 
23
23
  `gem 'zendesk_apps_support', path: '../zendesk_apps_support'`
24
24
 
25
+ Then, comment-out the line referring to `zendesk_apps_support` in this project's `.gemspec` file.
26
+
27
+ ```
28
+ # s.add_runtime_dependency 'zendesk_apps_support', '~> X.YY.ZZ'
29
+ ```
30
+
25
31
  The path should point to your local ZAS directory. In this way, your clone of ZAT will use a local version of ZAS, which is very helpful for development. Run a `bundle install` after changing the Gemfile.
26
32
 
27
33
  ## Testing
@@ -1,11 +1,26 @@
1
1
  module ZendeskAppsTools
2
2
  module APIConnection
3
- FULL_URL = /https?:\/\//
4
- URL_TEMPLATE = 'https://%s.zendesk.com/'
3
+ DEFAULT_URL_TEMPLATE = 'https://%s.zendesk.com/'
4
+ # taken from zendesk/lib/vars.rb
5
+ SUBDOMAIN_VALIDATION_PATTERN = /^[a-z0-9][a-z0-9\-]{1,}[a-z0-9]$/i
6
+ ZENDESK_URL_VALIDATION_PATTERN = /^(https?):\/\/[a-z0-9]+(([\.]|[\-]{1,2})[a-z0-9]+)*\.([a-z]{2,16}|[0-9]{1,3})((:[0-9]{1,5})?(\/?|\/.*))?$/ix
7
+ EMAIL_REGEX = /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i
8
+
9
+ EMAIL_ERROR_MSG = 'Please enter a valid email address.'
10
+ PROMPT_FOR_URL = 'Enter your Zendesk subdomain or full URL (including protocol):'
11
+ URL_ERROR_MSG = [
12
+ 'URL error. Example URL: https://mysubdomain.zendesk.com',
13
+ 'If you are using a full URL, follow the url as shown above.',
14
+ 'If you are using a subdomain, ensure that it contains only valid characters (a-z, A-Z, 0-9, and hyphens).'
15
+ ].join('\n')
5
16
 
6
17
  def prepare_api_auth
7
- @subdomain ||= cache.fetch('subdomain') || get_value_from_stdin('Enter your Zendesk subdomain or full Zendesk URL:')
18
+ @subdomain ||= cache.fetch('subdomain') || get_value_from_stdin(PROMPT_FOR_URL)
19
+ say_error_and_exit URL_ERROR_MSG unless valid_subdomain? || valid_full_url?
20
+
8
21
  @username ||= cache.fetch('username', @subdomain) || get_value_from_stdin('Enter your username:')
22
+ say_error_and_exit EMAIL_ERROR_MSG unless valid_email?
23
+
9
24
  @password ||= cache.fetch('password', @subdomain) || get_password_from_stdin('Enter your password:')
10
25
 
11
26
  cache.save 'subdomain' => @subdomain, 'username' => @username
@@ -25,11 +40,19 @@ module ZendeskAppsTools
25
40
  private
26
41
 
27
42
  def full_url
28
- if FULL_URL =~ @subdomain
29
- @subdomain
30
- else
31
- URL_TEMPLATE % @subdomain
32
- end
43
+ valid_full_url? ? @subdomain : (DEFAULT_URL_TEMPLATE % @subdomain)
44
+ end
45
+
46
+ def valid_full_url?
47
+ !!ZENDESK_URL_VALIDATION_PATTERN.match(@subdomain)
48
+ end
49
+
50
+ def valid_subdomain?
51
+ !!SUBDOMAIN_VALIDATION_PATTERN.match(@subdomain)
52
+ end
53
+
54
+ def valid_email?
55
+ !!EMAIL_REGEX.match(@username)
33
56
  end
34
57
  end
35
58
  end
@@ -1,9 +1,16 @@
1
+ require 'faraday'
2
+ require 'zendesk_apps_tools/common'
3
+ require 'zendesk_apps_tools/api_connection'
4
+
1
5
  module ZendeskAppsTools
2
6
  module Deploy
7
+ include ZendeskAppsTools::Common
8
+ include ZendeskAppsTools::APIConnection
9
+ alias_method :connection, :get_connection
10
+
3
11
  def deploy_app(connection_method, url, body)
4
12
  body[:upload_id] = upload(options[:path]).to_s
5
13
  sleep 2 # Because the DB needs time to replicate
6
- connection = get_connection
7
14
 
8
15
  response = connection.send(connection_method) do |req|
9
16
  req.url url
@@ -19,7 +26,6 @@ module ZendeskAppsTools
19
26
 
20
27
  def app_exists?(app_id)
21
28
  url = "/api/v2/apps/#{app_id}.json"
22
- connection = get_connection
23
29
  response = connection.send(:get) do |req|
24
30
  req.url url
25
31
  end
@@ -28,7 +34,6 @@ module ZendeskAppsTools
28
34
  end
29
35
 
30
36
  def install_app(poll_job, product_name, installation)
31
- connection = get_connection
32
37
  response = connection.post do |req|
33
38
  req.url "api/#{product_name}/apps/installations.json"
34
39
  req.headers[:content_type] = 'application/json'
@@ -38,7 +43,6 @@ module ZendeskAppsTools
38
43
  end
39
44
 
40
45
  def upload(path)
41
- connection = get_connection :multipart
42
46
  zipfile_path = options[:zipfile]
43
47
 
44
48
  if zipfile_path
@@ -48,9 +52,11 @@ module ZendeskAppsTools
48
52
  package_path = Dir[File.join path, '/tmp/*.zip'].sort.last
49
53
  end
50
54
 
51
- payload = { uploaded_data: Faraday::UploadIO.new(package_path, 'application/zip') }
55
+ payload = {
56
+ uploaded_data: Faraday::UploadIO.new(package_path, 'application/zip')
57
+ }
52
58
 
53
- response = connection.post('/api/v2/apps/uploads.json', payload)
59
+ response = connection(:multipart).post('/api/v2/apps/uploads.json', payload)
54
60
  json_or_die(response.body)['id']
55
61
 
56
62
  rescue Faraday::Error::ClientError => e
@@ -59,25 +65,32 @@ module ZendeskAppsTools
59
65
 
60
66
  def find_app_id
61
67
  say_status 'Update', 'app ID is missing, searching...'
62
- name = get_value_from_stdin('Enter the name of the app:')
68
+ app_name = get_value_from_stdin('Enter the name of the app:')
69
+
70
+ all_apps_json = connection.get('/api/apps.json').body
63
71
 
64
- connection = get_connection
72
+ app =
73
+ unless all_apps_json.empty?
74
+ json_or_die(all_apps_json)['apps'].find { |app| app['name'] == app_name }
75
+ end
65
76
 
66
- all_apps = connection.get('/api/apps.json').body
77
+ unless app
78
+ say_error_and_exit(
79
+ "App not found. " \
80
+ "Please verify that your credentials, subdomain, and app name are correct."
81
+ )
82
+ end
67
83
 
68
- app_json = all_apps.empty? ? nil : json_or_die(all_apps)['apps'].find { |app| app['name'] == name }
69
- say_error_and_exit('The app was not found. Please verify your credentials, subdomain, and app name are correct.') unless app_json
70
- app_id = app_json['id']
84
+ cache.save 'app_id' => app['id']
85
+ app['id']
71
86
 
72
- cache.save 'app_id' => app_id
73
- app_id
74
87
  rescue Faraday::Error::ClientError => e
75
88
  say_error_and_exit e.message
76
89
  end
77
90
 
78
91
  def check_status(response, poll_job = true)
79
- job = response.body
80
- job_response = json_or_die(job)
92
+ job_response = json_or_die(response.body)
93
+
81
94
  say_error_and_exit job_response['error'] if job_response['error']
82
95
 
83
96
  if poll_job
@@ -87,22 +100,21 @@ module ZendeskAppsTools
87
100
  end
88
101
 
89
102
  def check_job(job_id)
90
- connection = get_connection
103
+ http_client = connection
91
104
 
92
105
  loop do
93
- response = connection.get("/api/v2/apps/job_statuses/#{job_id}")
106
+ response = http_client.get("/api/v2/apps/job_statuses/#{job_id}")
94
107
  info = json_or_die(response.body)
95
108
  status = info['status']
96
- message = info['message']
97
- app_id = info['app_id']
98
109
 
99
110
  if %w(completed failed).include? status
100
111
  case status
101
112
  when 'completed'
113
+ app_id = info['app_id']
102
114
  cache.save 'app_id' => app_id if app_id
103
115
  say_status @command, 'OK'
104
116
  when 'failed'
105
- say_status @command, message, :red
117
+ say_status @command, info['message'], :red
106
118
  exit 1
107
119
  end
108
120
  break
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ZendeskAppsTools
3
- VERSION = '2.12.0'
3
+ VERSION = '2.12.1'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zendesk_apps_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.12.0
4
+ version: 2.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James A. Rosen
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2018-10-30 00:00:00.000000000 Z
14
+ date: 2018-12-12 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: thor
@@ -321,18 +321,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
321
321
  version: 1.3.6
322
322
  requirements: []
323
323
  rubyforge_project:
324
- rubygems_version: 2.7.6
324
+ rubygems_version: 2.6.13
325
325
  signing_key:
326
326
  specification_version: 4
327
327
  summary: Tools to help you develop Zendesk Apps.
328
328
  test_files:
329
+ - features/clean.feature
329
330
  - features/create.feature
330
- - features/validate.feature
331
+ - features/fixtures/quote_character_translation.json
331
332
  - features/new.feature
332
- - features/clean.feature
333
+ - features/package.feature
334
+ - features/step_definitions/app_steps.rb
335
+ - features/support/env.rb
333
336
  - features/support/helpers.rb
334
337
  - features/support/webmock.rb
335
- - features/support/env.rb
336
- - features/step_definitions/app_steps.rb
337
- - features/fixtures/quote_character_translation.json
338
- - features/package.feature
338
+ - features/validate.feature