webflow_sync 5.0.0 → 6.1.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 +19 -24
- 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: bf8a9fdd99e65667dad7f82bd2e5eb7539999a3c48a363cfd8f68b1217b6bb84
|
4
|
+
data.tar.gz: e7aa812fd99148cf99cd41b5c999414d356dd2384e59cc610de61a73d7a3ecf1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ad5b0d2e7fb1724ab309f96630e3653dfe3b4419365b2131af623ec324b05b47e4a65275f977fc5a42744f12630892659bce92053de065d5cc92ebc2f2cc58a
|
7
|
+
data.tar.gz: b61fdc179fcc31af51ab45180eec3f108e842e3b92870463e5602515b470a6c5956a3d1825f7c37dc99e513322d76d615d30d957344a191d45018893b4c5873d
|
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,34 +56,32 @@ 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}"
|
88
80
|
response
|
89
81
|
end
|
90
82
|
|
83
|
+
def sites = make_request(:sites)
|
84
|
+
|
91
85
|
private
|
92
86
|
|
93
87
|
def client
|
@@ -95,7 +89,7 @@ module WebflowSync
|
|
95
89
|
end
|
96
90
|
|
97
91
|
def collections
|
98
|
-
@collections ||=
|
92
|
+
@collections ||= make_request(:collections, site_id)
|
99
93
|
end
|
100
94
|
|
101
95
|
def domain_names
|
@@ -106,16 +100,16 @@ module WebflowSync
|
|
106
100
|
# client.domains request does not return the default domain
|
107
101
|
# We need to get default domain name if there are no custom domains set to avoid error:
|
108
102
|
# Webflow::Error: Domain not found for site
|
109
|
-
site =
|
110
|
-
default_domain_name = "#{site
|
103
|
+
site = make_request(:site, site_id)
|
104
|
+
default_domain_name = "#{site.fetch('shortName')}.webflow.io"
|
111
105
|
names = [default_domain_name]
|
112
|
-
|
106
|
+
make_request(:domains, site_id).each { |domain| names << domain.fetch('name') }
|
113
107
|
|
114
108
|
names
|
115
109
|
end
|
116
110
|
|
117
111
|
def find_webflow_collection(collection_slug)
|
118
|
-
response = collections.find { |collection| collection
|
112
|
+
response = collections.find { |collection| collection.fetch('slug') == collection_slug }
|
119
113
|
raise "Cannot find collection #{collection_slug} for Webflow site #{site_id}" unless response
|
120
114
|
|
121
115
|
response
|
@@ -130,18 +124,19 @@ module WebflowSync
|
|
130
124
|
end
|
131
125
|
end
|
132
126
|
|
133
|
-
def make_request(method_name, *args,
|
127
|
+
def make_request(method_name, *args, **kwargs)
|
134
128
|
if kwargs.present?
|
135
129
|
client.public_send(method_name, *args, **kwargs)
|
136
130
|
else
|
137
131
|
client.public_send(method_name, *args)
|
138
132
|
end
|
139
133
|
rescue Webflow::Error => e
|
140
|
-
raise
|
134
|
+
raise unless e.message.strip == 'Rate limit hit'
|
135
|
+
|
136
|
+
puts 'Sleeping 10 seconds'
|
137
|
+
sleep 10
|
141
138
|
|
142
|
-
|
143
|
-
sleep 2**retries
|
144
|
-
make_request(method_name, *args, retries: retries + 1, **kwargs)
|
139
|
+
make_request(method_name, *args, **kwargs)
|
145
140
|
end
|
146
141
|
end
|
147
142
|
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.1.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
|