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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36b6c5dc80e752a95692afe908be134cdefd6193e0ed712c7a6d41440bb679e0
4
- data.tar.gz: 5bd56794f4d0f09634a776b18ca613844b149afaf99cbbb841fe6294ae5cc67a
3
+ metadata.gz: '008eacb6d73cdf03f36749df62fcdf48b68c59430c8aef274e8711cef46c2bab'
4
+ data.tar.gz: 2b802a58ab2f1b29bcb5bbd9731b9b4c0cc19798cd40bbe11304520ed9080a2f
5
5
  SHA512:
6
- metadata.gz: 83fe81d28e2aec28ef31bee07956f8a105b368053f60dbcff1e668ae853671e708e543db1444aad37571117562ac7c6412913600c1da0d35d80851d5438a827c
7
- data.tar.gz: 9e40ae99fa67b4d6ae787900e288009f2d7bc3c6633908e36f13efec62df3b676ec23ddcf0710cbd82a80beb5a573bf13da69c2d13c8f49c9db57686f8d60428
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
- WebflowSync::Api.new(record.webflow_site_id).create_item(record, collection_slug)
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
- record.update!(webflow_item_id: response['_id'])
19
- puts "Created #{record.inspect} in #{collection_slug}"
20
- response
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 :api_token, :skip_webflow_sync, :webflow_site_id
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WebflowSync
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webflow_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Viktor