zendesk_apps_tools 1.21.1 → 1.21.2

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
2
  SHA1:
3
- metadata.gz: 31889800a9bc18cfd1543f5b05279bcef4c6d684
4
- data.tar.gz: 32336ce53277c686109a718d016837b3af016f4d
3
+ metadata.gz: 3f8e6b79aced2f157e01d6a0d133fbee07f1f82a
4
+ data.tar.gz: a003cfef2eb60656a75289b8086925ac9e6dbe98
5
5
  SHA512:
6
- metadata.gz: 2e690d1a3f280ebec4ab9b2405640596ce13a70e29569d2f38fcc4b212fa5d9b61b1dab8dd60724338a6f53448ee5425ef9a40bc1c394c5e385b31546748fc17
7
- data.tar.gz: 1e3334a995f7e081b288a6ac28ae9410dd5c51128b66a4d6f32cceadbe28b61501a404847448592828b58b74314961b8f23317922e17936318c921426e531789
6
+ metadata.gz: 0bb36b96d341ed0a0e58cb0654f8842607d213a8d418bc53a3c10e24407b29939488a5772a888f4f57062869e189cb1614b79d2539aae2a07b6717691977849b
7
+ data.tar.gz: 4d848d14c6c2f16e2c139d76eaa7a0751fc8269f80f998a617e3ecdcf88a2f1044307b3bc0ceb8460a6045c8ef3c4baed89b021543dfe7bd5a6b1ad1fe18eb89
@@ -1,5 +1,6 @@
1
1
  require 'fileutils'
2
2
  require 'zip/zip'
3
+ require 'English'
3
4
 
4
5
  When /^I move to the app directory$/ do
5
6
  @previous_dir = Dir.pwd
@@ -17,7 +18,7 @@ Given /^an app directory "(.*?)" exists$/ do |app_dir|
17
18
  end
18
19
 
19
20
  Given /^an app is created in directory "(.*?)"$/ do |app_dir|
20
- steps %Q{
21
+ steps %(
21
22
  Given an app directory "#{app_dir}" exists
22
23
  And I run "zat new" command with the following details:
23
24
  | author name | John Citizen |
@@ -25,33 +26,33 @@ Given /^an app is created in directory "(.*?)"$/ do |app_dir|
25
26
  | author url | http://myapp.com |
26
27
  | app name | John Test App |
27
28
  | app dir | #{app_dir} |
28
- }
29
+ )
29
30
  end
30
31
 
31
32
  When /^I run "(.*?)" command with the following details:$/ do |cmd, table|
32
- IO.popen(cmd, "w+") do |pipe|
33
+ IO.popen(cmd, 'w+') do |pipe|
33
34
  # [ ['parameter name', 'value'] ]
34
35
  table.raw.each do |row|
35
36
  pipe.puts row.last
36
37
  end
37
38
  pipe.close_write
38
39
  @output = pipe.readlines
39
- @output.each {|line| puts line}
40
+ @output.each { |line| puts line }
40
41
  end
41
42
  end
42
43
 
43
- When /^I create a symlink from "(.*?)" to "(.*?)"$/ do |src, dest|
44
+ When /^I create a symlink from "(.*?)" to "(.*?)"$/ do |src, dest|
44
45
  @link_destname = File.basename(dest)
45
46
  # create a symlink
46
47
  FileUtils.ln_s(src, dest)
47
48
  end
48
49
 
49
- When /^I run the command "(.*?)" to (validate|package|clean) the app$/ do |cmd, action|
50
- IO.popen(cmd, "w+") do |pipe|
50
+ When /^I run the command "(.*?)" to (validate|package|clean) the app$/ do |cmd, _action|
51
+ IO.popen(cmd, 'w+') do |pipe|
51
52
  pipe.puts "\n"
52
53
  pipe.close_write
53
54
  @output = pipe.readlines
54
- @output.each {|line| puts line}
55
+ @output.each { |line| puts line }
55
56
  end
56
57
  end
57
58
 
@@ -60,7 +61,7 @@ Then /^the app file "(.*?)" is created with:$/ do |file, content|
60
61
  end
61
62
 
62
63
  Then /^the app file "(.*?)" is created$/ do |filename|
63
- File.exists?(filename).should be_truthy
64
+ File.exist?(filename).should be_truthy
64
65
  end
65
66
 
