webflow_sync 5.0.0 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -3
- data/Rakefile +1 -2
- data/app/jobs/webflow_sync/create_item_job.rb +1 -0
- data/app/services/webflow_sync/api.rb +12 -19
- data/lib/generators/webflow_sync/templates/webflow_sync.rb +0 -1
- data/lib/webflow_sync/configuration.rb +1 -2
- data/lib/webflow_sync/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98d3c00c861dd048087817fe1a709eb32a66cde4d5b79e0207ca6b19513dd9df
|
4
|
+
data.tar.gz: dac4374d4f30f254db0808669600b5f0e1d8418bd38e43dcfaa736fed25631ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 203099b7e60df11fe4ac8c4319c4e41603d737a269892fcc120ed4909ebbfb47ea3c4dc0ec2456404607f8a3ba5e155923cff5c781e75a7edd3417e1ac908268
|
7
|
+
data.tar.gz: '0993c797a70bf2efe1faa86eb3f439a85a1a7233201033c5ccc4ccb3b71fcf97f15df19839e9b92259013f4141b2955d84d9c7bdaf017d8ee7a81791989c4d26'
|
data/README.md
CHANGED
@@ -11,9 +11,12 @@ For the latest changes, check the [CHANGELOG.md](CHANGELOG.md).
|
|
11
11
|
|
12
12
|
## Installation
|
13
13
|
|
14
|
-
|
14
|
+
This gem currently only works with a fork of 'webflow-ruby' gem.
|
15
|
+
|
16
|
+
Add these lines to your application's Gemfile:
|
15
17
|
|
16
18
|
```ruby
|
19
|
+
gem 'webflow-ruby', github: 'vfonic/webflow-ruby', branch: 'allow-live-delete'
|
17
20
|
gem 'webflow_sync'
|
18
21
|
```
|
19
22
|
|
@@ -45,8 +48,7 @@ In `config/initializers/webflow_sync.rb` you can specify configuration options:
|
|
45
48
|
1. `api_token`
|
46
49
|
2. `webflow_site_id`
|
47
50
|
3. `skip_webflow_sync` - skip synchronization for different environments.
|
48
|
-
4. `
|
49
|
-
5. `sync_webflow_slug` - save slug generated on WebFlow to the Rails model, `webflow_slug` column.
|
51
|
+
4. `sync_webflow_slug` - save slug generated on WebFlow to the Rails model, `webflow_slug` column.
|
50
52
|
|
51
53
|
This can be useful if you want to link to WebFlow item directly from your Rails app:
|
52
54
|
|
data/Rakefile
CHANGED
@@ -11,8 +11,7 @@ require 'bundler/gem_tasks'
|
|
11
11
|
|
12
12
|
require 'stylecheck/rake_tasks' unless Rails.env.production?
|
13
13
|
|
14
|
-
load 'rspec/rails/tasks/rspec.rake'
|
14
|
+
load 'rspec/rails/tasks/rspec.rake' # runs all RSpec tests
|
15
15
|
task :default do
|
16
16
|
Rake::Task['style:rubocop:run'].execute
|
17
|
-
Rake::Task['spec'].execute
|
18
17
|
end
|
@@ -15,6 +15,7 @@ module WebflowSync
|
|
15
15
|
record = model_class.find_by(id:)
|
16
16
|
return if record.blank?
|
17
17
|
return if record.webflow_site_id.blank?
|
18
|
+
return WebflowSync::UpdateItemJob.perform_now(model_name, id, collection_slug) if record.webflow_item_id.present?
|
18
19
|
|
19
20
|
WebflowSync::Api.new(record.webflow_site_id).create_item(record, collection_slug)
|
20
21
|
end
|
@@ -37,16 +37,12 @@ module WebflowSync
|
|
37
37
|
make_request(:item, collection['_id'], webflow_item_id)
|
38
38
|
end
|
39
39
|
|
40
|
-
def create_item(record, collection_slug)
|
40
|
+
def create_item(record, collection_slug)
|
41
41
|
collection = find_webflow_collection(collection_slug)
|
42
42
|
response = make_request(:create_item, collection['_id'],
|
43
43
|
record.as_webflow_json.reverse_merge(_archived: false, _draft: false), live: true)
|
44
44
|
|
45
45
|
if update_record_columns(record, response)
|
46
|
-
# When the item is created, sometimes changes are not visible throughout the WebFlow site immediately (probably due to some caching).
|
47
|
-
# To make this change immediately visible from the WebFlow site, we need to publish the site.
|
48
|
-
publish
|
49
|
-
|
50
46
|
puts "Created #{record.inspect} in #{collection_slug}"
|
51
47
|
response
|
52
48
|
else
|
@@ -60,28 +56,24 @@ module WebflowSync
|
|
60
56
|
response = make_request(:update_item, { '_cid' => collection['_id'], '_id' => record.webflow_item_id },
|
61
57
|
record.as_webflow_json.reverse_merge(_archived: false, _draft: false), live: true)
|
62
58
|
|
63
|
-
# When the item is updated, sometimes changes are not visible throughout the WebFlow site immediately (probably due to some caching).
|
64
|
-
# To make this change immediately visible from the WebFlow site, we need to publish the site.
|
65
|
-
publish
|
66
|
-
|
67
59
|
puts "Updated #{record.inspect} in #{collection_slug}"
|
68
60
|
response
|
69
61
|
end
|
70
62
|
|
71
63
|
def delete_item(collection_slug, webflow_item_id)
|
72
64
|
collection = find_webflow_collection(collection_slug)
|
65
|
+
# deleting items from Webflow doesn't work as expected.
|
66
|
+
# if we delete without `live: true`, the item will stay visible on the site until the site is published again
|
67
|
+
# if we delete with `live: true`, the item will be set as draft and not visible on the site, but it will be visible in the Webflow CMS
|
68
|
+
# we then call delete again to remove the item from Webflow CMS
|
69
|
+
make_request(:delete_item, { '_cid' => collection['_id'], '_id' => webflow_item_id }, live: true)
|
73
70
|
response = make_request(:delete_item, { '_cid' => collection['_id'], '_id' => webflow_item_id })
|
74
|
-
# When the item is removed from WebFlow, it's still visible throughout the WebFlow site (probably due to some caching).
|
75
|
-
# To remove the item immediately from the WebFlow site, we need to publish the site.
|
76
|
-
publish
|
77
71
|
|
78
72
|
puts "Deleted #{webflow_item_id} from #{collection_slug}"
|
79
73
|
response
|
80
74
|
end
|
81
75
|
|
82
76
|
def publish
|
83
|
-
return unless WebflowSync.configuration.publish_on_sync
|
84
|
-
|
85
77
|
response = make_request(:publish, site_id, domain_names:)
|
86
78
|
|
87
79
|
puts "Publish all domains for Webflow site with id: #{site_id}"
|
@@ -130,18 +122,19 @@ module WebflowSync
|
|
130
122
|
end
|
131
123
|
end
|
132
124
|
|
133
|
-
def make_request(method_name, *args,
|
125
|
+
def make_request(method_name, *args, **kwargs)
|
134
126
|
if kwargs.present?
|
135
127
|
client.public_send(method_name, *args, **kwargs)
|
136
128
|
else
|
137
129
|
client.public_send(method_name, *args)
|
138
130
|
end
|
139
131
|
rescue Webflow::Error => e
|
140
|
-
raise
|
132
|
+
raise unless e.message.strip == 'Rate limit hit'
|
133
|
+
|
134
|
+
puts 'Sleeping 10 seconds'
|
135
|
+
sleep 10
|
141
136
|
|
142
|
-
|
143
|
-
sleep 2**retries
|
144
|
-
make_request(method_name, *args, retries: retries + 1, **kwargs)
|
137
|
+
make_request(method_name, *args, **kwargs)
|
145
138
|
end
|
146
139
|
end
|
147
140
|
end
|
@@ -7,7 +7,6 @@ module WebflowSync
|
|
7
7
|
def configure
|
8
8
|
self.configuration ||= Configuration.new
|
9
9
|
|
10
|
-
self.configuration.publish_on_sync = true
|
11
10
|
self.configuration.skip_webflow_sync = !Rails.env.production?
|
12
11
|
|
13
12
|
yield(self.configuration)
|
@@ -21,7 +20,7 @@ module WebflowSync
|
|
21
20
|
end
|
22
21
|
|
23
22
|
class Configuration
|
24
|
-
attr_accessor :skip_webflow_sync, :webflow_site_id, :sync_webflow_slug
|
23
|
+
attr_accessor :skip_webflow_sync, :webflow_site_id, :sync_webflow_slug
|
25
24
|
attr_reader :api_token
|
26
25
|
|
27
26
|
def api_token=(value)
|
data/lib/webflow_sync/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webflow_sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 6.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Viktor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '5.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sprockets-rails
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|