Class: Webflow::Client
- Inherits:
-
Object
- Object
- Webflow::Client
- Defined in:
- lib/webflow/client.rb
Constant Summary collapse
- HOST =
'https://api.webflow.com'- OJ_OPTIONS =
{mode: :strict, nilnil: true}
Class Method Summary collapse
Instance Method Summary collapse
- #collection(collection_id) ⇒ Object
- #collections(site_id) ⇒ Object
- #create_item(collection_id, data) ⇒ Object
- #delete_item(item) ⇒ Object
- #domains(site_id) ⇒ Object
- #info ⇒ Object
-
#initialize(token) ⇒ Client
constructor
A new instance of Client.
- #item(collection_id, item_id) ⇒ Object
- #items(collection_id, limit: 100) ⇒ Object
- #publish(site_id, domain_names: nil) ⇒ Object
- #rate_limit ⇒ Object
- #site(site_id) ⇒ Object
- #sites ⇒ Object
- #update_item(item, data) ⇒ Object
Constructor Details
#initialize(token) ⇒ Client
Returns a new instance of Client.
9 10 11 12 |
# File 'lib/webflow/client.rb', line 9 def initialize(token) @token = token @rate_limit = {} end |
Class Method Details
.error_codes ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/webflow/client.rb', line 129 def self.error_codes { [400, SyntaxError] => 'Request body was incorrectly formatted. Likely invalid JSON being sent up.', [400, InvalidAPIVersion] => 'Requested an invalid API version', [400, UnsupportedVersion] => 'Requested an API version that in unsupported by the requested route', [400, NotImplemented] => 'This feature is not currently implemented', [400, ValidationError] => 'Validation failure (see err field in the response)', [400, Conflict] => 'Request has a conflict with existing data.', [401, Unauthorized] => 'Provided access token is invalid or does not have access to requested resource', [404, NotFound] => 'Requested resource not found', [429, RateLimit] => 'The rate limit of the provided access_token has been reached. Please have your application respect the X-RateLimit-Remaining header we include on API responses.', [500, ServerError] => 'We had a problem with our server. Try again later.', [400, UnknownError] => 'An error occurred which is not enumerated here, but is not a server error.', } end |
Instance Method Details
#collection(collection_id) ⇒ Object
47 48 49 |
# File 'lib/webflow/client.rb', line 47 def collection(collection_id) get("/collections/#{collection_id}") end |
#collections(site_id) ⇒ Object
43 44 45 |
# File 'lib/webflow/client.rb', line 43 def collections(site_id) get("/sites/#{site_id}/collections") end |
#create_item(collection_id, data) ⇒ Object
61 62 63 |
# File 'lib/webflow/client.rb', line 61 def create_item(collection_id, data) post("/collections/#{collection_id}/items", fields: data) end |
#delete_item(item) ⇒ Object
71 72 73 |
# File 'lib/webflow/client.rb', line 71 def delete_item(item) delete("/collections/#{item['_cid']}/items/#{item['_id']}") end |
#domains(site_id) ⇒ Object
34 35 36 |
# File 'lib/webflow/client.rb', line 34 def domains(site_id) get("/sites/#{site_id}/domains") end |
#info ⇒ Object
18 19 20 |
# File 'lib/webflow/client.rb', line 18 def info get("/info") end |
#item(collection_id, item_id) ⇒ Object
56 57 58 59 |
# File 'lib/webflow/client.rb', line 56 def item(collection_id, item_id) json = get("/collections/#{collection_id}/items/#{item_id}") json['items'].first end |
#items(collection_id, limit: 100) ⇒ Object
51 52 53 54 |
# File 'lib/webflow/client.rb', line 51 def items(collection_id, limit: 100) json = get("/collections/#{collection_id}/items", params: {limit: limit}) json['items'] end |
#publish(site_id, domain_names: nil) ⇒ Object
38 39 40 41 |
# File 'lib/webflow/client.rb', line 38 def publish(site_id, domain_names: nil) domain_names ||= domains(site_id).map { |domain| domain['name'] } post("/sites/#{site_id}/publish", domains: domain_names) end |
#rate_limit ⇒ Object
14 15 16 |
# File 'lib/webflow/client.rb', line 14 def rate_limit @rate_limit end |
#site(site_id) ⇒ Object
30 31 32 |
# File 'lib/webflow/client.rb', line 30 def site(site_id) get("/sites/#{site_id}") end |
#sites ⇒ Object
26 27 28 |
# File 'lib/webflow/client.rb', line 26 def sites get("/sites") end |
#update_item(item, data) ⇒ Object
65 66 67 68 69 |
# File 'lib/webflow/client.rb', line 65 def update_item(item, data) # FIXME: (PS) looks like the API does not have partial updates... base = item.reject {|key, _| ['_id', 'published-by', 'published-on', 'created-on', 'created-by', 'updated-by', 'updated-on', '_cid'].include?(key) } put("/collections/#{item['_cid']}/items/#{item['_id']}", fields: base.merge(data)) end |