Class: Insup::Insales
- Inherits:
-
Object
show all
- Defined in:
- lib/insup/insales.rb
Defined Under Namespace
Classes: Asset, Base, Theme
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(settings) ⇒ Insales
Returns a new instance of Insales.
5
6
7
|
# File 'lib/insup/insales.rb', line 5
def initialize(settings)
@settings = settings
end
|
Class Method Details
.logger ⇒ Object
13
14
15
|
# File 'lib/insup/insales.rb', line 13
def self.logger
ActiveResource::Base.logger
end
|
.logger=(val) ⇒ Object
9
10
11
|
# File 'lib/insup/insales.rb', line 9
def self.logger=(val)
ActiveResource::Base.logger = val
end
|
Instance Method Details
#config ⇒ Object
28
29
30
|
# File 'lib/insup/insales.rb', line 28
def config
@settings.insales
end
|
17
18
19
20
21
|
# File 'lib/insup/insales.rb', line 17
def configure_api
if !@has_api
@has_api = ::Insup::Insales::Base.configure(config['api_key'], config['subdomain'], config['password'])
end
end
|
#download_theme(theme_id, dir) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/insup/insales.rb', line 32
def download_theme(theme_id, dir)
configure_api
theme = Theme.find(theme_id)
theme.assets.each do |asset|
next if !asset.dirname
path = File.join(dir, asset.path)
exists = File.exist?(path)
write = !exists
write = yield(asset, exists) if block_given?
if write
File.delete(path) if exists
Dir.mkdir(File.dirname(path)) if !Dir.exist?(File.dirname(path))
File.open(path, 'wb'){|f| f.write(asset.data)}
end
end
end
|
#themes ⇒ Object
23
24
25
26
|
# File 'lib/insup/insales.rb', line 23
def themes
configure_api
Theme.all
end
|