zendesk_apps_tools 2.12.2 → 2.12.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 81d1d14e680a0767baee661d22e0fe97abecce96
4
- data.tar.gz: 5ebc1cc78b823ed7da4c771fcf19ffa63247abbf
2
+ SHA256:
3
+ metadata.gz: 74674fe4161270694ce0357838a66ffeb431ea51577db11e323a559de1430160
4
+ data.tar.gz: cf485b548d4ee0d0e46c23b6101466794287fca0a0731e00122c478f30099922
5
5
  SHA512:
6
- metadata.gz: b993d22b624470ef4b2654fceedd478ccb212150320853624753f82cf528d381c77c8155f45878e3a0f435d3fdd2bbb1ac3f62075f0d86db1fa86a41aa700602
7
- data.tar.gz: b8d52c5e0166437aafee5093320cefcf6b50da930e7153dacebb651d27c035c7e8ef87e95ad2fcd527c3ef03d7ecaf5322fed3be9fdab54cb8dd1241fc1c90ac
6
+ metadata.gz: 9d53fb13befc32158c5bd83f68a152c044f96a4f8557f2b5bbe524f213f71bb16a756bb8e0145eb8f085f0ddc9afc764d83d49b79c60bf64bf8983002acf25c8
7
+ data.tar.gz: 76a32b9a948d65a74143514178037c1fb2650bd0d0a64c07387e702e9c38249276c3cbc8616a79f1494cc68ba8bdd8b04e16ae0129275a01622d564ffb75153d
data/README.md CHANGED
@@ -13,7 +13,7 @@ To install, run `gem install zendesk_apps_tools`.
13
13
 
14
14
  To get the latest version, run `gem update zendesk_apps_tools`.
15
15
 
