Class: WebflowSync::Api
- Inherits:
-
Object
- Object
- WebflowSync::Api
- Defined in:
- app/services/webflow_sync/api.rb
Instance Attribute Summary collapse
-
#site_id ⇒ Object
readonly
Returns the value of attribute site_id.
Class Method Summary collapse
Instance Method Summary collapse
- #collections ⇒ Object
- #create_item(collection_id:, record:) ⇒ Object
- #delete_item(collection_id:, webflow_item_id:) ⇒ Object
- #find_collection_id(collection_slug:) ⇒ Object
- #get_all_items(collection_id:) ⇒ Object
- #get_item(collection_id:, webflow_item_id:) ⇒ Object
-
#initialize(site_id: nil) ⇒ Api
constructor
A new instance of Api.
- #publish ⇒ Object
- #sites ⇒ Object
- #update_item(collection_id:, record:) ⇒ Object
Constructor Details
#initialize(site_id: nil) ⇒ Api
Returns a new instance of Api.
7 8 9 |
# File 'app/services/webflow_sync/api.rb', line 7 def initialize(site_id: nil) @site_id = site_id end |
Instance Attribute Details
#site_id ⇒ Object (readonly)
Returns the value of attribute site_id.
5 6 7 |
# File 'app/services/webflow_sync/api.rb', line 5 def site_id @site_id end |
Class Method Details
.sites ⇒ Object
32 |
# File 'app/services/webflow_sync/api.rb', line 32 def self.sites = self.new.sites |
Instance Method Details
#collections ⇒ Object
34 35 36 |
# File 'app/services/webflow_sync/api.rb', line 34 def collections @collections ||= make_request(:collections, site_id) end |
#create_item(collection_id:, record:) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'app/services/webflow_sync/api.rb', line 15 def create_item(collection_id:, record:) response = make_request(:create_item, collection_id, record.as_webflow_json) unless update_record_columns(record, response) raise "Failed to store webflow_item_id: '#{response.fetch(:id)}' after creating item in WebFlow collection #{record.inspect}" end response end |
#delete_item(collection_id:, webflow_item_id:) ⇒ Object
27 |
# File 'app/services/webflow_sync/api.rb', line 27 def delete_item(collection_id:, webflow_item_id:) = make_request(:delete_item, collection_id, webflow_item_id) |
#find_collection_id(collection_slug:) ⇒ Object
38 39 40 41 42 43 |
# File 'app/services/webflow_sync/api.rb', line 38 def find_collection_id(collection_slug:) response = collections.find { |collection| collection.fetch(:slug) == collection_slug } raise "Cannot find collection #{collection_slug} for Webflow site #{site_id}" unless response response.fetch(:id) end |
#get_all_items(collection_id:) ⇒ Object
11 |
# File 'app/services/webflow_sync/api.rb', line 11 def get_all_items(collection_id:) = make_request(:list_all_items, collection_id) |
#get_item(collection_id:, webflow_item_id:) ⇒ Object
13 |
# File 'app/services/webflow_sync/api.rb', line 13 def get_item(collection_id:, webflow_item_id:) = make_request(:get_item, collection_id, webflow_item_id) |
#publish ⇒ Object
29 |
# File 'app/services/webflow_sync/api.rb', line 29 def publish = make_request(:publish, site_id) |
#sites ⇒ Object
31 |
# File 'app/services/webflow_sync/api.rb', line 31 def sites = make_request(:sites) |
#update_item(collection_id:, record:) ⇒ Object
25 |
# File 'app/services/webflow_sync/api.rb', line 25 def update_item(collection_id:, record:) = make_request(:update_item, collection_id, record.webflow_item_id, record.as_webflow_json) |