Class: BooticCli::Themes::APITheme
- Inherits:
-
Object
- Object
- BooticCli::Themes::APITheme
show all
- Defined in:
- lib/bootic_cli/themes/api_theme.rb
Defined Under Namespace
Classes: EntityErrors, EntityTooLargeError, InvalidRequest, RequestFailed, UnknownResponse
Instance Method Summary
collapse
Constructor Details
#initialize(theme) ⇒ APITheme
Returns a new instance of APITheme.
75
76
77
78
|
# File 'lib/bootic_cli/themes/api_theme.rb', line 75
def initialize(theme)
@theme = theme
puts "Entity has errors: #{theme.errors.map(&:messages).join(', ')}" if theme.has?(:errors)
end
|
Instance Method Details
#add_asset(file_name, file) ⇒ Object
149
150
151
152
153
154
|
# File 'lib/bootic_cli/themes/api_theme.rb', line 149
def add_asset(file_name, file)
check_errors! theme.create_theme_asset(
file_name: file_name,
data: file
)
end
|
#add_template(file_name, body) ⇒ Object
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/bootic_cli/themes/api_theme.rb', line 124
def add_template(file_name, body)
params = {
file_name: file_name,
body: body
}
if ts = get_updated_on(file_name)
params.merge!(last_updated_on: ts.to_i)
end
check_errors!(theme.create_template(params)).tap do |entity|
template_updated(file_name, entity)
end
end
|
#assets ⇒ Object
120
121
122
|
# File 'lib/bootic_cli/themes/api_theme.rb', line 120
def assets
@assets ||= theme.assets.map { |t| APIAsset.new(t) }
end
|
#delete! ⇒ Object
96
97
98
99
100
101
102
|
# File 'lib/bootic_cli/themes/api_theme.rb', line 96
def delete!
if theme.can?(:delete_theme)
res = theme.delete_theme
return res.status <= 204
end
false
end
|
#dev? ⇒ Boolean
85
86
87
|
# File 'lib/bootic_cli/themes/api_theme.rb', line 85
def dev?
theme.can?(:publish_theme)
end
|
#path ⇒ Object
104
105
106
|
# File 'lib/bootic_cli/themes/api_theme.rb', line 104
def path
theme.rels[:theme_preview].href
end
|
#public? ⇒ Boolean
this is unique to API themes
81
82
83
|
# File 'lib/bootic_cli/themes/api_theme.rb', line 81
def public?
!dev?
end
|
#publish(opts = {}) ⇒ Object
89
90
91
92
93
94
|
# File 'lib/bootic_cli/themes/api_theme.rb', line 89
def publish(opts = {})
if theme.can?(:publish_theme)
@theme = theme.publish_theme(opts)
reload!(false)
end
end
|
#reload!(refetch = true) ⇒ Object
Implement generic Theme interface
109
110
111
112
113
114
|
# File 'lib/bootic_cli/themes/api_theme.rb', line 109
def reload!(refetch = true)
@templates = nil
@assets = nil
@theme = theme.self if refetch
self
end
|
#remove_asset(file_name) ⇒ Object
156
157
158
159
160
161
162
163
164
|
# File 'lib/bootic_cli/themes/api_theme.rb', line 156
def remove_asset(file_name)
asset = theme.assets.find { |t| t.file_name == file_name }
if asset and asset.can?(:delete_theme_asset)
res = asset.delete_theme_asset
res.status.to_i < 300
else
puts "Cannot delete asset: #{file_name}"
end
end
|
#remove_template(file_name) ⇒ Object
139
140
141
142
143
144
145
146
147
|
# File 'lib/bootic_cli/themes/api_theme.rb', line 139
def remove_template(file_name)
tpl = theme.templates.find { |t| t.file_name == file_name }
if tpl && tpl.can?(:delete_template)
res = tpl.delete_template
res.status.to_i < 300
else
puts "Cannot delete #{file_name}"
end
end
|
#templates ⇒ Object
116
117
118
|
# File 'lib/bootic_cli/themes/api_theme.rb', line 116
def templates
@templates ||= theme.templates.map { |t| ItemWithTime.new(t) }
end
|