66
67
  Then /^the fixture "(.*?)" is used for "(.*?)"$/ do |fixture, app_file|
@@ -70,7 +71,6 @@ Then /^the fixture "(.*?)" is used for "(.*?)"$/ do |fixture, app_file|
70
71
  FileUtils.cp(fixture_file, app_file_path)
71
72
  end
72
73
 
73
-
74
74
  Then /^the zip file should exist in directory "(.*?)"$/ do |path|
75
75
  Dir[path + '/app-*.zip'].size.should == 1
76
76
  end
@@ -85,7 +85,7 @@ end
85
85
 
86
86
  Then /^it should pass the validation$/ do
87
87
  @output.last.should =~ /OK/
88
- $?.should == 0
88
+ $CHILD_STATUS.should == 0
89
89
  end
90
90
 
91
91
  Then /^the command output should contain "(.*?)"$/ do |output|
@@ -97,7 +97,7 @@ Then /^"(.*?)" should be a symlink$/ do |path|
97
97
  end
98
98
 
99
99
  Then /^the zip file in "(.*?)" should not contain any symlinks$/ do |path|
100
- Zip::ZipFile.foreach Dir[path+'/app-*.zip'][0] do |p|
101
- p.symlink?.should be_falsy
100
+ Zip::ZipFile.foreach Dir[path + '/app-*.zip'][0] do |p|
101
+ p.symlink?.should be_falsy
102
102
  end
103
103
  end
@@ -4,28 +4,30 @@ module ZendeskAppsTools
4
4
  URL_TEMPLATE = 'https://%s.zendesk.com/'
5
5
 
6
6
  def prepare_api_auth
7
- @subdomain ||= get_cache('subdomain') || get_value_from_stdin('Enter your Zendesk subdomain or full Zendesk URL:')
8
- @username ||= get_cache('username') || get_value_from_stdin('Enter your username:')
9
- @password ||= get_cache('password') || get_password_from_stdin('Enter your password:')
7
+ @subdomain ||= fetch_cache('subdomain') || get_value_from_stdin('Enter your Zendesk subdomain or full Zendesk URL:')
8
+ @username ||= fetch_cache('username') || get_value_from_stdin('Enter your username:')
9
+ @password ||= fetch_cache('password') || get_password_from_stdin('Enter your password:')
10
10
 
11
- set_cache 'subdomain' => @subdomain, 'username' => @username
12
- end
13
-
14
- def get_full_url
15
- if FULL_URL =~ @subdomain
16
- @subdomain
17
- else
18
- URL_TEMPLATE % @subdomain
19
- end
11
+ save_cache 'subdomain' => @subdomain, 'username' => @username
20
12
  end
21
13
 
22
14
  def get_connection(encoding = :url_encoded)
23
15
  prepare_api_auth
24
- Faraday.new get_full_url do |f|
16
+ Faraday.new full_url do |f|
25
17
  f.request encoding
26
18
  f.adapter :net_http
27
19
  f.basic_auth @username, @password
28
20
  end
29
21
  end
22
+
23
+ private
24
+
25
+ def full_url
26
+ if FULL_URL =~ @subdomain
27
+ @subdomain
28
+ else
29
+ URL_TEMPLATE % @subdomain
30
+ end
31
+ end
30
32
  end
31
33
  end
@@ -2,20 +2,20 @@ module ZendeskAppsTools
2
2
  module Cache
3
3
  CACHE_FILE_NAME = '.zat'
4
4
 
5
- def set_cache(hash)
5
+ def save_cache(hash)
6
6
  return if options[:zipfile]
7
7
 
8
- @cache = File.exists?(cache_path) ? JSON.parse(File.read(@cache_path)).update(hash) : hash
8
+ @cache = File.exist?(cache_path) ? JSON.parse(File.read(@cache_path)).update(hash) : hash
9
9
  File.open(@cache_path, 'w') { |f| f.write JSON.pretty_generate(@cache) }
10
10
  end
11
11
 
12
- def get_cache(key)
13
- @cache ||= File.exists?(cache_path) ? JSON.parse(File.read(@cache_path)) : {}
12
+ def fetch_cache(key)
13
+ @cache ||= File.exist?(cache_path) ? JSON.parse(File.read(@cache_path)) : {}
14
14
  @cache[key] if @cache
15
15
  end
16
16
 
17
17
  def clear_cache