16
- For information on using the tools, see [Zendesk App Tools](https://developer.zendesk.com/apps/docs/apps-v2/getting_started#zendesk-app-tools) on developer.zendesk.com.
16
+ For information on using the tools, see [Zendesk App Tools](https://developer.zendesk.com/apps/docs/developer-guide/zat) on developer.zendesk.com.
17
17
 
18
18
  ## Work on ZAT
19
19
  If you want to help **develop** this tool, clone this repo and run `bundle install`.
@@ -10,7 +10,7 @@ module ZendeskAppsTools
10
10
  PROMPT_FOR_URL = 'Enter your Zendesk subdomain or full URL (including protocol):'
11
11
  URL_ERROR_MSG = [
12
12
  'URL error. Example URL: https://mysubdomain.zendesk.com',
13
- 'If you are using a full URL, follow the url as shown above.',
13
+ 'If you are using a full URL, follow the example format shown above.',
14
14
  'If you are using a subdomain, ensure that it contains only valid characters (a-z, A-Z, 0-9, and hyphens).'
15
15
  ].join('\n')
16
16
 
@@ -22,14 +22,13 @@ module ZendeskAppsTools
22
22
  say_error_and_exit EMAIL_ERROR_MSG unless valid_email?
23
23
 
24
24
  @password ||= cache.fetch('password', @subdomain) || get_password_from_stdin('Enter your password:')
25
-
26
- cache.save 'subdomain' => @subdomain, 'username' => @username
27
25
  end
28
26
 
29
27
  def get_connection(encoding = :url_encoded)
30
28
  require 'net/http'
31
29
  require 'faraday'
32
- prepare_api_auth
30
+ prepare_api_auth unless @subdomain && @username && @password
31
+
33
32
  Faraday.new full_url do |f|
34
33
  f.request encoding if encoding
35
34
  f.adapter :net_http
@@ -208,10 +208,11 @@ module ZendeskAppsTools
208
208
  setup_path(options[:path])
209
209
  @command = 'Update'
210
210
 
211
- app_id = cache.fetch('app_id') || find_app_id
211
+ product_name = product_names(manifest).first
212
+ app_id = cache.fetch('app_id') || find_app_id(product_name)
212
213
  app_url = "/api/v2/apps/#{app_id}.json"
213
214
  unless /\d+/ =~ app_id.to_s && app_exists?(app_id)
214
- say_error_and_exit "App id not found\nPlease try running command with --clean or check your internet connection"
215
+ say_error_and_exit "App ID not found. Please try running command with --clean or check your internet connection."
215
216
  end
216
217
 
217
218
  deploy_app(:put, app_url, {})
@@ -69,7 +69,7 @@ module ZendeskAppsTools
69
69
  require 'json'
70
70
  JSON.parse(value)
71
71
  rescue JSON::ParserError
72
- say_error_and_exit "\"#{value}\" is an invalid JSON"
72
+ say_error_and_exit "\"#{value}\" is an invalid JSON."
73
73
  end
74
74
 
75
75
  private
@@ -77,7 +77,7 @@ module ZendeskAppsTools
77
77
  def error_or_default_if_unattended(prompt, opts = {})
78
78
  if options[:unattended]
79
79
  return opts[:default] if opts.key? :default
80
- say_error 'Would have prompted for a value interactively, but zat is not listening to keyboard input.'
80
+ say_error 'Would have prompted for a value interactively, but ZAT is not listening to keyboard input.'
81
81
  say_error_and_exit prompt
82
82
  else
83
83
  yield
@@ -6,13 +6,12 @@ module ZendeskAppsTools
6
6
  module Deploy
7
7
  include ZendeskAppsTools::Common
8
8
  include ZendeskAppsTools::APIConnection
9
- alias_method :connection, :get_connection
10
9
 
11
10
  def deploy_app(connection_method, url, body)
12
11
  body[:upload_id] = upload(options[:path]).to_s
13
12
  sleep 2 # Because the DB needs time to replicate
14
13
 
15
- response = connection.send(connection_method) do |req|
14
+ response = cached_connection.send(connection_method) do |req|
16
15
  req.url url
17
16
  req.headers[:content_type] = 'application/json'
18
17
  req.body = JSON.generate body
@@ -26,7 +25,7 @@ module ZendeskAppsTools
26
25
 
27
26
  def app_exists?(app_id)
28
27
  url = "/api/v2/apps/#{app_id}.json"
29
- response = connection.send(:get) do |req|
28
+ response = cached_connection.send(:get) do |req|
30
29
  req.url url
31
30
  end
32
31
 
@@ -34,7 +33,7 @@ module ZendeskAppsTools
34
33
  end
35
34
 
36
35
  def install_app(poll_job, product_name, installation)
37
- response = connection.post do |req|
36
+ response = cached_connection.post do |req|
38
37
  req.url "api/#{product_name}/apps/installations.json"
39
38
  req.headers[:content_type] = 'application/json'
40
39
  req.body = JSON.generate(installation)
@@ -56,33 +55,35 @@ module ZendeskAppsTools
56
55
  uploaded_data: Faraday::UploadIO.new(package_path, 'application/zip')
57
56
  }
58
57
 
59
- response = connection(:multipart).post('/api/v2/apps/uploads.json', payload)
58
+ response = cached_connection(:multipart).post('/api/v2/apps/uploads.json', payload)
60
59
  json_or_die(response.body)['id']
61
60
 
62
61
  rescue Faraday::Error::ClientError => e
63
62
  say_error_and_exit e.message
64
63
  end
65
64
 
66
- def find_app_id
65
+ def find_app_id(product_name = 'v2') # use the v2 endpoint if no product name is provided
67
66
  say_status 'Update', 'app ID is missing, searching...'
68
- app_name = get_value_from_stdin('Enter the name of the app:')
67
+ app_name = get_value_from_stdin('Enter the name of the installed app:')
69
68
 
70
- all_apps_json = connection.get('/api/apps.json').body
69
+ response = cached_connection.get("/api/#{product_name}/apps/installations.json")
70
+ installations_json = json_or_die(response.body)
71
71
 
72
- app =
73
- unless all_apps_json.empty?
74
- json_or_die(all_apps_json)['apps'].find { |app| app['name'] == app_name }
75
- end
72
+ unless response.success? && installations_json.has_key?('installations')
73
+ say_error_and_exit "Unable to retrieve installations. Please check your credentials and internet connection."
74
+ else
75
+ installation = installations_json['installations'].find {
76
+ |i| i['settings'] && i['settings']['name'] == app_name
77
+ }
78
+ end
76
79
 
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
- )
80
+ unless installation
81
+ say_error_and_exit "App not found. Please check that your app name is correct."
82
82
  end
83
83
 
84
- cache.save 'app_id' => app['id']
85
- app['id']
84
+ app_id = installation['app_id']
85
+ cache.save 'app_id' => app_id
86
+ app_id
86
87
 
87
88
  rescue Faraday::Error::ClientError => e
88
89
  say_error_and_exit e.message
@@ -100,21 +101,18 @@ module ZendeskAppsTools
100
101
  end
101
102
 
102
103
  def check_job(job_id)
103
- http_client = connection
104
-
105
104
  loop do
