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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 50d48657245ea552e7d00e47ba3b4dedf8029a84
4
+ data.tar.gz: bbdd05874a0724ff6b55a3cf971fea4e1c599326
5
+ SHA512:
6
+ metadata.gz: 3ce233b700a9b5ee53e24a249264eaff80ae4f29132b4b789a7f40ddc84f5a66fdbab6b86de6a7ac059620ed04fceb8331d638b6a830960e8d446a39eff7aaf0
7
+ data.tar.gz: f187f739ed6c97646a3d1d5f54efeb6d29bdab8440e94bd4d5bf6e9e61c9a7c537be9a45aa9deca39bb4b81f8918a06a50879d6624a86c08596d85ccb575e98c
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /test/*
11
+ /bin/console
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.0.0
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in weeblycloud.gemspec
4
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,10 @@
1
+ License
2
+
3
+ Copyright (c) 2016, Weebly All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6
+
7
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
+ Neither the name of Weebly nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Weebly, Inc BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,249 @@
1
+ # Weebly Cloud Client: Ruby
2
+
3
+ ## Installation
4
+ To install the Weebly cloud client run:
5
+
6
+ $ gem install weeblycloud
7
+
8
+ ## Setup and Authentication
9
+ To use the Weebly Cloud client libraries require `weeblycloud` and configure your API keys.
10
+
11
+ ```ruby
12
+ require weeblycloud
13
+
14
+ Weeblycloud::CloudClient::configure(API_KEY, API_SECRET)
15
+ ```
16
+
17
+ All future calls will use that API key and secret pairing.
18
+
19
+ ## Examples
20
+
21
+ ### Creating a user and site, get a login link
22
+
23
+ ```ruby
24
+ account = Weeblycloud::Account.new
25
+ user = account.create_user("test@email.com")
26
+ site = user.create_site("domain.com", "site_title" => "My Website")
27
+ puts site.login_link()
28
+ ```
29
+
30
+ ### Printing the name of all pages in a site matching the query "help"
31
+
32
+ ```ruby
33
+ pages = site.list_pages("query" => "help")
34
+
35
+ pages.each { |page| puts page.get_property("title") }
36
+ ```
37
+
38
+ ## Error Handling
39
+ If a request is unsuccessful, a `ResponseError` exception is raised. This can be caught as follows:
40
+
41
+ ```ruby
42
+ begin
43
+ account = Weeblycloud::Account.new
44
+ user = account.create_user("test@email.com")
45
+ site = user.create_site("domain.com", "site_title" => "My Website")
46
+ puts site.login_link()
47
+ rescue Weeblycloud::ResponseError => err
48
+ puts err.code # Prints the error code
49
+ puts err.message # Prints the error message
50
+ end
51
+ ```
52
+
53
+ If a pagination method is called on a `WeeblyCloudResponse` that isn't paginated, a `PaginationError` exception is raised.
54
+
55
+
56
+ ## Resources
57
+
58
+ ### Using and Modifying Resources
59
+ - The method **`resource.get_property(name)`** of a resource will return the property **name** of **resource**. If the property does not exist it will return **nil**.
60
+ - The method **`resource.set_property(name, value)`** will set the propety **name** of **resource** to **value** and returns **true**. If the property does not exist, it will return **false**. Changes will not be saved until the **`resource.save()`** method is called. The Weebly Cloud API does not suppot modifying every resource type nor every property of resource types it supports. For more information, reference the [Cloud API Documentation](https://cloud-developer.weebly.com/about-the-rest-apis.html) for the resource in question's `PUT` method.
61
+ - The method **`resource.id()`** will return the resource ID.
62
+ - Use the **`to_s`** method to print a JSON representation of the resource's property (i.e. `account.to_s`). To get the resources properties as a hash, use `resource.properties`.
63
+
64
+ ### Optional parameters
65
+ Requests that take serveral optional parameters (i.e. filters or object properties) can have them passed with a options hash.
66
+
67
+ For instance, to sort all pages by title:
68
+
69
+ ```ruby
70
+ site.list_pages("filterby" => "title", "fitlerfor" => "menu")
71
+ ```
72
+
73
+ And to create a new site:
74
+
75
+ ```ruby
76
+ user.create_site("example.com", 4, "brand_name" => "Brand Name")
77
+ ```
78
+
79
+ ## Resource Types
80
+ ### Account
81
+ [API Documentation](https://cloud-developer.weebly.com/account.html)
82
+
83
+ - **`create_user(email, properties={})`** Creates a `User`. Requires the user's **email**, and optionally accepts keyword arguments of additional properties. Returns a `User` resource on success.
84
+ - **`get_user(user_id)`** Return the `User` with the given ID.
85
+ - **`list_plans()`** Returns a list of all `Plan` resources.
86
+ - **`get_plan(plan_id)`** Return the `Plan` with the given ID.
87
+
88
+ ### User
89
+ [API Documentation](https://cloud-developer.weebly.com/user.html)
90
+
91
+ - **`enable()`** Enables a user account after an account has been disabled. Enabling a user account will allow users to log into the editor. When a user is created, their account is automatically enabled.
92
+ - **`disable()`** Disables a user account. When a user account is disabled, the user will no longer be able to log into the editor. If an attempt to create a login link is made on a disabled account, an error is thrown.
93
+ - **`login_link()`** Generates a one-time link that will direct users to the editor for the last site that was modified in the account. This method requires that the account is enabled and that the account has at least one site.
94
+ - **`list_themes(filters={})`** Returns a list of `Theme` resources for a given user subject to filters.
95
+ - **`list_sites(filters={})`** Returns a list of `Site` resources for a given user subject to filters.
96
+ - **`get_site(site_id)`** Return the `Site` with the given ID.
97
+ - **`create_theme(name, zip_url)`** Creates a `Theme` with name **name**. Requires a **zip_url** and returns a `Theme` object.
98
+ - **`create_site(domain)`** Creates a `Site`. Requires the site's **domain** and optionally accepts keyword arguments of additional properties. Returns a `User` resource.
99
+
100
+ ### Site
101
+ [API Documentation](https://cloud-developer.weebly.com/site.html)
102
+
103
+ - **`delete()`** delete the site.
104
+ - **`publish()`** Publishes the site.
105
+ - **`unpublish()`** Unpublishes the site.
106
+ - **`login_link()`** Generates a one-time link that will direct users to the site specified. This method requires that the account is enabled.
107
+ - **`set_publish_credentials(options={})`** 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.
108
+ - **`restore(url)`** 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
109
+ - **`disable()`** 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.
110
+ - **`enable()`** 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.
111
+ - **`list_pages(filters={})`** Returns a list of `Page` resources for a given site subject to filters.
112
+ - **`list_members(filters={})`** Returns a list of `Member` resources for a given site subject to filters.
113
+ - **`list_groups(filters={})`** Returns a list of `Group` resources for a given site subject to filters.
114
+ - **`list_forms(filters={})`** Returns a list of `Form` resources for a given site subject to filters.
115
+ - **`list_blogs(filters={})`** Returns a list of `Blog` resources for a given site subject to filters.
116
+ - **`get_page(page_id)`** Return the `Page` with the given id.
117
+ - **`get_member(member_id)`** Return the `Member` with the given id.
118
+ - **`get_group(group_id)`** Return the `Group` with the given id.
119
+ - **`get_form(form_id)`** Return the `Form` with the given id.
120
+ - **`get_blog(blog_id)`** Return the `Blog` with the given id.
121
+ - **`get_plan()`** Returns the `Plan` resource for the site.
122
+ - **`set_plan(plan_id, term=None)`** 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).
123
+ - **`set_theme(theme_id, is_custom)`** 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.
124
+ - **`create_member(email, name, password, properties={})`** Creates a `Member`. Requires the member's **email**, **name**, **password**, and optionally accepts hash of additional properties. Returns a `Member` resource.
125
+ - **`create_group(name)`** Creates a `Group`. Requires the group's **name**. Returns a `Group` resource.
126
+
127
+ ### Theme
128
+ [API Documentation](https://cloud-developer.weebly.com/theme.html)
129
+
130
+ > There are no `Theme` specific methods.
131
+
132
+ ### Blog
133
+ [API Documentation](https://cloud-developer.weebly.com/blog.html)
134
+
135
+ - **`list_blog_posts(filters={})`** Returns a list of `BlogPost` resources for a given blog subject to filters.
136
+ - **`get_blog_post(blog_post_id)`** Return the `BlogPost` with the given id.
137
+ - **`create_blog_post(post_body, properties={})`** Creates a `BlogPost`. Requires the post's **body** and optionally accepts a hash of additional properties. Returns a `BlogPost` resource.
138
+
139
+ ### BlogPost
140
+ [API Documentation](https://cloud-developer.weebly.com/blog-post.html)
141
+
142
+ - **`delete()`** delete the blog post.
143
+
144
+ ### Form
145
+ [API Documentation](https://cloud-developer.weebly.com/form.html)
146
+
147
+ - **`list_form_entries(filters={})`** Returns a list of `FormEntry` resources for a given form subject to filters.
148
+ - **`get_form_entry(form_entry_id)`** Return the `FormEntry` with the given id.
149
+
150
+
151
+ ### FormEntry
152
+ [API Documentation](https://cloud-developer.weebly.com/form-entry.html)
153
+
154
+ > There are no `FormEntry` specific methods.
155
+
156
+ ### Page
157
+ [API Documentation](https://cloud-developer.weebly.com/page.html)
158
+
159
+ - **`change_title(title)`** Changes the title of the page to **title**. Does not require calling the `save()` method.
160
+
161
+ ### Plan
162
+ [API Documentation](https://cloud-developer.weebly.com/plan.html)
163
+
164
+ > There are no `Plan` specific methods.
165
+
166
+ ### Group
167
+ [API Documentation](https://cloud-developer.weebly.com/group.html)
168
+
169
+ - **`delete()`** Delete the group.
170
+
171
+ ### Member
172
+ [API Documentation](https://cloud-developer.weebly.com/member.html)
173
+
174
+ - **`delete()`** Delete the Member.
175
+
176
+ ## Making Raw API Calls
177
+ Not every resource has a cooresponding resource class. It is possible to make a raw API call using a `CloudClient` object.
178
+
179
+ ```ruby
180
+ client = weeblycloud::CloudClient.new
181
+ ```
182
+ Using that client, call `get`, `post`, `put`, `patch`, or `delete` which takes the endpoint and a hash of optional parameters:
183
+
184
+ - **content:** a hash of the request's body.
185
+ - **params:** a hash of query string parameters.
186
+ - **page (`get` only):** page of results to get
187
+ - **page_size (`get` only):** page size of results *(default is 25)*
188
+
189
+ #### Request examples
190
+
191
+ ##### Get cloud admin account account
192
+ ```ruby
193
+ # Create client
194
+ client = weeblycloud::CloudClient.new
195
+
196
+ # Request the /account endpoint
197
+ client.get("account")
198
+ ```
199
+
200
+ ##### Update a page title
201
+ ```ruby
202
+ # Create client
203
+ client = weeblycloud::CloudClient.new
204
+
205
+ # build endpoint with parameters
206
+ endpoint = "user/#{USER_ID}/site/#{SITE_ID}/page/#{PAGE_ID}"
207
+
208
+ # Make the request
209
+ client.patch(endpoint, :content => {"title":"New Title"})
210
+ ```
211
+
212
+ ##### Get all sites for a user (with filters)
213
+ ```ruby
214
+ # Create client
215
+ client = weeblycloud::CloudClient.new
216
+
217
+ # build endpoint with parameters
218
+ endpoint = "/user/#{USER_ID}/site"
219
+
220
+ # Make the request
221
+ client.get(endpoint, :params => {"role":"owner"})
222
+ ```
223
+
224
+
225
+ ### Handling Responses
226
+ All requests return a `WeeblyCloudResponse` object or raise an Exception (see error handling). Accessing the response is easy:
227
+
228
+ ```ruby
229
+ response = client.get("account") # Make a request
230
+ puts response.to_s # get the response as a JSON string
231
+ # or
232
+ puts response.to_hash # get the response as a hash
233
+ ```
234
+
235
+ If the results of a get request are paginated, then `response.paginated?` will be `true`.
236
+
237
+ - `response.max_page` contains the total number of pages.
238
+ - `response.current_page` contains the current page number.
239
+ - `response.records` is the number of total results.
240
+
241
+ ###Pagination example
242
+ ```ruby
243
+ client = weeblycloud::WeeblyCloud.new
244
+ response = client.get("user/#{USER_ID}/site")
245
+
246
+ # Print a list of site titles
247
+ puts response.map { |site| site['site_title'] }
248
+
249
+ ```
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$"\n\t"
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,22 @@
1
+ require "weeblycloud/version"
2
+ require "weeblycloud/account"
3
+ require "weeblycloud/blog"
4
+ require "weeblycloud/blogpost"
5
+ require "weeblycloud/cloudclient/cloudclient"
6
+ require "weeblycloud/cloudresource"
7
+ require "weeblycloud/deleteable"
8
+ require "weeblycloud/cloudclient/exceptions"
9
+ require "weeblycloud/form"
10
+ require "weeblycloud/formentry"
11
+ require "weeblycloud/group"
12
+ require "weeblycloud/member"
13
+ require "weeblycloud/page"
14
+ require "weeblycloud/plan"
15
+ require "weeblycloud/saveable"
16
+ require "weeblycloud/site"
17
+ require "weeblycloud/theme"
18
+ require "weeblycloud/cloudclient/weeblycloudresponse"
19
+
20
+ module Weeblycloud
21
+
22
+ end
@@ -0,0 +1,51 @@
1
+ require "weeblycloud/cloudresource"
2
+ require "weeblycloud/saveable"
3
+
4
+ require "weeblycloud/user"
5
+ require "weeblycloud/plan"
6
+
7
+ module Weeblycloud
8
+
9
+ # Represents an Account resource.
10
+ # https://cloud-developer.weebly.com/account.html
11
+ class Account < CloudResource
12
+ include Saveable
13
+
14
+ def initialize
15
+ @endpoint = "account"
16
+ super()
17
+ end
18
+
19
+ # Make an API call to get the resource
20
+ def get
21
+ response = @client.get(@endpoint)
22
+ @properties = response.json["account"]
23
+ end
24
+
25
+ # Creates a `User`. Requires the user's **email**, and optionally accepts
26
+ # a hash of additional properties. Returns a `User` resource.
27
+ # on success.
28
+ def create_user(email, properties={})
29
+ properties.merge!({"email"=>email})
30
+ response = @client.post("user", :content=>properties)
31
+ return User.new(response.json["user"]["user_id"])
32
+ end
33
+
34
+ # Get a user with a given ID
35
+ def get_user(user_id)
36
+ return User.new(user_id)
37
+ end
38
+
39
+ # Returns a iterable of all Plan resources.
40
+ def list_plans
41
+ result = @client.get("plan")
42
+ return result.map { |plan| Plan.new(plan["plan_id"]) }
43
+ end
44
+
45
+ # Return the Plan with the given ID.
46
+ def get_plan(plan_id)
47
+ return Plan.new(plan_id)
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,52 @@
1
+ require "weeblycloud/cloudresource"
2
+ require "weeblycloud/saveable"
3
+ require "weeblycloud/deleteable"
4
+
5
+ require "weeblycloud/blogpost"
6
+
7
+ module Weeblycloud
8
+
9
+ # Represents an Blog resource.
10
+ # https://cloud-developer.weebly.com/blog.html
11
+ class Blog < CloudResource
12
+ include Saveable
13
+ include Deleteable
14
+
15
+ def initialize(user_id, site_id, blog_id, data = nil)
16
+ @user_id = user_id.to_i
17
+ @site_id = site_id.to_i
18
+ @blog_id = blog_id.to_i
19
+ @endpoint = "user/#{@user_id}/site/#{@site_id}/blog/#{@blog_id}"
20
+
21
+ super(data)
22
+ end
23
+
24
+ # Returns the blog_id
25
+ def id
26
+ @blog_id
27
+ end
28
+
29
+ # Returns a iterable of `BlogPost` resources for a given blog subject to
30
+ # an optional hash of argument filters.
31
+ def list_blog_posts(filters={})
32
+ result = @client.get(@endpoint + "/post", :params=>filters)
33
+ return result.map { |i| BlogPost.new(@user_id, @site_id, @blog_id, i["post_id"], i) }
34
+ end
35
+
36
+ # Creates a `BlogPost`. Requires the post's **body** and optionally
37
+ # accepts keyword arguments of additional properties. Returns a
38
+ # `BlogPost` resource.
39
+ def create_blog_post(post_body, properties={})
40
+ properties.merge!({"post_body"=>post_body})
41
+ response = @client.post(@endpoint + "/post", :content=>properties)
42
+ return BlogPost.new(@user_id, @site_id, @blog_id, response.json["post_id"], response.json)
43
+ end
44
+
45
+ # Return the `BlogPost` with the given id.
46
+ def get_blog_post(blog_post_id)
47
+ return BlogPost.new(@user_id, @site_id, @blog_id, @blog_post_id)
48
+ end
49
+
50
+ end
51
+
52
+ end