commercelayer-cli 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b11154ba609b7e3f7a56f5a8d0904780c6b2f4d6088fd2debab2a053c7000dc
|
4
|
+
data.tar.gz: 309871f46db434adaae8ff20c826045f2c112321f35c3e16b32dc31f211c21a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d23eb152cd1ecb6edafee0150f91b8fe370e87b7575b465a31c787ec9292dfe8f79d4b1f60c32b6e552d400ae9aba9762305a91b8e8d0ce9863916db0fe19e0
|
7
|
+
data.tar.gz: bc2b07c689fe2fd0d7f8ebcdc31aa75382fad08801377cb7de75895f53c399fd7df93894ba02180db91ca2735cafbe37545311e03ce4edfa97236c9e30b90db7
|
data/Gemfile.lock
CHANGED
data/lib/commercelayer/cli.rb
CHANGED
@@ -6,6 +6,7 @@ require 'contentful/management'
|
|
6
6
|
require "commercelayer/cli/version"
|
7
7
|
require "commercelayer/cli/helpers"
|
8
8
|
require "commercelayer/cli/bootstrappers"
|
9
|
+
require "commercelayer/cli/exporters"
|
9
10
|
|
10
11
|
module Commercelayer
|
11
12
|
module CLI
|
@@ -13,6 +14,7 @@ module Commercelayer
|
|
13
14
|
|
14
15
|
include Helpers
|
15
16
|
include Bootstrappers
|
17
|
+
include Exporters
|
16
18
|
include Thor::Actions
|
17
19
|
|
18
20
|
desc "init", "Create a config file under $HOME/.commercelayer-cli.yml"
|
@@ -28,6 +30,13 @@ module Commercelayer
|
|
28
30
|
bootstrap_data!(destination)
|
29
31
|
end
|
30
32
|
|
33
|
+
desc "export DESTINATION", "Exports data from Commerce Layer to a destination"
|
34
|
+
def export(destination)
|
35
|
+
destination ||= ask "What is your destination?", limited_to: ["contentful", "datocms", "csv"]
|
36
|
+
export_data!(destination)
|
37
|
+
end
|
38
|
+
|
39
|
+
|
31
40
|
end
|
32
41
|
end
|
33
42
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative "exporters/contentful"
|
2
|
+
|
3
|
+
module Commercelayer
|
4
|
+
module CLI
|
5
|
+
module Exporters
|
6
|
+
|
7
|
+
def export_data!(destination)
|
8
|
+
commercelayer_client.authorize!
|
9
|
+
case destination
|
10
|
+
when "contentful"
|
11
|
+
if yes? "Warning: this will export your SKUs to Contentful. Continue?", :yellow
|
12
|
+
say "Exporting SKUs to Contentful...", :blue
|
13
|
+
Contentful.new.export!
|
14
|
+
else
|
15
|
+
say "Nothing to do here. Bye!", :blue
|
16
|
+
end
|
17
|
+
else
|
18
|
+
say "coming soon...", :yellow
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module Commercelayer
|
2
|
+
module CLI
|
3
|
+
module Exporters
|
4
|
+
class Contentful
|
5
|
+
|
6
|
+
include Helpers
|
7
|
+
|
8
|
+
def export!
|
9
|
+
last_product_reference = nil
|
10
|
+
last_product_id = nil
|
11
|
+
last_product_variants = []
|
12
|
+
Commercelayer::Sku.order(:reference).all.each_total do |sku|
|
13
|
+
puts "> #{sku.code}"
|
14
|
+
if sku.reference != last_product_reference
|
15
|
+
if last_product_id
|
16
|
+
product = master.entries.find(last_product_id)
|
17
|
+
product.update({
|
18
|
+
reference: last_product_reference,
|
19
|
+
variants: last_product_variants
|
20
|
+
})
|
21
|
+
product.publish
|
22
|
+
last_product_variants = []
|
23
|
+
end
|
24
|
+
|
25
|
+
begin
|
26
|
+
product = product_model.entries.create({
|
27
|
+
reference: sku.reference,
|
28
|
+
variants: []
|
29
|
+
})
|
30
|
+
last_product_reference = sku.reference
|
31
|
+
last_product_id = product.id
|
32
|
+
rescue => e
|
33
|
+
puts e.inspect
|
34
|
+
break
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
begin
|
39
|
+
variant = variant_model.entries.create({
|
40
|
+
code: sku.code,
|
41
|
+
name: sku.name,
|
42
|
+
description: sku.description,
|
43
|
+
image: image(sku)
|
44
|
+
})
|
45
|
+
variant.publish
|
46
|
+
last_product_variants << variant
|
47
|
+
rescue => e
|
48
|
+
puts e.inspect
|
49
|
+
break
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def client
|
57
|
+
::Contentful::Management::Client.new(config_data[:contentful][:access_token])
|
58
|
+
end
|
59
|
+
|
60
|
+
def environments
|
61
|
+
@environments ||= client.environments(config_data[:contentful][:space]).all
|
62
|
+
end
|
63
|
+
|
64
|
+
def master
|
65
|
+
@master ||= environments.find('master').first
|
66
|
+
end
|
67
|
+
|
68
|
+
def product_model
|
69
|
+
@product_model ||= master.content_types.find('product')
|
70
|
+
end
|
71
|
+
|
72
|
+
def variant_model
|
73
|
+
@variant_model ||= master.content_types.find('variant')
|
74
|
+
end
|
75
|
+
|
76
|
+
def image(sku, options={})
|
77
|
+
unless sku.image_url.blank?
|
78
|
+
image_file = ::Contentful::Management::File.new
|
79
|
+
image_file.properties[:contentType] = "image/jpeg"
|
80
|
+
image_file.properties[:fileName] = "#{sku.code}.jpg"
|
81
|
+
image_file.properties[:upload] = sku.image_url
|
82
|
+
image_file
|
83
|
+
image_asset = master.assets.create(title: sku.name, file: image_file)
|
84
|
+
image_asset.process_file
|
85
|
+
image_asset.publish
|
86
|
+
image_asset
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -11,15 +11,14 @@ module Commercelayer
|
|
11
11
|
"commercelayer" => {
|
12
12
|
"site" => "https://<subdomain>.commercelayer.io",
|
13
13
|
"client_id" => "YOUR-COMMERCELAYER-CLIENT-ID",
|
14
|
-
"client_secret" => "YOUR-COMMERCELAYER-CLIENT-SECRET"
|
15
|
-
"scope" => "market:<market_id>",
|
16
|
-
},
|
17
|
-
"dato" => {
|
18
|
-
"api_key" => "YOUR-DATOCMS-APIKEY"
|
14
|
+
"client_secret" => "YOUR-COMMERCELAYER-CLIENT-SECRET"
|
19
15
|
},
|
20
16
|
"contentful" => {
|
21
17
|
"space" => "YOUR-CONTENTFUL-SPACE-ID",
|
22
18
|
"access_token" => "YOUR-CONTENTFUL-ACCESS-TOKEN"
|
19
|
+
},
|
20
|
+
"dato" => {
|
21
|
+
"api_key" => "YOUR-DATOCMS-APIKEY"
|
23
22
|
}
|
24
23
|
}.to_yaml
|
25
24
|
end
|
@@ -32,7 +31,7 @@ module Commercelayer
|
|
32
31
|
Commercelayer::Client.new(
|
33
32
|
client_id: config_data[:commercelayer][:client_id],
|
34
33
|
client_secret: config_data[:commercelayer][:client_secret],
|
35
|
-
scope: config_data[:commercelayer][:scope],
|
34
|
+
# scope: config_data[:commercelayer][:scope],
|
36
35
|
site: config_data[:commercelayer][:site]
|
37
36
|
)
|
38
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: commercelayer-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Filippo Conforti
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -133,6 +133,8 @@ files:
|
|
133
133
|
- lib/commercelayer/cli/bootstrappers.rb
|
134
134
|
- lib/commercelayer/cli/bootstrappers/contentful.rb
|
135
135
|
- lib/commercelayer/cli/bootstrappers/datocms.rb
|
136
|
+
- lib/commercelayer/cli/exporters.rb
|
137
|
+
- lib/commercelayer/cli/exporters/contentful.rb
|
136
138
|
- lib/commercelayer/cli/helpers.rb
|
137
139
|
- lib/commercelayer/cli/version.rb
|
138
140
|
homepage: https://github.com/commercelayer/commercelayer-cli
|