webflow_sync 4.0.2 → 6.0.0

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: d3270f97e26a8b202ea1b11b2f28b41c58852e175712c155883082a9bea8e418
4
- data.tar.gz: 84c74465edb84ae559720358b7f7ab98178b76c8a028c49ce16378085a016d17
3
+ metadata.gz: 98d3c00c861dd048087817fe1a709eb32a66cde4d5b79e0207ca6b19513dd9df
4
+ data.tar.gz: dac4374d4f30f254db0808669600b5f0e1d8418bd38e43dcfaa736fed25631ca
5
5
  SHA512:
6
- metadata.gz: 69b4f9c12048b2c9902d876ec4c3b2676a559c421bf1a7ab96b886c655250a8103cc63d8dd6cc4285cfe7e9b17cbb9608dbf21dbf615e8cb2ccdb000d2dcc548
7
- data.tar.gz: 30dbde548e134d3dafab4f76a28e238111e709ea3ff469c0fc11071a58606a8fe3a197513d785ffa242125582106729a2807fe33039a34d33862c8acecc98a40
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
- Add this line to your application's Gemfile:
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. `publish_on_sync` - republish all domains after create, update and destroy actions.
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
 
@@ -230,9 +232,15 @@ This gem silently "fails" (does nothing) when `webflow_site_id` or `webflow_item
230
232
 
231
233
  PRs welcome!
232
234
 
235
+ To run RuboCop style check and RSpec tests run:
236
+
237
+ ```sh
238
+ bundle exec rake
239
+ ```
240
+
233
241
  ## Thanks and Credits
234
242
 
235
- This gem wouldn't be possible without the amazing work of [webflow-ruby](https://github.com/penseo/webflow-ruby) gem. Thank you, @phoet!
243
+ This gem wouldn't be possible without the amazing work of [webflow-ruby](https://github.com/penseo/webflow-ruby) gem. Thank you, [@phoet](https://github.com/phoet)!
236
244
 
237
245
 
238
246
  ## License
data/Rakefile CHANGED
@@ -11,5 +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'
15
- task default: :spec
14
+ load 'rspec/rails/tasks/rspec.rake' # runs all RSpec tests
15
+ task :default do
16
+ Rake::Task['style:rubocop:run'].execute
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) # rubocop:disable Metrics/MethodLength
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
- if update_record_colums(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
-
45
+ if update_record_columns(record, response)
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}"
@@ -121,7 +113,7 @@ module WebflowSync
121
113
  response
122
114
  end
123
115
 
124
- def update_record_colums(record, response)
116
+ def update_record_columns(record, response)
125
117
  # use update_column to skip callbacks to prevent WebflowSync::ItemSync to kick off
126
118
  if WebflowSync.configuration.sync_webflow_slug
127
119
  record.update_columns(webflow_item_id: response['_id'], webflow_slug: response['slug']) # rubocop:disable Rails/SkipsModelValidations
@@ -130,18 +122,19 @@ module WebflowSync
130
122
  end
131
123
  end
132
124
 
133
- def make_request(method_name, *args, retries: 0, **kwargs)
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 if retries >= 8 || e.message.strip != 'Rate limit hit'
132
+ raise unless e.message.strip == 'Rate limit hit'
133
+
134
+ puts 'Sleeping 10 seconds'
135
+ sleep 10
141
136
 
142
- puts "Sleeping #{2**retries} seconds"
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
@@ -5,5 +5,4 @@ WebflowSync.configure do |config|
5
5
  # config.skip_webflow_sync = Rails.env.test? # default
6
6
  config.webflow_site_id = ENV.fetch('WEBFLOW_SITE_ID')
7
7
  config.sync_webflow_slug = ENV.fetch('SYNC_WEBFLOW_SLUG')
8
- config.publish_on_sync = true
9
8
  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, :publish_on_sync
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WebflowSync
4
- VERSION = '4.0.2'
4
+ VERSION = '6.0.0'
5
5
  end
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.0.2
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: 2022-10-03 00:00:00.000000000 Z
11
+ date: 2023-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: webflow-ruby
28
+ name: sprockets-rails
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,111 +39,13 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: dotenv-rails
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: factory_bot_rails
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: guard-rspec
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: net-smtp
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: pry-rails
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: rspec-rails
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: vcr
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
- - !ruby/object:Gem::Dependency
140
- name: webmock
42
+ name: webflow-ruby
141
43
  requirement: !ruby/object:Gem::Requirement
142
44
  requirements:
143
45
  - - ">="
144
46
  - !ruby/object:Gem::Version
145
47
  version: '0'
146
- type: :development
48
+ type: :runtime
147
49
  prerelease: false
148
50
  version_requirements: !ruby/object:Gem::Requirement
149
51
  requirements:
@@ -202,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
104
  - !ruby/object:Gem::Version
203
105
  version: '0'
204
106
  requirements: []
205
- rubygems_version: 3.3.17
107
+ rubygems_version: 3.3.26
206
108
  signing_key:
207
109
  specification_version: 4
208
110
  summary: Keep Rails models in sync with WebFlow.