Class: Smooster::Deploy::SiteTemplate

Inherits:
Object
  • Object
show all
Extended by:
SiteTemplates
Includes:
ActiveModel::Model, ActiveModel::Serializers::JSON
Defined in:
lib/smooster/deploy/site_template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SiteTemplates

collection, method_missing, reload!, response, upload_all

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



8
9
10
# File 'lib/smooster/deploy/site_template.rb', line 8

def body
  @body
end

#checksumObject

Returns the value of attribute checksum.



8
9
10
# File 'lib/smooster/deploy/site_template.rb', line 8

def checksum
  @checksum
end

#pathObject

Returns the value of attribute path.



8
9
10
# File 'lib/smooster/deploy/site_template.rb', line 8

def path
  @path
end

#smo_idObject

Returns the value of attribute smo_id.



8
9
10
# File 'lib/smooster/deploy/site_template.rb', line 8

def smo_id
  @smo_id
end

#titleObject

Returns the value of attribute title.



8
9
10
# File 'lib/smooster/deploy/site_template.rb', line 8

def title
  @title
end

Instance Method Details

#attributesObject



10
11
12
# File 'lib/smooster/deploy/site_template.rb', line 10

def attributes
    {'title' => title, 'body' => body, 'path' => path, 'checksum' => checksum, 'smo_id' => smo_id}
end

#load_checksumObject



18
19
20
# File 'lib/smooster/deploy/site_template.rb', line 18

def load_checksum
  store.transaction { store[self.short_path][:checksum] if store[self.short_path].present? }
end

#load_smo_idObject



22
23
24
# File 'lib/smooster/deploy/site_template.rb', line 22

def load_smo_id
  store.transaction { store[self.short_path][:smo_id] if store[self.short_path].present? }
end

#saveObject



44
45
46
47
48
# File 'lib/smooster/deploy/site_template.rb', line 44

def save
  store.transaction do
    store[self.short_path] = {:checksum => self.checksum.to_s, :smo_id => self.smo_id}
  end
end

#short_pathObject



26
27
28
# File 'lib/smooster/deploy/site_template.rb', line 26

def short_path
  self.path.gsub("#{Smooster::Application.instance.base_dir}/#{Smooster::Application.instance.html_folder()}","")
end

#storeObject



14
15
16
# File 'lib/smooster/deploy/site_template.rb', line 14

def store
  Smooster::Application.instance.site_templates_store
end

#uploadObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/smooster/deploy/site_template.rb', line 30

def upload
  return false if self.checksum.to_s == self.load_checksum.to_s

  if self.smo_id.present?
    response = RestClient.put "#{Smooster::Application.instance.api_url()}/#{Smooster::Application.instance.site_id()}/site_templates/#{self.smo_id}", {:site_template => {:body => self.body, :title => self.title}}, {"Authorization" => 'Token token="'+ Smooster::Application.instance.api_key() +'"', "Accept" => 'application/vnd.smoosterid.v2'}
  else
    response = RestClient.post "#{Smooster::Application.instance.api_url()}/#{Smooster::Application.instance.site_id()}/site_templates", {:body => self.body, :title => self.title}, {"Authorization" => 'Token token="'+ Smooster::Application.instance.api_key() +'"', "Accept" => 'application/vnd.smoosterid.v2'}
  end

  data = JSON.parse(response)
  self.smo_id = data['smo_id']
  self.save
end