106
- response = http_client.get("/api/v2/apps/job_statuses/#{job_id}")
107
- info = json_or_die(response.body)
108
- status = info['status']
105
+ request = cached_connection.get("/api/v2/apps/job_statuses/#{job_id}")
106
+ response = json_or_die(request.body)
107
+ status = response['status']
109
108
 
110
109
  if %w(completed failed).include? status
111
110
  case status
112
111
  when 'completed'
113
- app_id = info['app_id']
114
- cache.save 'app_id' => app_id if app_id
112
+ cache.save zat_contents(response)
115
113
  say_status @command, 'OK'
116
114
  when 'failed'
117
- say_status @command, info['message'], :red
115
+ say_status @command, response['message'], :red
118
116
  exit 1
119
117
  end
120
118
  break
@@ -126,5 +124,21 @@ module ZendeskAppsTools
126
124
  rescue Faraday::Error::ClientError => e
127
125
  say_error_and_exit e.message
128
126
  end
127
+
128
+ private
129
+
130
+ def zat_contents(response)
131
+ zat = {}
132
+ zat['subdomain'] = @subdomain
133
+ zat['username'] = @username
134
+ zat['app_id'] = response['app_id'] if response['app_id']
135
+
136
+ zat
137
+ end
138
+
139
+ def cached_connection(encoding = :url_encoded)
140
+ @connection ||= {}
141
+ @connection[encoding] ||= get_connection(encoding)
142
+ end
129
143
  end
130
144
  end
@@ -60,7 +60,7 @@ module ZendeskAppsTools
60
60
  say_status 'Error', error_hash
61
61
  end
62
62
  rescue JSON::ParserError
63
- say_error_and_exit 'Server error 😭'
63
+ say_error_and_exit 'Server error.'
64
64
  end
65
65
  end
66
66
 
@@ -34,7 +34,7 @@ module ZendeskAppsTools
34
34
  full_manifest_path = theme_package_path('manifest.json')
35
35
  JSON.parse(File.read(full_manifest_path))
36
36
  rescue Errno::ENOENT
37
- say_error_and_exit "There's no manifest file in #{full_manifest_path}"
37
+ say_error_and_exit "There is no manifest file in #{full_manifest_path}"
38
38
  rescue JSON::ParserError
39
39
  say_error_and_exit "The manifest file is invalid at #{full_manifest_path}"
40
40
  end
@@ -176,9 +176,9 @@ module ZendeskAppsTools
176
176
 
177
177
  return json_or_die(locale_response.body)['locales'] if locale_response.status == 200
178
178
  if locale_response.status == 401
179
- say_error_and_exit 'Authentication failed'
179
+ say_error_and_exit 'Authentication failed.'
180
180
  else
181
- say_error_and_exit "Failed to download locales, got HTTP status #{locale_response.status}"
181
+ say_error_and_exit "Failed to download locales, got HTTP status #{locale_response.status}."
182
182
  end
183
183
  end
184
184
 
@@ -228,13 +228,13 @@ module ZendeskAppsTools
228
228
  def package_name_from_json(error_out: false)
229
229
  package = en_json && en_json['app']['package']
230
230
  return package if package
231
- say_error_and_exit 'No package defined inside en.json!' if error_out
231
+ say_error_and_exit 'No package defined inside en.json.' if error_out
232
232
  end
233
233
 
234
234
  def package_name(error_out: false)
235
235
  package = en_hash && en_hash['app']['package']
236
236
  return package if package
237
- say_error_and_exit 'No package defined inside en.yml!' if error_out
237
+ say_error_and_exit 'No package defined inside en.yml.' if error_out
238
238
  end
239
239
  end
240
240
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ZendeskAppsTools
3
- VERSION = '2.12.2'
3
+ VERSION = '2.12.3'
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.2
4
+ version: 2.12.3
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-12-13 00:00:00.000000000 Z
14
+ date: 2019-01-08 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.6.13
324
+ rubygems_version: 2.7.6
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
330
329
  - features/create.feature
331
- - features/fixtures/quote_character_translation.json
330
+ - features/validate.feature
332
331
  - features/new.feature
333
- - features/package.feature
334
- - features/step_definitions/app_steps.rb
335
- - features/support/env.rb
332
+ - features/clean.feature
336
333
  - features/support/helpers.rb
337
334
  - features/support/webmock.rb
338
- - features/validate.feature
335
+ - features/support/env.rb
336
+ - features/step_definitions/app_steps.rb
337
+ - features/fixtures/quote_character_translation.json
338
+ - features/package.feature