18
- File.delete cache_path if options[:clean] && File.exists?(cache_path)
18
+ File.delete cache_path if options[:clean] && File.exist?(cache_path)
19
19
  end
20
20
 
21
21
  def cache_path
@@ -1,4 +1,4 @@
1
- require "thor"
1
+ require 'thor'
2
2
  require 'zip/zip'
3
3
  require 'pathname'
4
4
  require 'net/http'
@@ -9,11 +9,9 @@ require 'io/console'
9
9
  require 'zendesk_apps_tools/command_helpers'
10
10
 
11
11
  module ZendeskAppsTools
12
-
13
12
  require 'zendesk_apps_support'
14
13
 
15
14
  class Command < Thor
16
-
17
15
  SHARED_OPTIONS = {
18
16
  ['path', '-p'] => './',
19
17
  clean: false
@@ -23,24 +21,24 @@ module ZendeskAppsTools
23
21
  include ZendeskAppsSupport
24
22
  include ZendeskAppsTools::CommandHelpers
25
23
 
26
- source_root File.expand_path(File.join(File.dirname(__FILE__), "../.."))
24
+ source_root File.expand_path(File.join(File.dirname(__FILE__), '../..'))
27
25
 
28
26
  desc 'translate SUBCOMMAND', 'Manage translation files', hide: true
29
27
  subcommand 'translate', Translate
30
28
 
31
- desc "new", "Generate a new app"
29
+ desc 'new', 'Generate a new app'
32
30
  def new
33
- @author_name = get_value_from_stdin("Enter this app author's name:\n", error_msg: "Invalid name, try again:")
34
- @author_email = get_value_from_stdin("Enter this app author's email:\n", valid_regex: /^.+@.+\..+$/, error_msg: "Invalid email, try again:")
35
- @author_url = get_value_from_stdin("Enter this app author's url:\n", valid_regex: /^https?:\/\/.+$/, error_msg: "Invalid url, try again:", allow_empty: true)
36
- @app_name = get_value_from_stdin("Enter a name for this new app:\n", error_msg: "Invalid app name, try again:")
31
+ @author_name = get_value_from_stdin("Enter this app author's name:\n", error_msg: 'Invalid name, try again:')
32
+ @author_email = get_value_from_stdin("Enter this app author's email:\n", valid_regex: /^.+@.+\..+$/, error_msg: 'Invalid email, try again:')
33
+ @author_url = get_value_from_stdin("Enter this app author's url:\n", valid_regex: /^https?:\/\/.+$/, error_msg: 'Invalid url, try again:', allow_empty: true)
34
+ @app_name = get_value_from_stdin("Enter a name for this new app:\n", error_msg: 'Invalid app name, try again:')
37
35
 
38
- get_new_app_directory
36
+ prompt_new_app_dir
39
37
 
40
38
  directory('app_template', @app_dir)
41
39
  end
42
40
 
43
- desc "validate", "Validate your app"
41
+ desc 'validate', 'Validate your app'
44
42
  method_options SHARED_OPTIONS
45
43
  def validate
46
44
  setup_path(options[:path])
@@ -61,7 +59,7 @@ module ZendeskAppsTools
61
59
  true
62
60
  end
63
61
 
64
- desc "package", "Package your app"
62
+ desc 'package', 'Package your app'
65
63
  method_options SHARED_OPTIONS
66
64
  def package
67
65
  return false unless invoke(:validate, [])
@@ -73,27 +71,27 @@ module ZendeskAppsTools
73
71
 
74
72
  zip archive_path
75
73
 
76
- say_status "package", "created at #{archive_rel_path}"
74
+ say_status 'package', "created at #{archive_rel_path}"
77
75
  true
78
76
  end
79
77
 
80
- desc "clean", "Remove app packages in temp folder"
81
- method_option :path, default: './', required: false, aliases: "-p"
78
+ desc 'clean', 'Remove app packages in temp folder'
79
+ method_option :path, default: './', required: false, aliases: '-p'
82
80
  def clean
83
81
  setup_path(options[:path])
84
82
 
85
- return unless File.exists?(Pathname.new(File.join(app_dir, "tmp")).to_s)
83
+ return unless File.exist?(Pathname.new(File.join(app_dir, 'tmp')).to_s)
86
84
 
87
85
  FileUtils.rm(Dir["#{tmp_dir}/app-*.zip"])
88
86
  end
89
87
 
90
- DEFAULT_SERVER_PATH = "./"
91
- DEFAULT_CONFIG_PATH = "./settings.yml"
88
+ DEFAULT_SERVER_PATH = './'
89
+ DEFAULT_CONFIG_PATH = './settings.yml'
92
90
  DEFAULT_SERVER_PORT = 4567
93
91
 
94
- desc "server", "Run a http server to serve the local app"
95
- method_option :path, default: DEFAULT_SERVER_PATH, required: false, aliases: "-p"
96
- method_option :config, default: DEFAULT_CONFIG_PATH, required: false, aliases: "-c"
92
+ desc 'server', 'Run a http server to serve the local app'
93
+ method_option :path, default: DEFAULT_SERVER_PATH, required: false, aliases: '-p'
94
+ method_option :config, default: DEFAULT_CONFIG_PATH, required: false, aliases: '-c'
97
95
  method_option :port, default: DEFAULT_SERVER_PORT, required: false
98
96
  def server
99
97
  setup_path(options[:path])
@@ -116,7 +114,7 @@ module ZendeskAppsTools
116
114
  end
117
115
  end
118
116
 
119
- desc "create", "Create app on your account"
117
+ desc 'create', 'Create app on your account'
120
118
  method_options SHARED_OPTIONS
121
119
  method_option :zipfile, default: nil, required: false, type: :string
122
120
  def create
@@ -127,17 +125,17 @@ module ZendeskAppsTools
127
125
  app_name = JSON.parse(File.read(File.join options[:path], 'manifest.json'))['name']
128
126
  end
129
127
  app_name ||= get_value_from_stdin('Enter app name:')
130
- deploy_app(:post, '/api/v2/apps.json', { name: app_name })
128
+ deploy_app(:post, '/api/v2/apps.json', name: app_name)
131
129
  end
132
130
 
133
- desc "update", "Update app on the server"
131
+ desc 'update', 'Update app on the server'
134
132
  method_options SHARED_OPTIONS
135
133
  method_option :zipfile, default: nil, required: false, type: :string
136
134
  def update
137
135
  clear_cache
138
136
  @command = 'Update'
139
137
 
140
- app_id = get_cache('app_id') || find_app_id
138
+ app_id = fetch_cache('app_id') || find_app_id
141
139
  unless /\d+/ =~ app_id.to_s
142
140
  say_error_and_exit "App id not found\nPlease try running command with --clean or check your internet connection"
143
141
  end
@@ -149,6 +147,5 @@ module ZendeskAppsTools
149
147
  def setup_path(path)
150
148
  @destination_stack << relative_to_original_destination_root(path) unless @destination_stack.last == path
151
149
  end
152
-
153
150
  end
154
151
  end
@@ -19,18 +19,18 @@ module ZendeskAppsTools
19
19
  }.merge(opts)
