Class: Weeblycloud::Site

Inherits:
CloudResource show all
Includes:
Deleteable, Saveable
Defined in:
lib/weeblycloud/site.rb

Overview

Represents a Site resource. cloud-developer.weebly.com/site.html

Instance Attribute Summary

Attributes inherited from CloudResource

#properties

Instance Method Summary collapse

Methods included from Deleteable

#delete

Methods included from Saveable

#[]=, #save, #set_property

Methods inherited from CloudResource

#[], #get_property, #to_s

Constructor Details

#initialize(user_id, site_id, data = nil) ⇒ Site

Returns a new instance of Site.



20
21
22
23
24
25
26
# File 'lib/weeblycloud/site.rb', line 20

def initialize(user_id, site_id, data = nil)
  @user_id = user_id.to_i
  @site_id = site_id.to_i

  @endpoint = "user/#{@user_id}/site/#{@site_id}"
  super(data)
end

Instance Method Details

#create_group(name) ⇒ Object

Creates a Group. Requires the group’s name. Returns a Group resource.



153
154
155
156
157
# File 'lib/weeblycloud/site.rb', line 153

def create_group(name)
  data = {"name" => name}
  response = @client.post(@endpoint + "/group", :content=>data)
  return Group.new(@user_id, @site_id, response.json["group_id"], response.json)
end

#create_member(email, name, password, properties = {}) ⇒ Object

Creates a Member. Requires the member’s email, name, password, and optionally accepts hash of additional properties. Returns a Member resource.



162
163
164
165
166
# File 'lib/weeblycloud/site.rb', line 162

def create_member(email, name, password, properties={})
  properties.merge!({"email"=>email, "name"=>name, "password"=>password})
  response = @client.post(@endpoint + "/member", :content=>properties)
  return Member.new(@user_id, @site_id, response.json["member_id"], response.json)
end

#disableObject

Suspends access to the given user’s site in the editor by setting the suspended parameter to true. If a user attempts to access the site in the editor, an error is thrown.



79
80
81
82
# File 'lib/weeblycloud/site.rb', line 79

def disable
  response = @client.post(@endpoint + "/disable")
  return response.json["success"]
end

#enableObject

Re-enables a suspended site by setting the suspended parameter to false. Users can access the editor for the site. Sites are enabled by default when created.



87
88
89
90
# File 'lib/weeblycloud/site.rb', line 87

def enable
  response = @client.post(@endpoint + "/enable")
  return response.json["success"]
end

#getObject

Make an API call to get site properties



29
30
31
32
# File 'lib/weeblycloud/site.rb', line 29

def get
  response = @client.get(@endpoint)
  @properties = response.json["site"]
end

#get_blog(blog_id) ⇒ Object

Return the Blog with the given id.



189
190
191
# File 'lib/weeblycloud/site.rb', line 189

def get_blog(blog_id)
  return Blog.new(@user_id, @site_id, @blog_id)
end

#get_form(form_id) ⇒ Object

Return the Form with the given id.



184
185
186
# File 'lib/weeblycloud/site.rb', line 184

def get_form(form_id)
  return Form.new(@user_id, @site_id, @form_id)
end

#get_group(group_id) ⇒ Object

Return the Group with the given id.



179
180
181
# File 'lib/weeblycloud/site.rb', line 179

def get_group(group_id)
  return Group.new(@user_id, @site_id, @group_id)
end

#get_member(member_id) ⇒ Object

Return the Member with the given id.



174
175
176
# File 'lib/weeblycloud/site.rb', line 174

def get_member(member_id)
  return Member.new(@user_id, @site_id, @member_id)
end

#get_page(page_id) ⇒ Object

Return the Page with the given id.



169
170
171
# File 'lib/weeblycloud/site.rb', line 169

def get_page(page_id)
  return Page.new(@user_id, @site_id, @page_id)
end

#get_planObject

Returns the Plan resource for the site.



93
94
95
96
97
98
# File 'lib/weeblycloud/site.rb', line 93

def get_plan
  response = @client.get(@endpoint + "/plan")
  plan = response.json["plans"]
  plan = plan.values[0]
  return Plan.new(plan["plan_id"], plan)
end

#idObject

Returns the site_id



35
36
37
# File 'lib/weeblycloud/site.rb', line 35

def id
  @site_id
end

