webflow_sync 0.2.0 → 0.3.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 +7 -1
- data/app/jobs/webflow_sync/initial_sync_job.rb +11 -1
- data/app/jobs/webflow_sync/update_item_job.rb +1 -1
- data/app/models/concerns/webflow_sync/callbacks.rb +3 -3
- data/app/services/webflow_sync/api.rb +9 -4
- data/lib/webflow_sync/configuration.rb +3 -2
- data/lib/webflow_sync/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 462ca934ced66c135d9737e6d3a488d93e26c90b4a3e48e1e0b5b8a87c710fb4
|
4
|
+
data.tar.gz: 9473b40c6a4bc830a864902c013de92936edfd3b81985a77353c90dae481b905
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74d85eea27d5d66ddc36ae45c336422f64dc447a83d82a0764abcdcb470f6148732d60b76ac2209b6d9d37bab07e5fc28281c961f2e6d9bdf380dd5c8c6bc15e
|
7
|
+
data.tar.gz: ebec0cbb65c0f521724366c3fe85be6b0f4c4e17939d62c5f3a0ffc3639a0003161e1d3c05676bf72af9a7e55816e03aa9e9f4c3afe81c1c4bc1149a03144a4b
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
![
|
1
|
+
[![Build Status](https://github.com/vfonic/webflow_sync/workflows/build/badge.svg)](https://github.com/vfonic/webflow_sync/actions)
|
2
|
+
|
2
3
|
|
3
4
|
# WebflowSync
|
4
5
|
|
@@ -158,6 +159,11 @@ This gem silently "fails" (does nothing) when `webflow_site_id` or `webflow_item
|
|
158
159
|
|
159
160
|
PRs welcome!
|
160
161
|
|
162
|
+
## Thanks and Credits
|
163
|
+
|
164
|
+
This gem wouldn't be possible without the amazing work of [webflow-ruby](https://github.com/penseo/webflow-ruby) gem. Thank you, @phoet!
|
165
|
+
|
166
|
+
|
161
167
|
## License
|
162
168
|
|
163
169
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -7,8 +7,18 @@ module WebflowSync
|
|
7
7
|
model_class.where(webflow_item_id: nil).find_each do |record|
|
8
8
|
next if record.webflow_site_id.blank?
|
9
9
|
|
10
|
-
|
10
|
+
client(record.webflow_site_id).create_item(record, collection_slug)
|
11
11
|
end
|
12
12
|
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def client(site_id)
|
17
|
+
if @client&.site_id == site_id
|
18
|
+
@client
|
19
|
+
else
|
20
|
+
@client = WebflowSync::Api.new(site_id)
|
21
|
+
end
|
22
|
+
end
|
13
23
|
end
|
14
24
|
end
|
@@ -7,7 +7,7 @@ module WebflowSync
|
|
7
7
|
record = model_class.find_by(id: id)
|
8
8
|
return if record.blank?
|
9
9
|
return if record.webflow_site_id.blank?
|
10
|
-
return if record.webflow_item_id.blank?
|
10
|
+
return WebflowSync::CreateItemJob.perform_now(collection_slug, id) if record.webflow_item_id.blank?
|
11
11
|
|
12
12
|
WebflowSync::Api.new(record.webflow_site_id).update_item(record, collection_slug)
|
13
13
|
end
|
@@ -8,9 +8,9 @@ module WebflowSync
|
|
8
8
|
included do
|
9
9
|
attr_accessor :skip_webflow_sync
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
after_commit :create_webflow_item, on: :create
|
12
|
+
after_commit :update_webflow_item, on: :update
|
13
|
+
after_commit :destroy_webflow_item, on: :destroy
|
14
14
|
|
15
15
|
def create_webflow_item
|
16
16
|
return if self.skip_webflow_sync || WebflowSync.configuration.skip_webflow_sync
|
@@ -8,16 +8,21 @@ module WebflowSync
|
|
8
8
|
@site_id = site_id
|
9
9
|
end
|
10
10
|
|
11
|
-
def create_item(record, collection_slug)
|
11
|
+
def create_item(record, collection_slug) # rubocop:disable Metrics/MethodLength
|
12
12
|
collection = find_webflow_collection(collection_slug)
|
13
13
|
response = client.create_item(
|
14
14
|
collection['_id'],
|
15
15
|
record.as_webflow_json.reverse_merge(_archived: false, _draft: false), live: true
|
16
16
|
)
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
# use update_column to skip callbacks to prevent WebflowSync::ItemSync to kick off
|
19
|
+
if record.update_column(:webflow_item_id, response['_id']) # rubocop:disable Rails/SkipsModelValidations
|
20
|
+
puts "Created #{record.inspect} in #{collection_slug}"
|
21
|
+
response
|
22
|
+
else
|
23
|
+
raise "Failed to store webflow_item_id: '#{response['_id']}' " \
|
24
|
+
"after creating item in WebFlow collection #{record.inspect}"
|
25
|
+
end
|
21
26
|
end
|
22
27
|
|
23
28
|
def update_item(record, collection_slug)
|
@@ -9,7 +9,7 @@ module WebflowSync
|
|
9
9
|
yield(self.configuration)
|
10
10
|
|
11
11
|
self.configuration.api_token ||= ENV.fetch('WEBFLOW_API_TOKEN')
|
12
|
-
self.configuration.skip_webflow_sync
|
12
|
+
defined?(self.configuration.skip_webflow_sync) or self.configuration.skip_webflow_sync = !Rails.env.production?
|
13
13
|
end
|
14
14
|
|
15
15
|
private
|
@@ -18,7 +18,8 @@ module WebflowSync
|
|
18
18
|
end
|
19
19
|
|
20
20
|
class Configuration
|
21
|
-
attr_accessor :
|
21
|
+
attr_accessor :skip_webflow_sync, :webflow_site_id
|
22
|
+
attr_reader :api_token
|
22
23
|
|
23
24
|
def api_token=(value)
|
24
25
|
@api_token = Webflow.config.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: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Viktor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|