20
20
 
21
21
  while input = ask(prompt)
22
- return "" if input.empty? && options[:allow_empty]
23
- unless input =~ options[:valid_regex]
24
- say(options[:error_msg], :red)
25
- else
22
+ return '' if input.empty? && options[:allow_empty]
23
+ if input =~ options[:valid_regex]
26
24
  break
25
+ else
26
+ say(options[:error_msg], :red)
27
27
  end
28
28
  end
29
29
 
30
- return input
30
+ input
31
31
  end
32
32
 
33
- def get_password_from_stdin(prompt, opts = {})
33
+ def get_password_from_stdin(prompt)
34
34
  print "#{prompt} "
35
35
  password = STDIN.noecho(&:gets).chomp
36
36
  puts
@@ -48,10 +48,10 @@ module ZendeskAppsTools
48
48
 
49
49
  all_apps = connection.get('/api/v2/apps.json').body
50
50
 
51
- app = JSON.parse(all_apps)['apps'].find { |app| app['name'] == name }
51
+ app_id = JSON.parse(all_apps)['apps'].find { |app| app['name'] == name }['id']
52
52
 
53
- set_cache 'app_id' => app['id']
54
- app['id']
53
+ save_cache 'app_id' => app_id
54
+ app_id
55
55
  rescue Faraday::Error::ClientError => e
56
56
  say_error_and_exit e.message
57
57
  end
@@ -59,9 +59,7 @@ module ZendeskAppsTools
59
59
  def check_status(response)
60
60
  job = response.body
61
61
  job_response = JSON.parse(job)
