zendesk_apps_tools 1.35.2 → 1.35.3

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: 35cc1aed2dc4672a92d4b2668727ebf8deca7b89
4
- data.tar.gz: 96a2be40599ae9cfbd86c786c929bdf0c9edfa86
3
+ metadata.gz: 343966d2380b3c6d32c9fc42d96267f3206b7006
4
+ data.tar.gz: 7d71b9491415e36fc335ab2a1d2b47b33756ecda
5
5
  SHA512:
6
- metadata.gz: 2d033b5b7ae1bf7ed0ba68b0c4f12da4a4e307e5aa3e6ea7a254058c2e6b3f4fb20018f61c8fcea5347d50093f54741c7b4c9b8a81648f93a5ce1a2cd9a148c7
7
- data.tar.gz: c207f8f3b3ef8be41fda1e85e49a519c075551c7f6337750337993b234b17b473ab7cccf6fec0bf109c3d4e2184396fd7df33f5a689bd72eab22a7fb231f9495
6
+ metadata.gz: 0b59451499cb844d058bbafc5009b72c1e07a12e53ed6f9cfc3f1fe1c121dd9ddd1b10f062ede756d143b6b58f395427be46b42cc01f72a94d7e624a91da1070
7
+ data.tar.gz: 2da8f6270e4fb93e0f5b895dfec71152fab50939c614f716eb7c2b54b7b9c075a202805e503370c8af5dc356476349e21ff98b807cf299905332e342ee2d6fea
@@ -4,11 +4,11 @@ module ZendeskAppsTools
4
4
  URL_TEMPLATE = 'https://%s.zendesk.com/'
5
5
 
6
6
  def prepare_api_auth
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:')
7
+ @subdomain ||= cache.fetch('subdomain') || get_value_from_stdin('Enter your Zendesk subdomain or full Zendesk URL:')
8
+ @username ||= cache.fetch('username', @subdomain) || get_value_from_stdin('Enter your username:')
9
+ @password ||= cache.fetch('password', @subdomain) || get_password_from_stdin('Enter your password:')
10
10
 
11
- save_cache 'subdomain' => @subdomain, 'username' => @username
11
+ cache.save 'subdomain' => @subdomain, 'username' => @username
12
12
  end
13
13
 
14
14
  def get_connection(encoding = :url_encoded)
@@ -1,25 +1,58 @@
1
+ # frozen_string_literal: true
2
+ require 'json'
3
+
1
4
  module ZendeskAppsTools
2
- module Cache
5
+ class Cache
3
6
  CACHE_FILE_NAME = '.zat'
4
7
 
5
- def save_cache(hash)
8
+ attr_reader :options
9
+
10
+ def initialize(options)
11
+ @options = options
12
+ end
13
+
14
+ def save(hash)
6
15
  return if options[:zipfile]
7
16
 
8
- @cache = File.exist?(cache_path) ? JSON.parse(File.read(@cache_path)).update(hash) : hash
9
- File.open(@cache_path, 'w') { |f| f.write JSON.pretty_generate(@cache) }
17
+ local_cache.update(hash)
18
+ File.open(local_cache_path, 'w') { |f| f.write JSON.pretty_generate(local_cache) }
19
+ end
20
+
21
+ def fetch(key, subdomain = nil)
22
+ # drop the default_proc and replace with Hash#dig if older Ruby versions are unsupported
23
+ local_cache[key] || global_cache[subdomain][key] || global_cache['default'][key]
24
+ end
25
+
26
+ def clear
27
+ File.delete local_cache_path if options[:clean] && File.exist?(local_cache_path)
28
+ end
29
+
30
+ private
31
+
32
+ def local_cache
33
+ @local_cache ||= File.exist?(local_cache_path) ? JSON.parse(File.read(local_cache_path)) : {}
10
34
  end
11
35
 
12
- def fetch_cache(key)
13
- @cache ||= File.exist?(cache_path) ? JSON.parse(File.read(@cache_path)) : {}
14
- @cache[key] if @cache
36
+ def global_cache
37
+ @global_cache ||= begin
38
+ if File.exist?(global_cache_path)
39
+ JSON.parse(File.read(global_cache_path)).tap do |cache|
40
+ cache.default_proc = proc do |_hash, _key|
41
+ {}
42
+ end
43
+ end
44
+ else
45
+ Hash.new({})
46
+ end
47
+ end
15
48
  end
