opencode_theme 0.0.5 → 0.0.7
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 +4 -4
- data/lib/opencode_theme/base_service.rb +28 -26
- data/lib/opencode_theme/cli.rb +64 -64
- data/lib/opencode_theme/version.rb +1 -1
- data/opencode_theme.gemspec +1 -1
- data/spec/functional/functional_spec.rb +15 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 984d1ba98be1a73eb1c8034d967000d49a20a0a4
|
4
|
+
data.tar.gz: 55c366e05c5e6b1da0513fd3f67579ab1ed7c8df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5255cfedecba38a26ee93e1039b96d53b2faed252d2919993beb0bf391cc5e0c44a816196a6b6978827f4d7f21a4bcd457c3c7e95aa5597600d2f9c17349e0a
|
7
|
+
data.tar.gz: 5fd046f49700f4f685128df8794823b2e8b10f8e4db3b8576a803d52a2842cf8bd1fe9dafd272914487d45e0b17ad0180c26cf9fea94034f2a4d92086a9bd565
|
@@ -4,66 +4,68 @@ module OpencodeTheme
|
|
4
4
|
default_options.update(verify: false)
|
5
5
|
@@current_api_call_count = 0
|
6
6
|
@@total_api_calls = 40
|
7
|
-
URL_API =
|
7
|
+
URL_API = 'https://opencode.tray.com.br'
|
8
8
|
|
9
9
|
def self.api_usage
|
10
|
-
"[API Limit: #{@@current_api_call_count ||
|
10
|
+
"[API Limit: #{@@current_api_call_count || '??'}/#{@@total_api_calls || '??'}]"
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.check_config
|
14
|
-
response = opencode_theme.post(
|
15
|
-
|
14
|
+
response = opencode_theme.post('/api/check', query: { theme_id: config[:theme_id] })
|
15
|
+
{ success: response.success?, response: JSON.parse(response.body) }
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.list
|
19
|
-
response = opencode_theme.get(
|
20
|
-
|
19
|
+
response = opencode_theme.get('/api/list')
|
20
|
+
{ success: response.success?, response: JSON.parse(response.body) }
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
def self.clean
|
24
|
+
response = opencode_theme.post('/api/clean_cache', query: { theme_id: config[:theme_id] })
|
25
|
+
{ success: response.success?, response: JSON.parse(response.body) }
|
26
|
+
end
|
27
27
|
|
28
28
|
def self.theme_delete(theme_id)
|
29
|
-
response = opencode_theme.delete("/api/themes/#{theme_id}", :
|
30
|
-
|
29
|
+
response = opencode_theme.delete("/api/themes/#{theme_id}", parser: NOOPParser)
|
30
|
+
{ success: response.success?, response: JSON.parse(response.body) }
|
31
31
|
end
|
32
32
|
|
33
33
|
def self.theme_new(theme_base, theme_name)
|
34
|
-
response = opencode_theme.post(
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
response = opencode_theme.post('/api/themes',
|
35
|
+
body: { theme: { theme_base: theme_name, name: theme_name } }.to_json,
|
36
|
+
headers: { 'Content-Type' => 'application/json'},
|
37
|
+
parser: NOOPParser)
|
38
|
+
assets = response.code == 200 ? JSON.parse(response.body)["assets"] : {}
|
39
|
+
{ success: response.success?, assets: assets, response: JSON.parse(response.body) }
|
38
40
|
end
|
39
41
|
|
40
42
|
def self.asset_list
|
41
|
-
response = opencode_theme.get(path, :
|
42
|
-
assets = response.code == 200 ? JSON.parse(response.body)[
|
43
|
+
response = opencode_theme.get(path, parser: NOOPParser)
|
44
|
+
assets = response.code == 200 ? JSON.parse(response.body)['assets'].collect {|a| a['key'][1..a['key'].length] } : {}
|
43
45
|
assets
|
44
46
|
end
|
45
47
|
|
46
48
|
def self.get_asset(asset)
|
47
|
-
|
48
|
-
|
49
|
-
|
49
|
+
response = opencode_theme.get(path, query: { key: "/#{asset}" }, parser: NOOPParser)
|
50
|
+
asset = response.code == 200 ? JSON.parse(response.body) : ''
|
51
|
+
asset
|
50
52
|
end
|
51
53
|
|
52
54
|
def self.send_asset(data)
|
53
|
-
response = opencode_theme.put(path, :
|
55
|
+
response = opencode_theme.put(path, body: data)
|
54
56
|
response
|
55
57
|
end
|
56
58
|
|
57
59
|
def self.delete_asset(asset)
|
58
|
-
response = opencode_theme.delete(path, :
|
60
|
+
response = opencode_theme.delete(path, body: { key: "/#{asset}" })
|
59
61
|
response
|
60
62
|
end
|
61
63
|
|
62
|
-
private
|
64
|
+
private
|
65
|
+
|
63
66
|
def self.opencode_theme
|
64
67
|
base_uri URL_API
|
65
|
-
headers
|
68
|
+
headers "Authorization" => "Token token=#{config[:api_key]}_#{config[:password]}"
|
66
69
|
OpencodeTheme
|
67
70
|
end
|
68
|
-
|
69
71
|
end
|
data/lib/opencode_theme/cli.rb
CHANGED
@@ -9,79 +9,83 @@ require 'json'
|
|
9
9
|
require 'filewatcher'
|
10
10
|
require 'launchy'
|
11
11
|
require 'mimemagic'
|
12
|
+
|
12
13
|
MimeMagic.add('application/json', extensions: %w(json js), parents: 'text/plain')
|
13
14
|
MimeMagic.add('application/x-pointplus', extensions: %w(scss), parents: 'text/css')
|
14
15
|
MimeMagic.add('application/vnd.ms-fontobject', extensions: %w(eot), parents: 'font/opentype')
|
15
16
|
|
16
|
-
|
17
17
|
module OpencodeTheme
|
18
18
|
class Cli < Thor
|
19
19
|
include Thor::Actions
|
20
20
|
|
21
21
|
IGNORE = %w(config.yml)
|
22
22
|
DEFAULT_WHITELIST = %w(configs/ css/ elements/ img/ layouts/ pages/ js/)
|
23
|
-
TIMEFORMAT =
|
23
|
+
TIMEFORMAT = '%H:%M:%S'
|
24
24
|
|
25
25
|
tasks.keys.abbrev.each do |shortcut, command|
|
26
26
|
map shortcut => command.to_sym
|
27
27
|
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
map 'new' => :bootstrap
|
30
|
+
map 'rm' => :remove
|
31
|
+
|
32
|
+
desc 'configure API_KEY PASSWORD THEME_ID', 'Configura o tema que sera modificado'
|
33
|
+
def configure(api_key = nil, password = nil, theme_id = nil)
|
34
|
+
config = { api_key: api_key, password: password, theme_id: theme_id }
|
32
35
|
OpencodeTheme.config = config
|
33
36
|
response = OpencodeTheme.check_config
|
34
37
|
if response[:success]
|
35
|
-
config.merge!(:
|
36
|
-
create_file('config.yml', config.to_yaml, :
|
37
|
-
say(
|
38
|
+
config.merge!(preview_url: response[:response]['preview'])
|
39
|
+
create_file('config.yml', config.to_yaml, force: true)
|
40
|
+
say('Configuration [OK]', :green)
|
38
41
|
else
|
39
|
-
say(
|
42
|
+
say('Configuration [FAIL]', :red)
|
40
43
|
end
|
41
44
|
end
|
42
45
|
|
43
|
-
desc
|
46
|
+
desc 'list', 'Lista todos os temas da loja'
|
44
47
|
def list
|
45
48
|
config = OpencodeTheme.config
|
46
49
|
response = OpencodeTheme.list
|
47
50
|
if response[:success]
|
48
51
|
say("\n")
|
49
|
-
response[:response][
|
50
|
-
color = theme['published'] ==
|
51
|
-
say(
|
52
|
+
response[:response]['themes'].each do |theme|
|
53
|
+
color = theme['published'] == '1' ? :green : :red
|
54
|
+
say('Theme name: ', color)
|
52
55
|
say("#{theme['name']}\n", color)
|
53
|
-
say(
|
56
|
+
say('Theme ID: ', color)
|
54
57
|
say("#{theme['id']}\n", color)
|
55
|
-
say(
|
58
|
+
say('Theme status: ', color)
|
56
59
|
say("#{(theme['published'])}\n\n", color)
|
57
60
|
end
|
58
61
|
else
|
59
|
-
report_error(Time.now,
|
62
|
+
report_error(Time.now, 'Could not list now', response[:response])
|
60
63
|
end
|
61
64
|
end
|
62
65
|
|
63
|
-
desc
|
66
|
+
desc 'clean', 'Limpa o cache de arquivos estáticos'
|
67
|
+
|
64
68
|
def clean
|
65
69
|
config = OpencodeTheme.config
|
66
70
|
response = OpencodeTheme.clean
|
67
71
|
if response[:success]
|
68
|
-
say(
|
72
|
+
say('Clean cache [OK]\n', :green)
|
69
73
|
else
|
70
|
-
say(
|
74
|
+
say('Clean cache [FAIL]', :red)
|
71
75
|
end
|
72
76
|
end
|
73
77
|
|
74
|
-
desc
|
75
|
-
method_option :master, :
|
76
|
-
def bootstrap(api_key=nil, password=nil, theme_name='default', theme_base='default')
|
77
|
-
OpencodeTheme.config = {:
|
78
|
+
desc 'bootstrap API_KEY PASSWORD THEME_NAME THEME_BASE', 'Cria um novo tema com o nome informado'
|
79
|
+
method_option :master, type: :boolean, default: false
|
80
|
+
def bootstrap(api_key = nil, password = nil, theme_name = 'default', theme_base = 'default')
|
81
|
+
OpencodeTheme.config = { api_key: api_key, password: password }
|
78
82
|
|
79
83
|
check_config = OpencodeTheme.check_config
|
80
84
|
|
81
85
|
if check_config[:success]
|
82
|
-
say(
|
86
|
+
say('Configuration [OK]', :green)
|
83
87
|
else
|
84
|
-
report_error(Time.now,
|
88
|
+
report_error(Time.now, 'Configuration [FAIL]', check_config[:response])
|
85
89
|
return
|
86
90
|
end
|
87
91
|
|
@@ -90,7 +94,7 @@ module OpencodeTheme
|
|
90
94
|
if response[:success]
|
91
95
|
say("Create #{theme_name} theme on store", :green)
|
92
96
|
else
|
93
|
-
report_error(Time.now,
|
97
|
+
report_error(Time.now, 'Could not create a new theme', response[:response])
|
94
98
|
return
|
95
99
|
end
|
96
100
|
|
@@ -103,18 +107,18 @@ module OpencodeTheme
|
|
103
107
|
|
104
108
|
say("Downloading #{theme_name} assets from Opencode")
|
105
109
|
Dir.chdir(theme_name)
|
106
|
-
download
|
110
|
+
download
|
107
111
|
end
|
108
112
|
|
109
|
-
desc
|
113
|
+
desc 'open', 'Abre a loja no navegador'
|
110
114
|
def open(*keys)
|
111
115
|
if Launchy.open opencode_theme_url
|
112
|
-
say(
|
116
|
+
say('Done.', :green)
|
113
117
|
end
|
114
118
|
end
|
115
119
|
|
116
|
-
desc
|
117
|
-
method_option :quiet, :
|
120
|
+
desc 'download FILE', 'Baixa o arquivo informado ou todos se FILE for omitido'
|
121
|
+
method_option :quiet, type: :boolean, default: false
|
118
122
|
method_option :exclude
|
119
123
|
def download(*keys)
|
120
124
|
assets = keys.empty? ? OpencodeTheme.asset_list : keys
|
@@ -123,35 +127,35 @@ module OpencodeTheme
|
|
123
127
|
end
|
124
128
|
|
125
129
|
assets.each do |asset|
|
126
|
-
|
130
|
+
asset = URI.decode(asset)
|
127
131
|
download_asset(asset)
|
128
132
|
say("#{OpencodeTheme.api_usage} Downloaded: #{asset}", :green) unless options['quiet']
|
129
133
|
end
|
130
|
-
say(
|
134
|
+
say('Done.', :green) unless options['quiet']
|
131
135
|
end
|
132
136
|
|
133
|
-
desc
|
134
|
-
method_option :quiet, :
|
137
|
+
desc 'upload FILE', 'Sobe o arquivo informado ou todos se FILE for omitido'
|
138
|
+
method_option :quiet, type: :boolean, default: false
|
135
139
|
def upload(*keys)
|
136
140
|
assets = keys.empty? ? local_assets_list : keys
|
137
141
|
assets.each do |asset|
|
138
142
|
send_asset("#{asset}", options['quiet'])
|
139
143
|
end
|
140
|
-
say(
|
144
|
+
say('Done.', :green) unless options['quiet']
|
141
145
|
end
|
142
146
|
|
143
|
-
desc
|
144
|
-
method_option :quiet, :
|
147
|
+
desc 'remove FILE', 'Remove um arquivo do tema (apenas se o tema nao estiver publicado)'
|
148
|
+
method_option :quiet, type: :boolean, default: false
|
145
149
|
def remove(*keys)
|
146
150
|
keys.each do |key|
|
147
151
|
delete_asset(key, options['quiet'])
|
148
152
|
end
|
149
|
-
say(
|
153
|
+
say('Done.', :green) unless options['quiet']
|
150
154
|
end
|
151
155
|
|
152
|
-
desc
|
153
|
-
method_option :quiet, :
|
154
|
-
method_option :keep_files, :
|
156
|
+
desc 'watch', 'Baixa e sobe um arquivo sempre que ele for salvo'
|
157
|
+
method_option :quiet, type: :boolean, default: false
|
158
|
+
method_option :keep_files, type: :boolean, default: false
|
155
159
|
def watch
|
156
160
|
watcher do |filename, event|
|
157
161
|
filename = filename.gsub("#{Dir.pwd}/", '')
|
@@ -160,7 +164,7 @@ module OpencodeTheme
|
|
160
164
|
next
|
161
165
|
end
|
162
166
|
action = if [:changed, :new].include?(event)
|
163
|
-
|
167
|
+
:send_asset
|
164
168
|
elsif event == :delete
|
165
169
|
:delete_asset
|
166
170
|
else
|
@@ -170,26 +174,25 @@ module OpencodeTheme
|
|
170
174
|
end
|
171
175
|
end
|
172
176
|
|
173
|
-
desc
|
177
|
+
desc 'systeminfo', 'Mostra informacoes do sistema'
|
174
178
|
def systeminfo
|
175
179
|
ruby_version = "#{RUBY_VERSION}"
|
176
180
|
ruby_version += "-p#{RUBY_PATCHLEVEL}" if RUBY_PATCHLEVEL
|
177
181
|
puts "Ruby: v#{ruby_version}"
|
178
182
|
puts "Operating System: #{RUBY_PLATFORM}"
|
179
|
-
%w(
|
183
|
+
%w(HTTParty Launchy).each do |lib|
|
180
184
|
require "#{lib.downcase}/version"
|
181
|
-
puts "#{lib}: v" +
|
185
|
+
puts "#{lib}: v" + Kernel.const_get("#{lib}::VERSION")
|
182
186
|
end
|
183
187
|
end
|
184
188
|
|
185
|
-
|
186
|
-
protected
|
189
|
+
protected
|
187
190
|
|
188
191
|
def config
|
189
192
|
@config ||= YAML.load_file 'config.yml'
|
190
193
|
end
|
191
194
|
|
192
|
-
private
|
195
|
+
private
|
193
196
|
|
194
197
|
def notify_and_sleep(message)
|
195
198
|
say(message, :red)
|
@@ -197,14 +200,13 @@ private
|
|
197
200
|
end
|
198
201
|
|
199
202
|
def binary_file?(path)
|
200
|
-
|
203
|
+
!MimeMagic.by_path(path).text?
|
201
204
|
end
|
202
205
|
|
203
206
|
def opencode_theme_url
|
204
207
|
config[:preview_url]
|
205
208
|
end
|
206
209
|
|
207
|
-
|
208
210
|
def send_asset(asset, quiet = false)
|
209
211
|
if valid_name?(asset)
|
210
212
|
return unless valid?(asset)
|
@@ -227,7 +229,7 @@ private
|
|
227
229
|
end
|
228
230
|
end
|
229
231
|
|
230
|
-
def delete_asset(key, quiet=false)
|
232
|
+
def delete_asset(key, quiet = false)
|
231
233
|
return unless valid?(key)
|
232
234
|
response = show_during("[#{timestamp}] Removing: #{key}", quiet) do
|
233
235
|
OpencodeTheme.delete_asset(key)
|
@@ -240,7 +242,7 @@ private
|
|
240
242
|
end
|
241
243
|
|
242
244
|
def watcher
|
243
|
-
FileWatcher.new(Dir.pwd).watch
|
245
|
+
FileWatcher.new(Dir.pwd).watch do |filename, event|
|
244
246
|
yield("#{filename}", event)
|
245
247
|
end
|
246
248
|
end
|
@@ -270,12 +272,12 @@ private
|
|
270
272
|
time.strftime(TIMEFORMAT)
|
271
273
|
end
|
272
274
|
|
273
|
-
|
274
|
-
name = key.split(
|
275
|
+
def valid_name?(key)
|
276
|
+
name = key.split('/').last
|
275
277
|
if name =~ /^[0-9a-zA-Z\-_.]+\.(ttf|eot|svg|woff|css|scss|html|js|jpg|gif|png|json|TTF|EOT|SVG|WOFF|CSS|SCSS|HTML|JS|PNG|GIF|JPG|JSON)$/
|
276
278
|
valid = true
|
277
279
|
else
|
278
|
-
|
280
|
+
report_error(Time.now, "INVALID NAME #{name}", key)
|
279
281
|
end
|
280
282
|
valid
|
281
283
|
end
|
@@ -283,22 +285,22 @@ private
|
|
283
285
|
def download_asset(key)
|
284
286
|
if valid_name?(key)
|
285
287
|
return unless valid?(key)
|
286
|
-
notify_and_sleep(
|
288
|
+
notify_and_sleep('Approaching limit of API permits. Naptime until more permits become available!') if OpencodeTheme.needs_sleep?
|
287
289
|
asset = OpencodeTheme.get_asset(URI.encode(key))
|
288
290
|
unless asset['key']
|
289
291
|
report_error(Time.now, "Could not download #{key}", asset)
|
290
292
|
return
|
291
293
|
end
|
292
294
|
if asset['content']
|
293
|
-
|
294
|
-
|
295
|
-
format =
|
295
|
+
content = Base64.decode64(asset['content'])
|
296
|
+
content = content.force_encoding('UTF-8')
|
297
|
+
format = 'w+b:ISO-8859-1'
|
296
298
|
elsif asset['attachment']
|
297
299
|
content = Base64.decode64(asset['attachment'])
|
298
|
-
format =
|
300
|
+
format = 'w+b'
|
299
301
|
end
|
300
302
|
FileUtils.mkdir_p(File.dirname(URI.decode(key)))
|
301
|
-
File.open(key, format) {|f| f.write content} if content
|
303
|
+
File.open(key, format) { |f| f.write content } if content
|
302
304
|
end
|
303
305
|
end
|
304
306
|
|
@@ -313,7 +315,5 @@ private
|
|
313
315
|
say("[#{timestamp(time)}] Error: #{message}", :red)
|
314
316
|
say("Error Details: #{response}", :yellow)
|
315
317
|
end
|
316
|
-
|
317
318
|
end
|
318
|
-
|
319
319
|
end
|
data/opencode_theme.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = "http://tray-tecnologia.github.io/theme-template/"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
|
-
spec.add_dependency('thor', '>= 0.
|
16
|
+
spec.add_dependency('thor', '>= 0.19.1')
|
17
17
|
spec.add_dependency('httparty', '~> 0.13.0')
|
18
18
|
spec.add_dependency('json', '~> 1.8.0')
|
19
19
|
spec.add_dependency('mimemagic')
|
@@ -42,8 +42,20 @@ describe OpencodeTheme::Cli, :functional do
|
|
42
42
|
expect(File.exists? 'config.yml').to eq false
|
43
43
|
end
|
44
44
|
|
45
|
-
it '
|
46
|
-
output = capture(:stdout) { subject.configure API_KEY, PASSWORD }
|
45
|
+
it 'fails to create config.yml file when called with inexistent theme_id' do
|
46
|
+
output = capture(:stdout) { subject.configure API_KEY, PASSWORD, 2147483647 }
|
47
|
+
expect(output).to include 'Configuration [FAIL]'
|
48
|
+
expect(File.exists? 'config.yml').to eq false
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'fails to create config.yml file when called with invalid theme_id' do
|
52
|
+
output = capture(:stdout) { subject.configure API_KEY, PASSWORD, 'aaa' }
|
53
|
+
expect(output).to include 'Configuration [FAIL]'
|
54
|
+
expect(File.exists? 'config.yml').to eq false
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'creates config.yml when called with valid theme_id' do
|
58
|
+
output = capture(:stdout) { subject.configure API_KEY, PASSWORD, 1 }
|
47
59
|
expect(output).to include 'Configuration [OK]'
|
48
60
|
expect(File.exists? 'config.yml').to eq true
|
49
61
|
end
|
@@ -88,6 +100,7 @@ describe OpencodeTheme::Cli, :functional do
|
|
88
100
|
expect(output).to include 'Downloaded'
|
89
101
|
expect(output).to include "Downloaded: #{ FILE_NAME }"
|
90
102
|
expect(output).not_to include 'Error'
|
103
|
+
expect(output).not_to include 'Net::ReadTimeout'
|
91
104
|
expect(output).to include 'Done.'
|
92
105
|
end
|
93
106
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opencode_theme
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rafael Takashi Tanaka
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.19.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.19.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: httparty
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|