62
- if job_response['error']
63
- say_error_and_exit job_response['error']
64
- end
62
+ say_error_and_exit job_response['error'] if job_response['error']
65
63
 
66
64
  job_id = job_response['job_id']
67
65
  check_job job_id
@@ -77,10 +75,10 @@ module ZendeskAppsTools
77
75
  message = info['message']
78
76
  app_id = info['app_id']
79
77
 
80
- if ['completed', 'failed'].include? status
78
+ if %w(completed failed).include? status
81
79
  case status
82
80
  when 'completed'
83
- set_cache 'app_id' => app_id
81
+ save_cache 'app_id' => app_id
84
82
  say_status @command, 'OK'
85
83
  when 'failed'
86
84
  say_status @command, message
@@ -94,6 +92,5 @@ module ZendeskAppsTools
94
92
  rescue Faraday::Error::ClientError => e
95
93
  say_error_and_exit e.message
96
94
  end
97
-
98
95
  end
99
96
  end
@@ -1,30 +1,28 @@
1
1
  module ZendeskAppsTools
2
2
  module Directory
3
-
4
3
  def app_dir
5
4
  @app_dir ||= Pathname.new(destination_root)
6
5
  end
7
6
 
8
7
  def tmp_dir
9
- @tmp_dir ||= Pathname.new(File.join(app_dir, "tmp")).tap do |dir|
8
+ @tmp_dir ||= Pathname.new(File.join(app_dir, 'tmp')).tap do |dir|
10
9
  FileUtils.mkdir_p(dir)
11
10
  end
12
11
  end
13
12
 
14
- def get_new_app_directory
13
+ def prompt_new_app_dir
15
14
  prompt = "Enter a directory name to save the new app (will create the dir if it does not exist, default to current dir):\n"
16
15
  opts = { valid_regex: /^(\w|\/|\\)*$/, allow_empty: true }
17
- while @app_dir = get_value_from_stdin(prompt, opts) do
16
+ while @app_dir = get_value_from_stdin(prompt, opts)
18
17
  @app_dir = './' and break if @app_dir.empty?
19
- if !File.exists?(@app_dir)
18
+ if !File.exist?(@app_dir)
20
19
  break
21
20
  elsif !File.directory?(@app_dir)
22
- puts "Invalid dir, try again:"
21
+ puts 'Invalid dir, try again:'
23
22
  else
24
23
  break
25
24
  end
26
25
  end
27
26
  end
28
-
29
27
  end
30
28
  end
@@ -4,11 +4,7 @@ module ZendeskAppsTools
4
4
 
5
5
  # Convert :"en-US-x-12" to 'en-US'
6
6
  def initialize(code)
7
- @locale_id = if code.start_with?('en-US') #default locale
8
- 'en-US'
9
- else
10
- code.sub(/-x-.*/, '').downcase
11
- end
7
+ @locale_id = code.start_with?('en-US') ? 'en-US' : code.sub(/-x-.*/, '').downcase
12
8
  end
13
9
  end
14
10
  end
@@ -1,20 +1,18 @@
1
1
  module ZendeskAppsTools
2
-
3
2
  require 'zendesk_apps_support'
4
3
 
5
4
  module PackageHelper
6
-
7
5
  include ZendeskAppsSupport
8
6
 
9
7
  def app_package
10
- @app_package ||= Package.new(self.app_dir.to_s)
8
+ @app_package ||= Package.new(app_dir.to_s)
11
9
  end
12
10
 
13
11
  def zip(archive_path)
14
12
  Zip::ZipFile.open(archive_path, 'w') do |zipfile|
15
13
  app_package.files.each do |file|
16
14
  path = file.relative_path
17
- say_status "package", "adding #{path}"
15
+ say_status 'package', "adding #{path}"
18
16
 
19
17
  # resolve symlink to source path
20
18
  if File.symlink? file.absolute_path
@@ -24,6 +22,5 @@ module ZendeskAppsTools
24
22
  end
25
23
  end
26
24
  end
27
-
28
25
  end
29
26
  end
@@ -3,12 +3,11 @@ require 'zendesk_apps_support/package'
3
3
 
4
4
  module ZendeskAppsTools
5
5
  class Server < Sinatra::Base
6
- set :public_folder, Proc.new {"#{settings.root}/assets"}
6
+ set :public_folder, proc { "#{settings.root}/assets" }
7
7
 
