zendesk_apps_tools 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,5 +7,6 @@
7
7
  "defaultLocale": "en",
8
8
  "private": true,
9
9
  "location": "ticket_sidebar",
10
+ "version": "1.0",
10
11
  "frameworkVersion": "0.5"
11
12
  }
data/features/new.feature CHANGED
@@ -1,5 +1,17 @@
1
1
  Feature: create a template for a new zendesk app
2
2
 
3
+ Scenario: Create a new app in an existing directory
4
+ Given an app directory "tmp/aruba" exists
5
+ And I move to the app directory
6
+ When I run "zat new" command with the following details:
7
+ | author name | John Citizen |
8
+ | author email | john@example.com |
9
+ | app name | John Test App |
10
+ | app dir | |
11
+
12
+ Then the app file "manifest.json" is created
13
+ And I reset the working directory
14
+
3
15
  Scenario: create a template for a new zendesk app by running 'zat new' command
4
16
  Given an app directory "tmp/aruba" exists
5
17
  When I run "zat new" command with the following details:
@@ -19,6 +31,7 @@ Feature: create a template for a new zendesk app
19
31
  "defaultLocale": "en",
20
32
  "private": true,
21
33
  "location": "ticket_sidebar",
34
+ "version": "1.0",
22
35
  "frameworkVersion": "0.5"
23
36
  }
