discourse_theme 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/discourse_theme/scaffold.rb +2 -0
- data/lib/discourse_theme/uploader.rb +28 -4
- data/lib/discourse_theme/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5aeb29aae52cfe3e665464d04e2b8813a2bc7128
|
4
|
+
data.tar.gz: 31b93b745ce43c33598e60fc2009ebaa59f15a87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4c8a5dd67329602d0941fe25d96a533699b255572abf99cbd649d7e68b84c10685b6b002bab80e90a605b3905f4402b0723dac8fe1f49e0e1c36c6ccd1e021d
|
7
|
+
data.tar.gz: bc614b8b759385faa5d6fe8834d4a3eaea8e770625c9e7c267225fff40ff150ba24424939504c5cb6e6153ad970a1dcf5bbd2723ce5711b5786a800fe91f8d51
|
@@ -1,9 +1,12 @@
|
|
1
1
|
class DiscourseTheme::Uploader
|
2
2
|
|
3
|
+
THEME_CREATOR_REGEX = /^https:\/\/theme-creator.discourse.org$/i
|
4
|
+
|
3
5
|
def initialize(dir:, api_key:, site:)
|
4
6
|
@dir = dir
|
5
7
|
@api_key = api_key
|
6
8
|
@site = site
|
9
|
+
@is_theme_creator = !!(THEME_CREATOR_REGEX =~ site)
|
7
10
|
@theme_id = nil
|
8
11
|
end
|
9
12
|
|
@@ -55,14 +58,20 @@ class DiscourseTheme::Uploader
|
|
55
58
|
}
|
56
59
|
}
|
57
60
|
|
58
|
-
|
61
|
+
endpoint =
|
62
|
+
if @is_theme_creator
|
63
|
+
"/user_themes/#{@theme_id}"
|
64
|
+
else
|
65
|
+
"/admin/themes/#{@theme_id}?api_key=#{@api_key}"
|
66
|
+
end
|
59
67
|
|
68
|
+
uri = URI.parse(@site + endpoint)
|
60
69
|
http = Net::HTTP.new(uri.host, uri.port)
|
61
70
|
http.use_ssl = URI::HTTPS === uri
|
62
71
|
|
63
72
|
request = Net::HTTP::Put.new(uri.request_uri, 'Content-Type' => 'application/json')
|
64
73
|
request.body = args.to_json
|
65
|
-
|
74
|
+
add_headers(request)
|
66
75
|
http.start do |h|
|
67
76
|
response = h.request(request)
|
68
77
|
if response.code.to_i == 200
|
@@ -80,8 +89,14 @@ class DiscourseTheme::Uploader
|
|
80
89
|
filename = "#{Pathname.new(Dir.tmpdir).realpath}/bundle_#{SecureRandom.hex}.tar.gz"
|
81
90
|
compress_dir(filename, @dir)
|
82
91
|
|
83
|
-
|
84
|
-
|
92
|
+
endpoint =
|
93
|
+
if @is_theme_creator
|
94
|
+
"/user_themes/import.json"
|
95
|
+
else
|
96
|
+
"/admin/themes/import.json?api_key=#{@api_key}"
|
97
|
+
end
|
98
|
+
|
99
|
+
uri = URI.parse(@site + endpoint)
|
85
100
|
http = Net::HTTP.new(uri.host, uri.port)
|
86
101
|
http.use_ssl = URI::HTTPS === uri
|
87
102
|
File.open(filename) do |tgz|
|
@@ -90,6 +105,7 @@ class DiscourseTheme::Uploader
|
|
90
105
|
uri.request_uri,
|
91
106
|
"bundle" => UploadIO.new(tgz, "application/tar+gzip", "bundle.tar.gz"),
|
92
107
|
)
|
108
|
+
add_headers(request)
|
93
109
|
response = http.request(request)
|
94
110
|
if response.code.to_i == 201
|
95
111
|
json = JSON.parse(response.body)
|
@@ -107,4 +123,12 @@ class DiscourseTheme::Uploader
|
|
107
123
|
ensure
|
108
124
|
FileUtils.rm_f filename
|
109
125
|
end
|
126
|
+
|
127
|
+
private
|
128
|
+
|
129
|
+
def add_headers(request)
|
130
|
+
if @is_theme_creator
|
131
|
+
request["User-Api-Key"] = @api_key
|
132
|
+
end
|
133
|
+
end
|
110
134
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: discourse_theme
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|