8
8
  get '/app.js' do
9
9
  content_type 'text/javascript'
10
10
  ZendeskAppsSupport::Package.new(settings.root).readified_js(nil, 0, "http://localhost:#{settings.port}/", settings.parameters)
11
11
  end
12
-
13
12
  end
14
- end
13
+ end
@@ -3,7 +3,6 @@ require 'yaml'
3
3
 
4
4
  module ZendeskAppsTools
5
5
  class Settings
6
-
7
6
  def get_settings_from_user_input(user_input, parameters)
8
7
  return {} if parameters.nil?
9
8
 
@@ -28,7 +27,7 @@ module ZendeskAppsTools
28
27
 
29
28
  def get_settings_from_file(filepath, parameters)
30
29
  return {} if parameters.nil?
31
- return nil unless File.exists? filepath
30
+ return nil unless File.exist? filepath
32
31
 
33
32
  begin
34
33
  settings_file = File.read(filepath)
@@ -36,15 +35,17 @@ module ZendeskAppsTools
36
35
  if filepath =~ /\.json$/ || settings_file =~ /\A\s*{/
37
36
  settings_data = JSON.load(settings_file)
38
37
  else
39
- settings_data = YAML::load(settings_file)
38
+ settings_data = YAML.load(settings_file)
40
39
  end
41
40
 
42
41
  settings_data.each do |index, setting|
43
- if (setting.is_a?(Hash) || setting.is_a?(Array))
42
+ if setting.is_a?(Hash) || setting.is_a?(Array)
44
43
  settings_data[index] = JSON.dump(setting)
45
44
  end
46
45
  end
47
46
  rescue => err
47
+ puts "Failed to load #{filepath}"
48
+ puts err.message
48
49
  return nil
49
50
  end
50
51
 
@@ -72,11 +73,10 @@ module ZendeskAppsTools
72
73
  private
73
74
 
74
75
  def convert_to_boolean_for_checkbox(input)
75
- if ![TrueClass, FalseClass].include?(input.class)
76
+ unless [TrueClass, FalseClass].include?(input.class)
76
77
  return (input =~ /^(true|t|yes|y|1)$/i) ? true : false
77
78
  end
78
79
  input
79
80
  end
80
-
81
81
  end
82
82
  end
@@ -12,7 +12,7 @@ module ZendeskAppsTools
12
12
  include ZendeskAppsTools::Common
13
13
  include ZendeskAppsSupport::BuildTranslation
14
14
 
15
- LOCALE_ENDPOINT = "https://support.zendesk.com/api/v2/locales/agent.json"
15
+ LOCALE_ENDPOINT = 'https://support.zendesk.com/api/v2/locales/agent.json'
16
16
 
17
17
  desc 'to_yml', 'Create Zendesk translation file from en.json'
18
18
  method_option :path, default: './', required: false
@@ -22,14 +22,14 @@ module ZendeskAppsTools
22
22
  app_name = manifest['name']
23
23
 
24
24
  unless app_name
25
- app_name = get_value_from_stdin('What is the name of this app?', error_msg: "Invalid name, try again:")
25
+ app_name = get_value_from_stdin('What is the name of this app?', error_msg: 'Invalid name, try again:')
26
26
  end
27
27
 
28
28
  en_json = JSON.parse(File.open("#{destination_root}/translations/en.json").read)
29
29
 
30
- package = en_json["app"]["package"]
30
+ package = en_json['app']['package']
31
31
  say('No package defined inside en.json! Abort.', :red) and exit 1 unless package
32
- en_json["app"].delete("package")
32
+ en_json['app'].delete('package')
33
33
 
34
34
  write_yml(en_json, app_name, package)
35
35
  end
@@ -39,50 +39,48 @@ module ZendeskAppsTools
39
39
  def to_json
40
40
  setup_path(options[:path]) if options[:path]
41
41
  en_yml = YAML.load_file("#{destination_root}/translations/en.yml")
42
- en_yml['parts'][0]['translation']['key'] =~ /^txt.apps.([^\.]+)/
43
- package = $1
42
+ package = /^txt.apps.([^\.]+)/.match(en_yml['parts'][0]['translation']['key'])[1]
44
43
  translations = en_yml['parts'].map { |part| part['translation'] }
45
44
  en_json = array_to_nested_hash(translations)['txt']['apps'][package]
46
45
  en_json['app']['package'] = package
47
46
 
48
- write_json("translations/en.json", en_json)
47
+ write_json('translations/en.json', en_json)
49
48
  end
50
49
 
51
50
  desc 'update', 'Update translation files from Zendesk'
52
51
  method_option :path, default: './', required: false
53
52
  def update(request_builder = Faraday.new)
54
53
  setup_path(options[:path]) if options[:path]
55
- 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:")
54
+ 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:')
56
55
 
57
56
  key_prefix = "txt.apps.#{app_package}."
58
57
 
59
- say("Fetching translations...")
58
+ say('Fetching translations...')
60
59
  locale_response = api_request(LOCALE_ENDPOINT, request_builder)
61
60
 
62
61
  if locale_response.status == 200
63
- locales = JSON.parse(locale_response.body)["locales"]
62
+ locales = JSON.parse(locale_response.body)['locales']
64
63
 
65
64
  locales.each do |locale|
66
- locale_url = "#{locale["url"]}?include=translations&packages=app_#{app_package}"
65
+ locale_url = "#{locale['url']}?include=translations&packages=app_#{app_package}"
67
66
  locale_response = api_request(locale_url, request_builder).body
68
67
  translations = JSON.parse(locale_response)['locale']['translations']
69
68
 
70
69
  locale_name = ZendeskAppsTools::LocaleIdentifier.new(locale['locale']).locale_id
71
70
  write_json("#{destination_root}/translations/#{locale_name}.json", nest_translations_hash(translations, key_prefix))
72
71
  end
73
- say("Translations updated", :green)
72
+ say('Translations updated', :green)
74
73
 
75
74
  elsif locale_response.status == 401
76
- say("Authentication failed", :red)
75
+ say('Authentication failed', :red)
77
76
  end
78
77
  end
79
78
 
80
79
  def self.source_root
81
- File.expand_path(File.join(File.dirname(__FILE__), "../.."))
80
+ File.expand_path(File.join(File.dirname(__FILE__), '../..'))
82
81
  end
83
82
 
84
83
  no_commands do
85
-
86
84
  def setup_path(path)
87
85
  @destination_stack << relative_to_original_destination_root(path) unless @destination_stack.last == path
88
86
  end
@@ -100,13 +98,11 @@ module ZendeskAppsTools
100
98
  context = result
101
99
 
102
100
  parts.each_with_index do |part, i|
103
-
104
101
  if parts_count == i
105
102
  context[part] = value
106
103
  else
107
104
  context = context[part] ||= {}
108
105
  end
109
-
110
106
  end
111
107
  end
112
108
 
@@ -116,10 +112,10 @@ module ZendeskAppsTools
116
112
  def write_yml(en_json, app_name, package_name)
117
113
  titles = to_flattened_namespaced_hash(en_json, I18N_TITLE_KEY)
118
114
  values = to_flattened_namespaced_hash(en_json, I18N_VALUE_KEY)
119
- @translations = titles.each { |k, v| titles[k] = {"title" => v, "value" => escape_special_characters(values[k]) }}
115
+ @translations = titles.each { |k, v| titles[k] = { 'title' => v, 'value' => escape_special_characters(values[k]) } }
120
116
  @app_name = app_name
121
117
  @package_name = package_name
122
- template(File.join(Translate.source_root, 'templates/translation.erb.tt'), "translations/en.yml")
118
+ template(File.join(Translate.source_root, 'templates/translation.erb.tt'), 'translations/en.yml')
123
119
  end
124
120
 
125
121
  def escape_special_characters(v)
@@ -133,7 +129,7 @@ module ZendeskAppsTools
133
129
  keys[0..-2].each do |key|
134
130
  current = (current[key] ||= {})
135
131
  end
136
- current[keys[-1]] = {'title' => item['title'], 'value' => item['value']}
132
+ current[keys[-1]] = { 'title' => item['title'], 'value' => item['value'] }
137
133
  result
138
134
  end
139
135
  end
@@ -3,4 +3,3 @@ module ZendeskAppsTools
3
3
  autoload :Translate, 'zendesk_apps_tools/translate'
4
4
  autoload :LocaleIdentifier, 'zendesk_apps_tools/locale_identifier'
5
5
  end
6
-
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.21.1
4
+ version: 1.21.2
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: 2014-11-05 00:00:00.000000000 Z
14
+ date: 2015-02-02 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: thor