16
49
 
17
- def clear_cache
18
- File.delete cache_path if options[:clean] && File.exist?(cache_path)
50
+ def global_cache_path
51
+ @global_cache_path ||= File.join(Dir.home, CACHE_FILE_NAME)
19
52
  end
20
53
 
21
- def cache_path
22
- @cache_path ||= File.join options[:path], CACHE_FILE_NAME
54
+ def local_cache_path
55
+ @local_cache_path ||= File.join(options[:path], CACHE_FILE_NAME)
23
56
  end
24
57
  end
25
58
  end
@@ -155,7 +155,7 @@ module ZendeskAppsTools
155
155
  method_options SHARED_OPTIONS
156
156
  method_option :zipfile, default: nil, required: false, type: :string
157
157
  def create
158
- clear_cache
158
+ cache.clear
159
159
  @command = 'Create'
160
160
 
161
161
  unless options[:zipfile]
@@ -169,10 +169,10 @@ module ZendeskAppsTools
169
169
  method_options SHARED_OPTIONS
170
170
  method_option :zipfile, default: nil, required: false, type: :string
171
171
  def update
172
- clear_cache
172
+ cache.clear
173
173
  @command = 'Update'
174
174
 
175
- app_id = fetch_cache('app_id') || find_app_id
175
+ app_id = cache.fetch('app_id') || find_app_id
176
176
  unless /\d+/ =~ app_id.to_s
177
177
  say_error_and_exit "App id not found\nPlease try running command with --clean or check your internet connection"
178
178
  end
@@ -1,4 +1,3 @@
1
- require 'zendesk_apps_tools/cache'
2
1
  require 'zendesk_apps_tools/common'
3
2
  require 'zendesk_apps_tools/api_connection'
4
3
  require 'zendesk_apps_tools/deploy'
@@ -9,11 +8,17 @@ require 'zendesk_apps_tools/bump'
9
8
 
10
9
  module ZendeskAppsTools
11
10
  module CommandHelpers
12
- include ZendeskAppsTools::Cache
13
11
  include ZendeskAppsTools::Common
14
12
  include ZendeskAppsTools::APIConnection
15
13
  include ZendeskAppsTools::Deploy
16
14
  include ZendeskAppsTools::Directory
17
15
  include ZendeskAppsTools::PackageHelper
16
+
17
+ def cache
18
+ @cache ||= begin
19
+ require 'zendesk_apps_tools/cache'
20
+ Cache.new(options)
21
+ end
22
+ end
18
23
  end
19
24
  end
@@ -48,7 +48,7 @@ module ZendeskAppsTools
48
48
  say_error_and_exit('The app was not found. Please verify your credentials, subdomain, and app name are correct.') unless app_json
49
49
  app_id = app_json['id']
50
50
 
51
- save_cache 'app_id' => app_id
51
+ cache.save 'app_id' => app_id
52
52
  app_id
53
53
  rescue Faraday::Error::ClientError => e
54
54
  say_error_and_exit e.message
@@ -76,7 +76,7 @@ module ZendeskAppsTools
76
76
  if %w(completed failed).include? status
77
77
  case status
78
78
  when 'completed'
79
- save_cache 'app_id' => app_id
79
+ cache.save 'app_id' => app_id
80
80
  say_status @command, 'OK'
81
81
  when 'failed'
82
82
  say_status @command, message, :red
@@ -39,6 +39,11 @@ module ZendeskAppsTools
39
39
 
40
40
  enable :cross_origin
41
41
 
42
+ def send_file(*args)
43
+ access_control_allow_origin
44
+ super(*args)
45
+ end
46
+
42
47
  # This is for any preflight request
43
48
  # It reads 'Access-Control-Request-Headers' to set 'Access-Control-Allow-Headers'
44
49
  # And also sets 'Access-Control-Allow-Origin' header
@@ -1,3 +1,3 @@
1
1
  module ZendeskAppsTools
2
- VERSION = "1.35.2"
2
+ VERSION = "1.35.3"
3
3
  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.35.2
4
+ version: 1.35.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: 2016-09-02 00:00:00.000000000 Z
14
+ date: 2016-09-27 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: thor