webflow_sync 0.2.0 → 0.2.2
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 -0
- data/app/jobs/webflow_sync/initial_sync_job.rb +11 -1
- data/app/services/webflow_sync/api.rb +9 -4
- data/lib/webflow_sync/configuration.rb +2 -1
- data/lib/webflow_sync/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '008eacb6d73cdf03f36749df62fcdf48b68c59430c8aef274e8711cef46c2bab'
|
4
|
+
data.tar.gz: 2b802a58ab2f1b29bcb5bbd9731b9b4c0cc19798cd40bbe11304520ed9080a2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da35c26f4b754220b0d95f7b29889bd1ccf43ab26f9378e0ce4cbdb7cd911a212498d3b44b5b4557624430862e289ece374de642c0f758b9a3ac5f141e6acbb5
|
7
|
+
data.tar.gz: dec5b2f89ec60203db3a29f3bb7dff0431fe66734a214c3e897ec998d55a6c88ca2ab7c74501b2e22c339d5c7daf584118e4304e599facb040223a29c7f155dc
|
data/README.md
CHANGED
@@ -158,6 +158,11 @@ This gem silently "fails" (does nothing) when `webflow_site_id` or `webflow_item
|
|
158
158
|
|
159
159
|
PRs welcome!
|
160
160
|
|
161
|
+
## Thanks and Credits
|
162
|
+
|
163
|
+
This gem wouldn't be possible without the amazing work of [webflow-ruby](https://github.com/penseo/webflow-ruby) gem. Thank you, @phoet!
|
164
|
+
|
165
|
+
|
161
166
|
## License
|
162
167
|
|
163
168
|
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
|
@@ -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)
|
@@ -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