webflow_sync 6.0.0 → 6.1.1

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: 98d3c00c861dd048087817fe1a709eb32a66cde4d5b79e0207ca6b19513dd9df
4
- data.tar.gz: dac4374d4f30f254db0808669600b5f0e1d8418bd38e43dcfaa736fed25631ca
3
+ metadata.gz: 3874cf42b829542c647a91935f17fe61d04072b8ad3f30ac8a483e8a019bb6ab
4
+ data.tar.gz: 32af885137c5c68b1720e6ec816adf584b4215540cc004fac9824fe71bcea3d4
5
5
  SHA512:
6
- metadata.gz: 203099b7e60df11fe4ac8c4319c4e41603d737a269892fcc120ed4909ebbfb47ea3c4dc0ec2456404607f8a3ba5e155923cff5c781e75a7edd3417e1ac908268
7
- data.tar.gz: '0993c797a70bf2efe1faa86eb3f439a85a1a7233201033c5ccc4ccb3b71fcf97f15df19839e9b92259013f4141b2955d84d9c7bdaf017d8ee7a81791989c4d26'
6
+ metadata.gz: 32209b9c2500d2ba13f229fc4826296ead24d002fd2ee429f2c4c71076c70f8a23fb3bad1b4386cf4253120a958bfef10bd832ab4c2496b3914a542282d3beca
7
+ data.tar.gz: d447ac378e5c6ceb3ee19e400e2e337baefbc152146a58b5a64a371fe49d18c1fc72f4e9e9328a924a37749e22608faadf1d449847ef55b32296f56902b4384e
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WebflowSync
4
- class Api
4
+ class Api # rubocop:disable Metrics/ClassLength
5
5
  attr_reader :site_id
6
6
 
7
- def initialize(site_id)
7
+ def initialize(site_id = nil)
8
8
  @site_id = site_id
9
9
  end
10
10
 
@@ -21,8 +21,7 @@ module WebflowSync
21
21
  items = result['items']
22
22
 
23
23
  (2..total_pages).each do |page_number|
24
- next_page_items = make_request(:paginate_items, collection_id,
25
- page: page_number, per_page: max_items_per_page)['items']
24
+ next_page_items = make_request(:paginate_items, collection_id, page: page_number, per_page: max_items_per_page)['items']
26
25
  puts "Get all items from WebFlow for #{collection_slug} page: #{page_number}"
27
26
 
28
27
  items.concat next_page_items
@@ -31,11 +30,14 @@ module WebflowSync
31
30
  items
32
31
  end
33
32
 
33
+ def self.get_all_items(collection_slug:, page_limit: 100) = new.get_all_items(collection_slug:, page_limit:)
34
+
34
35
  def get_item(collection_slug, webflow_item_id)
35
36
  collection = find_webflow_collection(collection_slug)
36
37
 
37
38
  make_request(:item, collection['_id'], webflow_item_id)
38
39
  end
40
+ def self.get_item(collection_slug, webflow_item_id) = new.get_item(collection_slug, webflow_item_id)
39
41
 
40
42
  def create_item(record, collection_slug)
41
43
  collection = find_webflow_collection(collection_slug)
@@ -51,6 +53,8 @@ module WebflowSync
51
53
  end
52
54
  end
53
55
 
56
+ def self.create_item(record, collection_slug) = new.create_item(record, collection_slug)
57
+
54
58
  def update_item(record, collection_slug)
55
59
  collection = find_webflow_collection(collection_slug)
56
60
  response = make_request(:update_item, { '_cid' => collection['_id'], '_id' => record.webflow_item_id },
@@ -60,6 +64,8 @@ module WebflowSync
60
64
  response
61
65
  end
62
66
 
67
+ def self.update_item(record, collection_slug) = new.update_item(record, collection_slug)
68
+
63
69
  def delete_item(collection_slug, webflow_item_id)
64
70
  collection = find_webflow_collection(collection_slug)
65
71
  # deleting items from Webflow doesn't work as expected.
@@ -73,6 +79,8 @@ module WebflowSync
73
79
  response
74
80
  end
75
81
 
82
+ def self.delete_item(collection_slug, webflow_item_id) = new.delete_item(collection_slug, webflow_item_id)
83
+
76
84
  def publish
77
85
  response = make_request(:publish, site_id, domain_names:)
78
86
 
@@ -80,6 +88,9 @@ module WebflowSync
80
88
  response
81
89
  end
82
90
 
91
+ def sites = make_request(:sites)
92
+ def self.sites = new.sites
93
+
83
94
  private
84
95
 
85
96
  def client
@@ -87,7 +98,7 @@ module WebflowSync
87
98
  end
88
99
 
89
100
  def collections
90
- @collections ||= client.collections(site_id)
101
+ @collections ||= make_request(:collections, site_id)
91
102
  end
92
103
 
93
104
  def domain_names
@@ -98,16 +109,16 @@ module WebflowSync
98
109
  # client.domains request does not return the default domain
99
110
  # We need to get default domain name if there are no custom domains set to avoid error:
100
111
  # Webflow::Error: Domain not found for site
101
- site = client.site(site_id)
102
- default_domain_name = "#{site['shortName']}.webflow.io"
112
+ site = make_request(:site, site_id)
113
+ default_domain_name = "#{site.fetch('shortName')}.webflow.io"
103
114
  names = [default_domain_name]
104
- client.domains(site_id).each { |domain| names << domain['name'] }
115
+ make_request(:domains, site_id).each { |domain| names << domain.fetch('name') }
105
116
 
106
117
  names
107
118
  end
108
119
 
109
120
  def find_webflow_collection(collection_slug)
110
- response = collections.find { |collection| collection['slug'] == collection_slug }
121
+ response = collections.find { |collection| collection.fetch('slug') == collection_slug }
111
122
  raise "Cannot find collection #{collection_slug} for Webflow site #{site_id}" unless response
112
123
 
113
124
  response
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WebflowSync
4
- VERSION = '6.0.0'
4
+ VERSION = '6.1.1'
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: 6.0.0
4
+ version: 6.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Viktor