webflow_sync 7.0.0 → 8.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: f639ebd2128267a119b8dd6a93e2d06858e8713a2faeb6b6f17bc123e60438bb
4
- data.tar.gz: 43294f31bc2fa6e5b0772ecbd28480b8c071c6472c1748b05a3109bd2818dc47
3
+ metadata.gz: 133f038b4f15d4557856a3c5e7fa95062105fc2681d37f900155e8f1788b24dd
4
+ data.tar.gz: da9361bcabb54bdcaea7842e9809e40751cf5a69acb79069c74a5cd6617d572c
5
5
  SHA512:
6
- metadata.gz: 2fac06bf9bc32b9618636acd2ab18437385f01071435757db1d311225c4f032800cb210c51168c9fb659bc095dcec5d716ce718d1c2e89449bbbf842e59bf4a8
7
- data.tar.gz: 8109face21e162c8826b25fec73409009a4bc94ffd519c1648c9c7916f9a4ae6b7bdbe5c328d95031ae0fadfbc0ade771c196a83b3cf4232be80e1cefe19a8de
6
+ metadata.gz: 2510e4fb4ba776b3c287029b7df253cdbfcf4110f327417e29a7b58ab19f9c6fa8ddf8ab259936e10a69fd4ad054ab54b98d7c2f5829a68d7b03756a5170a03e
7
+ data.tar.gz: 1136fd8be0375a1817563acbe9b311633f807ab94c374cd5c6921bb2fdf7847c7b94873e9ac2fe41de269fe09f921cae8b8e1d5a7bc80a995f3d5140ed72f682
data/README.md CHANGED
@@ -1,22 +1,18 @@
1
1
  [![Build Status](https://github.com/vfonic/webflow_sync/workflows/build/badge.svg)](https://github.com/vfonic/webflow_sync/actions)
2
2
 
3
-
4
3
  # WebflowSync
5
4
 
6
- Keep your Ruby on Rails records in sync with WebFlow.*
5
+ Keep your Ruby on Rails records in sync with WebFlow.\*
7
6
 
8
- *Currently only one way Rails => WebFlow synchronization.
7
+ \*Currently only one way Rails => WebFlow synchronization.
9
8
 
10
9
  For the latest changes, check the [CHANGELOG.md](CHANGELOG.md).
11
10
 
12
11
  ## Installation
13
12
 
14
- This gem currently only works with a fork of 'webflow-ruby' gem.
15
-
16
- Add these lines to your application's Gemfile:
13
+ Add this line to your application's Gemfile:
17
14
 
18
15
  ```ruby
19
- gem 'webflow-ruby', github: 'vfonic/webflow-ruby', branch: 'allow-live-delete'
20
16
  gem 'webflow_sync'
21
17
  ```
22
18
 
@@ -36,11 +32,8 @@ bundle exec rails generate webflow_sync:install
36
32
 
37
33
  ### Generate and set WebFlow API token
38
34
 
39
- Run API token Rails generator and follow instructions:
35
+ The easiest way to generate API v2 token is to clone the official [webflow-app-starter-v2](https://github.com/Webflow-Examples/webflow-app-starter-v2) repo and follow the instructions in their README.md.
40
36
 
41
- ```bash
42
- bundle exec rails generate webflow_sync:api_token_flow
43
- ```
44
37
  ### Configuration options
45
38
 
46
39
  In `config/initializers/webflow_sync.rb` you can specify configuration options:
@@ -50,25 +43,25 @@ In `config/initializers/webflow_sync.rb` you can specify configuration options:
50
43
  3. `skip_webflow_sync` - skip synchronization for different environments.
51
44
  4. `sync_webflow_slug` - save slug generated on WebFlow to the Rails model, `webflow_slug` column.
52
45
 
53
- This can be useful if you want to link to WebFlow item directly from your Rails app:
46
+ This can be useful if you want to link to WebFlow item directly from your Rails app:
54
47
 
55
- ```rb
56
- link_to('View on site', "https://#{webflow_domain}/articles/#{record.webflow_slug}", target: :blank)
57
- ```
48
+ ```rb
49
+ link_to('View on site', "https://#{webflow_domain}/articles/#{record.webflow_slug}", target: :blank)
50
+ ```
58
51
 
59
- To save slug generated on WebFlow in Rails model, `webflow_slug` column:
52
+ To save slug generated on WebFlow in Rails model, `webflow_slug` column:
60
53
 
61
- 1. add `webflow_slug` column on the model table, then
62
- 2. set the `sync_webflow_slug` option to `true`.
54
+ 1. add `webflow_slug` column on the model table, then
55
+ 2. set the `sync_webflow_slug` option to `true`.
63
56
 
64
- Example:
57
+ Example:
65
58
 
66
- ```rb
67
- WebflowSync.configure do |config|
68
- config.skip_webflow_sync = ActiveModel::Type::Boolean.new.cast(ENV.fetch('SKIP_WEBFLOW_SYNC'))
69
- config.sync_webflow_slug = ActiveModel::Type::Boolean.new.cast(ENV.fetch('SYNC_WEBFLOW_SLUG'))
70
- end
71
- ```
59
+ ```rb
60
+ WebflowSync.configure do |config|
61
+ config.skip_webflow_sync = ActiveModel::Type::Boolean.new.cast(ENV.fetch('SKIP_WEBFLOW_SYNC'))
62
+ config.sync_webflow_slug = ActiveModel::Type::Boolean.new.cast(ENV.fetch('SYNC_WEBFLOW_SLUG'))
63
+ end
64
+ ```
72
65
 
73
66
  ### Add WebflowSync to models
74
67
 
@@ -78,7 +71,7 @@ For each model that you want to sync to WebFlow, you need to run the collection
78
71
  bundle exec rails generate webflow_sync:collection Article
79
72
  ```
80
73
 
81
- Please note that this _does not_ create a WebFlow collection as that's not possible to do through WebFlow API.
74
+ Please note that this _does not_ create a collection in WebFlow. You need to create collections in Webflow manually.
82
75
 
83
76
  ### Create WebFlow collections
84
77
 
@@ -97,12 +90,13 @@ Your WebFlow collection `slug` should be `"articles"`.
97
90
 
98
91
  For Rails models named with multiple words, make a collection that have a space between words in the name. WebFlow will set the `slug` by replacing space for "-".
99
92
 
100
- For example, for `FeaturedArticle` model:
93
+ For example, for `FeaturedArticle` model in your Rails app, in Webflow you'll create a collection called `"Featured Articles"`:
101
94
 
102
95
  ```ruby
103
96
  > FeaturedArticle.model_name.to_s.underscore.dasherize.pluralize
104
97
  # => "featured-articles"
105
98
  ```
99
+
106
100
  Your WebFlow collection `slug` in this case should be `"featured-articles"`.
107
101
 
108
102
  ### Set `webflow_site_id`
@@ -128,8 +122,8 @@ To do this, override the `#webflow_site_id` method provided by `WebflowSync::Ite
128
122
  For example, you could have `Site` model in your codebase:
129
123
 
130
124
  ```ruby
131
- # app/models/site.rb
132
- class Site < ApplicationRecord
125
+ # app/models/webflow_site.rb
126
+ class WebflowSite < ApplicationRecord
133
127
  has_many :articles
134
128
  end
135
129
 
@@ -137,10 +131,10 @@ end
137
131
  class Article < ApplicationRecord
138
132
  include WebflowSync::ItemSync
139
133
 
140
- belongs_to :site
134
+ belongs_to :webflow_site
141
135
 
142
136
  def webflow_site_id
143
- self.site.webflow_site_id
137
+ self.webflow_site.webflow_site_id
144
138
  end
145
139
  end
146
140
  ```
@@ -180,10 +174,10 @@ end
180
174
 
181
175
  ### Sync a Rails model with the custom collection
182
176
 
183
- If collection `slug` does not match the Rails model collection name, you can still sync with WebFlow collection, but need to specify collection slug for each `CreateItemJob` and `UpdateItemJob` call. If not specified, model name is used as a default slug name.
184
- You would also need to replace included `WebflowSync::ItemSync` with custom callbacks that will call appropriate WebflowSync jobs.
177
+ If collection `slug` in Webflow does not match the Rails model collection name, you can override `webflow_collection_slug` method in your Rails model.
178
+ If you want to call `WebflowSync::CreateItemJob`, `WebflowSync::UpdateItemJob`, or `WebflowSync::DestroyItemJob` directly in your code, you can do so by passing the `collection_slug` as an argument.
185
179
 
186
- For example:
180
+ Here are method signatures:
187
181
 
188
182
  ```ruby
189
183
  WebflowSync::CreateItemJob.perform_later(model_name, id, collection_slug)
@@ -193,15 +187,15 @@ WebflowSync::DestroyItemJob.perform_later(collection_slug:, webflow_site_id:, we
193
187
 
194
188
  Where:
195
189
 
196
- 1. `model_name` - Rails model that has `webflow_site_id` and `webflow_item_id` defined
197
- 2. `collection_slug` - slug of the WebFlow collection (defaults to: `model_name.underscore.dasherize.pluralize `)
198
-
190
+ 1. `model_name` - Rails model that has `webflow_site_id` and `webflow_item_id` defined
191
+ 2. `collection_slug` - slug of the WebFlow collection (defaults to: `model_name.underscore.dasherize.pluralize`)
199
192
 
200
193
  For example:
201
194
 
202
195
  ```ruby
203
196
  WebflowSync::CreateItemJob.perform_now('articles', 1, 'stories')
204
197
  ```
198
+
205
199
  Or, if you want to use the default 'articles' collection_slug:
206
200
 
207
201
  ```ruby
@@ -222,7 +216,7 @@ You can also run this from a Rake task:
222
216
  bundle exec rails "webflow_sync:initial_sync[articles]"
223
217
  ```
224
218
 
225
- *Quotes are needed in order for this to work in all shells.
219
+ \*Quotes are needed in order for this to work in all shells.
226
220
 
227
221
  ### Important note
228
222
 
@@ -242,7 +236,6 @@ bundle exec rake
242
236
 
243
237
  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)!
244
238
 
245
-
246
239
  ## License
247
240
 
248
241
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -2,15 +2,7 @@
2
2
 
3
3
  module WebflowSync
4
4
  class CreateItemJob < ApplicationJob
5
- # WebFlow collection slug should be in plural form.
6
- # For collections that have spaces in their name, WebFlow sets slug by replacing space for "-".
7
- # 'JobListing'.underscore.dasherize.pluralize => "job-listings"
8
- # 'job_listing'.underscore.dasherize.pluralize => "job-listings"
9
- # We can sync Rails model that has different class name than its WebFlow collection
10
- # model_name => Rails model that has webflow_site_id and webflow_item_id columns
11
- # collection_slug => slug of the WebFlow collection
12
- # model_name = 'articles'; id = article.id, collection_slug = 'stories'
13
- def perform(model_name, id, collection_slug = model_name.underscore.dasherize.pluralize)
5
+ def perform(collection_id:, model_name:, id:)
14
6
  return if WebflowSync.configuration.skip_webflow_sync
15
7
 
16
8
  model_class = model_name.underscore.classify.constantize
@@ -18,9 +10,9 @@ module WebflowSync
18
10
  return if record.blank?
19
11
  return if record.skip_webflow_sync
20
12
  return if record.webflow_site_id.blank?
21
- return WebflowSync::UpdateItemJob.perform_later(model_name, id, collection_slug) if record.webflow_item_id.present?
13
+ return WebflowSync::UpdateItemJob.perform_later(collection_id:, model_name:, id:) if record.webflow_item_id.present?
22
14
 
23
- WebflowSync::Api.new(record.webflow_site_id).create_item(record, collection_slug)
15
+ WebflowSync::Api.new(site_id: record.webflow_site_id).create_item(collection_id:, record:)
24
16
  end
25
17
  end
26
18
  end
@@ -2,12 +2,12 @@
2
2
 
3
3
  module WebflowSync
4
4
  class DestroyItemJob < ApplicationJob
5
- def perform(collection_slug:, webflow_site_id:, webflow_item_id:)
5
+ def perform(collection_id:, webflow_site_id:, webflow_item_id:)
6
6
  return if WebflowSync.configuration.skip_webflow_sync
7
7
  return if webflow_site_id.blank?
8
8
  return if webflow_item_id.blank?
9
9
 
10
- WebflowSync::Api.new(webflow_site_id).delete_item(collection_slug, webflow_item_id)
10
+ WebflowSync::Api.new(site_id: webflow_site_id).delete_item(collection_id:, webflow_item_id:)
11
11
  end
12
12
  end
13
13
  end
@@ -7,7 +7,8 @@ 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
- client(record.webflow_site_id).create_item(record, collection_slug)
10
+ collection_id = client(record.webflow_site_id).find_collection_id(collection_slug:)
11
+ client(record.webflow_site_id).create_item(collection_id:, record:)
11
12
  end
12
13
  end
13
14
 
@@ -17,7 +18,7 @@ module WebflowSync
17
18
  if @client&.site_id == site_id
18
19
  @client
19
20
  else
20
- @client = WebflowSync::Api.new(site_id)
21
+ @client = WebflowSync::Api.new(site_id:)
21
22
  end
22
23
  end
23
24
  end
@@ -2,11 +2,7 @@
2
2
 
3
3
  module WebflowSync
4
4
  class UpdateItemJob < ApplicationJob
5
- # WebFlow collection slug should be in plural form.
6
- # For collections that have spaces in their name, WebFlow sets slug by replacing space for "-".
7
- # 'JobListing'.underscore.dasherize.pluralize => 'job-listings'
8
- # 'job_listing'.underscore.dasherize.pluralize => 'job-listings'
9
- def perform(model_name, id, collection_slug = model_name.underscore.dasherize.pluralize)
5
+ def perform(collection_id:, model_name:, id:)
10
6
  return if WebflowSync.configuration.skip_webflow_sync
11
7
 
12
8
  model_class = model_name.underscore.classify.constantize
@@ -14,9 +10,9 @@ module WebflowSync
14
10
  return if record.blank?
15
11
  return if record.skip_webflow_sync
16
12
  return if record.webflow_site_id.blank?
17
- return WebflowSync::CreateItemJob.perform_later(model_name, id, collection_slug) if record.webflow_item_id.blank?
13
+ return WebflowSync::CreateItemJob.perform_later(collection_id:, model_name:, id:) if record.webflow_item_id.blank?
18
14
 
19
- WebflowSync::Api.new(record.webflow_site_id).update_item(record, collection_slug)
15
+ WebflowSync::Api.new(site_id: record.webflow_site_id).update_item(collection_id:, record:)
20
16
  end
21
17
  end
22
18
  end
@@ -13,27 +13,29 @@ module WebflowSync
13
13
  after_commit :destroy_webflow_item, on: :destroy
14
14
 
15
15
  def create_webflow_item
16
- return if WebflowSync.configuration.skip_webflow_sync || self.skip_webflow_sync || self.webflow_site_id.blank?
16
+ return if self.should_skip_webflow_sync?
17
17
 
18
- WebflowSync::CreateItemJob.perform_later(self.model_name.collection, self.id)
18
+ WebflowSync::CreateItemJob.perform_later(collection_id: self.webflow_collection_id, model_name: self.model_name.name, id:)
19
19
  end
20
20
 
21
21
  def update_webflow_item
22
- return if WebflowSync.configuration.skip_webflow_sync || self.skip_webflow_sync || self.webflow_site_id.blank?
22
+ return if self.should_skip_webflow_sync?
23
23
 
24
- WebflowSync::UpdateItemJob.perform_later(self.model_name.collection, self.id)
24
+ WebflowSync::UpdateItemJob.perform_later(collection_id: self.webflow_collection_id, model_name: self.model_name.name, id:)
25
25
  end
26
26
 
27
27
  def destroy_webflow_item
28
- return if WebflowSync.configuration.skip_webflow_sync || self.skip_webflow_sync || self.webflow_site_id.blank?
28
+ return if self.should_skip_webflow_sync?
29
29
 
30
- # Make sure slug is in the plural form, and multiple words slug separated by dashes
31
- collection_slug = self.model_name.collection.underscore.dasherize
32
-
33
- WebflowSync::DestroyItemJob.perform_later(collection_slug:,
34
- webflow_site_id: self.webflow_site_id,
35
- webflow_item_id: self.webflow_item_id)
30
+ WebflowSync::DestroyItemJob.perform_later(collection_id: self.webflow_collection_id, webflow_site_id:, webflow_item_id:)
36
31
  end
32
+
33
+ private
34
+
35
+ def should_skip_webflow_sync?
36
+ WebflowSync.configuration.skip_webflow_sync || self.skip_webflow_sync ||
37
+ self.webflow_site_id.blank? || self.webflow_collection_id.blank?
38
+ end
37
39
  end
38
40
  end
39
41
  end
@@ -23,8 +23,16 @@ module WebflowSync
23
23
  # end
24
24
  # end
25
25
  #
26
- def webflow_site_id
27
- WebflowSync.configuration.webflow_site_id
26
+ def webflow_site_id = WebflowSync.configuration.webflow_site_id
27
+
28
+ # override this method in your model to match the collection slug in Webflow
29
+ def webflow_collection_slug = self.model_name.collection.underscore.dasherize
30
+
31
+ # override this method in your model to match the collection id in Webflow
32
+ # overriding this method is optional, but it will save you a Webflow API call!
33
+ def webflow_collection_id
34
+ @webflow_collection_id ||= WebflowSync::Api.new(site_id: self.webflow_site_id)
35
+ .find_collection_id(collection_slug: self.webflow_collection_slug)
28
36
  end
29
37
 
30
38
  # You can customize this to your liking:
@@ -36,9 +44,7 @@ module WebflowSync
36
44
  # image: self.image_url
37
45
  # }
38
46
  # end
39
- def as_webflow_json
40
- self.as_json
41
- end
47
+ def as_webflow_json = self.as_json
42
48
  end
43
49
  end
44
50
  end
@@ -4,98 +4,56 @@ module WebflowSync
4
4
  class Api
5
5
  attr_reader :site_id
6
6
 
7
- def initialize(site_id = nil)
7
+ def initialize(site_id: nil)
8
8
  @site_id = site_id
9
9
  end
10
10
 
11
- def get_all_items(collection_slug:, page_limit: 100) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
12
- collection_id = find_webflow_collection(collection_slug).fetch('id')
13
- max_items_per_page = [page_limit, 100].min
14
- first_page_number = 1
11
+ def get_all_items(collection_id:) = make_request(:list_all_items, collection_id)
15
12
 
16
- result = make_request(:paginate_items, collection_id, page: first_page_number, per_page: max_items_per_page)
17
- puts "Get all items from WebFlow for #{collection_slug} page: #{first_page_number}"
13
+ def get_item(collection_id:, webflow_item_id:) = make_request(:get_item, collection_id, webflow_item_id)
18
14
 
19
- total_items = result.dig('pagination', 'total')
20
- total_pages = (total_items.to_f / max_items_per_page).ceil
21
- items = result.fetch('items')
15
+ def create_item(collection_id:, record:)
16
+ response = make_request(:create_item, collection_id, record.as_webflow_json)
22
17
 
23
- (2..total_pages).each do |page_number|
24
- next_page_items = make_request(:paginate_items, collection_id, page: page_number, per_page: max_items_per_page).fetch('items')
25
- puts "Get all items from WebFlow for #{collection_slug} page: #{page_number}"
26
-
27
- items.concat next_page_items
18
+ unless update_record_columns(record, response)
19
+ raise "Failed to store webflow_item_id: '#{response.fetch(:id)}' after creating item in WebFlow collection #{record.inspect}"
28
20
  end
29
21
 
30
- items
22
+ response
31
23
  end
32
24
 
33
- def get_item(collection_slug, webflow_item_id)
34
- collection = find_webflow_collection(collection_slug)
25
+ def update_item(collection_id:, record:) = make_request(:update_item, collection_id, record.webflow_item_id, record.as_webflow_json)
35
26
 
36
- make_request(:item, collection.fetch('id'), webflow_item_id)
37
- end
27
+ def delete_item(collection_id:, webflow_item_id:) = make_request(:delete_item, collection_id, webflow_item_id)
38
28
 
39
- def create_item(record, collection_slug)
40
- collection = find_webflow_collection(collection_slug)
41
- response = make_request(:create_item, collection.fetch('id'), record.as_webflow_json, publish: true)
29
+ def publish = make_request(:publish, site_id)
42
30
 
43
- if update_record_columns(record, response)
44
- puts "Created #{record.inspect} in #{collection_slug}"
45
- response
46
- else
47
- raise "Failed to store webflow_item_id: '#{response.fetch('id')}' " \
48
- "after creating item in WebFlow collection #{record.inspect}"
49
- end
50
- end
51
-
52
- def update_item(record, collection_slug)
53
- collection = find_webflow_collection(collection_slug)
54
- response = make_request(:update_item, collection.fetch('id'), record.webflow_item_id, record.as_webflow_json, publish: true)
55
- puts "Updated #{record.inspect} in #{collection_slug}"
56
- response
57
- end
31
+ def sites = make_request(:sites)
32
+ def self.sites = self.new.sites
58
33
 
59
- def delete_item(collection_slug, webflow_item_id)
60
- collection = find_webflow_collection(collection_slug)
61
- response = make_request(:delete_item, collection.fetch('id'), webflow_item_id)
62
- puts "Deleted #{webflow_item_id} from #{collection_slug}"
63
- response
34
+ def collections
35
+ @collections ||= make_request(:collections, site_id)
64
36
  end
65
37
 
66
- def publish
67
- response = make_request(:publish, site_id)
38
+ def find_collection_id(collection_slug:)
39
+ response = collections.find { |collection| collection.fetch(:slug) == collection_slug }
40
+ raise "Cannot find collection #{collection_slug} for Webflow site #{site_id}" unless response
68
41
 
69
- puts "Publish all domains for Webflow site with id: #{site_id}"
70
- response
42
+ response.fetch(:id)
71
43
  end
72
44
 
73
- def sites = make_request(:sites)
74
- def self.sites = new.sites
75
-
76
45
  private
77
46
 
78
47
  def client
79
- @client ||= ::Webflow::Client.new
80
- end
81
-
82
- def collections
83
- @collections ||= make_request(:collections, site_id).fetch('collections')
84
- end
85
-
86
- def find_webflow_collection(collection_slug)
87
- response = collections.find { |collection| collection.fetch('slug') == collection_slug }
88
- raise "Cannot find collection #{collection_slug} for Webflow site #{site_id}" unless response
89
-
90
- response
48
+ @client ||= Webflow::Client.new
91
49
  end
92
50
 
93
51
  def update_record_columns(record, response)
94
52
  # use update_column to skip callbacks to prevent WebflowSync::ItemSync to kick off
95
53
  if WebflowSync.configuration.sync_webflow_slug
96
- record.update_columns(webflow_item_id: response.fetch('id'), webflow_slug: response.dig('fieldData', 'slug')) # rubocop:disable Rails/SkipsModelValidations
54
+ record.update_columns(webflow_item_id: response.fetch(:id), webflow_slug: response.dig(:fieldData, :slug)) # rubocop:disable Rails/SkipsModelValidations
97
55
  else
98
- record.update_column(:webflow_item_id, response.fetch('id')) # rubocop:disable Rails/SkipsModelValidations
56
+ record.update_column(:webflow_item_id, response.fetch(:id)) # rubocop:disable Rails/SkipsModelValidations
99
57
  end
100
58
  end
101
59
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WebflowSync
4
- VERSION = '7.0.0'
4
+ VERSION = '8.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: 7.0.0
4
+ version: 8.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: 2023-11-06 00:00:00.000000000 Z
11
+ date: 2023-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -25,21 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: sprockets-rails
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: webflow-ruby
28
+ name: webflow-rb
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - ">="
@@ -69,11 +55,8 @@ files:
69
55
  - app/models/concerns/webflow_sync/callbacks.rb
70
56
  - app/models/concerns/webflow_sync/item_sync.rb
71
57
  - app/services/webflow_sync/api.rb
72
- - lib/generators/webflow_sync/api_token_flow_generator.rb
73
58
  - lib/generators/webflow_sync/collection_generator.rb
74
59
  - lib/generators/webflow_sync/install_generator.rb
75
- - lib/generators/webflow_sync/templates/api_token/omniauth_webflow.rb.erb
76
- - lib/generators/webflow_sync/templates/api_token/webflow_callback_controller.rb.erb
77
60
  - lib/generators/webflow_sync/templates/migration.rb.erb
78
61
  - lib/generators/webflow_sync/templates/webflow_sync.rb
79
62
  - lib/tasks/webflow_sync.rake
@@ -104,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
87
  - !ruby/object:Gem::Version
105
88
  version: '0'
106
89
  requirements: []
107
- rubygems_version: 3.4.21
90
+ rubygems_version: 3.4.22
108
91
  signing_key:
109
92
  specification_version: 4
110
93
  summary: Keep Rails models in sync with WebFlow.
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails/generators/active_record'
4
-
5
- module WebflowSync
6
- module Generators
7
- class ApiTokenFlowGenerator < Rails::Generators::Base
8
- desc 'Generates Omniauth flow for authenticating WebFlow application to get WebFlow API token'
9
-
10
- source_root File.expand_path('templates/api_token', __dir__)
11
-
12
- def generate
13
- gem 'omniauth-webflow'
14
- run 'bundle install'
15
- template 'webflow_callback_controller.rb.erb', 'app/controllers/webflow_callback_controller.rb'
16
- template 'omniauth_webflow.rb.erb', 'config/initializers/omniauth_webflow.rb'
17
- route "post '/auth/webflow/callback', to: 'webflow_callback#index'"
18
- route "get '/auth/webflow/callback', to: 'webflow_callback#index'"
19
-
20
- puts <<~END_OF_INSTRUCTIONS.indent(4)
21
-
22
-
23
- We've generated all the files needed to successfully authenticate
24
- with WebFlow to get API token.
25
- There are couple of steps left to get the token:
26
-
27
- 1. Download ngrok: https://ngrok.com/download
28
- 2. Run `ngrok http 3000`
29
- 3. Copy the URL that ngrok gives you (something like: https://dd7cc807bf91.ngrok.io)
30
- 4. Go to: https://webflow.com/dashboard/account/integrations
31
- 5. Register New Application
32
- 6. In "Redirect URI" put: https://dd7cc807bf91.ngrok.io/auth/webflow/callback
33
- 7. Save
34
- 8. Copy client ID and client secret to ENV variables or add
35
- them directly in config/initializers/omniauth_webflow.rb
36
- 9. Start rails server locally
37
- 10. Go to https://dd7cc807bf91.ngrok.io/auth/webflow
38
- 11. Finally authenticate, beware which permissions to give
39
- (some are "allow access", some are "restrict access", it's confusing)
40
- 12. Copy the rendered API token and put it in ENV.fetch('WEBFLOW_API_TOKEN')
41
- 13. After you've got the API token, you probably don't need
42
- the Omniauth WebFlow code so you can remove the code that this
43
- generator created from your codebase.
44
- It is also a security issue to leave the Omniauth endpoint in your
45
- codebase, that has the ability to generate API tokens for your WebFlow
46
- account!!!
47
-
48
- Easy.
49
-
50
-
51
- END_OF_INSTRUCTIONS
52
- end
53
- end
54
- end
55
- end
@@ -1,3 +0,0 @@
1
- Rails.application.config.middleware.use OmniAuth::Builder do
2
- provider :webflow, ENV.fetch('WEBFLOW_CLIENT_ID'), ENV.fetch('WEBFLOW_CLIENT_SECRET')
3
- end
@@ -1,8 +0,0 @@
1
- class WebflowCallbackController < ApplicationController
2
- skip_before_action :verify_authenticity_token, only: :index
3
-
4
- # Go to /auth/webflow to start oauth flow
5
- def index
6
- render plain: request.env['omniauth.auth'].dig('credentials', 'token')
7
- end
8
- end