zendesk_apps_tools 1.37.5 → 2.0.0

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
2
  SHA1:
3
- metadata.gz: 9190f863d9094fea70c25cc333fa7702ebc9003e
4
- data.tar.gz: 66a375f1c763afc68ad4ce3c6eb700b55e37f86c
3
+ metadata.gz: 2aa8d1a04c58a6751dd96d0687835f37544ad2ee
4
+ data.tar.gz: e794bc24aa0504a80a204d1343bef70709fcc6dc
5
5
  SHA512:
6
- metadata.gz: 3ce71c34ab028eb09171fd4a0ca004bf0ce54499f411a577be7fc2bb0c357670aec76c1103d37e08e25b5c39e0414ea9dca924f1417880ebfa3b8616c5986984
7
- data.tar.gz: 5fd7b2d5f0f743cfd2232f4f25142a794107305d21bb25e7a4df251a5a77e7f94a305edfd661c23de706a3ea73869c2db046afe39da4b57c8b7ecada7fef3b99
6
+ metadata.gz: 9349fb4006085842c5df59f3c773f3ac3a0f4bfdd112d07c1fb36f9351a772ca37ed48a2a52ddaf171f5ab1c9d9c540ca008c4d1acb87cd6627d2b1cd2b85b6a
7
+ data.tar.gz: 72cf6af1f015140e146d39823d04f85aa831cf9f6c43e072bb1d1f2fed3ecb2815652784983831d6e003a2b3e69fa12f4d6009c1c9de03206749d746f40d3c04
@@ -131,16 +131,6 @@ module ZendeskAppsTools
131
131
  method_option :bind, required: false
132
132
  def server
133
133
  setup_path(options[:path])
134
- manifest = app_package.manifest
135
-
136
- require 'zendesk_apps_tools/settings'
137
- settings_helper = ZendeskAppsTools::Settings.new(self)
138
-
139
- settings = settings_helper.get_settings_from_file options[:config], manifest.original_parameters
140
-
141
- unless settings
142
- settings = settings_helper.get_settings_from_user_input manifest.original_parameters
143
- end
144
134
 
145
135
  require 'zendesk_apps_tools/server'
146
136
  ZendeskAppsTools::Server.tap do |server|
@@ -155,18 +145,24 @@ module ZendeskAppsTools
155
145
  end
156
146
  end
157
147
 
158
- desc 'create', 'Create app on your account'
148
+ desc 'create', 'Create and install app on your account'
159
149
  shared_options
160
150
  method_option :zipfile, default: nil, required: false, type: :string
151
+ method_option :config, default: DEFAULT_CONFIG_PATH, required: false, aliases: '-c'
152
+ method_option :install, default: true, type: :boolean, desc: 'Also create an installation with some settings immediately after uploading.'
161
153
  def create
162
154
  cache.clear
163
155
  @command = 'Create'
164
156
 
165
157
  unless options[:zipfile]
166
- app_name = JSON.parse(File.read(File.join options[:path], 'manifest.json'))['name']
158
+ app_name = manifest.name
167
159
  end
168
160
  app_name ||= get_value_from_stdin('Enter app name:')
169
161
  deploy_app(:post, '/api/v2/apps.json', name: app_name)
162
+ has_requirements = File.exist?(File.join(options[:path], 'requirements.json'))
163
+ return unless options[:install]
164
+ say_status 'Install', 'installing'
165
+ install_app(has_requirements, app_id: cache.fetch('app_id'), settings: settings.merge(name: app_name))
170
166
  end
171
167
 
172
168
  desc 'update', 'Update app on the server'
@@ -204,5 +200,17 @@ module ZendeskAppsTools
204
200
  def setup_path(path)
205
201
  @destination_stack << relative_to_original_destination_root(path) unless @destination_stack.last == path
206
202
  end
203
+
204
+ def settings
205
+ settings_helper.get_settings_from_file(options[:config], manifest.original_parameters) ||
206
+ settings_helper.get_settings_from_user_input(manifest.original_parameters)
207
+ end
208
+
209
+ def settings_helper
210
+ @settings_helper ||= begin
211
+ require 'zendesk_apps_tools/settings'
212
+ ZendeskAppsTools::Settings.new(self)
213
+ end
214
+ end
207
215
  end
208
216
  end
@@ -16,6 +16,16 @@ module ZendeskAppsTools
16
16
  say_error_and_exit e.message
17
17
  end
18
18
 
19
+ def install_app(poll_job, installation)
20
+ connection = get_connection
21
+ response = connection.post do |req|
22
+ req.url 'api/v2/apps/installations.json'
23
+ req.headers[:content_type] = 'application/json'
24
+ req.body = JSON.generate(installation)
25
+ end
26
+ check_status(response, poll_job)
27
+ end
28
+
19
29
  def upload(path)
20
30
  connection = get_connection :multipart
21
31
  zipfile_path = options[:zipfile]
@@ -54,13 +64,15 @@ module ZendeskAppsTools
54
64
  say_error_and_exit e.message
55
65
  end
56
66
 
57
- def check_status(response)
67
+ def check_status(response, poll_job = true)
58
68
  job = response.body
59
69
  job_response = json_or_die(job)
60
70
  say_error_and_exit job_response['error'] if job_response['error']
61
71
 
62
- job_id = job_response['job_id']
63
- check_job job_id
72
+ if poll_job
73
+ job_id = job_response['job_id'] || job_response['pending_job_id']
74
+ check_job job_id
75
+ end
64
76
  end
65
77
 
66
78
  def check_job(job_id)
@@ -76,7 +88,7 @@ module ZendeskAppsTools
76
88
  if %w(completed failed).include? status
77
89
  case status
78
90
  when 'completed'
79
- cache.save 'app_id' => app_id
91
+ cache.save 'app_id' => app_id if app_id
80
92
  say_status @command, 'OK'
81
93
  when 'failed'
82
94
  say_status @command, message, :red
@@ -6,6 +6,10 @@ module ZendeskAppsTools
6
6
  @app_package ||= ZendeskAppsSupport::Package.new(app_dir.to_s)
7
7
  end
8
8
 
9
+ def manifest
10
+ @manifest ||= app_package.manifest
11
+ end
12
+
9
13
  def zip(archive_path)
10
14
  require 'zip'
11
15
  Zip::File.open(archive_path, 'w') do |zipfile|
@@ -1,5 +1,6 @@
1
1
  require 'sinatra/base'
2
2
  require 'sinatra/cross_origin'
3
+ require 'zendesk_apps_support' # dependency of zendesk_apps_support/package
3
4
  require 'zendesk_apps_support/package'
4
5
 
5
6
  module ZendeskAppsTools
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ZendeskAppsTools
3
- VERSION = '1.37.5'
3
+ VERSION = '2.0.0'
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: 1.37.5
4
+ version: 2.0.0
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: 2017-03-08 00:00:00.000000000 Z
14
+ date: 2017-03-14 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: thor