weeblycloud 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.md +10 -0
- data/README.md +249 -0
- data/Rakefile +10 -0
- data/bin/setup +8 -0
- data/lib/weeblycloud.rb +22 -0
- data/lib/weeblycloud/account.rb +51 -0
- data/lib/weeblycloud/blog.rb +52 -0
- data/lib/weeblycloud/blogpost.rb +28 -0
- data/lib/weeblycloud/cloudclient/cloudclient.rb +119 -0
- data/lib/weeblycloud/cloudclient/exceptions.rb +17 -0
- data/lib/weeblycloud/cloudclient/weeblycloudresponse.rb +141 -0
- data/lib/weeblycloud/cloudresource.rb +62 -0
- data/lib/weeblycloud/deleteable.rb +13 -0
- data/lib/weeblycloud/form.rb +39 -0
- data/lib/weeblycloud/formentry.rb +26 -0
- data/lib/weeblycloud/group.rb +30 -0
- data/lib/weeblycloud/member.rb +30 -0
- data/lib/weeblycloud/page.rb +38 -0
- data/lib/weeblycloud/plan.rb +27 -0
- data/lib/weeblycloud/saveable.rb +36 -0
- data/lib/weeblycloud/site.rb +194 -0
- data/lib/weeblycloud/theme.rb +26 -0
- data/lib/weeblycloud/user.rb +71 -0
- data/lib/weeblycloud/version.rb +3 -0
- data/weeblycloud.gemspec +33 -0
- metadata +128 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
require "weeblycloud/cloudresource"
|
2
|
+
require "weeblycloud/saveable"
|
3
|
+
require "weeblycloud/deleteable"
|
4
|
+
|
5
|
+
module Weeblycloud
|
6
|
+
|
7
|
+
# Represents a Group resource.
|
8
|
+
# https://cloud-developer.weebly.com/group.html
|
9
|
+
class Group < CloudResource
|
10
|
+
include Saveable
|
11
|
+
include Deleteable
|
12
|
+
|
13
|
+
def initialize(user_id, site_id, group_id, data = nil)
|
14
|
+
@user_id = user_id.to_i
|
15
|
+
@site_id = site_id.to_i
|
16
|
+
@group_id = group_id.to_i
|
17
|
+
|
18
|
+
@endpoint = "user/#{@user_id}/site/#{@site_id}/group/#{@group_id}"
|
19
|
+
|
20
|
+
super(data)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns the group_id
|
24
|
+
def id
|
25
|
+
@group_id
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "weeblycloud/cloudresource"
|
2
|
+
require "weeblycloud/saveable"
|
3
|
+
require "weeblycloud/deleteable"
|
4
|
+
|
5
|
+
module Weeblycloud
|
6
|
+
|
7
|
+
# Represents a Member resource.
|
8
|
+
# https://cloud-developer.weebly.com/member.html
|
9
|
+
class Member < CloudResource
|
10
|
+
include Saveable
|
11
|
+
include Deleteable
|
12
|
+
|
13
|
+
def initialize(user_id, site_id, member_id, data = nil)
|
14
|
+
@user_id = user_id.to_i
|
15
|
+
@site_id = site_id.to_i
|
16
|
+
@member_id = member_id.to_i
|
17
|
+
|
18
|
+
@endpoint = "user/#{@user_id}/site/#{@site_id}/member/#{@member_id}"
|
19
|
+
|
20
|
+
super(data)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns the member_id
|
24
|
+
def id
|
25
|
+
@member_id
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "weeblycloud/cloudresource"
|
2
|
+
|
3
|
+
module Weeblycloud
|
4
|
+
|
5
|
+
# Represents a Page resource.
|
6
|
+
# https://cloud-developer.weebly.com/page.html
|
7
|
+
class Page < CloudResource
|
8
|
+
|
9
|
+
def initialize(user_id, site_id, page_id, data = nil)
|
10
|
+
@user_id = user_id.to_i
|
11
|
+
@site_id = site_id.to_i
|
12
|
+
@page_id = page_id.to_i
|
13
|
+
|
14
|
+
@endpoint = "user/#{@user_id}/site/#{@site_id}/page/#{@page_id}"
|
15
|
+
|
16
|
+
super(data)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Returns the page_id
|
20
|
+
def id
|
21
|
+
@page_id
|
22
|
+
end
|
23
|
+
|
24
|
+
# Changes the title of the page to title. Does not require calling the
|
25
|
+
# save() method.
|
26
|
+
def change_title(title)
|
27
|
+
data = {"title"=>title}
|
28
|
+
response = @client.patch(@endpoint, :content=>data)
|
29
|
+
if response.json["title"] == title
|
30
|
+
return true
|
31
|
+
else
|
32
|
+
return false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "weeblycloud/cloudresource"
|
2
|
+
|
3
|
+
module Weeblycloud
|
4
|
+
|
5
|
+
class Plan < CloudResource
|
6
|
+
|
7
|
+
def initialize(plan_id, data = nil)
|
8
|
+
@plan_id = plan_id.to_i
|
9
|
+
@endpoint = "plan/#{@plan_id}"
|
10
|
+
super(data)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Makes an API call to get the resource
|
14
|
+
def get
|
15
|
+
response = @client.get(@endpoint)
|
16
|
+
plan = response.json["plans"]
|
17
|
+
@properties = plan[plan.keys.first]
|
18
|
+
end
|
19
|
+
|
20
|
+
# Returns the plan_id
|
21
|
+
def id
|
22
|
+
@plan_id
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Weeblycloud
|
2
|
+
|
3
|
+
# CloudResource objects may use this module if they can be modified
|
4
|
+
module Saveable
|
5
|
+
|
6
|
+
# Set a property, prop, to value, val.
|
7
|
+
def set_property(prop, value)
|
8
|
+
if @properties.include?(prop)
|
9
|
+
@properties[prop] = value
|
10
|
+
@changed[prop] = value
|
11
|
+
return true
|
12
|
+
else
|
13
|
+
if @got
|
14
|
+
return nil
|
15
|
+
else
|
16
|
+
@got = true
|
17
|
+
get()
|
18
|
+
return set_property(prop, value)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Set a property using the [] setter
|
24
|
+
def []=(prop)
|
25
|
+
set_property(prop)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Make an API call to save changes to the resource
|
29
|
+
def save
|
30
|
+
@client.patch(@endpoint, :content=>@changed)
|
31
|
+
return nil
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,194 @@
|
|
1
|
+
require "weeblycloud/cloudresource"
|
2
|
+
require "weeblycloud/saveable"
|
3
|
+
require "weeblycloud/deleteable"
|
4
|
+
|
5
|
+
require "weeblycloud/plan"
|
6
|
+
require "weeblycloud/theme"
|
7
|
+
require "weeblycloud/page"
|
8
|
+
require "weeblycloud/member"
|
9
|
+
require "weeblycloud/group"
|
10
|
+
require "weeblycloud/blog"
|
11
|
+
|
12
|
+
module Weeblycloud
|
13
|
+
|
14
|
+
# Represents a Site resource.
|
15
|
+
# https://cloud-developer.weebly.com/site.html
|
16
|
+
class Site < CloudResource
|
17
|
+
include Saveable
|
18
|
+
include Deleteable
|
19
|
+
|
20
|
+
def initialize(user_id, site_id, data = nil)
|
21
|
+
@user_id = user_id.to_i
|
22
|
+
@site_id = site_id.to_i
|
23
|
+
|
24
|
+
@endpoint = "user/#{@user_id}/site/#{@site_id}"
|
25
|
+
super(data)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Make an API call to get site properties
|
29
|
+
def get
|
30
|
+
response = @client.get(@endpoint)
|
31
|
+
@properties = response.json["site"]
|
32
|
+
end
|
33
|
+
|
34
|
+
# Returns the site_id
|
35
|
+
def id
|
36
|
+
@site_id
|
37
|
+
end
|
38
|
+
|
39
|
+
# Publishes the site
|
40
|
+
def publish
|
41
|
+
response = @client.post(@endpoint + "/publish")
|
42
|
+
return response.json["success"]
|
43
|
+
end
|
44
|
+
|
45
|
+
# Unpublishes the site
|
46
|
+
def unpublish
|
47
|
+
response = @client.post(@endpoint + "/publish")
|
48
|
+
return response.json["success"]
|
49
|
+
end
|
50
|
+
|
51
|
+
# Generates a one-time link that will direct users to the site
|
52
|
+
# specified. This method requires that the account is enabled.
|
53
|
+
def login_link
|
54
|
+
response = @client.post(@endpoint + "/loginLink")
|
55
|
+
return response.json["link"]
|
56
|
+
end
|
57
|
+
|
58
|
+
# Sets publish credentials to fields set in keyword arguments.
|
59
|
+
# If a user’s site will not be hosted by Weebly, publish credentials
|
60
|
+
# can be provided. When these values are set, the site will be published
|
61
|
+
# to the location specified.
|
62
|
+
def set_publish_credentials(options = {})
|
63
|
+
response = @client.post(@endpoint + "/setPublishCredentials", :content => options)
|
64
|
+
return response.json["success"]
|
65
|
+
end
|
66
|
+
|
67
|
+
# When a site is restored the owner of the site is granted access to it
|
68
|
+
# in the exact state it was when it was deleted, including the Weebly
|
69
|
+
# plan assigned. Restoring a site does not issue an automatic publish.
|
70
|
+
def restore(url)
|
71
|
+
data = {"domain" => url}
|
72
|
+
response = @client.post(@endpoint + "/restore", :content => data)
|
73
|
+
return response.json["success"]
|
74
|
+
end
|
75
|
+
|
76
|
+
# Suspends access to the given user’s site in the editor by setting the
|
77
|
+
# suspended parameter to true. If a user attempts to access the site in
|
78
|
+
# the editor, an error is thrown.
|
79
|
+
def disable
|
80
|
+
response = @client.post(@endpoint + "/disable")
|
81
|
+
return response.json["success"]
|
82
|
+
end
|
83
|
+
|
84
|
+
# Re-enables a suspended site by setting the suspended parameter to
|
85
|
+
# false. Users can access the editor for the site. Sites are enabled
|
86
|
+
# by default when created.
|
87
|
+
def enable
|
88
|
+
response = @client.post(@endpoint + "/enable")
|
89
|
+
return response.json["success"]
|
90
|
+
end
|
91
|
+
|
92
|
+
# Returns the Plan resource for the site.
|
93
|
+
def get_plan
|
94
|
+
response = @client.get(@endpoint + "/plan")
|
95
|
+
plan = response.json["plans"]
|
96
|
+
plan = plan.values[0]
|
97
|
+
return Plan.new(plan["plan_id"], plan)
|
98
|
+
end
|
99
|
+
|
100
|
+
# Sets the site’s plan to plan_id with an optional term length.
|
101
|
+
# If no term is provided the Weebly Cloud default is used (check
|
102
|
+
# API documentation).
|
103
|
+
def set_plan(plan_id, term=nil)
|
104
|
+
data = {"plan_id" => plan_id}
|
105
|
+
|
106
|
+
if term
|
107
|
+
data.merge!({"term" => term})
|
108
|
+
end
|
109
|
+
|
110
|
+
response = @client.post(@endpoint + "/plan", :content=>data)
|
111
|
+
return response.json["success"]
|
112
|
+
end
|
113
|
+
|
114
|
+
# Sets the site’s theme to theme_id. Requires a parameter is_custom,
|
115
|
+
# distinguishing whether the theme is a Weebly theme or a custom theme.
|
116
|
+
def set_theme(theme_id, is_custom)
|
117
|
+
data = {"theme_id" => theme_id, "is_custom" => is_custom}
|
118
|
+
response = @client.post(@endpoint + "/theme", :content=>data)
|
119
|
+
return response.json["success"]
|
120
|
+
end
|
121
|
+
|
122
|
+
# Returns a list of Page resources for a given site subject to filters.
|
123
|
+
def list_pages(filters={})
|
124
|
+
result = @client.get(@endpoint + "/page", :params=>filters)
|
125
|
+
return result.map { |i| Page.new(@user_id, @site_id, i["page_id"], i) }
|
126
|
+
end
|
127
|
+
|
128
|
+
# Returns a list of Member resources for a given site subject to filters.
|
129
|
+
def list_members(filters={})
|
130
|
+
result = @client.get(@endpoint + "/member", :params=>filters)
|
131
|
+
return result.map { |i| Member.new(@user_id, @site_id, i["member_id"], i) }
|
132
|
+
end
|
133
|
+
|
134
|
+
# Returns a list of Group resources for a given site subject to filters.
|
135
|
+
def list_groups(filters={})
|
136
|
+
result = @client.get(@endpoint + "/group", :params=>filters)
|
137
|
+
return result.map { |i| Group.new(@user_id, @site_id, i["group_id"], i) }
|
138
|
+
end
|
139
|
+
|
140
|
+
# Returns a list of Form resources for a given site subject to filters.
|
141
|
+
def list_forms(filters={})
|
142
|
+
result = @client.get(@endpoint + "/form", :params=>filters)
|
143
|
+
return result.map { |i| Form.new(@user_id, @site_id, i["form_id"], i) }
|
144
|
+
end
|
145
|
+
|
146
|
+
# Returns a list of Blog resources for a given site subject to filters.
|
147
|
+
def list_blogs(filters={})
|
148
|
+
result = @client.get(@endpoint + "/blog", :params=>filters)
|
149
|
+
return result.map { |i| Blog.new(@user_id, @site_id, i["blog_id"], i) }
|
150
|
+
end
|
151
|
+
|
152
|
+
# Creates a Group. Requires the group’s name. Returns a Group resource.
|
153
|
+
def create_group(name)
|
154
|
+
data = {"name" => name}
|
155
|
+
response = @client.post(@endpoint + "/group", :content=>data)
|
156
|
+
return Group.new(@user_id, @site_id, response.json["group_id"], response.json)
|
157
|
+
end
|
158
|
+
|
159
|
+
# Creates a Member. Requires the member’s email, name, password,
|
160
|
+
# and optionally accepts hash of additional properties.
|
161
|
+
# Returns a Member resource.
|
162
|
+
def create_member(email, name, password, properties={})
|
163
|
+
properties.merge!({"email"=>email, "name"=>name, "password"=>password})
|
164
|
+
response = @client.post(@endpoint + "/member", :content=>properties)
|
165
|
+
return Member.new(@user_id, @site_id, response.json["member_id"], response.json)
|
166
|
+
end
|
167
|
+
|
168
|
+
# Return the Page with the given id.
|
169
|
+
def get_page(page_id)
|
170
|
+
return Page.new(@user_id, @site_id, @page_id)
|
171
|
+
end
|
172
|
+
|
173
|
+
# Return the Member with the given id.
|
174
|
+
def get_member(member_id)
|
175
|
+
return Member.new(@user_id, @site_id, @member_id)
|
176
|
+
end
|
177
|
+
|
178
|
+
# Return the Group with the given id.
|
179
|
+
def get_group(group_id)
|
180
|
+
return Group.new(@user_id, @site_id, @group_id)
|
181
|
+
end
|
182
|
+
|
183
|
+
# Return the Form with the given id.
|
184
|
+
def get_form(form_id)
|
185
|
+
return Form.new(@user_id, @site_id, @form_id)
|
186
|
+
end
|
187
|
+
|
188
|
+
# Return the Blog with the given id.
|
189
|
+
def get_blog(blog_id)
|
190
|
+
return Blog.new(@user_id, @site_id, @blog_id)
|
191
|
+
end
|
192
|
+
|
193
|
+
end
|
194
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "weeblycloud/cloudresource"
|
2
|
+
|
3
|
+
module Weeblycloud
|
4
|
+
|
5
|
+
# Represents a Theme resource.
|
6
|
+
# https://cloud-developer.weebly.com/theme.html
|
7
|
+
class Theme < CloudResource
|
8
|
+
|
9
|
+
def initialize(user_id, theme_id, data = nil)
|
10
|
+
@user_id = user_id.to_i
|
11
|
+
@theme_id = theme_id.to_i
|
12
|
+
|
13
|
+
super(data)
|
14
|
+
end
|
15
|
+
|
16
|
+
def get
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def id
|
21
|
+
@theme_id
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require "weeblycloud/cloudresource"
|
2
|
+
require "weeblycloud/saveable"
|
3
|
+
|
4
|
+
require "weeblycloud/site"
|
5
|
+
require "weeblycloud/theme"
|
6
|
+
|
7
|
+
module Weeblycloud
|
8
|
+
|
9
|
+
# Represents a User resource.
|
10
|
+
# https://cloud-developer.weebly.com/user.html
|
11
|
+
class User < CloudResource
|
12
|
+
include Saveable
|
13
|
+
|
14
|
+
def initialize(user_id, data = nil)
|
15
|
+
@user_id = user_id.to_i
|
16
|
+
@endpoint = "user/#{@user_id}"
|
17
|
+
super(data)
|
18
|
+
end
|
19
|
+
|
20
|
+
def id
|
21
|
+
@user_id
|
22
|
+
end
|
23
|
+
|
24
|
+
def get
|
25
|
+
response = @client.get(@endpoint)
|
26
|
+
@properties = response.json["user"]
|
27
|
+
end
|
28
|
+
|
29
|
+
def enable
|
30
|
+
result = @client.post(@endpoint + "/enable")
|
31
|
+
return result.json["success"]
|
32
|
+
end
|
33
|
+
|
34
|
+
def disable
|
35
|
+
result = @client.post(@endpoint + "/disable")
|
36
|
+
return result.json["success"]
|
37
|
+
end
|
38
|
+
|
39
|
+
def login_link
|
40
|
+
result = @client.post(@endpoint + "/loginLink")
|
41
|
+
return result.json["link"]
|
42
|
+
end
|
43
|
+
|
44
|
+
def list_themes(filters={})
|
45
|
+
result = @client.get(@endpoint + "/theme", :params=>filters)
|
46
|
+
return result.map {|i| Theme.new(@user_id, i["theme_id"], i)}
|
47
|
+
end
|
48
|
+
|
49
|
+
def list_sites(filters={})
|
50
|
+
result = @client.get(@endpoint + "/site", :params=>filters)
|
51
|
+
return result.map {|i| Site.new(@user_id, i["site_id"], i)}
|
52
|
+
end
|
53
|
+
|
54
|
+
def create_theme(name, zip_url)
|
55
|
+
data = {"theme_name" => name, "theme_zip" => zip_url}
|
56
|
+
response = @client.post(@endpoint + "/theme", :content=>data)
|
57
|
+
return Theme.new(@user_id, response.json["theme_id"])
|
58
|
+
end
|
59
|
+
|
60
|
+
def create_site(domain, properties={})
|
61
|
+
properties.merge!({"domain"=>domain})
|
62
|
+
response = @client.post(@endpoint + "/site", :content=>properties)
|
63
|
+
return Site.new(@user_id, response.json["site"]["site_id"])
|
64
|
+
end
|
65
|
+
|
66
|
+
def get_site(site_id)
|
67
|
+
return Site.new(@user_id, site_id)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|