24
37
  """
@@ -1,5 +1,14 @@
1
1
  require 'fileutils'
2
2
 
3
+ When /^I move to the app directory$/ do
4
+ @previous_dir = Dir.pwd
5
+ Dir.chdir(@app_dir)
6
+ end
7
+
8
+ When /^I reset the working directory$/ do
9
+ Dir.chdir(@previous_dir)
10
+ end
11
+
3
12
  Given /^an app directory "(.*?)" exists$/ do |app_dir|
4
13
  @app_dir = app_dir
5
14
  FileUtils.rm_rf(@app_dir)
@@ -42,6 +51,10 @@ Then /^the app file "(.*?)" is created with:$/ do |file, content|
42
51
  File.read(file).chomp.gsub(' ', '').should == content.gsub(' ', '')
43
52
  end
44
53
 
54
+ Then /^the app file "(.*?)" is created$/ do |filename|
55
+ File.exists?(filename).should be_true
56
+ end
57
+
45
58
  Then /^the fixture "(.*?)" is used for "(.*?)"$/ do |fixture, app_file|
46
59
  fixture_file = File.join('features', 'fixtures', fixture)
47
60
  app_file_path = File.join(@app_dir, app_file)
@@ -3,6 +3,9 @@ require 'zip/zip'
3
3
  require 'pathname'
4
4
  require 'net/http'
5
5
  require 'json'
6
+ require 'zendesk_apps_tools/translate'
7
+ require 'zendesk_apps_tools/common'
8
+ require 'zendesk_apps_tools/settings'
6
9
 
7
10
  module ZendeskAppsTools
8
11
  require 'zendesk_apps_support'
@@ -13,6 +16,7 @@ module ZendeskAppsTools
13
16
 
14
17
  include Thor::Actions
15
18
  include ZendeskAppsSupport
19
+ include ZendeskAppsTools::Common
16
20
 
17
21
  source_root File.expand_path(File.join(File.dirname(__FILE__), "../.."))
18
22
 
@@ -21,17 +25,13 @@ module ZendeskAppsTools
21
25
 
22
26
  desc "new", "Generate a new app"
23
27
  def new
24
- puts "Enter this app author's name:"
25
- @author_name = get_value_from_stdin(/^\w.*$/, "Invalid name, try again:")
28
+ @author_name = get_value_from_stdin("Enter this app author's name:\n", :error_msg => "Invalid name, try again:")
29
+ @author_email = get_value_from_stdin("Enter this app author's email:\n", :valid_regex => /^.+@.+\..+$/, :error_msg => "Invalid email, try again:")
30
+ @app_name = get_value_from_stdin("Enter a name for this new app:\n", :error_msg => "Invalid app name, try again:")
26
31
 
27
- puts "Enter this app author's email:"
28
- @author_email = get_value_from_stdin(/^.+@.+\..+$/, "Invalid email, try again:")
29
-
30
- puts "Enter a name for this new app:"
31
- @app_name = get_value_from_stdin(/^\w.*$/, "Invalid app name, try again:")
32
-
33
- puts "Enter a directory name to save the new app (will create the dir if it does not exist, default to current dir):"
34
- while @app_dir = $stdin.readline.chomp.strip do
32
+ prompt = "Enter a directory name to save the new app (will create the dir if it does not exist, default to current dir):\n"
33
+ opts = { :valid_regex => /^(\w|\/|\\)*$/, :allow_empty => true }
34
+ while @app_dir = get_value_from_stdin(prompt, opts) do
35
35
  @app_dir = './' and break if @app_dir.empty?
36
36
  if !File.exists?(@app_dir)
37
37
  break
@@ -48,8 +48,8 @@ module ZendeskAppsTools
48
48
  desc "validate", "Validate your app"
49
49
  method_option :path, :default => './', :required => false
50
50
  def validate
51
- puts "Enter a zendesk URL that you'd like to install the app (for example: 'http://abc.zendesk.com', default to '#{DEFAULT_ZENDESK_URL}'):"
52
- zendesk = get_value_from_stdin(/^http:\/\/\w+\.\w+|^$/, 'Invalid url, try again:')
51
+ prompt = "Enter a zendesk URL that you'd like to install the app (for example: 'http://abc.zendesk.com', default to '#{DEFAULT_ZENDESK_URL}'):\n"
52
+ zendesk = get_value_from_stdin(prompt, :valid_regex => /^http:\/\/\w+\.\w+|^$/, :error_msg => 'Invalid url, try again:')
53
53
  zendesk = DEFAULT_ZENDESK_URL if zendesk.empty?
54
54
  url = URI.parse(zendesk)
55
55
  response = Net::HTTP.start(url.host, url.port) { |http| http.get('/api/v2/apps/framework_versions.json') }
@@ -64,6 +64,7 @@ module ZendeskAppsTools
64
64
  valid = errors.none?
65
65
 
66
66
  if valid
67
+ app_package.warnings.each { |w| say w.to_s, :yellow }
67
68
  say_status 'validate', 'OK'
68
69
  else
69
70
  errors.each do |e|
@@ -117,7 +118,8 @@ module ZendeskAppsTools
117
118
  setup_path(options[:path])
118
119
  manifest = app_package.manifest_json
119
120
 
120
- settings = settings_for_parameters(manifest[:parameters])
121
+ settings_helper = ZendeskAppsTools::Settings.new
122
+ settings = settings_helper.get_settings_from(self, manifest[:parameters])
121
123
 
122
124
  require 'zendesk_apps_tools/server'
123
125
  ZendeskAppsTools::Server.tap do |server|
@@ -130,18 +132,6 @@ module ZendeskAppsTools
130
132
 
131
133
  protected
132
134
 
133
- def get_value_from_stdin(valid_regex, error_msg)
134
- while input = $stdin.readline.chomp.strip do
135
- unless input =~ valid_regex
136
- puts error_msg
137
- else
138
- break
139
- end
140
- end
141
-
142
- return input
143
- end
144
-
145
135
  def setup_path(path)
146
136
  @destination_stack << relative_to_original_destination_root(path) unless @destination_stack.last == path
147
137
  end
@@ -160,26 +150,6 @@ module ZendeskAppsTools
160
150
  @app_package ||= Package.new(self.app_dir.to_s)
161
151
  end
162
152
 
163
- def settings_for_parameters(parameters)
164
- return {} if parameters.nil?
165
-
166
- parameters.inject({}) do |settings, param|
167
- if param[:required]
168
- puts "Enter a value for required parameter '#{param[:name]}':"
169
- input = get_value_from_stdin(/\S+/, 'Invalid, try again:')
170
- else
171
- puts "Enter a value for optional parameter '#{param[:name]}': (press 'Return' to skip)"
172
- input = $stdin.readline.chomp.strip
173
- end
174
-
175
- unless input.empty?
176
- input = (input =~ /^(true|t|yes|y|1)$/i) ? true : false if param[:type] == 'checkbox'
177
- settings[param[:name]] = input
178
- end
179
-
180
- settings
181
- end
182
- end
183
153
  end
184
154
  end
185
155
 
@@ -7,10 +7,17 @@ module ZendeskAppsTools
7
7
  request.get(url)
8
8
  end
9
9
 
10
- def get_value_from_stdin(prompt, valid_regex, error_msg)
10
+ def get_value_from_stdin(prompt, opts = {})
11
+ options = {
12
+ :valid_regex => opts[:allow_empty] ? /^\w*$/ : /\S+/,
13
+ :error_msg => 'Invalid, try again:',
14
+ :allow_empty => false
15
+ }.merge(opts)
16
+
11
17
  while input = ask(prompt)
12
- unless input =~ valid_regex
13
- say(error_msg, :red)
18
+ return "" if input.empty? && options[:allow_empty]
19
+ unless input =~ options[:valid_regex]
20
+ say(options[:error_msg], :red)
14
21
  else
15
22
  break
16
23
  end
@@ -0,0 +1,30 @@
1
+ require 'zendesk_apps_tools/common'
2
+
3
+ module ZendeskAppsTools
4
+ class Settings
5
+
6
+ def get_settings_from(user_input, parameters)
7
+ return {} if parameters.nil?
8
+
9
+ parameters.inject({}) do |settings, param|
10
+ if param[:default]
11
+ input = user_input.get_value_from_stdin("Enter a value for parameter '#{param[:name]}' or press 'Return' to use the default value '#{param[:default]}':\n", :allow_empty => true)
12
+ input = param[:default] if input.empty?
13
+ elsif param[:required]
14
+ input = user_input.get_value_from_stdin("Enter a value for required parameter '#{param[:name]}':\n")
15
+ else
16
+ input = user_input.get_value_from_stdin("Enter a value for optional parameter '#{param[:name]}' or press 'Return' to skip:\n", :allow_empty => true)
17
+ end
18
+
19
+ unless input.empty?
20
+ input = (input =~ /^(true|t|yes|y|1)$/i) ? true : false if param[:type] == 'checkbox'
21
+ settings[param[:name]] = input
22
+ end
23
+
24
+ settings
25
+ end
26
+ end
27
+
28
+ end
29
+ end
30
+
@@ -18,19 +18,19 @@ module ZendeskAppsTools
18
18
  app_name = manifest['name']
19
19
 
20
20
  unless app_name
21
- app_name = get_value_from_stdin('What is the name of this app?', /^\w.*$/, "Invalid name, try again:")
21
+ app_name = get_value_from_stdin('What is the name of this app?', :error_msg => "Invalid name, try again:")
22
22
  end
23
23
 
24
- package = get_value_from_stdin('What is the package name for this app?', /^[a-z_]+$/, "Invalid package name, try again:")
24
+ package = get_value_from_stdin('What is the package name for this app?', :valid_regex => /^[a-z_]+$/, :error_msg => "Invalid package name, try again:")
25
25
 
26
26
  write_yaml(app_name, package)
27
27
  end
28
28
 
29
29
  desc 'update', 'Update translation files from Zendesk'
30
30
  def update(request_builder = Faraday.new)
31
- app_package = get_value_from_stdin("What is the package name for this app? (without app_)", /^[a-z_]+$/, "Invalid package name, try again:")
32
- user = get_value_from_stdin("What is your support.zendesk.com username?", /^.+@.+\..+$/, "Invalid email, try again:")
33
- token = get_value_from_stdin("What is your support.zendesk.com API token?", /^\w*$/, "Invalid API token, try again:")
31
+ app_package = get_value_from_stdin("What is the package name for this app? (without app_)", :valid_regex => /^[a-z_]+$/, :error_msg => "Invalid package name, try again:")
32
+ user = get_value_from_stdin("What is your support.zendesk.com username?", :valid_regex => /^.+@.+\..+$/, :error_msg => "Invalid email, try again:")
33
+ token = get_value_from_stdin("What is your support.zendesk.com API token?", :error_msg => "Invalid API token, try again:")
34
34
 
35
35
  user = "#{user}/token"
36
36
  key_prefix = "txt.apps.#{app_package}."
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.2.2
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2013-07-15 00:00:00.000000000 Z
15
+ date: 2013-09-18 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: thor
@@ -85,7 +85,7 @@ dependencies:
85
85
  requirements:
86
86
  - - ~>
87
87
  - !ruby/object:Gem::Version
88
- version: 1.2.0
88
+ version: 1.4.1
89
89
  type: :runtime
90
90
  prerelease: false
91
91
  version_requirements: !ruby/object:Gem::Requirement
@@ -93,7 +93,7 @@ dependencies:
93
93
  requirements:
94
94
  - - ~>
95
95
  - !ruby/object:Gem::Version
96
- version: 1.2.0
96
+ version: 1.4.1
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: cucumber
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -142,6 +142,22 @@ dependencies:
142
142
  - - ! '>='
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0'
145
+ - !ruby/object:Gem::Dependency
146
+ name: bump
147
+ requirement: !ruby/object:Gem::Requirement
148
+ none: false
149
+ requirements:
150
+ - - ! '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ type: :development
154
+ prerelease: false
155
+ version_requirements: !ruby/object:Gem::Requirement
156
+ none: false
157
+ requirements:
158
+ - - ! '>='
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
145
161
  description: Tools to help you develop Zendesk Apps.
146
162
  email:
147
163
  - dev@zendesk.com
@@ -155,6 +171,7 @@ files:
155
171
  - lib/zendesk_apps_tools/common.rb
156
172
  - lib/zendesk_apps_tools/locale_identifier.rb
157
173
  - lib/zendesk_apps_tools/server.rb
174
+ - lib/zendesk_apps_tools/settings.rb
158
175
  - lib/zendesk_apps_tools/translate.rb
159
176
  - lib/zendesk_apps_tools.rb
160
177
  - app_template/app.css