#list_blogs(filters = {}) ⇒ Object

Returns a list of Blog resources for a given site subject to filters.



147
148
149
150
# File 'lib/weeblycloud/site.rb', line 147

def list_blogs(filters={})
  result = @client.get(@endpoint + "/blog", :params=>filters)
  return result.map { |i| Blog.new(@user_id, @site_id, i["blog_id"], i) }
end

#list_forms(filters = {}) ⇒ Object

Returns a list of Form resources for a given site subject to filters.



141
142
143
144
# File 'lib/weeblycloud/site.rb', line 141

def list_forms(filters={})
  result = @client.get(@endpoint + "/form", :params=>filters)
  return result.map { |i| Form.new(@user_id, @site_id, i["form_id"], i) }
end

#list_groups(filters = {}) ⇒ Object

Returns a list of Group resources for a given site subject to filters.



135
136
137
138
# File 'lib/weeblycloud/site.rb', line 135

def list_groups(filters={})
  result = @client.get(@endpoint + "/group", :params=>filters)
  return result.map { |i| Group.new(@user_id, @site_id, i["group_id"], i) }
end

#list_members(filters = {}) ⇒ Object

Returns a list of Member resources for a given site subject to filters.



129
130
131
132
# File 'lib/weeblycloud/site.rb', line 129

def list_members(filters={})
  result = @client.get(@endpoint + "/member", :params=>filters)
  return result.map { |i| Member.new(@user_id, @site_id, i["member_id"], i) }
end

#list_pages(filters = {}) ⇒ Object

Returns a list of Page resources for a given site subject to filters.



123
124
125
126
# File 'lib/weeblycloud/site.rb', line 123

def list_pages(filters={})
  result = @client.get(@endpoint + "/page", :params=>filters)
  return result.map { |i| Page.new(@user_id, @site_id, i["page_id"], i) }
end

Generates a one-time link that will direct users to the site specified. This method requires that the account is enabled.



53
54
55
56
# File 'lib/weeblycloud/site.rb', line 53

def 
  response = @client.post(@endpoint + "/loginLink")
  return response.json["link"]
end

#publishObject

Publishes the site



40
41
42
43
# File 'lib/weeblycloud/site.rb', line 40

def publish
  response = @client.post(@endpoint + "/publish")
  return response.json["success"]
end

#restore(url) ⇒ Object

When a site is restored the owner of the site is granted access to it in the exact state it was when it was deleted, including the Weebly plan assigned. Restoring a site does not issue an automatic publish.



70
71
72
73
74
# File 'lib/weeblycloud/site.rb', line 70

def restore(url)
  data = {"domain" => url}
  response = @client.post(@endpoint + "/restore", :content => data)
  return response.json["success"]
end

#set_plan(plan_id, term = nil) ⇒ Object

Sets the site’s plan to plan_id with an optional term length. If no term is provided the Weebly Cloud default is used (check API documentation).



103
104
105
106
107
108
109
110
111
112
# File 'lib/weeblycloud/site.rb', line 103

def set_plan(plan_id, term=nil)
  data = {"plan_id" => plan_id}

  if term
    data.merge!({"term" => term})
  end

  response = @client.post(@endpoint + "/plan", :content=>data)
  return response.json["success"]
end

#set_publish_credentials(options = {}) ⇒ Object

Sets publish credentials to fields set in keyword arguments. If a user’s site will not be hosted by Weebly, publish credentials can be provided. When these values are set, the site will be published to the location specified.



62
63
64
65
# File 'lib/weeblycloud/site.rb', line 62

def set_publish_credentials(options = {})
  response = @client.post(@endpoint + "/setPublishCredentials", :content => options)
  return response.json["success"]
end

#set_theme(theme_id, is_custom) ⇒ Object

Sets the site’s theme to theme_id. Requires a parameter is_custom, distinguishing whether the theme is a Weebly theme or a custom theme.



116
117
118
119
120
# File 'lib/weeblycloud/site.rb', line 116

def set_theme(theme_id, is_custom)
  data = {"theme_id" => theme_id, "is_custom" => is_custom}
  response = @client.post(@endpoint + "/theme", :content=>data)
  return response.json["success"]
end

#unpublishObject

Unpublishes the site



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

def unpublish
  response = @client.post(@endpoint + "/publish")
  return response.json["success"]
end