Class: Siteleaf::Site

Inherits:
Entity
  • Object
show all
Defined in:
lib/siteleaf/site.rb

Instance Attribute Summary collapse

Attributes inherited from Entity

#error, #message

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Entity

all, #attributes, #attributes=, class_name, create, #create_endpoint, delete, #delete, endpoint, #entity_endpoint, find, #identifier, #initialize, #save

Constructor Details

This class inherits a constructor from Siteleaf::Entity

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



5
6
7
# File 'lib/siteleaf/site.rb', line 5

def created_at
  @created_at
end

#defaultsObject

Returns the value of attribute defaults.



4
5
6
# File 'lib/siteleaf/site.rb', line 4

def defaults
  @defaults
end

#domainObject

Returns the value of attribute domain.



4
5
6
# File 'lib/siteleaf/site.rb', line 4

def domain
  @domain
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/siteleaf/site.rb', line 5

def id
  @id
end

#metadataObject

Returns the value of attribute metadata.



4
5
6
# File 'lib/siteleaf/site.rb', line 4

def 
  @metadata
end

#timezoneObject

Returns the value of attribute timezone.



4
5
6
# File 'lib/siteleaf/site.rb', line 4

def timezone
  @timezone
end

#titleObject

Returns the value of attribute title.



4
5
6
# File 'lib/siteleaf/site.rb', line 4

def title
  @title
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



5
6
7
# File 'lib/siteleaf/site.rb', line 5

def updated_at
  @updated_at
end

#user_idObject (readonly)

Returns the value of attribute user_id.



5
6
7
# File 'lib/siteleaf/site.rb', line 5

def user_id
  @user_id
end

Class Method Details

.find_by_domain(domain) ⇒ Object



7
8
9
10
11
# File 'lib/siteleaf/site.rb', line 7

def self.find_by_domain(domain)
  results = Client.get self.endpoint
  result = results.find {|d| d['domain'] == domain }
  self.new(result) if result
end

.import(attrs) ⇒ Object



13
14
15
16
# File 'lib/siteleaf/site.rb', line 13

def self.import(attrs)
  result = Client.post "import", attrs
  Job.new(id: result["job_id"]) if result
end

Instance Method Details

#collectionsObject



28
29
30
31
# File 'lib/siteleaf/site.rb', line 28

def collections
  result = Client.get "#{entity_endpoint}/collections"
  result.map { |r| Collection.new(r) } if result.is_a? Array
end

#filenameObject



60
61
62
# File 'lib/siteleaf/site.rb', line 60

def filename
  "_config.yml"
end

#full_urlObject



56
57
58
# File 'lib/siteleaf/site.rb', line 56

def full_url
  "http://#{domain}"
end

#pagesObject



23
24
25
26
# File 'lib/siteleaf/site.rb', line 23

def pages
  result = Client.get "#{entity_endpoint}/pages"
  result.map { |r| Page.new(r) } if result.is_a? Array
end

#postsObject



33
34
35
# File 'lib/siteleaf/site.rb', line 33

def posts
  Collection.new(path: 'posts', site_id: id).documents
end

#previewObject



46
47
48
49
# File 'lib/siteleaf/site.rb', line 46

def preview
  result = Client.post "#{entity_endpoint}/preview", {}
  Job.new(id: result["job_id"]) if result
end

#publishObject



41
42
43
44
# File 'lib/siteleaf/site.rb', line 41

def publish
  result = Client.post "#{entity_endpoint}/publish", {}
  Job.new(id: result["job_id"]) if result
end

#shaObject



64
65
66
# File 'lib/siteleaf/site.rb', line 64

def sha
  Siteleaf::GitHash.string(to_file)
end

#source_files(dir = '.', opts = {}) ⇒ Object



18
19
20
21
# File 'lib/siteleaf/site.rb', line 18

def source_files(dir = '.', opts = {})
  result = Client.get ::File.join(entity_endpoint, "source", dir), opts
  result.map { |r| SourceFile.new(r.merge('site_id' => id)) } if result.is_a? Array
end

#uploadsObject



37
38
39
# File 'lib/siteleaf/site.rb', line 37

def uploads
  Collection.new(path: 'uploads', site_id: id).files
end

#usersObject



51
52
53
54
# File 'lib/siteleaf/site.rb', line 51

def users
  result = Client.get "#{entity_endpoint}/users"
  result.map { |r| User.new(r) } if result.is_a? Array
end